Skip to content

Module contract (ours-api) ​

crates/api is everything the kernel and modules agree on. A module is the constant MODULE: ours_api::Module in an ours-mod-* crate: a name, the list of modules it relies on, and the list of what it provides (Provide). The kernel and the configuration loader find everything through these lists; there are no direct "kernel → specific module" calls.

rust
pub const MODULE: ours_api::Module = ours_api::Module {
    name: "transport-ws",
    requires: &["transport"],
    provides: &[ours_api::Provide::Block { block: "transport", key: "ws", decode: ... }],
};

Module description ​

Kinds of Provide ​

KindDocument
Inbound, Outbound, Endpoint, BlocksInbound and outbound
Point, Extension, BlockPoints and extensions
Section, Source, Check, RuleSetSections, sources, checks
Rules, RuleSets, Condition, DnsRules, rule-sets, conditions, DNS
Unit, DispatcherUnits and the dispatcher
SchemaJSON Schema

Shared types ​

  • Services — Services: what modules publish for each other by type.
  • Runtime types — Metadata, Stream, PacketConn, Context, DnsCell, DialTable, Host, ShardInfo.
  • Options — ours_config::options: option types read by the kernel and several modules.

The decoded configuration (ours_api::config: Config, Blocks, Decoded, Decoders, Part, Scope, decoder helpers) is described in Configuration, the types — in ours_api::config types.

Modules of ours-api ​

FileWhat
module.rsModule, Provide, factories, Unit/Stage/Build, Extensions, Known
adapter.rsInbound, Outbound, Group, RuleSet, Outbounds, Context, unavailable
dispatch.rsDispatch, DispatchControl, Routing, Policies, Connected, Guard
route.rsAction, Rules, Evaluation, Needs, Traced
rules.rsCondition, Entry, Place, Group — conditions added by modules
dns.rsDns, DnsCell, DnsContext, Resolver, FakeIp, no_dns
config.rsthe decoded configuration (the parsing helpers, the schema helpers and defaults live in ours-config)
component.rs, plan.rs, shard.rsComponentId, Plan, ShardInfo/Handover
services.rs, dial_table.rs, host.rs, network.rsthe service registry, the detour table, the host, the network strategy
session.rs, stream.rsmetadata, streams
dial.rs, tls.rs, udp.rsthe dialer, TLS clients and servers and a dialer's UDP side, which the dial and tls modules implement for other modules, ours-http, ours-proto and ours-quic
cache.rsCache, Store, SavedRuleSet, Journal and Snapshot (a store written behind its owner): the cache file the cache module publishes for dns, group, router
memory.rsset_purge, purge: the binary installs its allocator's purge (ours-alloc), router calls it after building a rule-set
mux.rsMuxClient, MuxServer, Session, Route and the mux block's handles Client, Server: the multiplexers the mux module implements for trojan, vless, shadowsocks
options.rsDomainStrategy, DNSQueryType, ReloadPolicy, UDPNATBehavior, UDP_NAT_MAX: option values the contract's traits name
admin.rsAdmin, Endpoints: Admin API endpoints a module serves
detour.rsdetour: an inbound's detour to another inbound
panic.rswhat a panic ends: in a connection's task only that connection
task.rsspawn, boxed: spawning behind one future type

GPL-3.0-or-later