pub struct NetProxy { /* private fields */ }Expand description
Net Proxy for zero-copy multi-hop forwarding.
The proxy forwards packets without decrypting the payload, only reading and updating the routing header.
Implementations§
Source§impl NetProxy
impl NetProxy
Sourcepub async fn new(config: ProxyConfig) -> Result<Self>
pub async fn new(config: ProxyConfig) -> Result<Self>
Create a new proxy
Sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Get local address
Sourcepub fn add_route(&self, dest_id: u64, next_hop: SocketAddr)
pub fn add_route(&self, dest_id: u64, next_hop: SocketAddr)
Add a route to the next-hop table
Sourcepub fn remove_route(&self, dest_id: u64)
pub fn remove_route(&self, dest_id: u64)
Remove a route.
Drops both the next_hop entry and the matching hop_stats
entry. Removing only the former would let hop_stats grow
indefinitely (memory ∝ total-distinct-dest-ids-ever-seen,
not active dest count) for a peer churning through many
destinations.
Sourcepub fn lookup(&self, dest_id: u64) -> Option<SocketAddr>
pub fn lookup(&self, dest_id: u64) -> Option<SocketAddr>
Lookup next hop for destination
Sourcepub fn forward(&self, data: Bytes) -> ForwardResult
pub fn forward(&self, data: Bytes) -> ForwardResult
Forward a packet (zero-copy, no decryption).
This is the hot path - it only reads and updates the routing header, then forwards the entire packet to the next hop.
Sourcepub async fn forward_and_send(
&self,
data: Bytes,
) -> Result<ForwardResult, ProxyError>
pub async fn forward_and_send( &self, data: Bytes, ) -> Result<ForwardResult, ProxyError>
Forward and send a packet in one operation
Sourcepub async fn send_to(&self, data: &[u8], dest: SocketAddr) -> Result<usize>
pub async fn send_to(&self, data: &[u8], dest: SocketAddr) -> Result<usize>
Send data to a destination
Sourcepub fn stats(&self) -> ProxyStats
pub fn stats(&self) -> ProxyStats
Get proxy statistics
Sourcepub fn reset_stats(&self)
pub fn reset_stats(&self)
Reset statistics
Sourcepub fn hop_stats(&self, dest_id: u64) -> Option<(u64, u64, u64)>
pub fn hop_stats(&self, dest_id: u64) -> Option<(u64, u64, u64)>
Get hop stats for a destination
Sourcepub fn route_count(&self) -> usize
pub fn route_count(&self) -> usize
Get route count