Make RTP obfuscation hot path allocation-free
The per-packet wrap/unwrap path allocated a fresh output buffer, a key string for the AEAD cache lookup, and a nonce slice on every datagram (~1.3 KB / 3 allocs per packet). Under load this produced steady GC pressure on the server. Cache the cipher.AEAD on the wrapPacketConn at key-selection time and reuse per-conn rx/tx buffers, with the nonce built on the stack. The wire format is unchanged (verified by round-trip and old<->new cross-compat tests), so existing clients keep working without updates. Result: 1328 B/3 allocs -> 16 B/1 alloc per packet (the residual 16 B is the nonce escaping through the cipher.AEAD interface, payload-independent). Adds obfs_test.go covering nonce equivalence, round-trip across sizes, old/new wire compatibility, wrong-key rejection, key-store selection, an end-to-end wrapPacketConn exchange, and an allocation-bound regression guard (skipped under -race, which distorts alloc counts).
This commit is contained in:
1 parent
fe9f9d3d47
commit
72e9cda9d5
4 files changed
+563
-47
No files matched your search
@@ -0,0 +1,5 @@
|
||||
//go:build !race
|
||||
|
||||
package main
|
||||
|
||||
const raceEnabled = false
|
||||
Reference in new issue
Block a user