The quinn patches
Source files: 6 · checked against shinku-quic v0.1.0
shinku-quic/patches/quinn-proto.patchshinku-quic/scripts/check-vendor.shshinku-quic/vendor/quinn-proto/src/connection/pacing.rsshinku-quic/vendor/quinn-proto/src/connection/assembler.rsshinku-quic/vendor/quinn-proto/src/connection/paths.rsshinku-quic/vendor/quinn-proto/src/connection/streams/recv.rs
vendor/quinn and vendor/h3-quinn are upstream releases with no source changes; vendor/quinn-proto is quinn-proto 0.11.19 plus one file, patches/quinn-proto.patch. The patch holds two changes, both for one sender: Brutal, which sends at a fixed rate instead of probing for bandwidth. It touches src/connection/assembler.rs, mod.rs, pacing.rs, paths.rs and streams/recv.rs.
The pacer follows the controller’s rate
Section titled “The pacer follows the controller’s rate”quinn’s pacer refills its token bucket at 1.25 × cwnd / RTT, and a congestion::Controller can influence it only through window(). Brutal needs a window of twice the bandwidth-delay product, so that dropped packets, which count as in flight until quinn declares them lost, never stall it, and a pace of exactly its rate. With the stock pacer that window is paced at 2.5 times the rate: without the patch, a 20 Mbit/s Brutal over a 40 ms path sends at about 38 Mbit/s.
With the patch, Pacer::new and Pacer::delay take pacing_rate: Option<u64>, which the connection reads from Controller::metrics().pacing_rate on every decision (bits per second, a field the trait already has for qlog; paths::pacing_rate_bytes converts it, at least one byte per second). When it is Some:
- the burst is sized from the rate, with
rate × RTT / 1.25standing in for the window; - the bucket refills at the rate itself;
- a send that does not fit waits only for its own bytes, not for a full burst. Upstream waits for a full bucket and loses whatever the timer overshoots to the bucket’s cap; tokio rounds timers up to the millisecond, and at a fixed rate that loss would come straight off the rate, about 15% at 20 Mbit/s.
Controllers that leave pacing_rate at None, which are Cubic, NewReno and BBR, behave exactly as upstream.
The patch also carries upstream’s fix for the refill clock: when the bucket is polled faster than a whole byte accrues, the truncation to an integer yields nothing, and the previous refill time now advances only when tokens were added, so that time is not discarded.
The reassembly cap follows the receive window
Section titled “The reassembly cap follows the receive window”Upstream caps every receive stream at 1024 distinct spans and closes the connection with INTERNAL_ERROR("too many gaps in stream buffer") past that. That suits a sender that slows down when it loses packets. Brutal does not: at 1000 Mbit/s over a 150 ms path it keeps about 31 000 packets in flight and answers loss by sending more, so at 1% loss the receiver holds several hundred holes at once and reaches 1024 within seconds. Over a netem link with 150 ms of RTT and 1% loss, the stock cap closed the connection after 700 KB, which on the wire looks exactly like the path failing.
A hole costs one span, and a peer cannot leave more holes than its receive window has room for packets, so the cap now comes from that window: Assembler::set_window sets it to window / 1200, clamped between 1024 and 2^20, and Recv::new and Recv::reinit call it with the stream’s initial receive window. A peer flooding tiny gapped frames is still bounded, and its bookkeeping stays a few percent of the window. quinn’s default window gives 1041, so an untuned connection behaves as before.
This is the receiving side’s half: it matters on every endpoint a Brutal sender talks to, including a server receiving a Hysteria client’s uploads.
Vendoring rules
Section titled “Vendoring rules”- quinn and h3-quinn carry no source change; quinn-proto carries exactly
patches/quinn-proto.patch. Anything else that needs changing in quinn is a new, documented patch, never an edit in place. - Each vendored manifest names its upstream release in
[package.metadata.shinku] upstream, for examplequinn-proto 0.11.19. The other manifest changes are the package name, the version, the repository and publish settings, the dependency on the vendored sibling, and[lints.clippy]. scripts/check-vendor.shproves both claims: it downloads each named release from crates.io, applies the patch file where there is one, and comparessrc,tests,benches,examplesandbuild.rswithvendor/. It is the first of the repository’s gates.
Re-applying on a new release
Section titled “Re-applying on a new release”- Replace
vendor/<crate>/{src,tests,benches,examples,build.rs}and the licence files with the new release’s, keeping the manifest edits above, and bring over new upstream dependencies or features by hand. - For quinn-proto, apply
patches/quinn-proto.patchinsidevendor/quinn-protowithpatch -p1, resolve what does not apply, and regenerate the patch from the result against the pristine release. - Update
upstreamin each manifest, runscripts/check-vendor.sh, then the gates. The pacer and assembler unit tests in quinn-proto and the loopback tests inshinku-quic/tests/prove the patches still work.
Upstream’s unreleased 0.12 line has an equivalent rate limit, driven by a static transport setting rather than by the controller; when a release carries a controller-driven rate, the first patch can go.
The patch adds unit tests to quinn-proto: pacer tests for a rate-driven burst, refill and delay, and assembler tests for the window-derived span limit. The end-to-end proof is in shinku-quic/tests/brutal.rs: Brutal holding its rate over a delayed path, which needs the pacer patch, and through 3% loss, which needs the reassembly patch at the receiver. See Congestion control.