Skip to content

Commit

Permalink
Use a noopLogger if SetLogger() is called with nil.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbruens committed Sep 20, 2024
1 parent 44563eb commit 2f3393e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion service/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,16 @@ func makeValidatingTCPStreamDialer(targetIPValidator onet.TargetIPValidator) tra
// StreamHandler is a handler that handles stream connections.
type StreamHandler interface {
Handle(ctx context.Context, conn transport.StreamConn, connMetrics TCPConnMetrics)
// SetLogger sets the logger used to log messages.
// SetLogger sets the logger used to log messages. Uses a no-op logger if nil.
SetLogger(l Logger)
// SetTargetDialer sets the [transport.StreamDialer] to be used to connect to target addresses.
SetTargetDialer(dialer transport.StreamDialer)
}

func (s *streamHandler) SetLogger(l Logger) {
if l == nil {
l = &noopLogger{}
}
s.l = l
}

Expand Down
5 changes: 4 additions & 1 deletion service/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func NewPacketHandler(natTimeout time.Duration, cipherList CipherList, m UDPMetr

// PacketHandler is a running UDP shadowsocks proxy that can be stopped.
type PacketHandler interface {
// SetLogger sets the logger used to log messages.
// SetLogger sets the logger used to log messages. Uses a no-op logger if nil.
SetLogger(l Logger)
// SetTargetIPValidator sets the function to be used to validate the target IP addresses.
SetTargetIPValidator(targetIPValidator onet.TargetIPValidator)
Expand All @@ -117,6 +117,9 @@ type PacketHandler interface {
}

func (h *packetHandler) SetLogger(l Logger) {
if l == nil {
l = &noopLogger{}
}
h.l = l
}

Expand Down

0 comments on commit 2f3393e

Please sign in to comment.