English
shadowsocks
Shadowsocks: the legacy AEAD and 2022 methods from sing-box 1.14.4, inbound and outbound, TCP and UDP. For 2022 — single-key and multi-user servers.
| Crate | ours-mod-shadowsocks, modules/protocols/shadowsocks |
| Binary features | shadowsocks-inbound, shadowsocks-outbound (shadowsocks enables both) |
| Crate features | mux (the mux block), mux-smux, mux-yamux, mux-h2, mux-xray, mux-brutal, mux-padding — enable mux and gate only the crate's own code (the binary's mux-* switch on ours-mod-mux), v2ray-plugin (the v2ray-plugin plugin; its mux.cool session is its own, ours-wire/cool); all on by default |
requires
dial — the outbound connects through a Dialer; with the mux feature also mux; with v2ray-plugin also tls, transport, transport-ws — the plugin builds its WebSocket from the ws variant of the transport block, which it takes from Extensions.
provides
Provide::Blocks { section: "outbounds", key: "shadowsocks", blocks: ["dial", "mux"] },Provide::Blocks { section: "inbounds", key: "shadowsocks", blocks: ["mux"] }(mux— with themuxfeature).Provide::Inbound/Provide::Outbound { key: "shadowsocks" }, the schemasinbounds.shadowsocks,outbounds.shadowsocks.
Syntax: shadowsocks.
Dependencies
ours-relay, ours-net-sys, ours-bufpool, ours-api, ours-codec, ours-uot; ours-wire (sing-mux, the mux feature); ours-tls-options, ours-transport-api, ours-wire (cool) (the v2ray-plugin feature); the cryptography aes, aes-gcm, chacha20poly1305, ring, blake3, hkdf, md-5, sha1, sha2; getrandom.
Design
src/method.rs— the method: ciphers, key material, password → key (MD5 stretching for legacy, a base64 PSK for 2022,server:userfor multi-user).src/crypto.rs— ciphers and key derivation (HKDF-SHA1 / BLAKE3), framing: a length chunk and a data chunk, the nonce counts up little-endian.src/stream.rs— the stream: the handshake before the first payload, the server's response with its salt and (2022) an echo of the client's salt; implementsSplice.src/udp.rs— datagrams: legacy — a fresh salt per packet; 2022 — a session key, a header, a timestamp, padding; the AES forms hide the first 16 bytes with a block cipher.src/replay.rs— protection against 2022 salt replay (a 60 s window, as in sing-box).src/request.rs— the request forms; the address isours_api::Destinationin theSHADOWSOCKSvariant ofours-wire, its errors worded insrc/stream.rs(address_error).src/inbound.rs— the TCP request is read before the dispatcher, then the relay; UDP replies from the same socket. A request tosp.mux.sing-box.arpais a sing-mux session (with themuxblock), to the UoT addresses — a UDP flow.src/outbound.rs— a TCP stream and a UDP flow to the server; UDP over TCP (udp_over_tcp) and multiplexing (MuxClient::wrapof the block'sours_api::mux::Client), as in sing-box — not together.src/plugin.rs,src/plugin/— SIP003, built in as in sing-box (transport/sip003): parsingplugin_opts;obfs.rs— simple-obfs (http: a WebSocket upgrade request with the data in the body;tls: the data in the ClientHello's session ticket, then application data records);v2ray.rs— WebSocket, TLS withtls, one mux.cool session unlessmux=0: the WebSocket is decoded from atransport.wsblock made ofpathandhostby the decoder thewsmodule registers (the configuration keepsplugin_optsas written), the session iscool.rs(sing-vmess'sMuxConnWrapper). The plugin opens only TCP; UDP goes to the server directly.
Reload
Users (2022 multi-user) reload in place, as in http. validate_hot checks the new list (the keys under method): an invalid one rejects the reload.
Limitations
Rejected at build time: plugins other than obfs-local and v2ray-plugin (and its quic mode), managed, the relay server's destinations, the inbound's detour and netns. Stream ciphers (rc4-md5, aes-*-ctr, aes-*-cfb, chacha20-ietf) are not supported.
Tests
modules/protocols/shadowsocks/tests/: loopback.rs (all methods, TCP and UDP, mux, UoT, the Brutal exchange), singbox_interop.rs (bytes recorded from sing-box, tests/data/), detour.rs; unit tests in almost all files; the example examples/write_bench.rs. With the references — tests/interop/protocols_singbox.py (mux, UoT, plugins against sing-box, the v2ray-plugin server and the obfs-server emulator).