Files
KKRainbow d6b98c1b80 fix(peers): bound connection backpressure and batch local RPCs (#2831)
Large RPCs previously used one connection-queue slot per fragment.
Waiting for a slow destination could stall the shared dispatcher, while
queuing Pong behind ordinary traffic could also stall connection reads.

Keep each locally generated RPC's fragments in one ZCPacket batch until
the actual connection writer expands it. Preserve the existing packet
headers, individual wire frames, and per-fragment filters. Secure relay
still establishes and selects the final peer session in RelayPeerMap;
allocate encryption sequence numbers and encrypt each fragment in the
writer's PeerSessionTunnelFilter. Do not re-encrypt forwarded
ciphertext. Keep the existing 32-fragment pending-handshake limit.

Use a separate bounded Ping/Pong queue and check it between fragments.
Flush at most eight frames per round on the non-FEC path under the
existing seven-second timeout. Preserve FEC filter order and its per-
frame timeout.

Use try_send at ordinary PeerConn egress for every transport. A full
queue drops the current item, potentially an entire RPC batch, and
returns BufferFull without closing a healthy connection. Preserve typed
congestion errors through IP sending so the VPN Portal drops only the
rejected packet and keeps its client session alive. Fatal send errors
retain connection and Portal teardown. Leave generic MPSC senders and
internal RPC channels unchanged.

After a successful enqueue fills the ordinary queue, yield once to give
the writer a scheduling opportunity. This is a scheduling hint: Tokio
does not guarantee that the writer runs or drains before the producer
resumes. An already-full queue is still rejected immediately. There is
no capacity wait, retry, alternate-route selection, or queue
enlargement.

Queue limits count entries rather than bytes. Downstream drops may cause
RPC timeouts or incomplete forwarded RPCs, and IP traffic may be lost.
This does not provide complete isolation across shared paths, preempt
bytes already handed to TCP, or guarantee delivery on a slow link.
Multi-hop reassembly and application-level OSPF batching remain out of
scope. The individual wire encoding is unchanged; old-release binary
interoperability and an actual QUIC socket test were not run.

Validation:

- All six head CI workflows passed: 20 successful checks, four
  conditional skips, and 2060 tests passed with five skipped.
- Both original gateway failures passed 30 serial repetitions each at
  26c2e45f, with unchanged inputs, assertions, and timeouts: 60/60
  total. These observations do not establish a scheduling or no-loss
  guarantee.
- Reused targeted and regression results for 207-fragment delivery,
  direct and secure relay encryption, foreign forwarding, FEC, heartbeat
  scheduling, writer/session cleanup, queue admission, and Portal
  congestion and fatal-error lifecycles.
- Workspace fmt and strict all-target Clippy with full features passed.
  Final independent reviews found no remaining high-confidence defects.
- An earlier bounded 50 Mbit/s comparison showed similar throughput but
  more TCP retransmissions after try_send. The later yield change was
  not benchmarked; no saturation or throughput guarantee is claimed.
2026-11-15 01:30:49 +08:00
..