Skip to content

Commit

Permalink
Consolidate debug logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbruens committed Dec 18, 2024
1 parent 2f2268b commit bfe4b35
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions service/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ type association struct {

var _ Association = (*association)(nil)

func (a *association) debugLog(template string, attrs ...slog.Attr) {
debugUDP(a.logger, template, attrs...)
}

// Given the decrypted contents of a UDP packet, return
// the payload and the destination address, or an error if
// this packet cannot or should not be forwarded.
Expand All @@ -414,9 +418,9 @@ func (a *association) validatePacket(textData []byte) ([]byte, *net.UDPAddr, *on

func (a *association) HandlePacket(pkt []byte, lazySlice slicepool.LazySlice) {
defer lazySlice.Release()
defer debugUDP(a.logger, "Done")
defer a.debugLog("Done")

debugUDP(a.logger, "Outbound packet.", slog.Int("bytes", len(pkt)))
a.debugLog("Outbound packet.", slog.Int("bytes", len(pkt)))

var proxyTargetBytes int
connError := func() *onet.ConnectionError {
Expand Down Expand Up @@ -464,7 +468,7 @@ func (a *association) HandlePacket(pkt []byte, lazySlice slicepool.LazySlice) {
return onetErr
}

debugUDP(a.logger, "Proxy exit.")
a.debugLog("Proxy exit.")
proxyTargetBytes, err = a.targetConn.WriteTo(payload, tgtUDPAddr) // accept only UDPAddr despite the signature
if err != nil {
return onet.NewConnectionError("ERR_WRITE", "Failed to write to target", err)
Expand Down Expand Up @@ -533,7 +537,7 @@ func (a *association) timedCopy() {
return onet.NewConnectionError("ERR_READ", "Failed to read from target", err)
}

debugUDP(a.logger, "Got response.", slog.Any("rtarget", raddr))
a.debugLog("Got response.", slog.Any("rtarget", raddr))
srcAddr := socks.ParseAddr(raddr.String())
addrStart := bodyStart - len(srcAddr)
// `plainTextBuf` concatenates the SOCKS address and body:
Expand Down Expand Up @@ -562,7 +566,7 @@ func (a *association) timedCopy() {
}()
status := "OK"
if connError != nil {
a.logger.LogAttrs(nil, slog.LevelDebug, "UDP: Error", slog.String("msg", connError.Message), slog.Any("cause", connError.Cause))
a.debugLog("Error", slog.String("msg", connError.Message), slog.Any("cause", connError.Cause))
status = connError.Status
}
if expired {
Expand Down

0 comments on commit bfe4b35

Please sign in to comment.