Skip to content

Commit 6417816

Browse files
deps(iroh-next): move from igd to igd-next (#2134)
## Description [`igd`](https://github.com/sbstp/rust-igd) has been archived, [`igd-next`](https://docs.rs/igd-next) it's a replacement. This still does not use hyper 1 but will (hopefully) be [upgraded](dariusc93/rust-igd#4) soon™️ ## Notes & open questions n/a ## Change checklist - [x] Self-review. - [x] Documentation updates if relevant. - [ ] Tests if relevant.
1 parent ff88f65 commit 6417816

File tree

5 files changed

+25
-29
lines changed

5 files changed

+25
-29
lines changed

Cargo.lock

Lines changed: 7 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

iroh-net/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ http = "1"
3434
http-body-util = "0.1.0"
3535
hyper = { version = "1", features = ["server", "client", "http1"] }
3636
hyper-util = "0.1.1"
37-
igd = { version = "0.12.1", features = ["aio"] }
37+
igd-next = { version = "0.14.3", features = ["aio_tokio"] }
3838
iroh-base = { version = "0.13.0", path = "../iroh-base", features = ["key"] }
3939
libc = "0.2.139"
4040
num_enum = "0.7"

iroh-net/src/portmapper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl Client {
210210
struct Probe {
211211
/// When was the probe last updated.
212212
last_probe: Instant,
213-
/// The last [`igd::aio::Gateway`] and when was it last seen.
213+
/// The last [`upnp::Gateway`] and when was it last seen.
214214
last_upnp_gateway_addr: Option<(upnp::Gateway, Instant)>,
215215
/// Last time PCP was seen.
216216
last_pcp: Option<Instant>,

iroh-net/src/portmapper/mapping.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl Mapping {
5757
pub(crate) async fn new_upnp(
5858
local_ip: Ipv4Addr,
5959
local_port: NonZeroU16,
60-
gateway: Option<igd::aio::Gateway>,
60+
gateway: Option<upnp::Gateway>,
6161
external_port: Option<NonZeroU16>,
6262
) -> Result<Self> {
6363
upnp::Mapping::new(local_ip, local_port, gateway, external_port)

iroh-net/src/portmapper/upnp.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ use std::{
44
time::Duration,
55
};
66

7-
use anyhow::Result;
8-
use igd::aio as aigd;
7+
use anyhow::{anyhow, Result};
8+
use igd_next::aio as aigd;
99

1010
use iroh_metrics::inc;
1111
use tracing::debug;
1212

1313
use super::Metrics;
1414

15-
pub use aigd::Gateway;
15+
pub type Gateway = aigd::Gateway<aigd::tokio::Tokio>;
1616

1717
/// Seconds we ask the router to maintain the port mapping. 0 means infinite.
1818
const PORT_MAPPING_LEASE_DURATION_SECONDS: u32 = 0;
@@ -31,7 +31,7 @@ const PORT_MAPPING_DESCRIPTION: &str = "iroh-portmap";
3131
pub struct Mapping {
3232
/// The internet Gateway device (router) used to create this mapping.
3333
#[debug("{}", gateway)]
34-
gateway: aigd::Gateway,
34+
gateway: Gateway,
3535
/// The external address obtained by this mapping.
3636
external_ip: Ipv4Addr,
3737
/// External port obtained by this mapping.
@@ -42,7 +42,7 @@ impl Mapping {
4242
pub(crate) async fn new(
4343
local_addr: Ipv4Addr,
4444
port: NonZeroU16,
45-
gateway: Option<aigd::Gateway>,
45+
gateway: Option<Gateway>,
4646
preferred_port: Option<NonZeroU16>,
4747
) -> Result<Self> {
4848
let local_addr = SocketAddrV4::new(local_addr, port.into());
@@ -51,23 +51,25 @@ impl Mapping {
5151
let gateway = if let Some(known_gateway) = gateway {
5252
known_gateway
5353
} else {
54-
aigd::search_gateway(igd::SearchOptions {
54+
aigd::tokio::search_gateway(igd_next::SearchOptions {
5555
timeout: Some(SEARCH_TIMEOUT),
5656
..Default::default()
5757
})
5858
.await?
5959
};
6060

61-
let external_ip = gateway.get_external_ip().await?;
61+
let std::net::IpAddr::V4(external_ip) = gateway.get_external_ip().await? else {
62+
return Err(anyhow!("igd device's external ip is ipv6"));
63+
};
6264

6365
// if we are trying to get a specific external port, try this first. If this fails, default
6466
// to try to get any port
6567
if let Some(external_port) = preferred_port {
6668
if gateway
6769
.add_port(
68-
igd::PortMappingProtocol::UDP,
70+
igd_next::PortMappingProtocol::UDP,
6971
external_port.into(),
70-
local_addr,
72+
local_addr.into(),
7173
PORT_MAPPING_LEASE_DURATION_SECONDS,
7274
PORT_MAPPING_DESCRIPTION,
7375
)
@@ -84,8 +86,8 @@ impl Mapping {
8486

8587
let external_port = gateway
8688
.add_any_port(
87-
igd::PortMappingProtocol::UDP,
88-
local_addr,
89+
igd_next::PortMappingProtocol::UDP,
90+
local_addr.into(),
8991
PORT_MAPPING_LEASE_DURATION_SECONDS,
9092
PORT_MAPPING_DESCRIPTION,
9193
)
@@ -112,7 +114,7 @@ impl Mapping {
112114
..
113115
} = self;
114116
gateway
115-
.remove_port(igd::PortMappingProtocol::UDP, external_port.into())
117+
.remove_port(igd_next::PortMappingProtocol::UDP, external_port.into())
116118
.await?;
117119
Ok(())
118120
}
@@ -126,7 +128,7 @@ impl Mapping {
126128
/// Searches for UPnP gateways.
127129
pub async fn probe_available() -> Option<Gateway> {
128130
inc!(Metrics, upnp_probes);
129-
match aigd::search_gateway(igd::SearchOptions {
131+
match aigd::tokio::search_gateway(igd_next::SearchOptions {
130132
timeout: Some(SEARCH_TIMEOUT),
131133
..Default::default()
132134
})

0 commit comments

Comments
 (0)