mirror of
https://github.com/soypat/lneto.git
synced 2026-08-21 06:59:04 +00:00
fix: clean up misc TODO comments and improve UDP source filtering (#89)
- http/httpraw: cap header slice growth to pre-allocated capacity, fix benchmark to reuse Header across iterations (0 allocs/op) - internal/ring: replace TODO panic comments with invariant explanations - tcp/conn: document truncated-frame offset check - tcp/handler: replace TODO with net.ErrClosed on RST-closed connection - internet/stack-udpport: filter incoming packets by remote IP address when configured via SetStackNode; skip filter for IPv4 multicast destinations (class D) so mDNS and similar protocols work correctly Generated with LLM assistance. Signed-off-by: Marvin Drees <marvin.drees@9elements.com>
This commit is contained in:
@@ -112,13 +112,19 @@ func BenchmarkParseBytes(b *testing.B) {
|
||||
asRequest = false
|
||||
)
|
||||
req, _ := http.NewRequest(wantMethod, wantURI, strings.NewReader(wantMessage))
|
||||
var buf bytes.Buffer
|
||||
req.Write(&buf)
|
||||
data := buf.Bytes()
|
||||
var rawBuf bytes.Buffer
|
||||
req.Write(&rawBuf)
|
||||
data := rawBuf.Bytes()
|
||||
|
||||
// hdr is declared outside the loop so that ParseBytes can reuse the
|
||||
// backing arrays on Reset (headers slice and data buffer) without
|
||||
// allocating on every iteration. Declaring it inside the loop causes
|
||||
// two allocs per iteration: one for the headers slice (make in reset)
|
||||
// and one for the data buffer (append in readFromBytes).
|
||||
var hdr Header
|
||||
b.StartTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
var hdr Header
|
||||
err := hdr.ParseBytes(asRequest, data)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
|
||||
@@ -120,7 +120,13 @@ func (hb *headerBuf) free() int { return cap(hb.buf) - len(hb.buf) }
|
||||
func (hb *headerBuf) parseNextHeaders(ss *scannerState) {
|
||||
debuglog("http:nexthdr:loop")
|
||||
for kv := hb.next(ss); kv.isValid(); kv = hb.next(ss) {
|
||||
hb.headers = append(hb.headers, kv) // TODO(HEAP): inc=16B slice growth when capacity exceeded
|
||||
if len(hb.headers) == cap(hb.headers) {
|
||||
// Refuse to grow the headers slice: caller must pre-allocate
|
||||
// sufficient capacity via reset or use a larger initial size.
|
||||
ss.err = errOOM
|
||||
return
|
||||
}
|
||||
hb.headers = append(hb.headers, kv)
|
||||
}
|
||||
debuglog("http:nexthdr:done")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user