Juvix imports
module arch.node.engines.router;
import arch.node.engines.router_messages open;
import arch.node.engines.router_config open;
import arch.node.engines.router_environment open;
import arch.node.engines.router_behaviour open;
import arch.node.types.basics open;
import arch.node.types.engine open;
import arch.node.types.anoma as Anoma open;
open router_config_example;
open router_environment_example;
open router_behaviour_example;
Router Engine¶
Purpose¶
The Router engine is responsible for routing messages between local engines and remote nodes.
Operation¶
The Router may operate in different modes depending on requirements and constraints of the implementation:
- Centralized
- A single Router engine instance forwards messages to & from local engines. It may integrate the functionality of Pub/Sub Topic engines as well.
- Decentralized
- A separate Router engine instance is spawned for each destination node,
each of which forward messages for a single node only.
The engine instance name is derived from
NodeID
of the destination, which allows local engines to forward outgoing messages via the router engine instance responsible for the destination.
Spawning of Router and Pub/Sub Topic engines may be implemented
either manually when the first message is sent to the node or when the topic is subscribed,
or automatically as soon as a NodeAdvert
or TopicAdvert
is known for the destination.
In the following we assume decentralized operation with automatic spawning for simplicity.
Engine components¶
The type for a router engine¶
RouterEngine : Type :=
Engine
RouterLocalCfg
RouterLocalState
RouterMailboxState
RouterTimerHandle
RouterActionArguments
Anoma.Msg
Anoma.Cfg
Anoma.Env;
Example of a router engine¶
exRouterEngine : RouterEngine :=
mkEngine@{
cfg := exRouterCfg;
env := exRouterEnv;
behaviour := exRouterBehaviour;
};
Where exRouterCfg
is defined as follows:
exRouterCfg : RouterCfg :=
mkEngineCfg@{
node := Curve25519PubKey "0xabcd1234";
name := "router-0xab12cd34";
cfg := mkRouterLocalCfg;
};
exRouterEnv
is defined as follows:
exRouterEnv : RouterEnv :=
mkEngineEnv@{
localState := mkRouterLocalState;
mailboxCluster := Map.empty;
acquaintances := Set.empty;
timers := [];
};
and exRouterBehaviour
is defined as follows:
module router_behaviour_example;
exRouterBehaviour : RouterBehaviour :=
mkEngineBehaviour@{
guards := First [exampleReplyGuard];
};
end;