Skip to content

Commit

Permalink
refactor(iroh-net)!: Rename Endpoint::local_endpoints to direct_addre…
Browse files Browse the repository at this point in the history
…sses (#2369)

## Description

This renames Endpoint::local_endpoints to Endpoint::direct_addresses. As
a consequence it renames a lot of other things, e.g. config::Endpoint
type becomes magicsock::DirectAddr. This is hopefully the last ambiguous
use of "endpoint". The name "direct addresses" seemed to be the
consensus on a discord bikeshedding thread.

The entire config module is removed and the types are moved into
magicsock instead. These types did not have anything to do with
configuration and this was also a source of confusion. Because the
visibility of these types changed some dead code was removed as well.

## Breaking Changes

- iroh_net::Endpoint::local_endpoints ->
iroh_net::Endpoint::direct_addresses
- iroh_net::endpoint::LocalEndpointStream ->
iroh_net::endpoint::DirectAddrStream
- iroh_gossip::net::Gossip::update_endpoints ->
iroh_gossip::net::Gossip::update_direct_addresses
- iroh_net::config is removed.
- iroh_net::config::Endpoint -> iroh_net::magicsock::DirectAddr
- iroh_net::config::EndpointType -> iroh_net::magicsock::DirectAddrType
- iroh_net::config::NetInfo -> removed
- iroh_net::config::LinkInfo -> removed

## Notes & open questions

<!-- Any notes, remarks or open questions you have to make about the PR.
-->

## Change checklist

- [x] Self-review.
- [x] Documentation updates if relevant.
- ~~[ ] Tests if relevant.~~
- [x] All breaking changes documented.
  • Loading branch information
flub authored Jun 18, 2024
1 parent f57c34f commit 2ac3d01
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 207 deletions.
4 changes: 2 additions & 2 deletions iroh-cli/src/commands/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ async fn make_endpoint(
};
let endpoint = endpoint.bind(0).await?;

tokio::time::timeout(Duration::from_secs(10), endpoint.local_endpoints().next())
tokio::time::timeout(Duration::from_secs(10), endpoint.direct_addresses().next())
.await
.context("wait for relay connection")?
.context("no endpoints")?;
Expand Down Expand Up @@ -727,7 +727,7 @@ async fn accept(
) -> anyhow::Result<()> {
let endpoint = make_endpoint(secret_key.clone(), relay_map, discovery).await?;
let endpoints = endpoint
.local_endpoints()
.direct_addresses()
.next()
.await
.context("no endpoints")?;
Expand Down
23 changes: 13 additions & 10 deletions iroh-gossip/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type ProtoMessage = proto::Message<PublicKey>;
#[derive(Debug, Clone)]
pub struct Gossip {
to_actor_tx: mpsc::Sender<ToActor>,
on_endpoints_tx: mpsc::Sender<Vec<iroh_net::config::Endpoint>>,
on_direct_addrs_tx: mpsc::Sender<Vec<iroh_net::endpoint::DirectAddr>>,
_actor_handle: Arc<JoinHandle<anyhow::Result<()>>>,
max_message_size: usize,
}
Expand Down Expand Up @@ -99,7 +99,7 @@ impl Gossip {
to_actor_rx,
in_event_rx,
in_event_tx,
on_endpoints_rx,
on_direct_addr_rx: on_endpoints_rx,
conns: Default::default(),
conn_send_tx: Default::default(),
pending_sends: Default::default(),
Expand All @@ -121,7 +121,7 @@ impl Gossip {
);
Self {
to_actor_tx,
on_endpoints_tx,
on_direct_addrs_tx: on_endpoints_tx,
_actor_handle: Arc::new(actor_handle),
max_message_size,
}
Expand Down Expand Up @@ -241,16 +241,19 @@ impl Gossip {
Ok(())
}

/// Set info on our local endpoints.
/// Set info on our direct addresses.
///
/// This will be sent to peers on Neighbor and Join requests so that they can connect directly
/// to us.
///
/// This is only best effort, and will drop new events if backed up.
pub fn update_endpoints(&self, endpoints: &[iroh_net::config::Endpoint]) -> anyhow::Result<()> {
let endpoints = endpoints.to_vec();
self.on_endpoints_tx
.try_send(endpoints)
pub fn update_direct_addresses(
&self,
addrs: &[iroh_net::endpoint::DirectAddr],
) -> anyhow::Result<()> {
let addrs = addrs.to_vec();
self.on_direct_addrs_tx
.try_send(addrs)
.map_err(|_| anyhow!("endpoints channel dropped"))?;
Ok(())
}
Expand Down Expand Up @@ -342,7 +345,7 @@ struct Actor {
/// Input events to the state (emitted from the connection loops)
in_event_rx: mpsc::Receiver<InEvent>,
/// Updates of discovered endpoint addresses
on_endpoints_rx: mpsc::Receiver<Vec<iroh_net::config::Endpoint>>,
on_direct_addr_rx: mpsc::Receiver<Vec<iroh_net::endpoint::DirectAddr>>,
/// Queued timers
timers: Timers<Timer>,
/// Currently opened quinn connections to peers
Expand Down Expand Up @@ -375,7 +378,7 @@ impl Actor {
}
}
},
new_endpoints = self.on_endpoints_rx.recv() => {
new_endpoints = self.on_direct_addr_rx.recv() => {
match new_endpoints {
Some(endpoints) => {
let addr = NodeAddr::from_parts(
Expand Down
2 changes: 1 addition & 1 deletion iroh-net/examples/connect-unreliable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async fn main() -> anyhow::Result<()> {
println!("node id: {me}");
println!("node listening addresses:");
for local_endpoint in endpoint
.local_endpoints()
.direct_addresses()
.next()
.await
.context("no endpoints")?
Expand Down
2 changes: 1 addition & 1 deletion iroh-net/examples/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async fn main() -> anyhow::Result<()> {
println!("node id: {me}");
println!("node listening addresses:");
for local_endpoint in endpoint
.local_endpoints()
.direct_addresses()
.next()
.await
.context("no endpoints")?
Expand Down
2 changes: 1 addition & 1 deletion iroh-net/examples/listen-unreliable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async fn main() -> anyhow::Result<()> {
println!("node listening addresses:");

let local_addrs = endpoint
.local_endpoints()
.direct_addresses()
.next()
.await
.context("no endpoints")?
Expand Down
2 changes: 1 addition & 1 deletion iroh-net/examples/listen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async fn main() -> anyhow::Result<()> {
println!("node listening addresses:");

let local_addrs = endpoint
.local_endpoints()
.direct_addresses()
.next()
.await
.context("no endpoints")?
Expand Down
128 changes: 0 additions & 128 deletions iroh-net/src/config.rs

This file was deleted.

14 changes: 7 additions & 7 deletions iroh-net/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ pub use quinn::{
};

pub use super::magicsock::{
ConnectionInfo, ConnectionType, ConnectionTypeStream, ControlMsg, DirectAddrInfo,
LocalEndpointsStream,
ConnectionInfo, ConnectionType, ConnectionTypeStream, ControlMsg, DirectAddr, DirectAddrInfo,
DirectAddrType, DirectAddrsStream,
};

pub use iroh_base::node_addr::{AddrInfo, NodeAddr};
Expand Down Expand Up @@ -567,10 +567,10 @@ impl Endpoint {
///
/// The returned [`NodeAddr`] will have the current [`RelayUrl`] and local IP endpoints
/// as they would be returned by [`Endpoint::home_relay`] and
/// [`Endpoint::local_endpoints`].
/// [`Endpoint::direct_addresses`].
pub async fn node_addr(&self) -> Result<NodeAddr> {
let addrs = self
.local_endpoints()
.direct_addresses()
.next()
.await
.ok_or(anyhow!("No IP endpoints found"))?;
Expand Down Expand Up @@ -637,13 +637,13 @@ impl Endpoint {
/// # let rt = tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap();
/// # rt.block_on(async move {
/// let mep = Endpoint::builder().bind(0).await.unwrap();
/// let _endpoints = mep.local_endpoints().next().await;
/// let _addrs = mep.direct_addresses().next().await;
/// # });
/// ```
///
/// [STUN]: https://en.wikipedia.org/wiki/STUN
pub fn local_endpoints(&self) -> LocalEndpointsStream {
self.msock.local_endpoints()
pub fn direct_addresses(&self) -> DirectAddrsStream {
self.msock.direct_addresses()
}

/// Returns the local socket addresses on which the underlying sockets are bound.
Expand Down
1 change: 0 additions & 1 deletion iroh-net/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@
#![recursion_limit = "256"]
#![deny(missing_docs, rustdoc::broken_intra_doc_links)]

pub mod config;
pub mod defaults;
pub mod dialer;
mod disco;
Expand Down
Loading

0 comments on commit 2ac3d01

Please sign in to comment.