Skip to content

shinku-quic overview

Source files: 10 · checked against shinku-quic v0.1.0 · Etemenanki 46c12e4
  • shinku-quic/Cargo.toml
  • shinku-quic/shinku-quic/Cargo.toml
  • shinku-quic/shinku-quic/src/lib.rs
  • shinku-quic/shinku-quic/src/bandwidth.rs
  • shinku-quic/vendor/quinn-proto/Cargo.toml
  • shinku-quic/vendor/quinn/Cargo.toml
  • shinku-quic/vendor/h3-quinn/Cargo.toml
  • Etemenanki/Cargo.toml
  • Etemenanki/protocols/Cargo.toml
  • Etemenanki/protocols/src/hysteria/config.rs

shinku-quic is the QUIC stack under Etemenanki’s Hysteria 2: a vendored quinn with two patches to quinn-proto, and a small crate, also called shinku-quic, holding the sending policy Hysteria needs on top of it: Hysteria’s fixed-rate Brutal sender, a controller that is switched to Brutal after the handshake, and client-side port hopping. It is a separate repository, released to the same private Cargo registry as the kernel crates.

This page covers the packages, the boundaries between them and the protocol code, how a downstream depends on them, and the Bandwidth type. Congestion control, Port hopping and The quinn patches cover the rest.

Package Directory Library name What it is
shinku-quinn-proto vendor/quinn-proto quinn_proto quinn-proto 0.11.19 plus patches/quinn-proto.patch
shinku-quinn vendor/quinn quinn quinn 0.11.12, unmodified, built on shinku-quinn-proto
shinku-h3-quinn vendor/h3-quinn h3_quinn h3-quinn 0.0.10, unmodified, built on shinku-quinn
shinku-quic shinku-quic shinku_quic Bandwidth, congestion::{Brutal, BrutalConfig, Negotiated, CongestionSwitch, Fallback}, hop::{HoppingSocket, HopInterval, BindSocket}

All four are version 0.1.0 and pin each other with =, so they move as one unit. They are published in dependency order: shinku-quinn-proto, shinku-quinn, shinku-h3-quinn, shinku-quic.

The vendored crates keep their upstream library names, so code written against quinn compiles unchanged. The vendored manifests differ from upstream only in the package names, versions, the dependency on the vendored sibling and [package.metadata.shinku] upstream, which names the release each one is; see The quinn patches.

  • vendor/ is upstream. quinn and h3-quinn carry no source change, and quinn-proto carries exactly one patch file. Any further change to quinn is a new, documented patch, never an edit in place.
  • shinku-quic knows QUIC, not Hysteria. It has no authentication, no obfuscation and no rule for whose rate wins. It sends at a rate it is given, switches a connection to that rate when told, and hops ports when asked; the protocol decides when. Those rules live in etemenanki-protocols, in protocols/src/hysteria/negotiate.rs (see Hysteria 2 server).
  • The stack is one unit. Brutal is correct only on the patched quinn-proto: the pacer must release at the controller’s rate, and a receiver must tolerate the holes a sender that does not back off leaves. A build must therefore never mix the vendored quinn with crates.io’s.
  • Hopping is client-only. On a server, a port range is a firewall rule forwarding to one listening port; nothing in the crate runs there.

shinku_quic re-exports the patched quinn as shinku_quic::quinn, so code using the types here is on the vendored stack by construction. A downstream that also names quinn directly takes it under a package alias, not a [patch] section, which would be easy to forget in one consumer:

Etemenanki Cargo.toml (workspace dependencies)
quinn = { package = "shinku-quinn", version = "0.1", default-features = false, features = ["runtime-tokio", "rustls-ring", "log"] }
h3-quinn = { package = "shinku-h3-quinn", version = "0.1" }
shinku-quic = { version = "0.1" }

In Etemenanki, etemenanki-protocols takes shinku-quic as an optional dependency of its hysteria feature, beside dep:quinn and dep:h3-quinn. The supervisor and the environment crate’s quic feature use the same aliased quinn. The manifests also name the private registry for each of these, which is why building etemenanki-app or katana needs read access to it.

What Etemenanki uses:

Item Where
Bandwidth Re-exported from protocols/src/hysteria/config.rs as the type of BandwidthConfig::{up, down}, parsed from the app’s bandwidth strings
congestion::Fallback The congestion setting of both sides
congestion::BrutalConfig Built by negotiate::brutal once a rate is agreed
congestion::Negotiated, CongestionSwitch One factory per client connection and per accepted server connection; the switch moves the connection to Brutal after /auth
hop::{HoppingSocket, BindSocket, HopInterval} The client’s bind_socket in protocols/src/hysteria/connection.rs, under Salamander

Bandwidth is a rate in bytes per second that is never zero; “no rate” is Option<Bandwidth>.

shinku-quic/src/bandwidth.rs
pub struct Bandwidth(NonZeroU64);
impl Bandwidth {
pub const fn from_bytes_per_second(bytes_per_second: u64) -> Option<Self>;
pub const fn from_mbps(mbps: u64) -> Option<Self>; // 10^6 bits; None on overflow
pub const fn bytes_per_second(self) -> u64;
pub const fn bits_per_second(self) -> u64; // saturating
pub fn min(self, other: Self) -> Self;
}
impl FromStr for Bandwidth { type Err = ParseBandwidthError; }
impl fmt::Display for Bandwidth {}
pub enum ParseBandwidthError { Format, Unit(String), Range }

FromStr follows Hysteria’s StringToBps: decimal digits, optional spaces, then a unit, without regard to case. The units are bits: b/bps, k/kb/kbps, m/mb/mbps, g/gb/gbps and t/tb/tbps, in powers of 1000. The result is bytes per second, rounded down. A bare number is refused with Format, because Hysteria reads one as bytes per second and other clients as megabits; an unknown unit is Unit, and zero, less than a byte per second or an overflow is Range. The messages are the ones etemenanki-app prints for a bad rate.

Display writes the largest unit that states the rate exactly, so the text reads back to the same value: 100 mbps, 1 gbps, or 8 bps for one byte per second.

bandwidth.rs has unit tests for Hysteria’s spellings, the refusals (bare numbers, unknown units, zero, under a byte, overflow) and the Display round trip. The congestion and hopping tests are on their pages.

The gates are scripts/check-vendor.sh, cargo fmt -p shinku-quic -- --check, cargo test --workspace and cargo clippy -p shinku-quic --all-targets -- -D warnings. The vendored upstream code is not held to the crate’s fmt and clippy rules. The crate sets unsafe_code = "forbid".