add stringer methods

This commit is contained in:
soypat
2025-02-20 23:41:27 -03:00
parent c9d1c4f239
commit d996040d92
6 changed files with 43 additions and 4 deletions
+8 -3
View File
@@ -11,7 +11,8 @@ import (
)
var (
errMismatchedPort = errors.New("mismatched port")
errMismatchedSrcPort = errors.New("source port mismatch")
errMismatchedDstPort = errors.New("destination port mismatch")
)
// Handler is a low level TCP handling data structure. It implements logic
@@ -120,13 +121,14 @@ func (h *Handler) Recv(b []byte) error {
if err != nil {
return err
}
remotePort := tfrm.SourcePort()
if h.remotePort != 0 && remotePort != h.remotePort {
return errMismatchedPort
return errMismatchedSrcPort
}
dstPort := tfrm.DestinationPort()
if h.localPort != dstPort {
return errMismatchedPort
return errMismatchedDstPort
}
payload := tfrm.Payload()
if len(payload) > h.bufRx.Free() {
@@ -160,6 +162,9 @@ func (h *Handler) Recv(b []byte) error {
h.debug("tcp.Handler:rx-remoteport-set", slog.Uint64("port", uint64(h.localPort)), slog.Uint64("remoteport", uint64(remotePort)))
h.remotePort = remotePort
}
if h.logenabled(internal.LevelTrace) {
h.trace("tcp.Handler:rx-done", slog.Uint64("port", uint64(h.localPort)), slog.Uint64("remoteport", uint64(remotePort)), slog.String("seg", segIncoming.String()))
}
return nil
}