Rework outbound buffer management

Outbound element buffers now come from the sing allocator sized to the
actual packet instead of the bounded MaxMessageSize pool, element and
container pools become plain sync.Pools, and the bounded message buffer
pool serves only the receive path. Packets injected via
InputPacket/InputPackets are dropped before they are copied once a peer
has 2048 packets queued: injection runs on the caller's read loop, which
must never block on pool exhaustion, and the queues are bounded in
containers, so a flood was buffered instead of dropped.
This commit is contained in:
世界 2026-07-06 21:05:53 +08:00
parent 9de6dc32df
commit 8403cdb937
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
5 changed files with 78 additions and 35 deletions

View file

@ -25,6 +25,8 @@ type Peer struct {
rxBytes atomic.Uint64 // bytes received from peer
lastHandshakeNano atomic.Int64 // nano seconds since epoch
queuedOutboundPackets atomic.Int32 // packets in staged+outbound queues, for input backpressure
endpoint struct {
sync.Mutex
val conn.Endpoint
@ -193,6 +195,7 @@ func (peer *Peer) Start() {
// reset routine state
peer.stopping.Wait()
peer.stopping.Add(2)
peer.queuedOutboundPackets.Store(0)
peer.handshake.mutex.Lock()
peer.handshake.lastSentHandshake = time.Now().Add(-(RekeyTimeout + time.Second))