Skip to content

Commit

Permalink
Merge branch 'main' into flub/relay-send-channel-1
Browse files Browse the repository at this point in the history
  • Loading branch information
flub committed Dec 12, 2024
2 parents 51d136a + 08671bb commit c6d5834
Show file tree
Hide file tree
Showing 18 changed files with 168 additions and 110 deletions.
3 changes: 0 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion iroh-dns-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ http = "1.0.0"
humantime-serde = "1.1.1"
iroh-metrics = { version = "0.29.0" }
lru = "0.12.3"
parking_lot = "0.12.1"
pkarr = { version = "2.2.0", features = [ "async", "relay", "dht"], default-features = false }
rcgen = "0.13"
redb = "2.0.0"
Expand Down
4 changes: 4 additions & 0 deletions iroh-net-report/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
//! etc and reachability to the configured relays.
// Based on <https://github.com/tailscale/tailscale/blob/main/net/netcheck/netcheck.go>

#![cfg_attr(iroh_docsrs, feature(doc_auto_cfg))]
#![deny(missing_docs, rustdoc::broken_intra_doc_links)]
#![cfg_attr(not(test), deny(clippy::unwrap_used))]

use std::{
collections::{BTreeMap, HashMap},
fmt::{self, Debug},
Expand Down
4 changes: 2 additions & 2 deletions iroh-net-report/src/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Pinger {
fn get_client(&self, kind: ICMP) -> Result<Client> {
let client = match kind {
ICMP::V4 => {
let mut opt_client = self.0.client_v4.lock().unwrap();
let mut opt_client = self.0.client_v4.lock().expect("poisoned");
match *opt_client {
Some(ref client) => client.clone(),
None => {
Expand All @@ -66,7 +66,7 @@ impl Pinger {
}
}
ICMP::V6 => {
let mut opt_client = self.0.client_v6.lock().unwrap();
let mut opt_client = self.0.client_v6.lock().expect("poisoned");
match *opt_client {
Some(ref client) => client.clone(),
None => {
Expand Down
1 change: 0 additions & 1 deletion iroh-relay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ iroh-metrics = { version = "0.29.0", default-features = false }
libc = "0.2.139"
num_enum = "0.7"
once_cell = "1.18.0"
parking_lot = "0.12.1"
pin-project = "1"
postcard = { version = "1", default-features = false, features = [
"alloc",
Expand Down
1 change: 1 addition & 0 deletions iroh-relay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#![cfg_attr(iroh_docsrs, feature(doc_auto_cfg))]
#![deny(missing_docs, rustdoc::broken_intra_doc_links)]
#![cfg_attr(not(test), deny(clippy::unwrap_used))]

pub mod client;
pub mod defaults;
Expand Down
3 changes: 2 additions & 1 deletion iroh-relay/src/quic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ pub(crate) mod server {
vec![crate::quic::ALPN_QUIC_ADDR_DISC.to_vec()];
let server_config = QuicServerConfig::try_from(quic_config.server_config)?;
let mut server_config = quinn::ServerConfig::with_crypto(Arc::new(server_config));
let transport_config = Arc::get_mut(&mut server_config.transport).unwrap();
let transport_config =
Arc::get_mut(&mut server_config.transport).expect("not used yet");
transport_config
.max_concurrent_uni_streams(0_u8.into())
.max_concurrent_bidi_streams(0_u8.into())
Expand Down
1 change: 0 additions & 1 deletion iroh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ netdev = "0.31.0"
netwatch = { version = "0.2.0" }
num_enum = "0.7"
once_cell = "1.18.0"
parking_lot = "0.12.1"
pin-project = "1"
pkarr = { version = "2", default-features = false, features = [
"async",
Expand Down
6 changes: 3 additions & 3 deletions iroh/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,11 @@ mod tests {
use std::{
collections::{BTreeSet, HashMap},
net::SocketAddr,
sync::Arc,
sync::{Arc, Mutex},
time::SystemTime,
};

use iroh_base::SecretKey;
use parking_lot::Mutex;
use rand::Rng;
use tokio_util::task::AbortOnDropHandle;

Expand Down Expand Up @@ -499,6 +498,7 @@ mod tests {
self.shared
.nodes
.lock()
.unwrap()
.insert(self.node_id, (url.cloned(), addrs.clone(), now));
}

Expand All @@ -508,7 +508,7 @@ mod tests {
node_id: NodeId,
) -> Option<BoxStream<Result<DiscoveryItem>>> {
let addr_info = match self.resolve_wrong {
false => self.shared.nodes.lock().get(&node_id).cloned(),
false => self.shared.nodes.lock().unwrap().get(&node_id).cloned(),
true => {
let ts = system_time_now() - 100_000;
let port: u16 = rand::thread_rng().gen_range(10_000..20_000);
Expand Down
22 changes: 13 additions & 9 deletions iroh/src/discovery/pkarr/dht.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,11 @@ impl Builder {

/// Builds the discovery mechanism.
pub fn build(self) -> anyhow::Result<DhtDiscovery> {
let pkarr = self
.client
.unwrap_or_else(|| PkarrClient::new(Default::default()).unwrap())
.as_async();
let pkarr = match self.client {
Some(client) => client,
None => PkarrClient::new(Default::default())?,
};
let pkarr = pkarr.as_async();
let ttl = self.ttl.unwrap_or(DEFAULT_PKARR_TTL);
let relay_url = self.pkarr_relay;
let dht = self.dht;
Expand Down Expand Up @@ -259,8 +260,8 @@ impl DhtDiscovery {
let relay_publish = async {
if let Some(relay) = this.0.pkarr_relay.as_ref() {
tracing::info!(
"publishing to relay: {}",
this.0.relay_url.as_ref().unwrap().to_string()
"publishing to relay: {:?}",
this.0.relay_url.as_ref().map(|r| r.to_string())
);
match relay.publish(&signed_packet).await {
Ok(_) => {
Expand All @@ -286,8 +287,11 @@ impl DhtDiscovery {
let Some(relay) = &self.0.pkarr_relay else {
return;
};
let url = self.0.relay_url.as_ref().unwrap();
tracing::info!("resolving {} from relay {}", pkarr_public_key.to_z32(), url);
tracing::info!(
"resolving {} from relay {:?}",
pkarr_public_key.to_z32(),
self.0.relay_url
);
let response = relay.resolve(&pkarr_public_key).await;
match response {
Ok(Some(signed_packet)) => {
Expand Down Expand Up @@ -382,7 +386,7 @@ impl Discovery for DhtDiscovery {
};
let this = self.clone();
let curr = tokio::spawn(this.publish_loop(keypair.clone(), signed_packet));
let mut task = self.0.task.lock().unwrap();
let mut task = self.0.task.lock().expect("poisoned");
*task = Some(AbortOnDropHandle::new(curr));
}

Expand Down
10 changes: 5 additions & 5 deletions iroh/src/discovery/static_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl StaticProvider {
pub fn set_node_addr(&self, info: impl Into<NodeAddr>) -> Option<NodeAddr> {
let last_updated = SystemTime::now();
let info: NodeAddr = info.into();
let mut guard = self.nodes.write().unwrap();
let mut guard = self.nodes.write().expect("poisoned");
let previous = guard.insert(
info.node_id,
NodeInfo {
Expand All @@ -96,7 +96,7 @@ impl StaticProvider {
pub fn add_node_addr(&self, info: impl Into<NodeAddr>) {
let info: NodeAddr = info.into();
let last_updated = SystemTime::now();
let mut guard = self.nodes.write().unwrap();
let mut guard = self.nodes.write().expect("poisoned");
match guard.entry(info.node_id) {
Entry::Occupied(mut entry) => {
let existing = entry.get_mut();
Expand All @@ -116,7 +116,7 @@ impl StaticProvider {

/// Get node info for the given node id.
pub fn get_node_addr(&self, node_id: NodeId) -> Option<NodeAddr> {
let guard = self.nodes.read().unwrap();
let guard = self.nodes.read().expect("poisoned");
let info = guard.get(&node_id)?;
Some(NodeAddr {
node_id,
Expand All @@ -127,7 +127,7 @@ impl StaticProvider {

/// Remove node info for the given node id.
pub fn remove_node_addr(&self, node_id: NodeId) -> Option<NodeAddr> {
let mut guard = self.nodes.write().unwrap();
let mut guard = self.nodes.write().expect("poisoned");
let info = guard.remove(&node_id)?;
Some(NodeAddr {
node_id,
Expand All @@ -145,7 +145,7 @@ impl Discovery for StaticProvider {
_endpoint: crate::Endpoint,
node_id: NodeId,
) -> Option<futures_lite::stream::Boxed<anyhow::Result<super::DiscoveryItem>>> {
let guard = self.nodes.read().unwrap();
let guard = self.nodes.read().expect("poisoned");
let info = guard.get(&node_id);
match info {
Some(addr_info) => {
Expand Down
18 changes: 11 additions & 7 deletions iroh/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl Builder {
.collect::<Vec<_>>();
let discovery: Option<Box<dyn Discovery>> = match discovery.len() {
0 => None,
1 => Some(discovery.into_iter().next().unwrap()),
1 => Some(discovery.into_iter().next().expect("checked length")),
_ => Some(Box::new(ConcurrentDiscovery::from_services(discovery))),
};
let msock_opts = magicsock::Options {
Expand Down Expand Up @@ -313,12 +313,16 @@ impl Builder {
pub fn discovery_dht(mut self) -> Self {
use crate::discovery::pkarr::dht::DhtDiscovery;
self.discovery.push(Box::new(|secret_key| {
Some(Box::new(
DhtDiscovery::builder()
.secret_key(secret_key.clone())
.build()
.unwrap(),
))
match DhtDiscovery::builder()
.secret_key(secret_key.clone())
.build()
{
Ok(discovery) => Some(Box::new(discovery)),
Err(err) => {
tracing::error!("failed to build discovery: {:?}", err);
None
}
}
}));
self
}
Expand Down
1 change: 1 addition & 0 deletions iroh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@
#![recursion_limit = "256"]
#![deny(missing_docs, rustdoc::broken_intra_doc_links)]
#![cfg_attr(not(test), deny(clippy::unwrap_used))]
#![cfg_attr(iroh_docsrs, feature(doc_auto_cfg))]

mod disco;
Expand Down
Loading

0 comments on commit c6d5834

Please sign in to comment.