pub struct ReconnectionManager { /* private fields */ }Expand description
Manager for auto-reconnection with exponential backoff
Tracks disconnected peers and determines when to attempt reconnection based on exponential backoff.
Implementations§
Source§impl ReconnectionManager
impl ReconnectionManager
Sourcepub fn new(config: ReconnectionConfig) -> Self
pub fn new(config: ReconnectionConfig) -> Self
Create a new reconnection manager with the given configuration
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a manager with default configuration
Sourcepub fn track_disconnection(&mut self, address: String)
pub fn track_disconnection(&mut self, address: String)
Track a peer for reconnection after disconnection
Call this when a peer disconnects unexpectedly.
Sourcepub fn is_tracked(&self, address: &str) -> bool
pub fn is_tracked(&self, address: &str) -> bool
Check if a peer is being tracked for reconnection
Sourcepub fn get_status(&self, address: &str) -> ReconnectionStatus
pub fn get_status(&self, address: &str) -> ReconnectionStatus
Get the reconnection status for a peer
Sourcepub fn get_peers_to_reconnect(&self) -> Vec<String>
pub fn get_peers_to_reconnect(&self) -> Vec<String>
Get all peers that are ready for a reconnection attempt
Returns addresses of peers that:
- Haven’t exceeded max attempts
- Have waited long enough since the last attempt (first attempt is immediate)
Sourcepub fn record_attempt(&mut self, address: &str)
pub fn record_attempt(&mut self, address: &str)
Record a reconnection attempt for a peer
Call this when starting a reconnection attempt.
Sourcepub fn on_connection_success(&mut self, address: &str)
pub fn on_connection_success(&mut self, address: &str)
Called when a connection succeeds
Removes the peer from reconnection tracking.
Sourcepub fn stop_tracking(&mut self, address: &str)
pub fn stop_tracking(&mut self, address: &str)
Stop tracking a peer (e.g., peer was intentionally removed)
Sourcepub fn tracked_count(&self) -> usize
pub fn tracked_count(&self) -> usize
Get the number of peers being tracked
Sourcepub fn get_peer_stats(&self, address: &str) -> Option<PeerReconnectionStats>
pub fn get_peer_stats(&self, address: &str) -> Option<PeerReconnectionStats>
Get statistics for a peer
Sourcepub fn check_interval(&self) -> Duration
pub fn check_interval(&self) -> Duration
Get the check interval from configuration