Move from igd to igd-next (#5068)

* Move from igd to igd-next

* Fix clippy error

warning: useless conversion to the same type: `std::net::IpAddr`
This commit is contained in:
Akihito Nakano 2024-02-01 00:48:01 +09:00 committed by GitHub
parent 8353ec9785
commit b9c519d565
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 45 deletions

35
Cargo.lock generated
View File

@ -362,18 +362,6 @@ dependencies = [
"pin-project-lite", "pin-project-lite",
] ]
[[package]]
name = "attohttpc"
version = "0.16.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fdb8867f378f33f78a811a8eb9bf108ad99430d7aad43315dd9319c827ef6247"
dependencies = [
"http 0.2.11",
"log",
"url",
"wildmatch",
]
[[package]] [[package]]
name = "attohttpc" name = "attohttpc"
version = "0.24.1" version = "0.24.1"
@ -3677,19 +3665,6 @@ dependencies = [
"windows", "windows",
] ]
[[package]]
name = "igd"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "556b5a75cd4adb7c4ea21c64af1c48cefb2ce7d43dc4352c720a1fe47c21f355"
dependencies = [
"attohttpc 0.16.3",
"log",
"rand",
"url",
"xmltree",
]
[[package]] [[package]]
name = "igd-next" name = "igd-next"
version = "0.14.3" version = "0.14.3"
@ -3697,7 +3672,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "064d90fec10d541084e7b39ead8875a5a80d9114a2b18791565253bae25f49e4" checksum = "064d90fec10d541084e7b39ead8875a5a80d9114a2b18791565253bae25f49e4"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"attohttpc 0.24.1", "attohttpc",
"bytes", "bytes",
"futures", "futures",
"http 0.2.11", "http 0.2.11",
@ -5221,7 +5196,7 @@ dependencies = [
"genesis", "genesis",
"hex", "hex",
"if-addrs 0.6.7", "if-addrs 0.6.7",
"igd", "igd-next",
"itertools", "itertools",
"lazy_static", "lazy_static",
"lighthouse_metrics", "lighthouse_metrics",
@ -8966,12 +8941,6 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8" checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8"
[[package]]
name = "wildmatch"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f44b95f62d34113cf558c93511ac93027e03e9c29a60dd0fd70e6e025c7270a"
[[package]] [[package]]
name = "winapi" name = "winapi"
version = "0.3.9" version = "0.3.9"

View File

@ -35,7 +35,7 @@ lazy_static = { workspace = true }
lighthouse_metrics = { workspace = true } lighthouse_metrics = { workspace = true }
logging = { workspace = true } logging = { workspace = true }
task_executor = { workspace = true } task_executor = { workspace = true }
igd = "0.12.1" igd-next = "0.14.3"
itertools = { workspace = true } itertools = { workspace = true }
num_cpus = { workspace = true } num_cpus = { workspace = true }
lru_cache = { workspace = true } lru_cache = { workspace = true }

View File

@ -66,7 +66,7 @@ pub fn construct_upnp_mappings<T: EthSpec>(
log: slog::Logger, log: slog::Logger,
) { ) {
info!(log, "UPnP Attempting to initialise routes"); info!(log, "UPnP Attempting to initialise routes");
match igd::search_gateway(Default::default()) { match igd_next::search_gateway(Default::default()) {
Err(e) => info!(log, "UPnP not available"; "error" => %e), Err(e) => info!(log, "UPnP not available"; "error" => %e),
Ok(gateway) => { Ok(gateway) => {
// Need to find the local listening address matched with the router subnet // Need to find the local listening address matched with the router subnet
@ -109,12 +109,12 @@ pub fn construct_upnp_mappings<T: EthSpec>(
// router, they should ideally try to set different port numbers. // router, they should ideally try to set different port numbers.
mappings.tcp_port = add_port_mapping( mappings.tcp_port = add_port_mapping(
&gateway, &gateway,
igd::PortMappingProtocol::TCP, igd_next::PortMappingProtocol::TCP,
libp2p_socket, libp2p_socket,
"tcp", "tcp",
&log, &log,
).map(|_| { ).map(|_| {
let external_socket = external_ip.as_ref().map(|ip| SocketAddr::new((*ip).into(), config.tcp_port)).map_err(|_| ()); let external_socket = external_ip.as_ref().map(|ip| SocketAddr::new(*ip, config.tcp_port)).map_err(|_| ());
info!(log, "UPnP TCP route established"; "external_socket" => format!("{}:{}", external_socket.as_ref().map(|ip| ip.to_string()).unwrap_or_else(|_| "".into()), config.tcp_port)); info!(log, "UPnP TCP route established"; "external_socket" => format!("{}:{}", external_socket.as_ref().map(|ip| ip.to_string()).unwrap_or_else(|_| "".into()), config.tcp_port));
config.tcp_port config.tcp_port
}).ok(); }).ok();
@ -123,7 +123,7 @@ pub fn construct_upnp_mappings<T: EthSpec>(
let udp_socket = SocketAddrV4::new(address, udp_port); let udp_socket = SocketAddrV4::new(address, udp_port);
add_port_mapping( add_port_mapping(
&gateway, &gateway,
igd::PortMappingProtocol::UDP, igd_next::PortMappingProtocol::UDP,
udp_socket, udp_socket,
"udp", "udp",
&log, &log,
@ -156,8 +156,8 @@ pub fn construct_upnp_mappings<T: EthSpec>(
/// Sets up a port mapping for a protocol returning the mapped port if successful. /// Sets up a port mapping for a protocol returning the mapped port if successful.
fn add_port_mapping( fn add_port_mapping(
gateway: &igd::Gateway, gateway: &igd_next::Gateway,
protocol: igd::PortMappingProtocol, protocol: igd_next::PortMappingProtocol,
socket: SocketAddrV4, socket: SocketAddrV4,
protocol_string: &'static str, protocol_string: &'static str,
log: &slog::Logger, log: &slog::Logger,
@ -168,10 +168,16 @@ fn add_port_mapping(
// router, they should ideally try to set different port numbers. // router, they should ideally try to set different port numbers.
let mapping_string = &format!("lighthouse-{}", protocol_string); let mapping_string = &format!("lighthouse-{}", protocol_string);
for _ in 0..2 { for _ in 0..2 {
match gateway.add_port(protocol, socket.port(), socket, 0, mapping_string) { match gateway.add_port(
protocol,
socket.port(),
SocketAddr::V4(socket),
0,
mapping_string,
) {
Err(e) => { Err(e) => {
match e { match e {
igd::AddPortError::PortInUse => { igd_next::AddPortError::PortInUse => {
// Try and remove and re-create // Try and remove and re-create
debug!(log, "UPnP port in use, attempting to remap"; "protocol" => protocol_string, "port" => socket.port()); debug!(log, "UPnP port in use, attempting to remap"; "protocol" => protocol_string, "port" => socket.port());
match gateway.remove_port(protocol, socket.port()) { match gateway.remove_port(protocol, socket.port()) {
@ -202,10 +208,10 @@ fn add_port_mapping(
pub fn remove_mappings(mappings: &EstablishedUPnPMappings, log: &slog::Logger) { pub fn remove_mappings(mappings: &EstablishedUPnPMappings, log: &slog::Logger) {
if mappings.is_some() { if mappings.is_some() {
debug!(log, "Removing UPnP port mappings"); debug!(log, "Removing UPnP port mappings");
match igd::search_gateway(Default::default()) { match igd_next::search_gateway(Default::default()) {
Ok(gateway) => { Ok(gateway) => {
if let Some(tcp_port) = mappings.tcp_port { if let Some(tcp_port) = mappings.tcp_port {
match gateway.remove_port(igd::PortMappingProtocol::TCP, tcp_port) { match gateway.remove_port(igd_next::PortMappingProtocol::TCP, tcp_port) {
Ok(()) => debug!(log, "UPnP Removed TCP port mapping"; "port" => tcp_port), Ok(()) => debug!(log, "UPnP Removed TCP port mapping"; "port" => tcp_port),
Err(e) => { Err(e) => {
debug!(log, "UPnP Failed to remove TCP port mapping"; "port" => tcp_port, "error" => %e) debug!(log, "UPnP Failed to remove TCP port mapping"; "port" => tcp_port, "error" => %e)
@ -213,7 +219,7 @@ pub fn remove_mappings(mappings: &EstablishedUPnPMappings, log: &slog::Logger) {
} }
} }
for udp_port in mappings.udp_ports() { for udp_port in mappings.udp_ports() {
match gateway.remove_port(igd::PortMappingProtocol::UDP, *udp_port) { match gateway.remove_port(igd_next::PortMappingProtocol::UDP, *udp_port) {
Ok(()) => debug!(log, "UPnP Removed UDP port mapping"; "port" => udp_port), Ok(()) => debug!(log, "UPnP Removed UDP port mapping"; "port" => udp_port),
Err(e) => { Err(e) => {
debug!(log, "UPnP Failed to remove UDP port mapping"; "port" => udp_port, "error" => %e) debug!(log, "UPnP Failed to remove UDP port mapping"; "port" => udp_port, "error" => %e)