Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(iroh-net): Improve magicsock module visibility #2371

Merged
merged 11 commits into from
Jun 18, 2024
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
Loading