From 807c032facd4671c093a0d2744f27cd668260025 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= Date: Wed, 20 Mar 2024 16:35:46 +0000 Subject: [PATCH] disable libp2p upnp when passing --disable-upnp cli flag --- beacon_node/lighthouse_network/src/service/behaviour.rs | 3 ++- beacon_node/lighthouse_network/src/service/mod.rs | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/beacon_node/lighthouse_network/src/service/behaviour.rs b/beacon_node/lighthouse_network/src/service/behaviour.rs index 5a04d6c2d84..bd94bb88094 100644 --- a/beacon_node/lighthouse_network/src/service/behaviour.rs +++ b/beacon_node/lighthouse_network/src/service/behaviour.rs @@ -5,6 +5,7 @@ use crate::types::SnappyTransform; use crate::gossipsub; use libp2p::identify; +use libp2p::swarm::behaviour::toggle::Toggle; use libp2p::swarm::NetworkBehaviour; use libp2p::upnp::tokio::Behaviour as Upnp; use types::EthSpec; @@ -34,7 +35,7 @@ where /// Provides IP addresses and peer information. pub identify: identify::Behaviour, /// Libp2p UPnP port mapping. - pub upnp: Upnp, + pub upnp: Toggle, /// The routing pub-sub mechanism for eth2. pub gossipsub: Gossipsub, } diff --git a/beacon_node/lighthouse_network/src/service/mod.rs b/beacon_node/lighthouse_network/src/service/mod.rs index aed9d54baab..c6b85c04e3f 100644 --- a/beacon_node/lighthouse_network/src/service/mod.rs +++ b/beacon_node/lighthouse_network/src/service/mod.rs @@ -29,6 +29,7 @@ use api_types::{PeerRequestId, Request, RequestId, Response}; use futures::stream::StreamExt; use gossipsub_scoring_parameters::{lighthouse_gossip_thresholds, PeerScoreSettings}; use libp2p::multiaddr::{self, Multiaddr, Protocol as MProtocol}; +use libp2p::swarm::behaviour::toggle::Toggle; use libp2p::swarm::{Swarm, SwarmEvent}; use libp2p::{identify, PeerId, SwarmBuilder}; use slog::{crit, debug, info, o, trace, warn}; @@ -379,6 +380,11 @@ impl Network { libp2p::connection_limits::Behaviour::new(limits) }; + let upnp = Toggle::from( + config + .upnp_enabled + .then_some(libp2p::upnp::tokio::Behaviour::default()), + ); let behaviour = { Behaviour { gossipsub, @@ -387,7 +393,7 @@ impl Network { identify, peer_manager, connection_limits, - upnp: Default::default(), + upnp, } };