@@ -11,18 +11,15 @@ use serde::{Deserialize, Serialize};
1111use stun_rs:: TransactionId ;
1212use tracing:: { debug, info, instrument, trace, warn} ;
1313
14- use self :: {
15- best_addr:: ClearReason ,
16- node_state:: { NodeState , Options , PingHandled } ,
17- } ;
14+ use self :: node_state:: { NodeState , Options , PingHandled } ;
1815use super :: { ActorMessage , NodeIdMappedAddr , metrics:: Metrics , transports} ;
1916use crate :: disco:: { CallMeMaybe , Pong , SendAddr } ;
2017#[ cfg( any( test, feature = "test-utils" ) ) ]
2118use crate :: endpoint:: PathSelection ;
2219
23- mod best_addr;
2420mod node_state;
2521mod path_state;
22+ mod path_validity;
2623mod udp_paths;
2724
2825pub use node_state:: { ConnectionType , ControlMsg , DirectAddrInfo , RemoteInfo } ;
@@ -196,7 +193,7 @@ impl NodeMap {
196193 . expect ( "poisoned" )
197194 . get_mut ( NodeStateKey :: Idx ( id) )
198195 {
199- ep. ping_timeout ( tx_id) ;
196+ ep. ping_timeout ( tx_id, Instant :: now ( ) ) ;
200197 }
201198 }
202199
@@ -266,9 +263,10 @@ impl NodeMap {
266263 }
267264
268265 pub ( super ) fn reset_node_states ( & self ) {
266+ let now = Instant :: now ( ) ;
269267 let mut inner = self . inner . lock ( ) . expect ( "poisoned" ) ;
270268 for ( _, ep) in inner. node_states_mut ( ) {
271- ep. note_connectivity_change ( ) ;
269+ ep. note_connectivity_change ( now ) ;
272270 }
273271 }
274272
@@ -317,7 +315,7 @@ impl NodeMap {
317315 self . inner
318316 . lock ( )
319317 . expect ( "poisoned" )
320- . on_direct_addr_discovered ( discovered) ;
318+ . on_direct_addr_discovered ( discovered, Instant :: now ( ) ) ;
321319 }
322320}
323321
@@ -378,24 +376,28 @@ impl NodeMapInner {
378376 }
379377
380378 /// 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+ ) {
382384 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" )
384386 }
385387 }
386388
387389 /// 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 ) {
389391 if let Some ( id) = self . by_ip_port . remove ( & ipp) {
390392 if let Entry :: Occupied ( mut entry) = self . by_id . entry ( id) {
391393 let node = entry. get_mut ( ) ;
392- node. remove_direct_addr ( & ipp, reason ) ;
394+ node. remove_direct_addr ( & ipp, now , why ) ;
393395 if node. direct_addresses ( ) . count ( ) == 0 {
394396 let node_id = node. public_key ( ) ;
395397 let mapped_addr = node. quic_mapped_addr ( ) ;
396398 self . by_node_key . remove ( node_id) ;
397399 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" ) ;
399401 entry. remove ( ) ;
400402 }
401403 }
@@ -840,7 +842,7 @@ mod tests {
840842 }
841843
842844 info ! ( "Pruning addresses" ) ;
843- endpoint. prune_direct_addresses ( ) ;
845+ endpoint. prune_direct_addresses ( Instant :: now ( ) ) ;
844846
845847 // Half the offline addresses should have been pruned. All the active and alive
846848 // addresses should have been kept.
0 commit comments