@@ -51,37 +51,35 @@ const MAPPING_DURATION: u64 = 3600;
51
51
const MAPPING_TIMEOUT : u64 = MAPPING_DURATION / 2 ;
52
52
53
53
/// Map a port on the gateway.
54
- fn map_port < P : Provider + ' static > (
54
+ async fn map_port < P : Provider + ' static > (
55
55
gateway : Arc < P :: Gateway > ,
56
56
mapping : Mapping ,
57
57
permanent : bool ,
58
- ) -> BoxFuture < ' static , Event > {
58
+ ) -> Event {
59
59
let duration = if permanent { 0 } else { MAPPING_DURATION } ;
60
60
61
- P :: add_port (
61
+ match P :: add_port (
62
62
gateway,
63
63
mapping. protocol ,
64
64
mapping. internal_addr ,
65
65
Duration :: from_secs ( duration) ,
66
66
)
67
- . map ( move |result| match result {
67
+ . await
68
+ {
68
69
Ok ( ( ) ) => Event :: Mapped ( mapping) ,
69
70
Err ( err) => Event :: MapFailure ( mapping, err) ,
70
- } )
71
- . boxed ( )
71
+ }
72
72
}
73
73
74
74
/// Remove a port mapping on the gateway.
75
- fn remove_port_mapping < P : Provider + ' static > (
75
+ async fn remove_port_mapping < P : Provider + ' static > (
76
76
gateway : Arc < P :: Gateway > ,
77
77
mapping : Mapping ,
78
- ) -> BoxFuture < ' static , Event > {
79
- P :: remove_port ( gateway, mapping. protocol , mapping. internal_addr . port ( ) )
80
- . map ( move |result| match result {
81
- Ok ( ( ) ) => Event :: Removed ( mapping) ,
82
- Err ( err) => Event :: RemovalFailure ( mapping, err) ,
83
- } )
84
- . boxed ( )
78
+ ) -> Event {
79
+ match P :: remove_port ( gateway, mapping. protocol , mapping. internal_addr . port ( ) ) . await {
80
+ Ok ( ( ) ) => Event :: Removed ( mapping) ,
81
+ Err ( err) => Event :: RemovalFailure ( mapping, err) ,
82
+ }
85
83
}
86
84
87
85
/// A [`Provider::Gateway`] event.
@@ -260,11 +258,10 @@ where
260
258
multiaddr : multiaddr. clone ( ) ,
261
259
} ;
262
260
263
- self . pending_events . push ( map_port :: < P > (
264
- gateway. clone ( ) ,
265
- mapping. clone ( ) ,
266
- self . config . permanent ,
267
- ) ) ;
261
+ self . pending_events . push (
262
+ map_port :: < P > ( gateway. clone ( ) , mapping. clone ( ) , self . config . permanent )
263
+ . boxed ( ) ,
264
+ ) ;
268
265
269
266
self . mappings . insert ( mapping, MappingState :: Pending ) ;
270
267
}
@@ -281,8 +278,9 @@ where
281
278
} ) => {
282
279
if let GatewayState :: Available ( ( gateway, _external_addr) ) = & self . state {
283
280
if let Some ( ( mapping, _state) ) = self . mappings . remove_entry ( & listener_id) {
284
- self . pending_events
285
- . push ( remove_port_mapping :: < P > ( gateway. clone ( ) , mapping. clone ( ) ) ) ;
281
+ self . pending_events . push (
282
+ remove_port_mapping :: < P > ( gateway. clone ( ) , mapping. clone ( ) ) . boxed ( ) ,
283
+ ) ;
286
284
self . mappings . insert ( mapping, MappingState :: Pending ) ;
287
285
}
288
286
}
@@ -435,8 +433,9 @@ where
435
433
mapping. internal_addr,
436
434
mapping. protocol
437
435
) ;
438
- self . pending_events
439
- . push ( remove_port_mapping :: < P > ( gateway. clone ( ) , mapping) ) ;
436
+ self . pending_events . push (
437
+ remove_port_mapping :: < P > ( gateway. clone ( ) , mapping) . boxed ( ) ,
438
+ ) ;
440
439
}
441
440
}
442
441
}
@@ -445,20 +444,22 @@ where
445
444
for ( mapping, state) in self . mappings . iter_mut ( ) {
446
445
match state {
447
446
MappingState :: Inactive => {
448
- self . pending_events . push ( map_port :: < P > (
449
- gateway. clone ( ) ,
450
- mapping. clone ( ) ,
451
- self . config . permanent ,
452
- ) ) ;
447
+ self . pending_events . push (
448
+ map_port :: < P > (
449
+ gateway. clone ( ) ,
450
+ mapping. clone ( ) ,
451
+ self . config . permanent ,
452
+ )
453
+ . boxed ( ) ,
454
+ ) ;
453
455
* state = MappingState :: Pending ;
454
456
}
455
457
MappingState :: Active ( timeout) => {
456
458
if Pin :: new ( timeout) . poll ( cx) . is_ready ( ) {
457
- self . pending_events . push ( map_port :: < P > (
458
- gateway. clone ( ) ,
459
- mapping. clone ( ) ,
460
- false ,
461
- ) ) ;
459
+ self . pending_events . push (
460
+ map_port :: < P > ( gateway. clone ( ) , mapping. clone ( ) , false )
461
+ . boxed ( ) ,
462
+ ) ;
462
463
}
463
464
}
464
465
MappingState :: Pending | MappingState :: Permanent => { }
0 commit comments