Trait Peers
pub trait Peers: PeersInfo {
Show 19 methods
// Required methods
fn add_trusted_peer_id(&self, peer: FixedBytes<64>);
fn add_peer_kind(
&self,
peer: FixedBytes<64>,
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: FixedBytes<64>,
) -> impl Future<Output = Result<Option<PeerInfo>, NetworkError>> + Send;
fn get_peers_by_id(
&self,
peer_ids: Vec<FixedBytes<64>>,
) -> impl Future<Output = Result<Vec<PeerInfo>, NetworkError>> + Send;
fn remove_peer(&self, peer: FixedBytes<64>, kind: PeerKind);
fn disconnect_peer(&self, peer: FixedBytes<64>);
fn disconnect_peer_with_reason(
&self,
peer: FixedBytes<64>,
reason: DisconnectReason,
);
fn connect_peer_kind(
&self,
peer: FixedBytes<64>,
kind: PeerKind,
tcp_addr: SocketAddr,
udp_addr: Option<SocketAddr>,
);
fn reputation_change(
&self,
peer_id: FixedBytes<64>,
kind: ReputationChangeKind,
);
fn reputation_by_id(
&self,
peer_id: FixedBytes<64>,
) -> impl Future<Output = Result<Option<i32>, NetworkError>> + Send;
// Provided methods
fn add_peer(&self, peer: FixedBytes<64>, tcp_addr: SocketAddr) { ... }
fn add_peer_with_udp(
&self,
peer: FixedBytes<64>,
tcp_addr: SocketAddr,
udp_addr: SocketAddr,
) { ... }
fn add_trusted_peer(&self, peer: FixedBytes<64>, tcp_addr: SocketAddr) { ... }
fn add_trusted_peer_with_udp(
&self,
peer: FixedBytes<64>,
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: FixedBytes<64>, tcp_addr: SocketAddr) { ... }
}
Expand description
Provides an API for managing the peers of the network.
Required Methods§
fn add_trusted_peer_id(&self, peer: FixedBytes<64>)
fn add_trusted_peer_id(&self, peer: FixedBytes<64>)
Adds a trusted [PeerId
] to the peer set.
This allows marking a peer as trusted without having to know the peer’s address.
fn add_peer_kind(
&self,
peer: FixedBytes<64>,
kind: PeerKind,
tcp_addr: SocketAddr,
udp_addr: Option<SocketAddr>,
)
fn add_peer_kind( &self, peer: FixedBytes<64>, kind: PeerKind, tcp_addr: SocketAddr, udp_addr: Option<SocketAddr>, )
Adds a peer to the known peer set, with the given kind.
fn 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.
fn 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.
fn get_peer_by_id(
&self,
peer_id: FixedBytes<64>,
) -> impl Future<Output = Result<Option<PeerInfo>, NetworkError>> + Send
fn get_peer_by_id( &self, peer_id: FixedBytes<64>, ) -> 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.
fn get_peers_by_id(
&self,
peer_ids: Vec<FixedBytes<64>>,
) -> impl Future<Output = Result<Vec<PeerInfo>, NetworkError>> + Send
fn get_peers_by_id( &self, peer_ids: Vec<FixedBytes<64>>, ) -> 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.
fn remove_peer(&self, peer: FixedBytes<64>, kind: PeerKind)
fn remove_peer(&self, peer: FixedBytes<64>, kind: PeerKind)
Removes a peer from the peer set that corresponds to given kind.
fn disconnect_peer(&self, peer: FixedBytes<64>)
fn disconnect_peer(&self, peer: FixedBytes<64>)
Disconnect an existing connection to the given peer.
fn disconnect_peer_with_reason(
&self,
peer: FixedBytes<64>,
reason: DisconnectReason,
)
fn disconnect_peer_with_reason( &self, peer: FixedBytes<64>, reason: DisconnectReason, )
Disconnect an existing connection to the given peer using the provided reason
fn connect_peer_kind(
&self,
peer: FixedBytes<64>,
kind: PeerKind,
tcp_addr: SocketAddr,
udp_addr: Option<SocketAddr>,
)
fn connect_peer_kind( &self, peer: FixedBytes<64>, kind: PeerKind, tcp_addr: SocketAddr, udp_addr: Option<SocketAddr>, )
Connects a peer to the known peer set, with the given kind.
fn reputation_change(&self, peer_id: FixedBytes<64>, kind: ReputationChangeKind)
fn reputation_change(&self, peer_id: FixedBytes<64>, kind: ReputationChangeKind)
Send a reputation change for the given peer.
Provided Methods§
fn add_peer(&self, peer: FixedBytes<64>, tcp_addr: SocketAddr)
fn add_peer(&self, peer: FixedBytes<64>, tcp_addr: SocketAddr)
Adds a peer to the peer set with TCP SocketAddr
.
fn add_peer_with_udp(
&self,
peer: FixedBytes<64>,
tcp_addr: SocketAddr,
udp_addr: SocketAddr,
)
fn add_peer_with_udp( &self, peer: FixedBytes<64>, tcp_addr: SocketAddr, udp_addr: SocketAddr, )
Adds a peer to the peer set with TCP and UDP SocketAddr
.
fn add_trusted_peer(&self, peer: FixedBytes<64>, tcp_addr: SocketAddr)
fn add_trusted_peer(&self, peer: FixedBytes<64>, tcp_addr: SocketAddr)
Adds a trusted peer to the peer set with TCP SocketAddr
.
fn add_trusted_peer_with_udp(
&self,
peer: FixedBytes<64>,
tcp_addr: SocketAddr,
udp_addr: SocketAddr,
)
fn add_trusted_peer_with_udp( &self, peer: FixedBytes<64>, tcp_addr: SocketAddr, udp_addr: SocketAddr, )
Adds a trusted peer with TCP and UDP SocketAddr
to the peer set.
fn 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.
fn 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.
fn connect_peer(&self, peer: FixedBytes<64>, tcp_addr: SocketAddr)
fn connect_peer(&self, peer: FixedBytes<64>, 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
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.