internet: further use handlers data structure

This commit is contained in:
Patricio Whittingslow
2025-12-18 19:16:35 -03:00
parent ac7f752447
commit eaa36a589a
4 changed files with 89 additions and 145 deletions
+3 -10
View File
@@ -4,6 +4,7 @@ import (
"encoding/binary"
"io"
"math"
"strconv"
"github.com/soypat/lneto"
)
@@ -29,7 +30,7 @@ func (ps *StackPorts) Reset(protocol uint64, dstPortOffset uint16, maxNodes int)
} else if maxNodes <= 0 {
return errZeroMaxNodesArg
}
ps.handlers.reset(maxNodes)
ps.handlers.reset("StackPorts(proto="+strconv.Itoa(int(protocol))+")", maxNodes)
*ps = StackPorts{
connID: ps.connID + 1,
handlers: ps.handlers,
@@ -58,15 +59,7 @@ func (ps *StackPorts) Demux(b []byte, offset int) (err error) {
return io.ErrShortBuffer
}
port := binary.BigEndian.Uint16(b[int(ps.dstPortOff)+offset:])
node := ps.handlers.nodeByPort(port)
if node == nil {
return nil
}
err = node.demux(b, offset)
if ps.handlers.tryHandleError(node, err) {
// discarded handler gracefully.
err = nil
}
_, err = ps.handlers.demuxByPort(b, offset, port)
return err
}