Skip to content

Commit

Permalink
Merge branch 'sbruens/logger' into sbruens/caddy
Browse files Browse the repository at this point in the history
  • Loading branch information
sbruens committed Sep 20, 2024
2 parents 88bf8cb + 9b1b801 commit 5e2c496
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 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
4 changes: 2 additions & 2 deletions service/tcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func BenchmarkTCPFindCipherFail(b *testing.B) {
}
clientIP := clientConn.RemoteAddr().(*net.TCPAddr).AddrPort().Addr()
b.StartTimer()
findAccessKey(clientConn, clientIP, cipherList, nil)
findAccessKey(clientConn, clientIP, cipherList, &noopLogger{})
b.StopTimer()
}
}
Expand Down Expand Up @@ -205,7 +205,7 @@ func BenchmarkTCPFindCipherRepeat(b *testing.B) {
cipher := cipherEntries[cipherNumber].CryptoKey
go shadowsocks.NewWriter(writer, cipher).Write(makeTestPayload(50))
b.StartTimer()
_, _, _, _, err := findAccessKey(&c, clientIP, cipherList, nil)
_, _, _, _, err := findAccessKey(&c, clientIP, cipherList, &noopLogger{})
b.StopTimer()
if err != nil {
b.Error(err)
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
6 changes: 3 additions & 3 deletions service/udp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func BenchmarkUDPUnpackFail(b *testing.B) {
testIP := netip.MustParseAddr("192.0.2.1")
b.ResetTimer()
for n := 0; n < b.N; n++ {
findAccessKeyUDP(testIP, textBuf, testPayload, cipherList, nil)
findAccessKeyUDP(testIP, textBuf, testPayload, cipherList, &noopLogger{})
}
}

Expand Down Expand Up @@ -439,7 +439,7 @@ func BenchmarkUDPUnpackRepeat(b *testing.B) {
cipherNumber := n % numCiphers
ip := ips[cipherNumber]
packet := packets[cipherNumber]
_, _, _, err := findAccessKeyUDP(ip, testBuf, packet, cipherList, nil)
_, _, _, err := findAccessKeyUDP(ip, testBuf, packet, cipherList, &noopLogger{})
if err != nil {
b.Error(err)
}
Expand Down Expand Up @@ -468,7 +468,7 @@ func BenchmarkUDPUnpackSharedKey(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
ip := ips[n%numIPs]
_, _, _, err := findAccessKeyUDP(ip, testBuf, packet, cipherList, nil)
_, _, _, err := findAccessKeyUDP(ip, testBuf, packet, cipherList, &noopLogger{})
if err != nil {
b.Error(err)
}
Expand Down

0 comments on commit 5e2c496

Please sign in to comment.