Additional address filter

This commit is contained in:
arkpar 2016-02-15 21:43:30 +01:00
parent 0bef355494
commit 64913d5009
3 changed files with 16 additions and 5 deletions

View File

@ -356,7 +356,11 @@ impl Discovery {
} }
let mut entry = NodeEntry { id: node.clone(), endpoint: source.clone() }; let mut entry = NodeEntry { id: node.clone(), endpoint: source.clone() };
if !entry.endpoint.is_valid() { 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(); entry.endpoint.address = from.clone();
} }
self.update_node(entry.clone()); self.update_node(entry.clone());

View File

@ -105,12 +105,12 @@ impl NetworkConfiguration {
if self.nat_enabled { if self.nat_enabled {
info!("Enabling NAT..."); info!("Enabling NAT...");
match search_gateway() { match search_gateway() {
Err(ref err) => info!("Error: {}", err), Err(ref err) => warn!("Port mapping error: {}", err),
Ok(gateway) => { Ok(gateway) => {
let int_addr = SocketAddrV4::from_str("127.0.0.1:30304").unwrap(); 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") { match gateway.get_any_address(PortMappingProtocol::TCP, int_addr, 0, "Parity Node/TCP") {
Err(ref err) => { Err(ref err) => {
info!("There was an error! {}", err); warn!("Port mapping error: {}", err);
}, },
Ok(ext_addr) => { Ok(ext_addr) => {
info!("Local gateway: {}, External ip address: {}", gateway, ext_addr); info!("Local gateway: {}, External ip address: {}", gateway, ext_addr);
@ -356,7 +356,7 @@ impl<Message> Host<Message> where Message: Send + Sync + Clone {
}, },
|s| KeyPair::from_secret(s).expect("Error creating node secret key")) |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 discovery = Discovery::new(&keys, endpoint, DISCOVERY);
let path = config.config_path.clone(); let path = config.config_path.clone();
let mut host = Host::<Message> { let mut host = Host::<Message> {

View File

@ -96,6 +96,13 @@ impl NodeEndpoint {
SocketAddr::V6(a) => !a.ip().is_unspecified() 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 { impl FromStr for NodeEndpoint {