From 84f0ad2ae7464795a8d2ed92d0d4126eff163b5e Mon Sep 17 00:00:00 2001 From: Age Manning Date: Thu, 21 Mar 2019 13:42:02 +1100 Subject: [PATCH] Add Ping protocol to lighthouse --- beacon_node/eth2-libp2p/src/behaviour.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/beacon_node/eth2-libp2p/src/behaviour.rs b/beacon_node/eth2-libp2p/src/behaviour.rs index a3ac8417f9..458b32cf93 100644 --- a/beacon_node/eth2-libp2p/src/behaviour.rs +++ b/beacon_node/eth2-libp2p/src/behaviour.rs @@ -8,6 +8,7 @@ use libp2p::{ }, gossipsub::{Gossipsub, GossipsubEvent}, identify::{protocol::IdentifyInfo, Identify, IdentifyEvent}, + ping::{Ping, PingEvent}, tokio_io::{AsyncRead, AsyncWrite}, NetworkBehaviour, PeerId, }; @@ -26,10 +27,14 @@ pub struct Behaviour { serenity_rpc: Rpc, /// Allows discovery of IP addresses for peers on the network. identify: Identify, + /// Keep regular connection to peers and disconnect if absent. + // TODO: Keepalive, likely remove this later. + // TODO: Make the ping time customizeable. + ping: Ping, #[behaviour(ignore)] events: Vec, - #[behaviour(ignore)] /// Logger for behaviour actions. + #[behaviour(ignore)] log: slog::Logger, } @@ -88,6 +93,14 @@ impl NetworkBehaviourEventProcess NetworkBehaviourEventProcess + for Behaviour +{ + fn inject_event(&mut self, _event: PingEvent) { + // not interested in ping responses at the moment. + } +} + impl Behaviour { pub fn new(local_public_key: PublicKey, net_conf: &NetworkConfig, log: &slog::Logger) -> Self { let local_peer_id = local_public_key.clone().into_peer_id(); @@ -102,6 +115,7 @@ impl Behaviour { identify_config.user_agent, local_public_key, ), + ping: Ping::new(), events: Vec::new(), log: behaviour_log, }