feat : add the ability to connect to a peer (#10028)

Co-authored-by: Emilia Hane <emiliaha95@gmail.com>
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
nk_ysg
2024-08-24 15:16:34 +08:00
committed by GitHub
parent a7a9f9f3b3
commit 22f928a2b1
7 changed files with 150 additions and 0 deletions

View File

@ -184,6 +184,21 @@ pub trait Peers: PeersInfo {
/// Disconnect an existing connection to the given peer using the provided reason
fn disconnect_peer_with_reason(&self, peer: PeerId, reason: DisconnectReason);
/// 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`.
fn connect_peer(&self, peer: PeerId, tcp_addr: SocketAddr) {
self.connect_peer_kind(peer, PeerKind::Static, tcp_addr, None)
}
/// Connects a peer to the known peer set, with the given kind.
fn connect_peer_kind(
&self,
peer: PeerId,
kind: PeerKind,
tcp_addr: SocketAddr,
udp_addr: Option<SocketAddr>,
);
/// Send a reputation change for the given peer.
fn reputation_change(&self, peer_id: PeerId, kind: ReputationChangeKind);

View File

@ -102,6 +102,15 @@ impl Peers for NoopNetwork {
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) {}
async fn reputation_by_id(&self, _peer_id: PeerId) -> Result<Option<Reputation>, NetworkError> {