Skip to content

Runtime types ​

The shared contract types through which components work with connections and with each other.

Connection ​

  • Metadata (crates/api/src/session.rs) — what is known about a connection: id, inbound (tag), inbound_type, network (Tcp/Udp), source, destination (Destination::Socket or Domain(name, port)), address/port overrides from rules, UDP flags. What is learned along the way is Learned (lazily, metadata.learn()): the original destination, the sniffed protocol and domain, the client, resolved addresses, the fake address, the user, the process (Process), the source's MAC and hostname, the interface type. restore_destination() returns the destination the inbound saw (for a repeated rule walk).
  • Stream (crates/api/src/stream.rs) — a byte stream: Tcp, Spliced(Box<dyn Splice>) — a protocol over a socket, each direction of which can hand the socket to splice when the protocol has nothing more to do there, and Boxed. TLS uses Spliced to offer kTLS splice sides, TLS record I/O and a way to put back sniffed bytes.
  • PacketConn — a packet stream: poll_recv → (Buf, Destination), poll_send_ready, send, poll_flush, enable_batching. Wrappers: Prefixed (data read by the sniffer, in front of the stream), Queued (packets taken by the sniffer).
  • ours_net_sys::batch — UDP socket batching (Receiver, Sender), shared by direct, transparent NAT and framed UDP transports.
  • Destination in the address layouts of ours-wire: read, write, written_len (and *_optional for a layout's "no address") in the protocol's Variant; read_from and read_optional_from take one off a stream; from_host reads a host written as text.

Build context ​

Context<'a> (crates/api/src/adapter.rs) — what a component factory sees besides its own blocks:

FieldWhat
default_markroute.default_mark for an outbound without its own mark
dns: &Arc<DnsCell>the DNS of the running configuration
host: Option<&Arc<dyn Host>>the host's interfaces and process/neighbour lookup
services: &Servicesthe configuration's services (Services)

Outbounds { tagged, default } — the configuration's outbounds for components that open connections themselves (rule-sets, DNS).

Cells that survive reload ​

Components reused by reload must see what is running now, not what they were built with. So they hold cells, and the kernel changes their contents:

  • DnsCell (crates/api/src/dns.rs) — the current Dns and route.default_domain_resolver; lookup substitutes the default resolver if the outbound has none of its own. DNS transports hold it weakly (DnsContext::dns: Weak), because DNS owns the transports.
  • DialTable (crates/api/src/dial_table.rs) — outbounds by tag for detour (an ArcSwap snapshot). A dialer holds it through Weak: the table owns the outbounds, an outbound owns its dialer, and a strong back reference would keep the configuration alive forever. It switches together with routing (Reload).

Host and network ​

  • Host is the contract implemented by ours_runtime::host::SystemHost. Each configuration builds one from route (ours_config::options::host_options). It supplies the interfaces and the default route's interface, process lookup by socket, neighbours (MAC, hostname from DHCP leases). probe(needs) rejects a configuration whose conditions need an unavailable mechanism. It is installed into dialers (through HostCell) and handed to the rules.
  • NetworkOptions, Selection (crates/api/src/network.rs) — the network strategy: interface types, fallback, delay; Selection::Default or Interfaces { primary, fallback }. The choice itself (ours_runtime::host::select) and the conversion of ours-net-info types into the contract's (InterfaceType, session::Process, host::Neighbour) live in ours-runtime.

Shards ​

ShardInfo, Handover, Plane, Sockets (crates/api/src/shard.rs) — where an inbound is started and how sockets pass to its successor: Runtime and shards.

Identity and plan ​

ComponentId, ComponentKind, effective_tag (component.rs), Plan, Change (plan.rs) — Graph, Plan.

GPL-3.0-or-later