English
ours_api::config types
Code: crates/api/src/config.rs. This is the contract between the loader, the modules and the kernel: a module returns Decoded, the loader assembles a Config, the kernel and the factories read Blocks.
Decoded
A block or a section as the module decoded it.
| Field | Meaning |
|---|---|
value: Arc<dyn Any + Send + Sync> | the module's value; only it knows the type |
canonical: Value | the same, encoded back (Encode), without positions: equal options give an equal form, however they were written |
references: Vec<Reference> | the names of other components (References); the graph builds edges from them |
cold: Option<Value> | canonical without what reload applies in place; None — everything is cold, Some(Null) — everything is hot (hot()) |
written: Vec<Span> | for a list section: where each element is written (rule positions) |
gives: Vec<Given> | blocks the section gives to others |
parts: Vec<Part> | the components the section is split into; empty for an entity block |
defaults: Vec<Reference> | components the section makes the default of their kind |
Constructors: Decoded::of::<T>(node) — decode a node into T with exact field names; Decoded::new(value) — from a ready value (computes canonical and references); hot(), whole(kind) (the section is one component), each::<T>(kind, name) (a list section, one component per element).
Given
{ section, name, block, decoded } — a block block that a section gives to the entity name of the section list; an empty name — to another section. Used only by DNS — see dns.
Part
A component for reload: kind (ComponentKind: DnsServer, HttpClient, RuleSet, …), name (empty — the only one of its kind), cold (what rebuilds the component), references, defaults: Vec<RefKind> (the kinds whose default it uses without naming it), reads: Vec<(section, key)> (other sections' fields that go into its fingerprint). Part::of(kind, name, &value). A kind without its own variant is ComponentKind::Other(name).
Blocks
The decoded blocks of one entity (or the sections of Config::sections) by name, in decoding order; kind is the name of the protocol block.
of(kind, protocol),set_protocol,insert(replaces one with the same name);protocol::<T>(),get::<T>(name)— the value by type;canonical_of(name),sets(name)(the block is present and non-empty),canonical(),cold();references()— the references of all blocks;PartialEqandDebug— bycanonical().
Config
rust
pub struct Config {
pub sections: Blocks, // sections by key
pub inbounds: Vec<(String, Blocks)>,
pub outbounds: Vec<(String, Blocks)>,
pub endpoints: Vec<(String, Blocks)>,
pub rule_sets: Vec<(String, Blocks)>,
}Clone, PartialEq (comparing canonical forms), Default. The kernel gets nothing else about the configuration: neither the text nor the YAML tree.
Decoders
The build's decoders and the knowledge of what is not in the build. Built by Modules::decoders() + modules::own; the fields are filled with with_*/and_*.
| Field | Source | Methods |
|---|---|---|
entries | Provide::Block, Inbound, Outbound, Endpoint, own | decode, decode_side, decode_protocol |
takes | Provide::Blocks | takes |
known | build.rs (Known) | left_out, knows_section, error texts |
extensions | Provide::Extension, Provide::Condition, Provide::Block (its decoder) | extension, extensions |
sections | Provide::Section (with the section's kind), own | has_section, decode_section |
rule_sets | Provide::RuleSet | decode_rule_set |
sources | Provide::Source | has_source, expand |
held | with_held | replaces a source's state (tests, a draft) |
checks | Provide::Check | check |
schemas | Provide::Schema | schemas |
Scope
What the decoder of a section, a rule, a rule-set or a source sees about the rest of the configuration. The loader's implementation is Context (crates/native-config/src/rules.rs); for reading outside a configuration (a rule-set's rules, tests) — ours_route_api::rules::Detached(&[modules]), which knows only extensions.
| Method | Purpose |
|---|---|
kind(name) | outbound/group for a known name |
of_kind(node, kind) | a reference with a kind: outbound: x, group: x |
any(node, what) | a reference to an outbound or a group (not to a subscription server) |
select(pattern, span) | names by pattern + a "currently empty" warning |
has_rule_set(name) | a rule-set with this name exists |
warn(text) | a loading warning |
extension(point, key), left_out(point, key) | another module's variant / a module that is not in the build |
namespace(name) | declare a subscription namespace |
unique(section, base) | a free name base/base-<n>, taken right away |
accepts(&Entity) | whether an entity will load (a trial lowering) |
Entity, Expanded, Expand
A source (Provide::Source { section, expand }) gives Expanded { entities }; Entity is { section, name, node, namespace }, where section is inbounds, outbounds, groups or route.rules, node is the entity in native form, namespace is the subscription namespace. Expand = fn(&Node, &dyn Scope, held: Option<&dyn Any>) -> Result<Expanded>.
View, Seen, Located, Check
Check = fn(&dyn View) -> Result<(), Located> runs after all entities have been decoded. View::entities() — inbounds and outbounds as Seen { section, name, blocks, supplied } (supplied — the section whose source gave the entity, for example dns); View::written(section, name, path) — the spans of the key and the value in the written (merged with defaults) node. Located { message, span, first }. Example — modules/protocols/tproxy/src/config.rs (auto_nft only on one inbound, requirements on dns.listen).
Node helpers (ours_config)
They live in crates/config (ours_config), not in ours_api::config: members, take, finish (an error on the first extra key with the list of allowed ones), string, strings, list, single, tagged, address, split_address, rename, enable, refuse, listener_members/dialer_members, listener/dialer, fuse_options, same, error, kind_of. All errors are ours_codec::Error with an offset.