Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions neptune-core/src/application/loops/connect_to_peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions neptune-core/src/application/network/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down
Loading