English
dispatch
The dispatcher: it takes a connection from an inbound, walks the rules (with sniffing where they say so), chooses an outbound, connects and starts the relay. The only provider of the Dispatcher slot in the binary.
| Crate | ours-mod-dispatch, modules/system/dispatch |
| Binary feature | none, always in the build; sniff enables ours-mod-dispatch/sniff |
| Crate features | sniff → ours-sniff/all (not checked in src/, it only enables the sniffers) |
requires
Nothing: the dispatcher works with the ours-api abstractions (Routing, Outbound, Dns), not with other modules' crates.
provides
Provide::Dispatcher— the factoryDispatcher::new(routing). Besides the dispatcher itself it putsArc<Tracker>(live connections; the Admin API reads it throughInstance::service,app/ui/src/api.rs) andArc<Dispatcher>into the instance's services.
The kernel requires exactly one Dispatcher provider (see the contract).
Dependencies
ours-api, ours-relay (moving data, splice), ours-tracker (the connection registry), ours-sniff, ours-net-sys, ours-bufpool, arc-swap.
Design
The whole module is src/lib.rs:
Dispatcher— holds theRoutingsnapshot behind anArcSwap. Inbounds hold the dispatcher for their whole life; reload replaces only the snapshot.Dispatch::route/connect/packet— the connection's path: the tracker entry is created before routing (the task handle goes there too, a connection has no stop handle of its own), then the rule walk, connecting, the relay.- Sniffing (the
sniffaction, like sing-box'sactionSniff): skipped for server-first ports, after a protocol has already been determined and after the same sniffers have failed. Plain TCP is only "peeked at" (peek), so that the data stays in the socket for splice; while it waits for more,SO_RCVLOWATis one byte above what was seen, so readiness means new data or the end, and is put back to one however the wait ends. Other streams are read and the data is put back in front of the stream. - DNS hijack: a connection sent to DNS gets a
DnsOutbound— the stream's queries (length + message) and packets are answered by the DNS module; tracking and the reload policy are the same as for ordinary connections. The timeout is sing-box'sC.DNSTimeout. - FakeIP and
override_*: for a packet stream with a changed destination,Translatedsubstitutes addresses there and back; an unknown fake address closes the connection. - The
resolveaction — resolving the destination domain for the following rules. - "On demand" metadata: the process, the neighbour's MAC and so on are requested from the host only if the rules need them (
RuleNeeds), and the process — only for connections from the host's own addresses.
Reload
reload(routing)— new connections follow the new snapshot; live ones walk the rules again on the already collected metadata, and the reload policy decides: keep, close, redirect (only for a packet stream). The same outbound object, if reload did not rebuild it, counts as the same.preview(&routing)— the same estimate without changes (fordiff/the dashboard).rule_set_updated(tag)— a small reload: it concerns only connections whose rules looked at this rule-set;rule_sets_changed()wakes those who watch the rules outside the dispatcher.
Tests
Unit tests in src/lib.rs; behaviour on live connections — in the router tests (modules/routing/router/tests/live.rs, dns_live.rs, rule_set_updates.rs).