[−][src]Struct tari_comms::PeerManager
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]
database: CommsDatabase,
file_lock: Option<File>
) -> Result<PeerManager, PeerManagerError>
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]
&self,
node_id: &NodeId
) -> Result<(), PeerManagerError>
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]
&self,
peer_query: PeerQuery<'_>
) -> Result<Vec<Peer>, PeerManagerError>
Performs the given PeerQuery.
pub async fn find_by_node_id(
&self,
node_id: &NodeId
) -> Result<Peer, PeerManagerError>
[src]
&self,
node_id: &NodeId
) -> Result<Peer, PeerManagerError>
Find the peer with the provided NodeID
pub async fn find_by_public_key(
&self,
public_key: &CommsPublicKey
) -> Result<Peer, PeerManagerError>
[src]
&self,
public_key: &CommsPublicKey
) -> Result<Peer, PeerManagerError>
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]
&self,
pubkey: &CommsPublicKey,
node_id: NodeId,
addresses: Vec<Multiaddr>,
peer_features: PeerFeatures
) -> Result<Peer, PeerManagerError>
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]
&self,
node_id: &NodeId
) -> Result<Option<Peer>, PeerManagerError>
Get a peer matching the given node ID
pub async fn direct_identity_public_key(
&self,
public_key: &CommsPublicKey
) -> Result<Option<Peer>, PeerManagerError>
[src]
&self,
public_key: &CommsPublicKey
) -> Result<Option<Peer>, PeerManagerError>
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]
F: FnMut(Peer) -> IterationResult,
pub async fn closest_peers(
&self,
node_id: &NodeId,
n: usize,
excluded_peers: &[NodeId],
features: Option<PeerFeatures>
) -> Result<Vec<Peer>, PeerManagerError>
[src]
&self,
node_id: &NodeId,
n: usize,
excluded_peers: &[NodeId],
features: Option<PeerFeatures>
) -> Result<Vec<Peer>, PeerManagerError>
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]
&self,
n: usize,
excluded: &[NodeId]
) -> Result<Vec<Peer>, PeerManagerError>
Fetch n random peers
pub async fn in_network_region(
&self,
node_id: &NodeId,
region_node_id: &NodeId,
n: usize
) -> Result<bool, PeerManagerError>
[src]
&self,
node_id: &NodeId,
region_node_id: &NodeId,
n: usize
) -> Result<bool, PeerManagerError>
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]
&self,
region_node_id: &NodeId,
n: usize,
features: PeerFeatures
) -> Result<NodeDistance, PeerManagerError>
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]
&self,
public_key: &CommsPublicKey,
duration: Duration,
reason: String
) -> Result<NodeId, PeerManagerError>
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]
&self,
node_id: &NodeId,
duration: Duration,
reason: String
) -> Result<NodeId, PeerManagerError>
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]
&self,
node_id: &NodeId,
is_offline: bool
) -> Result<bool, PeerManagerError>
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]
&self,
node_id: &NodeId,
net_address: &Multiaddr
) -> Result<(), PeerManagerError>
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]
F: FnMut(Peer) -> Option<Peer>,
pub async fn get_peer_features(
&self,
node_id: &NodeId
) -> Result<PeerFeatures, PeerManagerError>
[src]
&self,
node_id: &NodeId
) -> Result<PeerFeatures, PeerManagerError>
pub async fn set_peer_metadata(
&self,
node_id: &NodeId,
key: u8,
data: Vec<u8>
) -> Result<Option<Vec<u8>>, PeerManagerError>
[src]
&self,
node_id: &NodeId,
key: u8,
data: Vec<u8>
) -> Result<Option<Vec<u8>>, PeerManagerError>
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
Auto Trait Implementations
impl !RefUnwindSafe for PeerManager
[src]
impl Send for PeerManager
[src]
impl Sync for PeerManager
[src]
impl Unpin for PeerManager
[src]
impl !UnwindSafe for PeerManager
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> Cast<U> for T where
U: FromCast<T>,
U: FromCast<T>,
pub fn cast(self) -> U
impl<T> From<T> for T
[src]
impl<T> FromBits<T> for T
pub fn from_bits(t: T) -> T
impl<T> FromCast<T> for T
pub fn from_cast(t: T) -> T
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> IntoBits<U> for T where
U: FromBits<T>,
U: FromBits<T>,
pub fn into_bits(self) -> U
impl<T> SafeBorrow<T> for T where
T: ?Sized,
T: ?Sized,
pub fn borrow_replacement(ptr: &T) -> &T
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]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,