Skip to content

Commit

Permalink
Merge remote-tracking branch 'n0/main' into do-not-dial-self
Browse files Browse the repository at this point in the history
  • Loading branch information
divagant-martian committed Jun 18, 2024
2 parents acf09c3 + d37a4a4 commit 73c4781
Show file tree
Hide file tree
Showing 26 changed files with 1,643 additions and 1,246 deletions.
10 changes: 5 additions & 5 deletions iroh-cli/src/commands/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use iroh::{
},
docs::{Capability, DocTicket},
net::{
defaults::DEFAULT_RELAY_STUN_PORT,
defaults::DEFAULT_STUN_PORT,
discovery::{
dns::DnsDiscovery, pkarr_publish::PkarrPublisher, ConcurrentDiscovery, Discovery,
},
Expand Down Expand Up @@ -93,7 +93,7 @@ pub enum Commands {
#[clap(long)]
stun_host: Option<String>,
/// The port of the STUN server.
#[clap(long, default_value_t = DEFAULT_RELAY_STUN_PORT)]
#[clap(long, default_value_t = DEFAULT_STUN_PORT)]
stun_port: u16,
},
/// Wait for incoming requests from iroh doctor connect
Expand Down Expand Up @@ -631,7 +631,7 @@ async fn passive_side(gui: Gui, connection: Connection) -> anyhow::Result<()> {
}

fn configure_local_relay_map() -> RelayMap {
let stun_port = DEFAULT_RELAY_STUN_PORT;
let stun_port = DEFAULT_STUN_PORT;
let url = "http://localhost:3340".parse().unwrap();
RelayMap::default_from_node(url, stun_port)
}
Expand Down 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
10 changes: 5 additions & 5 deletions iroh-gossip/examples/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ async fn handle_connection(
let alpn = conn.alpn().await?;
let conn = conn.await?;
let peer_id = iroh_net::endpoint::get_remote_node_id(&conn)?;
match alpn.as_bytes() {
GOSSIP_ALPN => gossip
.handle_connection(conn)
.await
.context(format!("connection to {peer_id} with ALPN {alpn} failed"))?,
match alpn.as_ref() {
GOSSIP_ALPN => gossip.handle_connection(conn).await.context(format!(
"connection to {peer_id} with ALPN {} failed",
String::from_utf8_lossy(&alpn)
))?,
_ => println!("> ignoring connection from {peer_id}: unsupported ALPN protocol"),
}
Ok(())
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 @@ -72,7 +72,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 @@ -101,7 +101,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 @@ -123,7 +123,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 @@ -243,16 +243,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 @@ -344,7 +347,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 @@ -377,7 +380,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
5 changes: 3 additions & 2 deletions 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 Expand Up @@ -67,7 +67,8 @@ async fn main() -> anyhow::Result<()> {
let conn = conn.await?;
let node_id = iroh_net::endpoint::get_remote_node_id(&conn)?;
info!(
"new (unreliable) connection from {node_id} with ALPN {alpn} (coming from {})",
"new (unreliable) connection from {node_id} with ALPN {} (coming from {})",
String::from_utf8_lossy(&alpn),
conn.remote_address()
);
// spawn a task to handle reading and writing off of the connection
Expand Down
5 changes: 3 additions & 2 deletions 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 Expand Up @@ -66,7 +66,8 @@ async fn main() -> anyhow::Result<()> {
let conn = conn.await?;
let node_id = iroh_net::endpoint::get_remote_node_id(&conn)?;
info!(
"new connection from {node_id} with ALPN {alpn} (coming from {})",
"new connection from {node_id} with ALPN {} (coming from {})",
String::from_utf8_lossy(&alpn),
conn.remote_address()
);

Expand Down
Loading

0 comments on commit 73c4781

Please sign in to comment.