Skip to content

hysteria2 ​

Hysteria2 (sing-box's protocol/hysteria2 on top of sing-quic/hysteria2): a QUIC connection that the client authenticates with one HTTP/3 request; then a stream per TCP connection and QUIC datagrams for UDP, at the speed the sides agreed on. To unauthenticated ones the server answers as an ordinary HTTP/3 server (masquerade).

Crateours-mod-hysteria2, modules/protocols/hysteria2
Binary featureshysteria2-inbound, hysteria2-outbound (hysteria2 enables both) (enables tls and ours-mod-tls/quic)
Crate featuresnone

requires ​

dial, tls — as for hysteria: the socket through a Dialer, QUIC's TLS from the tls block.

provides ​

  • Provide::Blocks: inbound — tls; outbound — tls, dial.
  • Provide::Inbound/Provide::Outbound { key: "hysteria2" }, the schemas inbounds.hysteria2, outbounds.hysteria2.

Syntax: hysteria2.

Dependencies ​

ours-quic (endpoints, obfuscation, connect_early/0-RTT, port hopping), ours-quinn-ext (Salamander and Gecko, Brutal and the BBR profiles, HTTP/3), ours-http (the masquerade proxy's client), ours-tls-options, ours-bufpool, ours-api, ours-codec, ours-json, rand_core + getrandom, bytes, arc-swap, http.

Design ​

  • src/protocol.rs — the authentication request's fields, a TCP stream's request and response, the UDP message.
  • src/udp.rs — UDP over datagrams: a flow is a session of the connection, a packet is a message or its fragments.
  • src/outbound.rs — ours_quic::CONNECTIONS_PER_THREAD authenticated connections per runtime thread; a new stream takes the one with fewer open streams (ours_quic::Load), a flow — any; when one is lost — a new one; port hopping through ours_quic::hopping.
  • src/inbound.rs — HTTP/3 for everyone before authentication, the proxy after it; non-authentication is handed to masquerade in a separate task.
  • src/masquerade.rs — a string response, the files of a directory (Go's http.FileServer; file operations are in spawn_blocking) or a reverse proxy (httputil.ReverseProxy with Rewrite) through ours_http::Client over HTTP/1.1 with direct TCP.
  • src/options.rs — options, including obfs (salamander, gecko), realm, masquerade (file, proxy, string), users; URL parsing like Go's url.Parse.
  • src/lib.rs — the QUIC transport: bbr_profile — ours_quinn_ext::congestion::bbr, brutal_debug — SwitchFactory::debugged with the label inbound/hysteria2[tag] or outbound/hysteria2[tag]. disable_chrome_parrot is accepted and changes nothing.

realm is rejected at build time (… not implemented).

Reload ​

Users reload in place, as in http.

Tests ​

modules/protocols/hysteria2/tests/hysteria2.rs — TCP and UDP, Salamander and Gecko, the agreed speed, the BBR profiles with brutal_debug, a wrong password, masquerade with a directory and a proxy; unit tests in protocol.rs. E2E: tests/e2e/scenarios/hysteria2, hysteria2-ext.

GPL-3.0-or-later