Skip to content

Module order and Modules::new ​

crates/kernel/src/modules.rs. Modules is the checked module list of the binary, through which the kernel gets everything else.

Checks of Modules::new(list) ​

The list is static (&'static [Module]), so any error is a defect of the binary, not of the configuration; it is caught by the the_list_is_sound test in app/ours/src/modules.rs.

CheckError
the module name is uniquemodule x is listed twice
each of requires is in the listmodule xrequiresy, which is not built in
Provide::slot slots do not repeat (by the pair (point, key))modules aandbboth providekofp``
an Extension/Block extends a point someone opened (Provide::Point)module xextendsp, which no module opens
a module extending someone else's point requires its ownermodule xextendspofy without requiring it
there is no cycle in requiresmodules require each other in a cycle: a, b
exactly one Provide::Dispatcher (two are caught by the slot check)no module provides the dispatcher

The same key at different points is not a conflict: a slot is the pair (point, key). A module may extend its own point without requires (this is how router adds the dns condition to its own point conditions). Slots: Module.

Order ​

ordered() is a topological sort that preserves the original order: at every step the first module in the list whose requires are all already ordered is taken. This order determines:

  • the order in which units are built (Unit::build) — a unit sees the services published by the units of the modules its module requires;
  • the order in which units are closed — the reverse;
  • the lookup of factories and decoders — the first matching Provide (slot uniqueness makes it the only one).

What Modules hands out ​

  • decoders() — ours_api::config::Decoders for the loader: block decoders (Block, Inbound, Outbound), which blocks each type takes (Blocks), point extensions, sections, sources (Source), checks (Check), JSON Schema parts, rule-set sources; plus the kernel's own — the own() function: the log, reload, runtime, route sections (except what belongs to modules) and the reload block of inbound/outbound. The loader is described in Configuration.
  • inbound(key), outbound(key) — factories; if absent — an error with the available keys and a "not built in" note (with_known, see Building the binary).
  • rule_sets(), rules(), dns() — Option: without a module the kernel takes the stubs no_rule_sets, no_rules (crates/kernel/src/adapter.rs) and no_dns — they allow only a configuration without rule-sets, rules and DNS.
  • dispatcher() — the dispatcher factory (its presence is checked in new).
  • units() — an instance of every Provide::Unit (called once per Instance).
  • section(key) — an error for a section that no module of the build reads.
  • extensions() — Arc<Extensions>: all variants of the build's points; the kernel publishes it as a service.
  • has(point, key), key(point, key), names() — for the binary and the UI.

own() and the route section ​

route is decoded by the kernel (RouteOptions, crates/config/src/options/route.rs), but rules and rule-sets — by the router module (the route.rules, route.default_http_client sections). If route contains default_http_client and there is no router, own() answers "not built in (feature router)".

GPL-3.0-or-later