Skip to content

Commit

Permalink
add basic peer manager code
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomrsantos committed Jan 16, 2025
1 parent bc48f41 commit e04e07a
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
3 changes: 3 additions & 0 deletions anchor/network/src/behaviour.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::discovery::Discovery;
use crate::peer_manager::PeerManager;
use libp2p::swarm::NetworkBehaviour;
use libp2p::{gossipsub, identify, ping};

Expand All @@ -12,4 +13,6 @@ pub struct AnchorBehaviour {
pub gossipsub: gossipsub::Behaviour,
/// Discv5 Discovery protocol.
pub discovery: Discovery,
/// The peer manager that keeps track of peer's reputation and status.
pub peer_manager: PeerManager,
}
1 change: 1 addition & 0 deletions anchor/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod config;
mod discovery;
mod keypair_utils;
mod network;
mod peer_manager;
mod transport;
pub mod types;

Expand Down
4 changes: 4 additions & 0 deletions anchor/network/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::keypair_utils::load_private_key;
use crate::transport::build_transport;
use crate::Config;

use crate::peer_manager::PeerManager;
use crate::types::ssv_message::SignedSSVMessage;
use lighthouse_network::EnrExt;
use ssz::Decode;
Expand Down Expand Up @@ -217,11 +218,14 @@ async fn build_anchor_behaviour(
discovery
};

let peer_manager = PeerManager::new();

AnchorBehaviour {
identify,
ping: ping::Behaviour::default(),
gossipsub,
discovery,
peer_manager,
}
}

Expand Down
62 changes: 62 additions & 0 deletions anchor/network/src/peer_manager.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use discv5::libp2p_identity::PeerId;
use discv5::multiaddr::Multiaddr;
use libp2p::core::transport::PortUse;
use libp2p::core::Endpoint;
use libp2p::swarm::dummy::ConnectionHandler;
use libp2p::swarm::{
ConnectionDenied, ConnectionId, FromSwarm, NetworkBehaviour, THandler, THandlerInEvent,
THandlerOutEvent, ToSwarm,
};
use std::task::{Context, Poll};

pub struct PeerManager {}

impl PeerManager {
pub fn new() -> Self {
Self {}
}
}

impl NetworkBehaviour for PeerManager {
type ConnectionHandler = ConnectionHandler;
type ToSwarm = ();

fn handle_established_inbound_connection(
&mut self,
_connection_id: ConnectionId,
peer: PeerId,
local_addr: &Multiaddr,
remote_addr: &Multiaddr,
) -> Result<THandler<Self>, ConnectionDenied> {
todo!()
}

fn handle_established_outbound_connection(
&mut self,
_connection_id: ConnectionId,
peer: PeerId,
addr: &Multiaddr,
role_override: Endpoint,
port_use: PortUse,
) -> Result<THandler<Self>, ConnectionDenied> {
todo!()
}

fn on_swarm_event(&mut self, event: FromSwarm) {}

fn on_connection_handler_event(
&mut self,
_peer_id: PeerId,
_connection_id: ConnectionId,
_event: THandlerOutEvent<Self>,
) {
todo!()
}

fn poll(
&mut self,
cx: &mut Context<'_>,
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
todo!()
}
}

0 comments on commit e04e07a

Please sign in to comment.