[][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,
    file_lock: Option<File>
) -> 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: &[NodeId],
    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,
    reason: String
) -> 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,
    reason: String
) -> 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<bool, PeerManagerError>
[src]

Changes the offline flag bit of the peer. Return the previous offline state.

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, f: 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]

pub async fn set_peer_metadata(
    &self,
    node_id: &NodeId,
    key: u8,
    data: Vec<u8>
) -> Result<Option<Vec<u8>>, PeerManagerError>
[src]

This will store metadata inside of the metadata field in the peer provided by the nodeID. It will return None if the value was empty and the old value if the value was updated

Trait Implementations

impl Debug for PeerManager[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> Instrument for T[src]

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>,