@@ -11,18 +11,15 @@ use serde::{Deserialize, Serialize};
11
11
use stun_rs:: TransactionId ;
12
12
use tracing:: { debug, info, instrument, trace, warn} ;
13
13
14
- use self :: {
15
- best_addr:: ClearReason ,
16
- node_state:: { NodeState , Options , PingHandled } ,
17
- } ;
14
+ use self :: node_state:: { NodeState , Options , PingHandled } ;
18
15
use super :: { ActorMessage , NodeIdMappedAddr , metrics:: Metrics , transports} ;
19
16
use crate :: disco:: { CallMeMaybe , Pong , SendAddr } ;
20
17
#[ cfg( any( test, feature = "test-utils" ) ) ]
21
18
use crate :: endpoint:: PathSelection ;
22
19
23
- mod best_addr;
24
20
mod node_state;
25
21
mod path_state;
22
+ mod path_validity;
26
23
mod udp_paths;
27
24
28
25
pub use node_state:: { ConnectionType , ControlMsg , DirectAddrInfo , RemoteInfo } ;
@@ -196,7 +193,7 @@ impl NodeMap {
196
193
. expect ( "poisoned" )
197
194
. get_mut ( NodeStateKey :: Idx ( id) )
198
195
{
199
- ep. ping_timeout ( tx_id) ;
196
+ ep. ping_timeout ( tx_id, Instant :: now ( ) ) ;
200
197
}
201
198
}
202
199
@@ -266,9 +263,10 @@ impl NodeMap {
266
263
}
267
264
268
265
pub ( super ) fn reset_node_states ( & self ) {
266
+ let now = Instant :: now ( ) ;
269
267
let mut inner = self . inner . lock ( ) . expect ( "poisoned" ) ;
270
268
for ( _, ep) in inner. node_states_mut ( ) {
271
- ep. note_connectivity_change ( ) ;
269
+ ep. note_connectivity_change ( now ) ;
272
270
}
273
271
}
274
272
@@ -317,7 +315,7 @@ impl NodeMap {
317
315
self . inner
318
316
. lock ( )
319
317
. expect ( "poisoned" )
320
- . on_direct_addr_discovered ( discovered) ;
318
+ . on_direct_addr_discovered ( discovered, Instant :: now ( ) ) ;
321
319
}
322
320
}
323
321
@@ -378,24 +376,28 @@ impl NodeMapInner {
378
376
}
379
377
380
378
/// Prunes direct addresses from nodes that claim to share an address we know points to us.
381
- pub ( super ) fn on_direct_addr_discovered ( & mut self , discovered : BTreeSet < SocketAddr > ) {
379
+ pub ( super ) fn on_direct_addr_discovered (
380
+ & mut self ,
381
+ discovered : BTreeSet < SocketAddr > ,
382
+ now : Instant ,
383
+ ) {
382
384
for addr in discovered {
383
- self . remove_by_ipp ( addr. into ( ) , ClearReason :: MatchesOurLocalAddr )
385
+ self . remove_by_ipp ( addr. into ( ) , now , "matches our local addr" )
384
386
}
385
387
}
386
388
387
389
/// Removes a direct address from a node.
388
- fn remove_by_ipp ( & mut self , ipp : IpPort , reason : ClearReason ) {
390
+ fn remove_by_ipp ( & mut self , ipp : IpPort , now : Instant , why : & ' static str ) {
389
391
if let Some ( id) = self . by_ip_port . remove ( & ipp) {
390
392
if let Entry :: Occupied ( mut entry) = self . by_id . entry ( id) {
391
393
let node = entry. get_mut ( ) ;
392
- node. remove_direct_addr ( & ipp, reason ) ;
394
+ node. remove_direct_addr ( & ipp, now , why ) ;
393
395
if node. direct_addresses ( ) . count ( ) == 0 {
394
396
let node_id = node. public_key ( ) ;
395
397
let mapped_addr = node. quic_mapped_addr ( ) ;
396
398
self . by_node_key . remove ( node_id) ;
397
399
self . by_quic_mapped_addr . remove ( mapped_addr) ;
398
- debug ! ( node_id=%node_id. fmt_short( ) , ?reason , "removing node" ) ;
400
+ debug ! ( node_id=%node_id. fmt_short( ) , why , "removing node" ) ;
399
401
entry. remove ( ) ;
400
402
}
401
403
}
@@ -840,7 +842,7 @@ mod tests {
840
842
}
841
843
842
844
info ! ( "Pruning addresses" ) ;
843
- endpoint. prune_direct_addresses ( ) ;
845
+ endpoint. prune_direct_addresses ( Instant :: now ( ) ) ;
844
846
845
847
// Half the offline addresses should have been pruned. All the active and alive
846
848
// addresses should have been kept.
0 commit comments