From 32893e87a065a6ddca41a2d9566c7b484f87789c Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Mon, 17 Jun 2024 13:07:27 +0200 Subject: [PATCH] Rename the type DirectAddr This is more in line with other Addrs, e.g. SocketAddr. --- iroh-gossip/src/net.rs | 6 ++--- iroh-net/src/endpoint.rs | 4 +-- iroh-net/src/magicsock.rs | 56 ++++++++++++++++++--------------------- 3 files changed, 31 insertions(+), 35 deletions(-) diff --git a/iroh-gossip/src/net.rs b/iroh-gossip/src/net.rs index adac248824..5bbac2cf58 100644 --- a/iroh-gossip/src/net.rs +++ b/iroh-gossip/src/net.rs @@ -70,7 +70,7 @@ type ProtoMessage = proto::Message; #[derive(Debug, Clone)] pub struct Gossip { to_actor_tx: mpsc::Sender, - on_direct_addrs_tx: mpsc::Sender>, + on_direct_addrs_tx: mpsc::Sender>, _actor_handle: Arc>>, max_message_size: usize, } @@ -249,7 +249,7 @@ impl Gossip { /// This is only best effort, and will drop new events if backed up. pub fn update_direct_addresses( &self, - addrs: &[iroh_net::endpoint::DirectAddress], + addrs: &[iroh_net::endpoint::DirectAddr], ) -> anyhow::Result<()> { let addrs = addrs.to_vec(); self.on_direct_addrs_tx @@ -345,7 +345,7 @@ struct Actor { /// Input events to the state (emitted from the connection loops) in_event_rx: mpsc::Receiver, /// Updates of discovered endpoint addresses - on_direct_addr_rx: mpsc::Receiver>, + on_direct_addr_rx: mpsc::Receiver>, /// Queued timers timers: Timers, /// Currently opened quinn connections to peers diff --git a/iroh-net/src/endpoint.rs b/iroh-net/src/endpoint.rs index fb1542a97a..8f0e6510c0 100644 --- a/iroh-net/src/endpoint.rs +++ b/iroh-net/src/endpoint.rs @@ -47,8 +47,8 @@ pub use quinn::{ }; pub use super::magicsock::{ - ConnectionInfo, ConnectionType, ConnectionTypeStream, ControlMsg, DirectAddrInfo, - DirectAddress, DirectAddressType, DirectAdressesStream, + ConnectionInfo, ConnectionType, ConnectionTypeStream, ControlMsg, DirectAddr, DirectAddrInfo, + DirectAddrType, DirectAdressesStream, }; pub use iroh_base::node_addr::{AddrInfo, NodeAddr}; diff --git a/iroh-net/src/magicsock.rs b/iroh-net/src/magicsock.rs index 118912f419..375868d6ef 100644 --- a/iroh-net/src/magicsock.rs +++ b/iroh-net/src/magicsock.rs @@ -1499,7 +1499,7 @@ pub struct DirectAdressesStream { } impl Stream for DirectAdressesStream { - type Item = Vec; + type Item = Vec; fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { let this = &mut *self; @@ -1582,7 +1582,7 @@ enum DiscoBoxError { type RelayRecvResult = Result<(PublicKey, quinn_udp::RecvMeta, Bytes), io::Error>; /// Reports whether x and y represent the same set of endpoints. The order doesn't matter. -fn endpoint_sets_equal(xs: &[DirectAddress], ys: &[DirectAddress]) -> bool { +fn endpoint_sets_equal(xs: &[DirectAddr], ys: &[DirectAddr]) -> bool { if xs.is_empty() && ys.is_empty() { return true; } @@ -1598,7 +1598,7 @@ fn endpoint_sets_equal(xs: &[DirectAddress], ys: &[DirectAddress]) -> bool { return true; } } - let mut m: HashMap<&DirectAddress, usize> = HashMap::new(); + let mut m: HashMap<&DirectAddr, usize> = HashMap::new(); for x in xs { *m.entry(x).or_default() |= 1; } @@ -1962,7 +1962,7 @@ impl Actor { #[allow(clippy::map_entry)] if !$already.contains_key(&$ipp) { $already.insert($ipp, $et); - $eps.push(DirectAddress { + $eps.push(DirectAddr { addr: $ipp, typ: $et, }); @@ -1973,13 +1973,13 @@ impl Actor { let maybe_port_mapped = *portmap_watcher.borrow(); if let Some(portmap_ext) = maybe_port_mapped.map(SocketAddr::V4) { - add_addr!(already, eps, portmap_ext, DirectAddressType::Portmapped); + add_addr!(already, eps, portmap_ext, DirectAddrType::Portmapped); self.set_net_info_have_port_map().await; } if let Some(nr) = nr { if let Some(global_v4) = nr.global_v4 { - add_addr!(already, eps, global_v4.into(), DirectAddressType::Stun); + add_addr!(already, eps, global_v4.into(), DirectAddrType::Stun); // If they're behind a hard NAT and are using a fixed // port locally, assume they might've added a static @@ -1989,11 +1989,11 @@ impl Actor { if nr.mapping_varies_by_dest_ip.unwrap_or_default() && port != 0 { let mut addr = global_v4; addr.set_port(port); - add_addr!(already, eps, addr.into(), DirectAddressType::Stun4LocalPort); + add_addr!(already, eps, addr.into(), DirectAddrType::Stun4LocalPort); } } if let Some(global_v6) = nr.global_v6 { - add_addr!(already, eps, global_v6.into(), DirectAddressType::Stun); + add_addr!(already, eps, global_v6.into(), DirectAddrType::Stun); } } let local_addr_v4 = self.pconn4.local_addr().ok(); @@ -2051,7 +2051,7 @@ impl Actor { already, eps, SocketAddr::new(ip, port), - DirectAddressType::Local + DirectAddrType::Local ); } } @@ -2061,7 +2061,7 @@ impl Actor { already, eps, SocketAddr::new(ip, port), - DirectAddressType::Local + DirectAddrType::Local ); } } @@ -2073,7 +2073,7 @@ impl Actor { if let Some(addr) = local_addr_v4 { // Our local endpoint is bound to a particular address. // Do not offer addresses on other local interfaces. - add_addr!(already, eps, addr, DirectAddressType::Local); + add_addr!(already, eps, addr, DirectAddrType::Local); } } @@ -2081,7 +2081,7 @@ impl Actor { if let Some(addr) = local_addr_v6 { // Our local endpoint is bound to a particular address. // Do not offer addresses on other local interfaces. - add_addr!(already, eps, addr, DirectAddressType::Local); + add_addr!(already, eps, addr, DirectAddrType::Local); } } @@ -2402,7 +2402,7 @@ fn bind(port: u16) -> Result<(UdpConn, Option)> { struct DiscoveredEndpoints { /// Records the endpoints found during the previous /// endpoint discovery. It's used to avoid duplicate endpoint change notifications. - last_endpoints: Vec, + last_endpoints: Vec, /// The last time the endpoints were updated, even if there was no change. last_endpoints_time: Option, @@ -2415,18 +2415,18 @@ impl PartialEq for DiscoveredEndpoints { } impl DiscoveredEndpoints { - fn new(endpoints: Vec) -> Self { + fn new(endpoints: Vec) -> Self { Self { last_endpoints: endpoints, last_endpoints_time: Some(Instant::now()), } } - fn into_iter(self) -> impl Iterator { + fn into_iter(self) -> impl Iterator { self.last_endpoints.into_iter() } - fn iter(&self) -> impl Iterator + '_ { + fn iter(&self) -> impl Iterator + '_ { self.last_endpoints.iter() } @@ -2592,11 +2592,11 @@ fn disco_message_sent(msg: &disco::Message) { /// contacted. These can come from various sources depending on the network topology of the /// iroh-net node, see [`DirectAddressType`] for the several kinds of sources. #[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] -pub struct DirectAddress { +pub struct DirectAddr { /// The address. pub addr: SocketAddr, /// The origin of this direct address. - pub typ: DirectAddressType, + pub typ: DirectAddrType, } /// The type of direct address. @@ -2604,7 +2604,7 @@ pub struct DirectAddress { /// These are the various sources or origins from which an iroh-net node might have found a /// possible [`DirectAddress`]. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] -pub enum DirectAddressType { +pub enum DirectAddrType { /// Not yet determined.. Unknown, /// A locally bound socket address. @@ -2628,14 +2628,14 @@ pub enum DirectAddressType { Stun4LocalPort, } -impl Display for DirectAddressType { +impl Display for DirectAddrType { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - DirectAddressType::Unknown => write!(f, "?"), - DirectAddressType::Local => write!(f, "local"), - DirectAddressType::Stun => write!(f, "stun"), - DirectAddressType::Portmapped => write!(f, "portmap"), - DirectAddressType::Stun4LocalPort => write!(f, "stun4localport"), + DirectAddrType::Unknown => write!(f, "?"), + DirectAddrType::Local => write!(f, "local"), + DirectAddrType::Stun => write!(f, "stun"), + DirectAddrType::Portmapped => write!(f, "portmap"), + DirectAddrType::Stun4LocalPort => write!(f, "stun4localport"), } } } @@ -2773,11 +2773,7 @@ pub(crate) mod tests { #[instrument(skip_all)] async fn mesh_stacks(stacks: Vec) -> Result { /// Registers endpoint addresses of a node to all other nodes. - fn update_direct_addrs( - stacks: &[MagicStack], - my_idx: usize, - new_addrs: Vec, - ) { + fn update_direct_addrs(stacks: &[MagicStack], my_idx: usize, new_addrs: Vec) { let me = &stacks[my_idx]; for (i, m) in stacks.iter().enumerate() { if i == my_idx {