pub struct PeerStore { /* private fields */ }Expand description
Peer store for managing known peers
Implementations§
Source§impl PeerStore
impl PeerStore
Sourcepub fn with_config(config: PeerStoreConfig) -> Self
pub fn with_config(config: PeerStoreConfig) -> Self
Create a new peer store with configuration
Sourcepub fn config(&self) -> &PeerStoreConfig
pub fn config(&self) -> &PeerStoreConfig
Get peer store configuration
Sourcepub fn add_peer(&self, peer_id: PeerId, addrs: Vec<Multiaddr>)
pub fn add_peer(&self, peer_id: PeerId, addrs: Vec<Multiaddr>)
Add or update a peer with addresses
Sourcepub fn peer_connected(&self, peer_id: PeerId)
pub fn peer_connected(&self, peer_id: PeerId)
Record peer connection
Sourcepub fn peer_disconnected(&self, peer_id: &PeerId)
pub fn peer_disconnected(&self, peer_id: &PeerId)
Record peer disconnection
Sourcepub fn update_latency(&self, peer_id: &PeerId, rtt: Duration)
pub fn update_latency(&self, peer_id: &PeerId, rtt: Duration)
Update peer latency from ping
Sourcepub fn update_identify_info(
&self,
peer_id: &PeerId,
protocols: Vec<String>,
agent_version: Option<String>,
protocol_version: Option<String>,
addrs: Vec<Multiaddr>,
)
pub fn update_identify_info( &self, peer_id: &PeerId, protocols: Vec<String>, agent_version: Option<String>, protocol_version: Option<String>, addrs: Vec<Multiaddr>, )
Update peer info from identify
Sourcepub fn increase_reputation(&self, peer_id: &PeerId, amount: u8)
pub fn increase_reputation(&self, peer_id: &PeerId, amount: u8)
Increase peer reputation
Sourcepub fn decrease_reputation(&self, peer_id: &PeerId, amount: u8)
pub fn decrease_reputation(&self, peer_id: &PeerId, amount: u8)
Decrease peer reputation
Sourcepub fn is_connected(&self, peer_id: &PeerId) -> bool
pub fn is_connected(&self, peer_id: &PeerId) -> bool
Check if peer is connected
Sourcepub fn connected_peers(&self) -> Vec<PeerId>
pub fn connected_peers(&self) -> Vec<PeerId>
Get all connected peer IDs
Sourcepub fn connected_count(&self) -> usize
pub fn connected_count(&self) -> usize
Get number of connected peers
Sourcepub fn known_peers(&self) -> Vec<PeerId>
pub fn known_peers(&self) -> Vec<PeerId>
Get all known peer IDs
Sourcepub fn known_count(&self) -> usize
pub fn known_count(&self) -> usize
Get number of known peers
Sourcepub fn peers_by_reputation(&self) -> Vec<PeerInfo>
pub fn peers_by_reputation(&self) -> Vec<PeerInfo>
Get peers sorted by reputation (highest first)
Sourcepub fn peers_by_latency(&self) -> Vec<PeerInfo>
pub fn peers_by_latency(&self) -> Vec<PeerInfo>
Get peers sorted by latency (lowest first)
Sourcepub fn remove_peer(&self, peer_id: &PeerId)
pub fn remove_peer(&self, peer_id: &PeerId)
Remove a peer
Sourcepub fn stats(&self) -> PeerStoreStats
pub fn stats(&self) -> PeerStoreStats
Get peer store statistics
Sourcepub fn save_to_file(&self, path: &Path) -> Result<()>
pub fn save_to_file(&self, path: &Path) -> Result<()>
Save peer store to file
Sourcepub fn load_from_file(&self, path: &Path) -> Result<usize>
pub fn load_from_file(&self, path: &Path) -> Result<usize>
Load peer store from file
Sourcepub fn export_good_peers(&self, min_reputation: u8) -> Vec<PeerInfo>
pub fn export_good_peers(&self, min_reputation: u8) -> Vec<PeerInfo>
Export peers with high reputation (for sharing)
Sourcepub fn import_peers(&self, peers: &[PeerInfo]) -> usize
pub fn import_peers(&self, peers: &[PeerInfo]) -> usize
Import peers from another source
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PeerStore
impl !RefUnwindSafe for PeerStore
impl Send for PeerStore
impl Sync for PeerStore
impl Unpin for PeerStore
impl !UnwindSafe for PeerStore
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more