Crates.io | atm0s-sdn-network |
lib.rs | atm0s-sdn-network |
version | 0.6.1 |
source | src |
created_at | 2023-11-17 17:20:44.668749 |
updated_at | 2024-11-26 17:11:20.659021 |
description | Main network-plane of atm0s-sdn |
homepage | |
repository | |
max_upload_size | |
id | 1039287 |
size | 559,198 |
Network is split into 2 parts
This part handles the network and routing tables. The logic of routing table is not fixed, instead it is inject into with trait RoutingTable which provide bellow function
pub trait RouterTable: Send + Sync {
fn path_to_node(&self, dest: NodeId) -> RouteAction;
fn path_to_key(&self, key: NodeId) -> RouteAction;
fn path_to_service(&self, service_id: u8) -> RouteAction;
fn path_to(&self, route: &RouteRule, service_id: u8) -> RouteAction {
match route {
RouteRule::Node(dest) => self.path_to_node(*dest),
RouteRule::Closest(key) => self.path_to_key(*key),
RouteRule::Service => self.path_to_service(service_id),
}
}
}
By the way, network providing some based function to sending and handler message:
Message is sending to other node by routing table and transport
By provide a custom behaviour, we can add logic to application with modules style, each that will need to defined some parts:
Each part also can exchanged data with other part by using Agent, which is provide in each function handler
For reference bellow is trait of behaviour
pub trait NetworkBehavior<BE, HE, MSG>
where
MSG: Send + Sync,
{
fn service_id(&self) -> u8;
fn on_tick(&mut self, agent: &BehaviorAgent<HE, MSG>, ts_ms: u64, interval_ms: u64);
fn check_incoming_connection(
&mut self,
node: NodeId,
conn_id: ConnId,
) -> Result<(), ConnectionRejectReason>;
fn check_outgoing_connection(
&mut self,
node: NodeId,
conn_id: ConnId,
) -> Result<(), ConnectionRejectReason>;
fn on_incoming_connection_connected(
&mut self,
agent: &BehaviorAgent<HE, MSG>,
conn: Arc<dyn ConnectionSender<MSG>>,
) -> Option<Box<dyn ConnectionHandler<BE, HE, MSG>>>;
fn on_outgoing_connection_connected(
&mut self,
agent: &BehaviorAgent<HE, MSG>,
conn: Arc<dyn ConnectionSender<MSG>>,
) -> Option<Box<dyn ConnectionHandler<BE, HE, MSG>>>;
fn on_incoming_connection_disconnected(
&mut self,
agent: &BehaviorAgent<HE, MSG>,
conn: Arc<dyn ConnectionSender<MSG>>,
);
fn on_outgoing_connection_disconnected(
&mut self,
agent: &BehaviorAgent<HE, MSG>,
conn: Arc<dyn ConnectionSender<MSG>>,
);
fn on_outgoing_connection_error(
&mut self,
agent: &BehaviorAgent<HE, MSG>,
node_id: NodeId,
conn_id: ConnId,
err: &OutgoingConnectionError,
);
fn on_handler_event(
&mut self,
agent: &BehaviorAgent<HE, MSG>,
node_id: NodeId,
conn_id: ConnId,
event: BE,
);
fn on_rpc(
&mut self,
agent: &BehaviorAgent<HE, MSG>,
req: Req,
res: Box<dyn RpcAnswer<Res>>,
) -> bool;
}
Bellow is trait of ConnectionHandler
pub trait ConnectionHandler<BE, HE, MSG>: Send + Sync {
fn on_opened(&mut self, agent: &ConnectionAgent<BE, HE, MSG>);
fn on_tick(&mut self, agent: &ConnectionAgent<BE, HE, MSG>, ts_ms: u64, interval_ms: u64);
fn on_event(&mut self, agent: &ConnectionAgent<BE, HE, MSG>, event: ConnectionEvent<MSG>);
fn on_other_handler_event(
&mut self,
agent: &ConnectionAgent<BE, HE, MSG>,
from_node: NodeId,
from_conn: ConnId,
event: HE,
);
fn on_behavior_event(&mut self, agent: &ConnectionAgent<BE, HE, MSG>, event: HE);
fn on_closed(&mut self, agent: &ConnectionAgent<BE, HE, MSG>);
}