pub struct ReroutePolicy {
pub reroute_count: AtomicU64,
pub recovery_count: AtomicU64,
/* private fields */
}Expand description
Policy that automatically reroutes traffic when peers fail.
When a peer is marked as failed by the FailureDetector:
- Find all routes whose next-hop is the failed peer’s address
- For each, find an alternate peer (any other connected peer)
- Update the routing table to use the alternate
When the peer recovers:
- Restore the original routes (direct path is typically better)
Fields§
§reroute_count: AtomicU64Total reroutes performed
recovery_count: AtomicU64Total recoveries performed
Implementations§
Source§impl ReroutePolicy
impl ReroutePolicy
Sourcepub fn new(
routing_table: Arc<RoutingTable>,
peer_addrs: Arc<DashMap<u64, SocketAddr>>,
) -> Self
pub fn new( routing_table: Arc<RoutingTable>, peer_addrs: Arc<DashMap<u64, SocketAddr>>, ) -> Self
Create a new reroute policy.
Sourcepub fn with_proximity_graph(self, graph: Arc<ProximityGraph>) -> Self
pub fn with_proximity_graph(self, graph: Arc<ProximityGraph>) -> Self
Set the proximity graph for multi-hop alternate selection.
Sourcepub fn on_failure(&self, failed_node_id: u64)
pub fn on_failure(&self, failed_node_id: u64)
Called when the failure detector marks a peer as failed.
Finds all routes through the failed peer and reroutes them through an alternate peer. The original routes are saved for restoration on recovery.
Sourcepub fn on_recovery(&self, recovered_node_id: u64)
pub fn on_recovery(&self, recovered_node_id: u64)
Called when the failure detector marks a peer as recovered.
Restores original routes that were rerouted when this peer failed. The direct path is typically better (fewer hops, lower latency) than the alternate.
The filter is entry.failed_node_id == recovered_node_id
rather than entry.next_hop == recovered_addr. An addr-based
filter would miss every reroute when the peer reconnected
from a different SocketAddr (NAT rebind, mobile network
change, reconnect on different port) — saved_routes would
accumulate indefinitely across mobile / NAT-changing peers,
and routes would stay pinned to alternates after the peer
had actually recovered. The identity-based filter survives
addr changes; recovered_addr is re-resolved from
peer_addrs at recovery time so the restored route uses the
current addr.
Sourcepub fn active_reroutes(&self) -> usize
pub fn active_reroutes(&self) -> usize
Number of active reroutes (routes currently using alternates).