From 64913d5009816e23adff19fdb96e402baa8f6952 Mon Sep 17 00:00:00 2001 From: arkpar Date: Mon, 15 Feb 2016 21:43:30 +0100 Subject: [PATCH] Additional address filter --- util/src/network/discovery.rs | 6 +++++- util/src/network/host.rs | 8 ++++---- util/src/network/node_table.rs | 7 +++++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/util/src/network/discovery.rs b/util/src/network/discovery.rs index 08f5e5cf1..8ed49b274 100644 --- a/util/src/network/discovery.rs +++ b/util/src/network/discovery.rs @@ -356,7 +356,11 @@ impl Discovery { } let mut entry = NodeEntry { id: node.clone(), endpoint: source.clone() }; if !entry.endpoint.is_valid() { - debug!(target: "discovery", "Bad address: {:?}", entry); + debug!(target: "discovery", "Got bad address: {:?}, using {:?} instead", entry, from); + entry.endpoint.address = from.clone(); + } + if !entry.endpoint.is_global() { + debug!(target: "discovery", "Got local address: {:?}, using {:?} instead", entry, from); entry.endpoint.address = from.clone(); } self.update_node(entry.clone()); diff --git a/util/src/network/host.rs b/util/src/network/host.rs index c548d07cf..806ef2b92 100644 --- a/util/src/network/host.rs +++ b/util/src/network/host.rs @@ -39,7 +39,7 @@ use network::{NetworkProtocolHandler, PROTOCOL_VERSION}; use network::node_table::*; use network::stats::NetworkStats; use network::error::DisconnectReason; -use igd::{PortMappingProtocol,search_gateway}; +use igd::{PortMappingProtocol, search_gateway}; use network::discovery::{Discovery, TableUpdates, NodeEntry}; type Slab = ::slab::Slab; @@ -105,12 +105,12 @@ impl NetworkConfiguration { if self.nat_enabled { info!("Enabling NAT..."); match search_gateway() { - Err(ref err) => info!("Error: {}", err), + Err(ref err) => warn!("Port mapping error: {}", err), Ok(gateway) => { let int_addr = SocketAddrV4::from_str("127.0.0.1:30304").unwrap(); match gateway.get_any_address(PortMappingProtocol::TCP, int_addr, 0, "Parity Node/TCP") { Err(ref err) => { - info!("There was an error! {}", err); + warn!("Port mapping error: {}", err); }, Ok(ext_addr) => { info!("Local gateway: {}, External ip address: {}", gateway, ext_addr); @@ -356,7 +356,7 @@ impl Host where Message: Send + Sync + Clone { }, |s| KeyPair::from_secret(s).expect("Error creating node secret key")) }; - let endpoint = NodeEndpoint { address: addr.clone(), udp_port: addr.port() }; + let endpoint = NodeEndpoint { address: config.public_address.clone(), udp_port: addr.port() }; let discovery = Discovery::new(&keys, endpoint, DISCOVERY); let path = config.config_path.clone(); let mut host = Host:: { diff --git a/util/src/network/node_table.rs b/util/src/network/node_table.rs index 69d12dc87..c152efd4f 100644 --- a/util/src/network/node_table.rs +++ b/util/src/network/node_table.rs @@ -96,6 +96,13 @@ impl NodeEndpoint { SocketAddr::V6(a) => !a.ip().is_unspecified() } } + + pub fn is_global(&self) -> bool { + match self.address { + SocketAddr::V4(a) => a.ip().is_global(), + SocketAddr::V6(a) => a.ip().is_global() + } + } } impl FromStr for NodeEndpoint {