English
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
- Module and slots —
Module,Provide::slot,Known. - requires — what "requires" means and how it is checked.
Kinds of Provide
| Kind | Document |
|---|---|
Inbound, Outbound, Endpoint, Blocks | Inbound and outbound |
Point, Extension, Block | Points and extensions |
Section, Source, Check, RuleSet | Sections, sources, checks |
Rules, RuleSets, Condition, Dns | Rules, rule-sets, conditions, DNS |
Unit, Dispatcher | Units and the dispatcher |
Schema | JSON 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
| File | What |
|---|---|
module.rs | Module, Provide, factories, Unit/Stage/Build, Extensions, Known |
adapter.rs | Inbound, Outbound, Group, RuleSet, Outbounds, Context, unavailable |
dispatch.rs | Dispatch, DispatchControl, Routing, Policies, Connected, Guard |
route.rs | Action, Rules, Evaluation, Needs, Traced |
rules.rs | Condition, Entry, Place, Group — conditions added by modules |
dns.rs | Dns, DnsCell, DnsContext, Resolver, FakeIp, no_dns |
config.rs | the decoded configuration (the parsing helpers, the schema helpers and defaults live in ours-config) |
component.rs, plan.rs, shard.rs | ComponentId, Plan, ShardInfo/Handover |
services.rs, dial_table.rs, host.rs, network.rs | the service registry, the detour table, the host, the network strategy |
session.rs, stream.rs | metadata, streams |
dial.rs, tls.rs, udp.rs | the 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.rs | Cache, Store, SavedRuleSet, Journal and Snapshot (a store written behind its owner): the cache file the cache module publishes for dns, group, router |
memory.rs | set_purge, purge: the binary installs its allocator's purge (ours-alloc), router calls it after building a rule-set |
mux.rs | MuxClient, MuxServer, Session, Route and the mux block's handles Client, Server: the multiplexers the mux module implements for trojan, vless, shadowsocks |
options.rs | DomainStrategy, DNSQueryType, ReloadPolicy, UDPNATBehavior, UDP_NAT_MAX: option values the contract's traits name |
admin.rs | Admin, Endpoints: Admin API endpoints a module serves |
detour.rs | detour: an inbound's detour to another inbound |
panic.rs | what a panic ends: in a connection's task only that connection |
task.rs | spawn, boxed: spawning behind one future type |