Add BROKEN_NAT env variable to select Udp sender port workaround
This commit is contained in:
parent
0b56d603c2
commit
903ec27754
32
src/nat.rs
32
src/nat.rs
|
@ -8,6 +8,7 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr, UdpSocket};
|
||||||
|
|
||||||
use self::futures::Future;
|
use self::futures::Future;
|
||||||
use self::p2p::UdpSocketExt;
|
use self::p2p::UdpSocketExt;
|
||||||
|
use std::env;
|
||||||
|
|
||||||
/// A data type representing a public Udp socket
|
/// A data type representing a public Udp socket
|
||||||
pub struct UdpSocketPair {
|
pub struct UdpSocketPair {
|
||||||
|
@ -42,19 +43,24 @@ pub fn udp_public_bind(label: &str) -> UdpSocketPair {
|
||||||
// |public_addr| to the local |receiver| socket...
|
// |public_addr| to the local |receiver| socket...
|
||||||
let receiver = UdpSocket::bind(local_addr).unwrap();
|
let receiver = UdpSocket::bind(local_addr).unwrap();
|
||||||
|
|
||||||
// ... however for outbound packets, the NAT *will not* rewrite the
|
// TODO: try to autodetect a broken NAT (issue #496)
|
||||||
// source port from |receiver.local_addr().port()| to |public_addr.port()|.
|
let sender = if env::var("BROKEN_NAT").is_err() {
|
||||||
// This is currently a problem when talking with a fullnode as it
|
receiver.try_clone().unwrap()
|
||||||
// assumes it can send UDP packets back at the source. This hits the
|
} else {
|
||||||
// NAT as a datagram for |receiver.local_addr().port()| on the NAT's public
|
// ... however for outbound packets, some NATs *will not* rewrite the
|
||||||
// IP, which the NAT promptly discards. As a short term hack, create a
|
// source port from |receiver.local_addr().port()| to |public_addr.port()|.
|
||||||
// local UDP socket, |sender|, with the same port as |public_addr.port()|.
|
// This is currently a problem when talking with a fullnode as it
|
||||||
//
|
// assumes it can send UDP packets back at the source. This hits the
|
||||||
// TODO: Remove the |sender| socket and deal with the downstream changes to
|
// NAT as a datagram for |receiver.local_addr().port()| on the NAT's public
|
||||||
// the UDP signalling
|
// IP, which the NAT promptly discards. As a short term hack, create a
|
||||||
let mut local_addr_sender = local_addr.clone();
|
// local UDP socket, |sender|, with the same port as |public_addr.port()|.
|
||||||
local_addr_sender.set_port(public_addr.port());
|
//
|
||||||
let sender = UdpSocket::bind(local_addr_sender).unwrap();
|
// TODO: Remove the |sender| socket and deal with the downstream changes to
|
||||||
|
// the UDP signalling
|
||||||
|
let mut local_addr_sender = local_addr.clone();
|
||||||
|
local_addr_sender.set_port(public_addr.port());
|
||||||
|
UdpSocket::bind(local_addr_sender).unwrap()
|
||||||
|
};
|
||||||
|
|
||||||
UdpSocketPair {
|
UdpSocketPair {
|
||||||
addr: public_addr,
|
addr: public_addr,
|
||||||
|
|
Loading…
Reference in New Issue