[][src]Struct tari_comms::PeerManager

pub struct PeerManager { /* fields omitted */ }

The PeerManager consist of a routing table of previously discovered peers. It also provides functionality to add, find and delete peers.

Implementations

impl PeerManager[src]

pub fn new(database: CommsDatabase) -> Result<PeerManager, PeerManagerError>[src]

Constructs a new empty PeerManager

pub fn migrate_lmdb(database: &LMDBDatabase) -> Result<(), PeerManagerError>[src]

Migrate the peer database, this only applies to the LMDB database

pub async fn count<'_>(&'_ self) -> usize[src]

pub async fn add_peer<'_>(
    &'_ self,
    peer: Peer
) -> Result<PeerId, PeerManagerError>
[src]

Adds a peer to the routing table of the PeerManager if the peer does not already exist. When a peer already exist, the stored version will be replaced with the newly provided peer.

pub async fn delete_peer<'_, '_>(
    &'_ self,
    node_id: &'_ NodeId
) -> Result<(), PeerManagerError>
[src]

The peer with the specified public_key will be removed from the PeerManager

pub async fn perform_query<'_, '_>(
    &'_ self,
    peer_query: PeerQuery<'_>
) -> Result<Vec<Peer>, PeerManagerError>
[src]

Performs the given PeerQuery.

pub async fn find_by_node_id<'_, '_>(
    &'_ self,
    node_id: &'_ NodeId
) -> Result<Peer, PeerManagerError>
[src]

Find the peer with the provided NodeID

pub async fn find_by_public_key<'_, '_>(
    &'_ self,
    public_key: &'_ CommsPublicKey
) -> Result<Peer, PeerManagerError>
[src]

Find the peer with the provided PublicKey

pub async fn exists<'_, '_>(&'_ self, public_key: &'_ CommsPublicKey) -> bool[src]

Check if a peer exist using the specified public_key

pub async fn exists_node_id<'_, '_>(&'_ self, node_id: &'_ NodeId) -> bool[src]

Check if a peer exist using the specified node_id

pub async fn all<'_>(&'_ self) -> Result<Vec<Peer>, PeerManagerError>[src]

Returns all peers

pub async fn add_or_update_online_peer<'_, '_>(
    &'_ self,
    pubkey: &'_ CommsPublicKey,
    node_id: NodeId,
    addresses: Vec<Multiaddr>,
    peer_features: PeerFeatures
) -> Result<Peer, PeerManagerError>
[src]

Adds or updates a peer and sets the last connection as successful. If the peer is marked as offline, it will be unmarked.

pub async fn direct_identity_node_id<'_, '_>(
    &'_ self,
    node_id: &'_ NodeId
) -> Result<Option<Peer>, PeerManagerError>
[src]

Get a peer matching the given node ID

pub async fn direct_identity_public_key<'_, '_>(
    &'_ self,
    public_key: &'_ CommsPublicKey
) -> Result<Option<Peer>, PeerManagerError>
[src]

Get a peer matching the given public key

pub async fn flood_peers<'_>(&'_ self) -> Result<Vec<Peer>, PeerManagerError>[src]

Fetch all peers (except banned ones)

pub async fn for_each<F, '_>(&'_ self, f: F) -> Result<(), PeerManagerError> where
    F: FnMut(Peer) -> IterationResult
[src]

pub async fn closest_peers<'_, '_, '_>(
    &'_ self,
    node_id: &'_ NodeId,
    n: usize,
    excluded_peers: &'_ [CommsPublicKey],
    features: Option<PeerFeatures>
) -> Result<Vec<Peer>, PeerManagerError>
[src]

Fetch n nearest neighbours. If features are supplied, the function will return the closest peers matching that feature

pub async fn random_peers<'_, '_>(
    &'_ self,
    n: usize,
    excluded: &'_ [NodeId]
) -> Result<Vec<Peer>, PeerManagerError>
[src]

Fetch n random peers

pub async fn in_network_region<'_, '_, '_>(
    &'_ self,
    node_id: &'_ NodeId,
    region_node_id: &'_ NodeId,
    n: usize
) -> Result<bool, PeerManagerError>
[src]

Check if a specific node_id is in the network region of the N nearest neighbours of the region specified by region_node_id

pub async fn calc_region_threshold<'_, '_>(
    &'_ self,
    region_node_id: &'_ NodeId,
    n: usize,
    features: PeerFeatures
) -> Result<NodeDistance, PeerManagerError>
[src]

pub async fn unban_peer<'_, '_>(
    &'_ self,
    node_id: &'_ NodeId
) -> Result<(), PeerManagerError>
[src]

Unbans the peer if it is banned. This function is idempotent.

pub async fn ban_peer<'_, '_>(
    &'_ self,
    public_key: &'_ CommsPublicKey,
    duration: Duration
) -> Result<NodeId, PeerManagerError>
[src]

Ban the peer for a length of time specified by the duration

pub async fn ban_peer_by_node_id<'_, '_>(
    &'_ self,
    node_id: &'_ NodeId,
    duration: Duration
) -> Result<NodeId, PeerManagerError>
[src]

Ban the peer for a length of time specified by the duration

pub async fn set_offline<'_, '_>(
    &'_ self,
    node_id: &'_ NodeId,
    is_offline: bool
) -> Result<NodeId, PeerManagerError>
[src]

Changes the offline flag bit of the peer

pub async fn add_net_address<'_, '_, '_>(
    &'_ self,
    node_id: &'_ NodeId,
    net_address: &'_ Multiaddr
) -> Result<(), PeerManagerError>
[src]

Adds a new net address to the peer if it doesn't yet exist

pub async fn update_each<F, '_>(
    &'_ self,
    __arg1: F
) -> Result<usize, PeerManagerError> where
    F: FnMut(Peer) -> Option<Peer>, 
[src]

pub async fn get_peer_features<'_, '_>(
    &'_ self,
    node_id: &'_ NodeId
) -> Result<PeerFeatures, PeerManagerError>
[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T, U> Cast<U> for T where
    U: FromCast<T>, 

impl<T> From<T> for T[src]

impl<T> FromBits<T> for T

impl<T> FromCast<T> for T

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> IntoBits<U> for T where
    U: FromBits<T>, 

impl<T> SafeBorrow<T> for T where
    T: ?Sized

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,