mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-08-01 01:11:58 +00:00
transports/tcp: Bind to port, not local IP, when dialing (#2382)
When using PortReuse::Enabled, bind to INADDR_ANY to avoid picking the wrong IP. Co-authored-by: Max Inden <mail@max-inden.de>
This commit is contained in:
@@ -4,6 +4,9 @@
|
||||
|
||||
- Migrate to Rust edition 2021 (see [PR 2339]).
|
||||
|
||||
- When using PortReuse::Enabled, bind to INADDR_ANY to avoid picking the wrong IP (see [PR 2382]).
|
||||
|
||||
[PR 2382]: https://github.com/libp2p/rust-libp2p/pull/2382
|
||||
[PR 2339]: https://github.com/libp2p/rust-libp2p/pull/2339
|
||||
|
||||
# 0.30.0 [2021-11-01]
|
||||
|
@@ -57,7 +57,7 @@ use socket2::{Domain, Socket, Type};
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
io,
|
||||
net::{IpAddr, SocketAddr, TcpListener},
|
||||
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, TcpListener},
|
||||
pin::Pin,
|
||||
sync::{Arc, RwLock},
|
||||
task::{Context, Poll},
|
||||
@@ -151,7 +151,11 @@ impl PortReuse {
|
||||
if ip.is_ipv4() == remote_ip.is_ipv4()
|
||||
&& ip.is_loopback() == remote_ip.is_loopback()
|
||||
{
|
||||
return Some(SocketAddr::new(*ip, *port));
|
||||
if remote_ip.is_ipv4() {
|
||||
return Some(SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), *port));
|
||||
} else {
|
||||
return Some(SocketAddr::new(IpAddr::V6(Ipv6Addr::UNSPECIFIED), *port));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user