Skip to content

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.

Crateours-mod-socks, modules/protocols/socks
Binary featuressocks-inbound, socks-outbound (socks enables both)
Crate featuresnone

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 schemas inbounds.socks, outbounds.socks.

Syntax: socks.

Dependencies ​

ours-proto (socks-server), ours-uot, ours-api, ours-codec.

Design ​

  • src/lib.rs — MODULE; the inbound is ours_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; SocksStream implements Splice. Accepted serves SOCKS on a connection that another inbound accepted and whose beginning it has already read: this is how the SOCKS side of mixed works.
  • 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 is ours_api::Destination in the SOCKS5 variant of ours-wire, the SOCKS4a host its text::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.

GPL-3.0-or-later