UdpTpuConnection no longer restricts its local port to the 8000-10000 range
This commit is contained in:
parent
b3d1f8d1ac
commit
dd0852bc49
|
@ -19,8 +19,7 @@ pub struct UdpTpuConnection {
|
||||||
impl UdpTpuConnection {
|
impl UdpTpuConnection {
|
||||||
pub fn new(tpu_addr: SocketAddr) -> Self {
|
pub fn new(tpu_addr: SocketAddr) -> Self {
|
||||||
let socket =
|
let socket =
|
||||||
solana_net_utils::bind_in_validator_port_range(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)))
|
solana_net_utils::bind_with_any_port(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0))).unwrap();
|
||||||
.unwrap();
|
|
||||||
socket.set_nonblocking(true).unwrap();
|
socket.set_nonblocking(true).unwrap();
|
||||||
Self::new_with_std_socket(tpu_addr, socket)
|
Self::new_with_std_socket(tpu_addr, socket)
|
||||||
}
|
}
|
||||||
|
@ -104,8 +103,7 @@ mod tests {
|
||||||
let addr_str = "0.0.0.0:50101";
|
let addr_str = "0.0.0.0:50101";
|
||||||
let addr = addr_str.parse().unwrap();
|
let addr = addr_str.parse().unwrap();
|
||||||
let socket =
|
let socket =
|
||||||
solana_net_utils::bind_in_validator_port_range(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)))
|
solana_net_utils::bind_with_any_port(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0))).unwrap();
|
||||||
.unwrap();
|
|
||||||
socket.set_nonblocking(true).unwrap();
|
socket.set_nonblocking(true).unwrap();
|
||||||
let connection = UdpTpuConnection::new_with_std_socket(addr, socket);
|
let connection = UdpTpuConnection::new_with_std_socket(addr, socket);
|
||||||
let reader = UdpSocket::bind(addr_str).await.expect("bind");
|
let reader = UdpSocket::bind(addr_str).await.expect("bind");
|
||||||
|
|
|
@ -20,8 +20,7 @@ pub struct UdpTpuConnection {
|
||||||
impl UdpTpuConnection {
|
impl UdpTpuConnection {
|
||||||
pub fn new_from_addr(tpu_addr: SocketAddr) -> Self {
|
pub fn new_from_addr(tpu_addr: SocketAddr) -> Self {
|
||||||
let socket =
|
let socket =
|
||||||
solana_net_utils::bind_in_validator_port_range(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)))
|
solana_net_utils::bind_with_any_port(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0))).unwrap();
|
||||||
.unwrap();
|
|
||||||
Self {
|
Self {
|
||||||
socket,
|
socket,
|
||||||
addr: tpu_addr,
|
addr: tpu_addr,
|
||||||
|
|
|
@ -439,8 +439,16 @@ pub fn bind_in_range(ip_addr: IpAddr, range: PortRange) -> io::Result<(u16, UdpS
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bind_in_validator_port_range(ip_addr: IpAddr) -> io::Result<UdpSocket> {
|
pub fn bind_with_any_port(ip_addr: IpAddr) -> io::Result<UdpSocket> {
|
||||||
bind_in_range(ip_addr, VALIDATOR_PORT_RANGE).map(|(_, socket)| socket)
|
let sock = udp_socket(false)?;
|
||||||
|
let addr = SocketAddr::new(ip_addr, 0);
|
||||||
|
match sock.bind(&SockAddr::from(addr)) {
|
||||||
|
Ok(_) => Result::Ok(sock.into()),
|
||||||
|
Err(err) => Err(io::Error::new(
|
||||||
|
io::ErrorKind::Other,
|
||||||
|
format!("No available UDP port: {}", err),
|
||||||
|
)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// binds many sockets to the same port in a range
|
// binds many sockets to the same port in a range
|
||||||
|
@ -680,6 +688,17 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_bind_with_any_port() {
|
||||||
|
let ip_addr = IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0));
|
||||||
|
let x = bind_with_any_port(ip_addr).unwrap();
|
||||||
|
let y = bind_with_any_port(ip_addr).unwrap();
|
||||||
|
assert_ne!(
|
||||||
|
x.local_addr().unwrap().port(),
|
||||||
|
y.local_addr().unwrap().port()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_bind_in_range_nil() {
|
fn test_bind_in_range_nil() {
|
||||||
let ip_addr = IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0));
|
let ip_addr = IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0));
|
||||||
|
|
Loading…
Reference in New Issue