8
8
use std:: { collections:: BTreeMap , net:: SocketAddr } ;
9
9
10
10
use n0_future:: time:: Instant ;
11
+ use tracing:: { event, Level } ;
11
12
12
13
use super :: { path_state:: PathState , IpPort } ;
13
14
@@ -24,7 +25,7 @@ use super::{path_state::PathState, IpPort};
24
25
///
25
26
/// [`MagicSock`]: crate::magicsock::MagicSock
26
27
/// [`NodeState`]: super::node_state::NodeState
27
- #[ derive( Debug , Default , Clone , Copy ) ]
28
+ #[ derive( Debug , Default , Clone , Copy , PartialEq , Eq ) ]
28
29
pub ( super ) enum UdpSendAddr {
29
30
/// The UDP address can be relied on to deliver data to the remote node.
30
31
///
@@ -113,9 +114,34 @@ impl NodeUdpPaths {
113
114
& self . best
114
115
}
115
116
116
- pub ( super ) fn update_to_best_addr ( & mut self , now : Instant ) {
117
- self . best_ipv4 = self . best_addr ( false , now) ;
118
- self . best = self . best_addr ( true , now) ;
117
+ /// Changes the current best address(es) to ones chosen as described in [`Self::best_addr`] docs.
118
+ ///
119
+ /// Returns whether one of the best addresses had to change.
120
+ ///
121
+ /// This should be called any time that `paths` is modified.
122
+ pub ( super ) fn update_to_best_addr ( & mut self , now : Instant ) -> bool {
123
+ let best_ipv4 = self . best_addr ( false , now) ;
124
+ let best = self . best_addr ( true , now) ;
125
+ let mut changed = false ;
126
+ if best_ipv4 != self . best_ipv4 {
127
+ event ! (
128
+ target: "iroh::_events::udp::best_ipv4" ,
129
+ Level :: DEBUG ,
130
+ ?best_ipv4,
131
+ ) ;
132
+ changed = true ;
133
+ }
134
+ if best != self . best {
135
+ event ! (
136
+ target: "iroh::_events::udp::best" ,
137
+ Level :: DEBUG ,
138
+ ?best,
139
+ ) ;
140
+ changed = true ;
141
+ }
142
+ self . best_ipv4 = best_ipv4;
143
+ self . best = best;
144
+ changed
119
145
}
120
146
121
147
pub ( super ) fn best_addr ( & self , have_ipv6 : bool , now : Instant ) -> UdpSendAddr {
0 commit comments