English
mixed
An HTTP proxy and SOCKS4/4a/5 inbound on one port, like sing-box 1.14.4's protocol/mixed. The protocol is determined by the connection's first byte: 4/5 — SOCKS, anything else — HTTP.
| Crate | ours-mod-mixed, modules/protocols/mixed |
| Binary feature | mixed |
| Crate features | none |
requires
dial, tls (the tls block on the HTTP side). The http and socks modules are not needed: the inbound is assembled from the HTTP and SOCKS servers of ours-proto, which those modules build on too.
provides
Provide::Blocks { section: "inbounds", key: "mixed", blocks: ["tls"] }, Provide::Inbound { key: "mixed" } (the decoder ours_config::listener_with_users), the schema inbounds.mixed. The options are ours_proto::http::options::HTTPMixedInboundOptions.
Syntax: mixed.
Dependencies
ours-proto (http-server, socks-server), ours-tls-options, ours-api, ours-codec, ours-config.
Design
src/lib.rs — build: the inbound is built by ours_proto::http::build_mixed, which is given the TLS server of the tls block (as the http module makes it) and an implementation of the ours_proto::http::Socks trait. The HTTP server reads the first byte and hands a SOCKS connection together with the bytes read to ours_proto::socks::Accepted::serve: from there everything is as in the socks inbound (CONNECT, UDP ASSOCIATE, UDP-over-TCP). The listen socket options are the same for both sides.
Reload
Users are moved out of the block's cold form (listener_with_users): changing them does not rebuild the inbound. The HTTP side's hot_changed replaces the list and passes it to the SOCKS side (Socks::users_changed → Accepted::set_users); new connections on both sides are checked against the new list.
Limitations
- SOCKS over TLS is rejected ("SOCKS over TLS on a mixed inbound is not supported"); sing-box allows it.
- The inbound's
detour,netns,set_system_proxy,domain_resolverare rejected at build time.
Tests
app/ours/tests/mixed.rs — SOCKS and HTTP on one port with one list of users. The HTTP side — modules/protocols/http/tests/inbound.rs.