English
socks
SOCKS4, SOCKS4a and SOCKS5: an inbound (one TCP port, CONNECT and UDP ASSOCIATE) and an outbound client over TCP and UDP, like sing-box 1.14.4's protocol/socks on top of sing/protocol/socks. The inbound and the wire formats are ours_proto::socks (the socks-server feature of ours-proto), shared with the mixed inbound.
| Crate | ours-mod-socks, modules/protocols/socks |
| Binary features | socks-inbound, socks-outbound (socks enables both) |
| Crate features | none |
requires
dial — the outbound connects to the SOCKS server through a Dialer.
provides
Provide::Blocks { section: "outbounds", key: "socks", blocks: ["dial"] }— SOCKS has no TLS.Provide::Inbound/Provide::Outbound { key: "socks" }, the schemasinbounds.socks,outbounds.socks.
Syntax: socks.
Dependencies
ours-proto (socks-server), ours-uot, ours-api, ours-codec.
Design
src/lib.rs—MODULE; the inbound isours_proto::socks::build.src/outbound.rs— the client for all versions (ClientConn).
The server and the wire formats, in crates/proto/src/socks/:
inbound.rs—SocksInbound: the version by the first byte, authentication, CONNECT, UDP ASSOCIATE;SocksStreamimplementsSplice.Acceptedserves SOCKS on a connection that another inbound accepted and whose beginning it has already read: this is how the SOCKS side ofmixedworks.associate.rs— UDP ASSOCIATE frames and the connection over which the session's datagrams go (Associate,RoutedAssociate).socks4.rs,socks5.rs— reading and writing as in sing-box, including the reply codes.wire.rs— reading a message as its bytes arrive (Reader,Wire); the SOCKS5 address itself isours_api::Destinationin theSOCKS5variant ofours-wire, the SOCKS4a host itstext::host.options.rs—SocksInboundOptions.
Reload
Users reload in place, as in http.
Limitations
The inbound's detour, netns and domain_resolver are rejected at build time.
Tests
modules/protocols/socks/tests/: socks.rs (all versions, CONNECT and ASSOCIATE, our outbound against servers and a recording mock), associate_isolation.rs, detour.rs; unit tests in socks4.rs, socks5.rs, associate.rs. Changing users without a rebuild — app/ours/tests/users.rs.