@@ -4,15 +4,15 @@ use std::{
4
4
time:: Duration ,
5
5
} ;
6
6
7
- use anyhow:: Result ;
8
- use igd :: aio as aigd;
7
+ use anyhow:: { anyhow , Result } ;
8
+ use igd_next :: aio as aigd;
9
9
10
10
use iroh_metrics:: inc;
11
11
use tracing:: debug;
12
12
13
13
use super :: Metrics ;
14
14
15
- pub use aigd:: Gateway ;
15
+ pub type Gateway = aigd:: Gateway < aigd :: tokio :: Tokio > ;
16
16
17
17
/// Seconds we ask the router to maintain the port mapping. 0 means infinite.
18
18
const PORT_MAPPING_LEASE_DURATION_SECONDS : u32 = 0 ;
@@ -31,7 +31,7 @@ const PORT_MAPPING_DESCRIPTION: &str = "iroh-portmap";
31
31
pub struct Mapping {
32
32
/// The internet Gateway device (router) used to create this mapping.
33
33
#[ debug( "{}" , gateway) ]
34
- gateway : aigd :: Gateway ,
34
+ gateway : Gateway ,
35
35
/// The external address obtained by this mapping.
36
36
external_ip : Ipv4Addr ,
37
37
/// External port obtained by this mapping.
@@ -42,7 +42,7 @@ impl Mapping {
42
42
pub ( crate ) async fn new (
43
43
local_addr : Ipv4Addr ,
44
44
port : NonZeroU16 ,
45
- gateway : Option < aigd :: Gateway > ,
45
+ gateway : Option < Gateway > ,
46
46
preferred_port : Option < NonZeroU16 > ,
47
47
) -> Result < Self > {
48
48
let local_addr = SocketAddrV4 :: new ( local_addr, port. into ( ) ) ;
@@ -51,23 +51,25 @@ impl Mapping {
51
51
let gateway = if let Some ( known_gateway) = gateway {
52
52
known_gateway
53
53
} else {
54
- aigd:: search_gateway ( igd :: SearchOptions {
54
+ aigd:: tokio :: search_gateway ( igd_next :: SearchOptions {
55
55
timeout : Some ( SEARCH_TIMEOUT ) ,
56
56
..Default :: default ( )
57
57
} )
58
58
. await ?
59
59
} ;
60
60
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
+ } ;
62
64
63
65
// if we are trying to get a specific external port, try this first. If this fails, default
64
66
// to try to get any port
65
67
if let Some ( external_port) = preferred_port {
66
68
if gateway
67
69
. add_port (
68
- igd :: PortMappingProtocol :: UDP ,
70
+ igd_next :: PortMappingProtocol :: UDP ,
69
71
external_port. into ( ) ,
70
- local_addr,
72
+ local_addr. into ( ) ,
71
73
PORT_MAPPING_LEASE_DURATION_SECONDS ,
72
74
PORT_MAPPING_DESCRIPTION ,
73
75
)
@@ -84,8 +86,8 @@ impl Mapping {
84
86
85
87
let external_port = gateway
86
88
. add_any_port (
87
- igd :: PortMappingProtocol :: UDP ,
88
- local_addr,
89
+ igd_next :: PortMappingProtocol :: UDP ,
90
+ local_addr. into ( ) ,
89
91
PORT_MAPPING_LEASE_DURATION_SECONDS ,
90
92
PORT_MAPPING_DESCRIPTION ,
91
93
)
@@ -112,7 +114,7 @@ impl Mapping {
112
114
..
113
115
} = self ;
114
116
gateway
115
- . remove_port ( igd :: PortMappingProtocol :: UDP , external_port. into ( ) )
117
+ . remove_port ( igd_next :: PortMappingProtocol :: UDP , external_port. into ( ) )
116
118
. await ?;
117
119
Ok ( ( ) )
118
120
}
@@ -126,7 +128,7 @@ impl Mapping {
126
128
/// Searches for UPnP gateways.
127
129
pub async fn probe_available ( ) -> Option < Gateway > {
128
130
inc ! ( Metrics , upnp_probes) ;
129
- match aigd:: search_gateway ( igd :: SearchOptions {
131
+ match aigd:: tokio :: search_gateway ( igd_next :: SearchOptions {
130
132
timeout : Some ( SEARCH_TIMEOUT ) ,
131
133
..Default :: default ( )
132
134
} )
0 commit comments