Trait reth_network_api::Peers
source · pub trait Peers: PeersInfo {
Show 19 methods
// Required methods
fn add_trusted_peer_id(&self, peer: PeerId);
fn add_peer_kind(
&self,
peer: PeerId,
kind: PeerKind,
tcp_addr: SocketAddr,
udp_addr: Option<SocketAddr>,
);
fn get_peers_by_kind(
&self,
kind: PeerKind,
) -> impl Future<Output = Result<Vec<PeerInfo>, NetworkError>> + Send;
fn get_all_peers(
&self,
) -> impl Future<Output = Result<Vec<PeerInfo>, NetworkError>> + Send;
fn get_peer_by_id(
&self,
peer_id: PeerId,
) -> impl Future<Output = Result<Option<PeerInfo>, NetworkError>> + Send;
fn get_peers_by_id(
&self,
peer_ids: Vec<PeerId>,
) -> impl Future<Output = Result<Vec<PeerInfo>, NetworkError>> + Send;
fn remove_peer(&self, peer: PeerId, kind: PeerKind);
fn disconnect_peer(&self, peer: PeerId);
fn disconnect_peer_with_reason(
&self,
peer: PeerId,
reason: DisconnectReason,
);
fn connect_peer_kind(
&self,
peer: PeerId,
kind: PeerKind,
tcp_addr: SocketAddr,
udp_addr: Option<SocketAddr>,
);
fn reputation_change(&self, peer_id: PeerId, kind: ReputationChangeKind);
fn reputation_by_id(
&self,
peer_id: PeerId,
) -> impl Future<Output = Result<Option<Reputation>, NetworkError>> + Send;
// Provided methods
fn add_peer(&self, peer: PeerId, tcp_addr: SocketAddr) { ... }
fn add_peer_with_udp(
&self,
peer: PeerId,
tcp_addr: SocketAddr,
udp_addr: SocketAddr,
) { ... }
fn add_trusted_peer(&self, peer: PeerId, tcp_addr: SocketAddr) { ... }
fn add_trusted_peer_with_udp(
&self,
peer: PeerId,
tcp_addr: SocketAddr,
udp_addr: SocketAddr,
) { ... }
fn get_trusted_peers(
&self,
) -> impl Future<Output = Result<Vec<PeerInfo>, NetworkError>> + Send { ... }
fn get_basic_peers(
&self,
) -> impl Future<Output = Result<Vec<PeerInfo>, NetworkError>> + Send { ... }
fn connect_peer(&self, peer: PeerId, tcp_addr: SocketAddr) { ... }
}
Expand description
Provides an API for managing the peers of the network.
Required Methods§
sourcefn add_trusted_peer_id(&self, peer: PeerId)
fn add_trusted_peer_id(&self, peer: PeerId)
Adds a trusted PeerId
to the peer set.
This allows marking a peer as trusted without having to know the peer’s address.
sourcefn add_peer_kind(
&self,
peer: PeerId,
kind: PeerKind,
tcp_addr: SocketAddr,
udp_addr: Option<SocketAddr>,
)
fn add_peer_kind( &self, peer: PeerId, kind: PeerKind, tcp_addr: SocketAddr, udp_addr: Option<SocketAddr>, )
Adds a peer to the known peer set, with the given kind.
sourcefn get_peers_by_kind(
&self,
kind: PeerKind,
) -> impl Future<Output = Result<Vec<PeerInfo>, NetworkError>> + Send
fn get_peers_by_kind( &self, kind: PeerKind, ) -> impl Future<Output = Result<Vec<PeerInfo>, NetworkError>> + Send
Returns the rpc PeerInfo
for all connected peers with the given kind.
sourcefn get_all_peers(
&self,
) -> impl Future<Output = Result<Vec<PeerInfo>, NetworkError>> + Send
fn get_all_peers( &self, ) -> impl Future<Output = Result<Vec<PeerInfo>, NetworkError>> + Send
Returns the rpc PeerInfo
for all connected peers.
sourcefn get_peer_by_id(
&self,
peer_id: PeerId,
) -> impl Future<Output = Result<Option<PeerInfo>, NetworkError>> + Send
fn get_peer_by_id( &self, peer_id: PeerId, ) -> impl Future<Output = Result<Option<PeerInfo>, NetworkError>> + Send
Returns the rpc PeerInfo
for the given peer id.
Returns None
if the peer is not connected.
sourcefn get_peers_by_id(
&self,
peer_ids: Vec<PeerId>,
) -> impl Future<Output = Result<Vec<PeerInfo>, NetworkError>> + Send
fn get_peers_by_id( &self, peer_ids: Vec<PeerId>, ) -> impl Future<Output = Result<Vec<PeerInfo>, NetworkError>> + Send
Returns the rpc PeerInfo
for the given peers if they are connected.
Note: This only returns peers that are connected, unconnected peers are ignored but keeping the order in which they were requested.
sourcefn remove_peer(&self, peer: PeerId, kind: PeerKind)
fn remove_peer(&self, peer: PeerId, kind: PeerKind)
Removes a peer from the peer set that corresponds to given kind.
sourcefn disconnect_peer(&self, peer: PeerId)
fn disconnect_peer(&self, peer: PeerId)
Disconnect an existing connection to the given peer.
sourcefn disconnect_peer_with_reason(&self, peer: PeerId, reason: DisconnectReason)
fn disconnect_peer_with_reason(&self, peer: PeerId, reason: DisconnectReason)
Disconnect an existing connection to the given peer using the provided reason
sourcefn connect_peer_kind(
&self,
peer: PeerId,
kind: PeerKind,
tcp_addr: SocketAddr,
udp_addr: Option<SocketAddr>,
)
fn connect_peer_kind( &self, peer: PeerId, kind: PeerKind, tcp_addr: SocketAddr, udp_addr: Option<SocketAddr>, )
Connects a peer to the known peer set, with the given kind.
sourcefn reputation_change(&self, peer_id: PeerId, kind: ReputationChangeKind)
fn reputation_change(&self, peer_id: PeerId, kind: ReputationChangeKind)
Send a reputation change for the given peer.
sourcefn reputation_by_id(
&self,
peer_id: PeerId,
) -> impl Future<Output = Result<Option<Reputation>, NetworkError>> + Send
fn reputation_by_id( &self, peer_id: PeerId, ) -> impl Future<Output = Result<Option<Reputation>, NetworkError>> + Send
Get the reputation of a peer.
Provided Methods§
sourcefn add_peer(&self, peer: PeerId, tcp_addr: SocketAddr)
fn add_peer(&self, peer: PeerId, tcp_addr: SocketAddr)
Adds a peer to the peer set with TCP SocketAddr
.
sourcefn add_peer_with_udp(
&self,
peer: PeerId,
tcp_addr: SocketAddr,
udp_addr: SocketAddr,
)
fn add_peer_with_udp( &self, peer: PeerId, tcp_addr: SocketAddr, udp_addr: SocketAddr, )
Adds a peer to the peer set with TCP and UDP SocketAddr
.
sourcefn add_trusted_peer(&self, peer: PeerId, tcp_addr: SocketAddr)
fn add_trusted_peer(&self, peer: PeerId, tcp_addr: SocketAddr)
Adds a trusted peer to the peer set with TCP SocketAddr
.
sourcefn add_trusted_peer_with_udp(
&self,
peer: PeerId,
tcp_addr: SocketAddr,
udp_addr: SocketAddr,
)
fn add_trusted_peer_with_udp( &self, peer: PeerId, tcp_addr: SocketAddr, udp_addr: SocketAddr, )
Adds a trusted peer with TCP and UDP SocketAddr
to the peer set.
sourcefn get_trusted_peers(
&self,
) -> impl Future<Output = Result<Vec<PeerInfo>, NetworkError>> + Send
fn get_trusted_peers( &self, ) -> impl Future<Output = Result<Vec<PeerInfo>, NetworkError>> + Send
Returns the rpc PeerInfo
for all connected PeerKind::Trusted
peers.
sourcefn get_basic_peers(
&self,
) -> impl Future<Output = Result<Vec<PeerInfo>, NetworkError>> + Send
fn get_basic_peers( &self, ) -> impl Future<Output = Result<Vec<PeerInfo>, NetworkError>> + Send
Returns the rpc PeerInfo
for all connected PeerKind::Basic
peers.
sourcefn connect_peer(&self, peer: PeerId, tcp_addr: SocketAddr)
fn connect_peer(&self, peer: PeerId, tcp_addr: SocketAddr)
Connect to the given peer. NOTE: if the maximum number out outbound sessions is reached,
this won’t do anything. See reth_network::SessionManager::dial_outbound
.