Skip to content

Multipath: dial fallback, fixed-rate paths, in-order delivery - #8

Merged
losfair merged 2 commits into
mainfrom
claude/wizardly-galileo-wtuew9
Oct 15, 2026
Merged

losfair merged 2 commits into
mainfrom
claude/wizardly-galileo-wtuew9

Conversation

@losfair

@losfair losfair commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

This fixes the three gaps in the "dedicated link A, overflow link B" setup:

  • A: a dedicated 50 Mbit/s link, the primary path.
  • B: a lower-quality frp (UDP-over-TCP) link at /priority=1.
  • Traffic: TCP inside WireGuard.

1. Dial fallback (A down at connect time)

  • Fallback: if the primary path doesn't answer the handshake within 3 s, the client tries the extra paths' proxy addresses in priority order, /backup last.
  • Which paths qualify: only paths without @LOCAL_IP and with a remote other than the primary's. A handshake can't pick its source address, and the path it creates mustn't be confused with another configured path.
  • Afterwards: path 0 is then that extra path, and the primary is opened like any other path once it works.
  • Before, the tunnel couldn't come up at all while A was down.

2. Fixed-rate paths (BBRv3 probing on a dedicated link)

  • Usage: --path .../rate=RATE and --primary-rate RATE (e.g. 48M) send on a path at a fixed rate with cc::FixedRate instead of BBRv3. This uses noq's new per-path controller (feat: per-path congestion controller, kept with the priority across migrations noq#5).
  • Why: BBRv3's probing and its periodic ProbeRTT window cuts each pushed traffic onto B. A known-capacity link doesn't need either.
  • Failover is unchanged:
    • The fixed-rate window is about two round trips at the rate, so when A dies it fills within a round trip and traffic moves to B.
    • Persistent congestion shrinks the window to a minimum until something is acknowledged again.
    • Ordinary loss is ignored.
  • The server applies it too:
    • The rate applies in both directions: the client announces it with a new control-stream frame, FRAME_PATH_RATE ("rmpf").
    • The proxy applies it up to --max-path-rate, capping larger requests.
    • Without that flag (the default) the proxy ignores the request, because a fixed-rate path has no congestion control.
  • Stats: /stats shows fixed_rate_bps per path.

3. In-order delivery (reordering when traffic spills from A to B)

  • Why: WireGuard hides the inner TCP flows from rapidmasque, so flows can't be pinned to a path. Instead, the receiver puts datagrams back in order.
  • Negotiation:
    • The client sends a rapidmasque-sequence: ?1 request header, and a rapidmasque proxy echoes it.
    • Both ends then send sequenced datagrams: HTTP datagram context 2, with a 4-byte sequence number per flow and direction.
    • Other MASQUE peers never echo it, and the flow keeps plain RFC 9298 datagrams.
  • Receiver (src/reorder.rs):
    • It holds a datagram that arrives ahead of a gap until the gap fills, or until the hold time passes, when it releases what it has, in order.
    • The hold time starts at 10 ms. It follows how late gap-filling (or skipped, then late) datagrams actually arrive, plus a quarter, up to 250 ms, and it decays while nothing is reordered.
    • Datagrams that arrive in order are never held.
  • Default on: --in-order-delivery false turns it off on the client.
  • MTU: the 4 bytes are included in WIREGUARD_1280_DATAGRAM, so the default minimum MTU grows to 1356.

Depends on

losfair/noq#5 (merged). noq is pinned to 38d92aa on dev.

Testing

cargo fmt --check, cargo clippy --all-targets -- -D warnings and cargo test (71 tests) pass. Full runs were repeated, because the in-order test was timing-sensitive under load; see below.

New tests:

  • handshake_falls_back_to_an_extra_path: the primary proxy address is a black hole, and the tunnel comes up over the extra path. Without the fallback it fails.
  • fixed_rate_path_applies_on_both_ends_up_to_the_proxy_cap:
    • The client's --primary-rate 8M gives its path the fixed-rate window.
    • The proxy, with --max-path-rate 4M, caps its side to 4M.
    • Both are checked through /stats (fixed_rate_bps and cwnd).
  • in_order_delivery_undoes_reordering:
    • A relay swaps every pair of packets from the proxy, and the test sends 200 numbered echoes after a warm-up.
    • With in-order delivery there were no inversions in repeated runs. The test allows up to 2, for a swap delayed past the learned hold time on a busy machine.
    • Without it the relay produced well over 20.
  • Unit tests: for the resequencer (in order, swaps, loss, hold learning, cap and decay, wraparound, duplicates, far jumps), sequenced framing, the fixed-rate controller, and rate parsing.

🤖 Generated with Claude Code

https://claude.ai/code/session_012baC35vUbLPPhuK4pz4uRz

For a dedicated link A with a lower-quality overflow link B:

- Dial fallback: if the primary path does not answer the handshake
  within 3 s, try the extra paths' proxy addresses (priority order,
  paths without @LOCAL_IP to another remote), so the tunnel comes up
  while A is down; A then joins as an ordinary path.
- Fixed-rate paths: --path .../rate=RATE and --primary-rate send on a
  path at a fixed rate (cc::FixedRate via noq's new per-path controller)
  instead of under BBRv3, whose probing and ProbeRTT dips moved traffic
  onto B. Its window (2 RTTs at the rate) still fills within a round
  trip when the link dies, so failover is unchanged. The client
  announces the rate (FRAME_PATH_RATE) and the proxy applies it up to
  --max-path-rate (off by default: such paths have no congestion
  control).
- In-order delivery (--in-order-delivery, default on): flows that
  negotiate the rapidmasque-sequence header carry 4-byte sequence
  numbers (HTTP datagram context 2) and the receiver resequences them
  with a self-tuning hold time (reorder.rs), so TCP inside WireGuard
  does not see the reordering of spilled traffic as loss. Other MASQUE
  peers keep plain RFC 9298 datagrams. The default minimum MTU grows by
  the 4 bytes to 1356.

noq is pinned to the per-path congestion controller branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012baC35vUbLPPhuK4pz4uRz
losfair/noq#5 merged as 38d92aa on dev (same tree as the pinned PR head
21d76fb).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012baC35vUbLPPhuK4pz4uRz
@losfair
losfair merged commit 4b0e546 into main Oct 15, 2026
11 checks passed
@losfair
losfair deleted the claude/wizardly-galileo-wtuew9 branch October 15, 2026 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants