diff --git a/neptune-core/src/application/loops/connect_to_peers.rs b/neptune-core/src/application/loops/connect_to_peers.rs index 67ba9b8a7..ae1963cf5 100644 --- a/neptune-core/src/application/loops/connect_to_peers.rs +++ b/neptune-core/src/application/loops/connect_to_peers.rs @@ -104,6 +104,8 @@ fn system_time_diff_seconds(peer: SystemTime, own: SystemTime) -> u128 { /// Initial check if incoming connection is allowed. Performed prior to the /// sending of the handshake. +/// +/// Returns false if the transaction should be rejected. pub(crate) fn precheck_incoming_connection_is_allowed( cli: &cli_args::Args, connecting_ip: IpAddr, diff --git a/neptune-core/src/application/network/gateway.rs b/neptune-core/src/application/network/gateway.rs index 54ae09231..75701e93b 100644 --- a/neptune-core/src/application/network/gateway.rs +++ b/neptune-core/src/application/network/gateway.rs @@ -19,6 +19,8 @@ use libp2p::swarm::ToSwarm; use libp2p::Multiaddr; use libp2p::PeerId; +use crate::application::config::parser::multiaddr::multiaddr_to_socketaddr; +use crate::application::loops::connect_to_peers::precheck_incoming_connection_is_allowed; use crate::application::network::actor::NetworkActor; use crate::application::network::handshake::HandshakeResult; use crate::application::network::handshake::HandshakeUpgrade; @@ -376,6 +378,14 @@ impl NetworkBehaviour for StreamGateway { } } + if let Some(incoming) = multiaddr_to_socketaddr(remote_addr) { + let incoming = incoming.ip(); + let allow = precheck_incoming_connection_is_allowed(self.global_state.cli(), incoming); + if !allow { + return Err(libp2p::swarm::ConnectionDenied::new("IP failed precheck")); + } + } + Ok(GatewayHandler { local_handshake: self.handshake_data(), pending_events: VecDeque::new(),