pub struct BootstrapManager { /* private fields */ }Expand description
Simplified bootstrap manager wrapping saorsa-transport’s cache
Provides Sybil protection via rate limiting and IP diversity enforcement while delegating core caching to saorsa-transport’s proven implementation.
Implementations§
Source§impl BootstrapManager
impl BootstrapManager
Sourcepub async fn new() -> Result<Self, P2PError>
pub async fn new() -> Result<Self, P2PError>
Create a new bootstrap manager with default configuration
Sourcepub async fn with_config(config: BootstrapConfig) -> Result<Self, P2PError>
pub async fn with_config(config: BootstrapConfig) -> Result<Self, P2PError>
Create a new bootstrap manager with custom configuration
Sourcepub async fn with_node_config(
config: BootstrapConfig,
node_config: &NodeConfig,
) -> Result<Self, P2PError>
pub async fn with_node_config( config: BootstrapConfig, node_config: &NodeConfig, ) -> Result<Self, P2PError>
Create a new bootstrap manager from a BootstrapConfig and a NodeConfig.
Derives the loopback policy from node_config.allow_loopback and merges
the node-level diversity_config (if set) so the transport and bootstrap
layers stay consistent.
Sourcepub fn start_maintenance(&mut self) -> Result<(), P2PError>
pub fn start_maintenance(&mut self) -> Result<(), P2PError>
Start background maintenance tasks (delegated to saorsa-transport)
Sourcepub async fn add_peer(
&self,
addr: &SocketAddr,
addresses: Vec<SocketAddr>,
) -> Result<(), P2PError>
pub async fn add_peer( &self, addr: &SocketAddr, addresses: Vec<SocketAddr>, ) -> Result<(), P2PError>
Add a peer to the cache with Sybil protection
Enforces:
- Rate limiting (per-subnet temporal limits)
- IP diversity (geographic/ASN limits)
Sourcepub async fn add_peer_trusted(
&self,
addr: &SocketAddr,
addresses: Vec<SocketAddr>,
)
pub async fn add_peer_trusted( &self, addr: &SocketAddr, addresses: Vec<SocketAddr>, )
Add a trusted peer bypassing Sybil protection
Use only for well-known bootstrap nodes or admin-approved peers.
Sourcepub async fn record_success(&self, addr: &SocketAddr, rtt_ms: u32)
pub async fn record_success(&self, addr: &SocketAddr, rtt_ms: u32)
Record a successful connection
Sourcepub async fn record_failure(&self, addr: &SocketAddr)
pub async fn record_failure(&self, addr: &SocketAddr)
Record a failed connection
Sourcepub async fn select_peers(&self, count: usize) -> Vec<CachedPeer>
pub async fn select_peers(&self, count: usize) -> Vec<CachedPeer>
Select peers for bootstrap using epsilon-greedy strategy
Sourcepub async fn select_relay_peers(&self, count: usize) -> Vec<CachedPeer>
pub async fn select_relay_peers(&self, count: usize) -> Vec<CachedPeer>
Select peers that support relay functionality
Sourcepub async fn select_coordinators(&self, count: usize) -> Vec<CachedPeer>
pub async fn select_coordinators(&self, count: usize) -> Vec<CachedPeer>
Select peers that support NAT coordination
Sourcepub async fn stats(&self) -> BootstrapStats
pub async fn stats(&self) -> BootstrapStats
Get cache statistics
Sourcepub async fn peer_count(&self) -> usize
pub async fn peer_count(&self) -> usize
Get the number of cached peers
Sourcepub async fn update_capabilities(
&self,
addr: &SocketAddr,
capabilities: PeerCapabilities,
)
pub async fn update_capabilities( &self, addr: &SocketAddr, capabilities: PeerCapabilities, )
Update peer capabilities
Sourcepub async fn contains(&self, addr: &SocketAddr) -> bool
pub async fn contains(&self, addr: &SocketAddr) -> bool
Check if a peer exists in the cache
Sourcepub async fn get_peer(&self, addr: &SocketAddr) -> Option<CachedPeer>
pub async fn get_peer(&self, addr: &SocketAddr) -> Option<CachedPeer>
Get a specific peer from the cache
Sourcepub fn diversity_config(&self) -> &IPDiversityConfig
pub fn diversity_config(&self) -> &IPDiversityConfig
Get the diversity config