2023-09-23 01:53:45 +00:00
|
|
|
pub mod peer;
|
2024-04-24 23:12:46 +08:00
|
|
|
// pub mod peer_conn;
|
2024-04-27 16:27:42 +08:00
|
|
|
pub mod peer_conn;
|
2024-04-24 23:12:46 +08:00
|
|
|
pub mod peer_conn_ping;
|
2023-09-23 01:53:45 +00:00
|
|
|
pub mod peer_manager;
|
|
|
|
|
pub mod peer_map;
|
2024-03-18 17:16:33 +08:00
|
|
|
pub mod peer_ospf_route;
|
2023-09-23 01:53:45 +00:00
|
|
|
pub mod peer_rpc;
|
2024-09-21 18:15:47 +08:00
|
|
|
pub mod peer_rpc_service;
|
2023-09-23 01:53:45 +00:00
|
|
|
pub mod route_trait;
|
|
|
|
|
pub mod rpc_service;
|
|
|
|
|
|
2024-03-06 20:59:17 +08:00
|
|
|
pub mod foreign_network_client;
|
|
|
|
|
pub mod foreign_network_manager;
|
|
|
|
|
|
2024-04-27 13:44:59 +08:00
|
|
|
pub mod encrypt;
|
|
|
|
|
|
2024-10-06 22:49:18 +08:00
|
|
|
pub mod peer_task;
|
|
|
|
|
|
2023-09-23 01:53:45 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
|
pub mod tests;
|
2024-03-18 17:14:43 +08:00
|
|
|
|
2024-04-24 23:12:46 +08:00
|
|
|
use crate::tunnel::packet_def::ZCPacket;
|
2024-03-18 17:14:43 +08:00
|
|
|
|
|
|
|
|
#[async_trait::async_trait]
|
|
|
|
|
#[auto_impl::auto_impl(Arc)]
|
|
|
|
|
pub trait PeerPacketFilter {
|
2024-04-24 23:12:46 +08:00
|
|
|
async fn try_process_packet_from_peer(&self, _zc_packet: ZCPacket) -> Option<ZCPacket> {
|
|
|
|
|
Some(_zc_packet)
|
2024-03-18 17:14:43 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[async_trait::async_trait]
|
|
|
|
|
#[auto_impl::auto_impl(Arc)]
|
|
|
|
|
pub trait NicPacketFilter {
|
2025-01-26 00:41:15 +08:00
|
|
|
async fn try_process_packet_from_nic(&self, data: &mut ZCPacket) -> bool;
|
2025-05-16 09:24:24 +08:00
|
|
|
|
|
|
|
|
fn id(&self) -> String {
|
|
|
|
|
format!("{:p}", self)
|
|
|
|
|
}
|
2024-03-18 17:14:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type BoxPeerPacketFilter = Box<dyn PeerPacketFilter + Send + Sync>;
|
|
|
|
|
type BoxNicPacketFilter = Box<dyn NicPacketFilter + Send + Sync>;
|
2024-04-24 23:12:46 +08:00
|
|
|
|
2025-01-17 06:50:21 +08:00
|
|
|
// pub type PacketRecvChan = tachyonix::Sender<ZCPacket>;
|
|
|
|
|
// pub type PacketRecvChanReceiver = tachyonix::Receiver<ZCPacket>;
|
|
|
|
|
// pub fn create_packet_recv_chan() -> (PacketRecvChan, PacketRecvChanReceiver) {
|
|
|
|
|
// tachyonix::channel(128)
|
|
|
|
|
// }
|
2024-04-24 23:12:46 +08:00
|
|
|
pub type PacketRecvChan = tokio::sync::mpsc::Sender<ZCPacket>;
|
|
|
|
|
pub type PacketRecvChanReceiver = tokio::sync::mpsc::Receiver<ZCPacket>;
|
2025-01-17 06:50:21 +08:00
|
|
|
pub fn create_packet_recv_chan() -> (PacketRecvChan, PacketRecvChanReceiver) {
|
|
|
|
|
tokio::sync::mpsc::channel(128)
|
|
|
|
|
}
|
|
|
|
|
pub async fn recv_packet_from_chan(
|
|
|
|
|
packet_recv_chan_receiver: &mut PacketRecvChanReceiver,
|
|
|
|
|
) -> Result<ZCPacket, anyhow::Error> {
|
|
|
|
|
packet_recv_chan_receiver
|
|
|
|
|
.recv()
|
|
|
|
|
.await
|
|
|
|
|
.ok_or(anyhow::anyhow!("recv_packet_from_chan failed"))
|
|
|
|
|
}
|