From 9039b02077ff0b6853a489a746239d212fbfc6bd Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Tue, 18 Jun 2024 01:43:45 +0200 Subject: [PATCH] refactor(iroh-net)!: Rename Endpoint::local_addr to bound_sockets (#2366) ## Description This renames Endpoint::local_addr to Endpoint::bound_sockets. We have a lot of different meanings for "addr" and also don't really have a notion of "local_" prefix, since the endpoint is not 1:1 connected with a peer. The "local_" naming comes from connected sockets which have local_addr and peer_addr, which is not applicable for the Endpoint. ## Breaking Changes - Endpoint::local_addr -> Endpoint::bound_sockets ## Notes & open questions ## Change checklist - [x] Self-review. - [x] Documentation updates if relevant. - ~~[ ] Tests if relevant.~~ - [x] All breaking changes documented. --- iroh-net/bench/src/iroh.rs | 2 +- iroh-net/src/endpoint.rs | 6 +++--- iroh/src/node.rs | 2 +- iroh/src/node/builder.rs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/iroh-net/bench/src/iroh.rs b/iroh-net/bench/src/iroh.rs index a359be35b2c..5a85952b7f4 100644 --- a/iroh-net/bench/src/iroh.rs +++ b/iroh-net/bench/src/iroh.rs @@ -29,7 +29,7 @@ pub fn server_endpoint(rt: &tokio::runtime::Runtime, opt: &Opt) -> (NodeAddr, En .bind(0) .await .unwrap(); - let addr = ep.local_addr(); + let addr = ep.bound_sockets(); let addr = SocketAddr::new("127.0.0.1".parse().unwrap(), addr.0.port()); let addr = NodeAddr::new(ep.node_id()).with_direct_addresses([addr]); (addr, ep) diff --git a/iroh-net/src/endpoint.rs b/iroh-net/src/endpoint.rs index 6b98bd4f45d..760809c1b45 100644 --- a/iroh-net/src/endpoint.rs +++ b/iroh-net/src/endpoint.rs @@ -650,7 +650,7 @@ impl Endpoint { /// /// The [`Endpoint`] always binds on an IPv4 address and also tries to bind on an IPv6 /// address if available. - pub fn local_addr(&self) -> (SocketAddr, Option) { + pub fn bound_sockets(&self) -> (SocketAddr, Option) { self.msock.local_addr() } @@ -1246,7 +1246,7 @@ mod tests { .bind(0) .await .unwrap(); - let eps = ep.local_addr(); + let eps = ep.bound_sockets(); info!(me = %ep.node_id().fmt_short(), ipv4=%eps.0, ipv6=?eps.1, "server bound"); for i in 0..n_clients { let now = Instant::now(); @@ -1291,7 +1291,7 @@ mod tests { .bind(0) .await .unwrap(); - let eps = ep.local_addr(); + let eps = ep.bound_sockets(); info!(me = %ep.node_id().fmt_short(), ipv4=%eps.0, ipv6=?eps.1, "client bound"); let node_addr = NodeAddr::new(server_node_id).with_relay_url(relay_url); info!(to = ?node_addr, "client connecting"); diff --git a/iroh/src/node.rs b/iroh/src/node.rs index 7f53324e352..2cbe09d4b77 100644 --- a/iroh/src/node.rs +++ b/iroh/src/node.rs @@ -108,7 +108,7 @@ impl Node { /// can contact the node consider using [`Node::local_endpoint_addresses`]. However the /// port will always be the concrete port. pub fn local_address(&self) -> Vec { - let (v4, v6) = self.inner.endpoint.local_addr(); + let (v4, v6) = self.inner.endpoint.bound_sockets(); let mut addrs = vec![v4]; if let Some(v6) = v6 { addrs.push(v6); diff --git a/iroh/src/node/builder.rs b/iroh/src/node/builder.rs index 59782b20104..62098833884 100644 --- a/iroh/src/node/builder.rs +++ b/iroh/src/node/builder.rs @@ -552,7 +552,7 @@ where ) { let rpc = RpcServer::new(rpc); let internal_rpc = RpcServer::new(internal_rpc); - let (ipv4, ipv6) = server.local_addr(); + let (ipv4, ipv6) = server.bound_sockets(); debug!( "listening at: {}{}", ipv4,