From ea9404073b453d98aea78f71611456a0ea67f162 Mon Sep 17 00:00:00 2001 From: sistemd Date: Mon, 5 Feb 2024 12:02:18 +0100 Subject: [PATCH] properly pass the ip_whitelist flag --- crates/p2p/src/lib.rs | 18 ------------------ crates/p2p/src/tests.rs | 10 +++++++++- crates/pathfinder/src/bin/pathfinder/config.rs | 2 ++ crates/pathfinder/src/bin/pathfinder/main.rs | 16 ++++++++++------ 4 files changed, 21 insertions(+), 25 deletions(-) diff --git a/crates/p2p/src/lib.rs b/crates/p2p/src/lib.rs index fd585a1475..795fd159a5 100644 --- a/crates/p2p/src/lib.rs +++ b/crates/p2p/src/lib.rs @@ -88,24 +88,6 @@ pub struct Config { pub bootstrap: BootstrapConfig, } -impl Config { - pub fn new( - max_inbound_direct_peers: usize, - max_inbound_relay_peers: usize, - bootstrap: BootstrapConfig, - ) -> Self { - Self { - direct_connection_timeout: Duration::from_secs(30), - relay_connection_timeout: Duration::from_secs(10), - max_inbound_direct_peers, - max_inbound_relayed_peers: max_inbound_relay_peers, - ip_whitelist: vec!["::/0".parse().unwrap(), "0.0.0.0/0".parse().unwrap()], - bootstrap, - eviction_timeout: Duration::from_secs(15 * 60), - } - } -} - #[derive(Copy, Clone, Debug)] pub struct BootstrapConfig { pub start_offset: Duration, diff --git a/crates/p2p/src/tests.rs b/crates/p2p/src/tests.rs index e0d12387d7..8d4f8e7aab 100644 --- a/crates/p2p/src/tests.rs +++ b/crates/p2p/src/tests.rs @@ -82,7 +82,15 @@ impl TestPeer { impl Default for TestPeer { fn default() -> Self { Self::new( - Config::new(10, 10, Default::default()), + Config { + direct_connection_timeout: Duration::from_secs(30), + relay_connection_timeout: Duration::from_secs(10), + max_inbound_direct_peers: 10, + max_inbound_relayed_peers: 10, + ip_whitelist: vec!["::/0".parse().unwrap(), "0.0.0.0/0".parse().unwrap()], + bootstrap: Default::default(), + eviction_timeout: Duration::from_secs(15 * 60), + }, Keypair::generate_ed25519(), ) } diff --git a/crates/pathfinder/src/bin/pathfinder/config.rs b/crates/pathfinder/src/bin/pathfinder/config.rs index 23a656ea9b..954912a067 100644 --- a/crates/pathfinder/src/bin/pathfinder/config.rs +++ b/crates/pathfinder/src/bin/pathfinder/config.rs @@ -549,6 +549,7 @@ pub struct P2PConfig { pub predefined_peers: Vec, pub max_inbound_direct_connections: usize, pub max_inbound_relayed_connections: usize, + pub ip_whitelist: Vec, } #[cfg(not(feature = "p2p"))] @@ -640,6 +641,7 @@ impl P2PConfig { listen_on: args.listen_on, bootstrap_addresses: parse_multiaddr_vec(args.bootstrap_addresses), predefined_peers: parse_multiaddr_vec(args.predefined_peers), + ip_whitelist: args.ip_whitelist, } } } diff --git a/crates/pathfinder/src/bin/pathfinder/main.rs b/crates/pathfinder/src/bin/pathfinder/main.rs index 3322c89c3f..b8117e8a20 100644 --- a/crates/pathfinder/src/bin/pathfinder/main.rs +++ b/crates/pathfinder/src/bin/pathfinder/main.rs @@ -348,7 +348,7 @@ async fn start_p2p( use p2p::libp2p::identity::Keypair; use pathfinder_lib::p2p_network::{client::HybridClient, P2PContext}; use serde::Deserialize; - use std::path::Path; + use std::{path::Path, time::Duration}; use zeroize::Zeroizing; #[derive(Clone, Deserialize)] @@ -381,11 +381,15 @@ async fn start_p2p( }; let context = P2PContext { - cfg: p2p::Config::new( - config.max_inbound_direct_connections, - config.max_inbound_relayed_connections, - Default::default(), - ), + cfg: p2p::Config { + direct_connection_timeout: Duration::from_secs(30), + relay_connection_timeout: Duration::from_secs(10), + max_inbound_direct_peers: config.max_inbound_direct_connections, + max_inbound_relayed_peers: config.max_inbound_relayed_connections, + ip_whitelist: config.ip_whitelist, + bootstrap: Default::default(), + eviction_timeout: Duration::from_secs(15 * 60), + }, chain_id, storage, proxy: config.proxy,