From 000f0351d8b8e971d27dbec780550eb5f8fc9444 Mon Sep 17 00:00:00 2001 From: Richard Watts Date: Tue, 19 Nov 2024 16:40:38 +0000 Subject: [PATCH] (feat) Allow whitelisted local addresses, so that local z2 networks can communicate --- zilliqa/src/p2p_node.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/zilliqa/src/p2p_node.rs b/zilliqa/src/p2p_node.rs index 1c1cedbcf..0893c9f62 100644 --- a/zilliqa/src/p2p_node.rs +++ b/zilliqa/src/p2p_node.rs @@ -3,6 +3,7 @@ use std::{ collections::HashMap, iter, + ops::BitAnd, sync::{atomic::AtomicUsize, Arc}, time::Duration, }; @@ -252,7 +253,17 @@ impl P2pNode { for addr in listen_addrs { // If the node is advertising a non-global address, ignore it. let is_non_global = addr.iter().any(|p| match p { - Protocol::Ip4(addr) => addr.is_loopback() || addr.is_private(), + Protocol::Ip4(addr) => { + if let Some((net, mask)) = self.config.listening_subnet { + let left = net.bitand(mask); + let right = addr.bitand(mask); + if left == right { + info!("p2p_identify: {addr:?} is in the listening subnet - passing"); + return false; + } + } + addr.is_loopback() || addr.is_private() + }, Protocol::Ip6(addr) => addr.is_loopback(), _ => false, });