Run all igd methods in its own thread (#10195)

This commit is contained in:
Nicolas Gotchac 2019-01-16 16:35:28 +01:00 committed by Afri Schoedon
parent a6c6c7c070
commit 1df6361753

View File

@ -309,14 +309,11 @@ pub fn select_public_address(port: u16) -> SocketAddr {
pub fn map_external_address(local: &NodeEndpoint) -> Option<NodeEndpoint> { pub fn map_external_address(local: &NodeEndpoint) -> Option<NodeEndpoint> {
if let SocketAddr::V4(ref local_addr) = local.address { if let SocketAddr::V4(ref local_addr) = local.address {
let local_ip = *local_addr.ip(); let local_ip = *local_addr.ip();
let local_port = local_addr.port();
let local_udp_port = local.udp_port;
let search_gateway_child = ::std::thread::spawn(move || { let search_gateway_child = ::std::thread::spawn(move || {
search_gateway_from_timeout(local_ip, Duration::new(5, 0)) match search_gateway_from_timeout(local_ip, Duration::new(5, 0)) {
});
let gateway_result = match search_gateway_child.join() {
Err(_) => return None,
Ok(gateway_result) => gateway_result,
};
match gateway_result {
Err(ref err) => debug!("Gateway search error: {}", err), Err(ref err) => debug!("Gateway search error: {}", err),
Ok(gateway) => { Ok(gateway) => {
match gateway.get_external_ip() { match gateway.get_external_ip() {
@ -324,12 +321,12 @@ pub fn map_external_address(local: &NodeEndpoint) -> Option<NodeEndpoint> {
debug!("IP request error: {}", err); debug!("IP request error: {}", err);
}, },
Ok(external_addr) => { Ok(external_addr) => {
match gateway.add_any_port(PortMappingProtocol::TCP, SocketAddrV4::new(*local_addr.ip(), local_addr.port()), 0, "Parity Node/TCP") { match gateway.add_any_port(PortMappingProtocol::TCP, SocketAddrV4::new(local_ip, local_port), 0, "Parity Node/TCP") {
Err(ref err) => { Err(ref err) => {
debug!("Port mapping error: {}", err); debug!("Port mapping error: {}", err);
}, },
Ok(tcp_port) => { Ok(tcp_port) => {
match gateway.add_any_port(PortMappingProtocol::UDP, SocketAddrV4::new(*local_addr.ip(), local.udp_port), 0, "Parity Node/UDP") { match gateway.add_any_port(PortMappingProtocol::UDP, SocketAddrV4::new(local_ip, local_udp_port), 0, "Parity Node/UDP") {
Err(ref err) => { Err(ref err) => {
debug!("Port mapping error: {}", err); debug!("Port mapping error: {}", err);
}, },
@ -343,6 +340,9 @@ pub fn map_external_address(local: &NodeEndpoint) -> Option<NodeEndpoint> {
} }
}, },
} }
None
});
return search_gateway_child.join().ok()?;
} }
None None
} }