refactor route so we can add other router (#15)

This commit is contained in:
Sijie.Sun
2024-02-06 20:17:08 +08:00
committed by GitHub
parent 4f98dd097c
commit 2c2e41be24
7 changed files with 126 additions and 178 deletions
+5 -4
View File
@@ -21,16 +21,17 @@ pub trait RouteInterface {
pub type RouteInterfaceBox = Box<dyn RouteInterface + Send + Sync>;
#[async_trait]
#[auto_impl::auto_impl(Box, Arc)]
pub trait Route {
async fn open(&self, interface: RouteInterfaceBox) -> Result<u8, ()>;
async fn close(&self);
async fn get_peer_id_by_ipv4(&self, ipv4: &Ipv4Addr) -> Option<PeerId>;
async fn get_next_hop(&self, peer_id: &PeerId) -> Option<PeerId>;
async fn handle_route_packet(&self, src_peer_id: PeerId, packet: Bytes);
async fn list_routes(&self) -> Vec<easytier_rpc::Route>;
async fn get_peer_id_by_ipv4(&self, _ipv4: &Ipv4Addr) -> Option<PeerId> {
None
}
}
pub type ArcRoute = Arc<Box<dyn Route + Send + Sync>>;