Skip to content

Commit 08671bb

Browse files
refactor: remove parking-lot dependency (#3034)
## Description Currently there was an inconsistent usage of `std::sync::Mutex` and `parking_lot::Mutex`. This normalizes the usage to always use `std::sync::Mutex` and remove the external dependency. ## Breaking Changes <!-- Optional, if there are any breaking changes document them, including how to migrate older code. --> ## Notes & open questions <!-- Any notes, remarks or open questions you have to make about the PR. --> ## Change checklist - [x] Self-review. - [x] Documentation updates following the [style guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text), if relevant. - [x] Tests if relevant. - [x] All breaking changes documented.
1 parent d9fb470 commit 08671bb

File tree

18 files changed

+168
-110
lines changed

18 files changed

+168
-110
lines changed

Cargo.lock

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

iroh-dns-server/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ http = "1.0.0"
3131
humantime-serde = "1.1.1"
3232
iroh-metrics = { version = "0.29.0" }
3333
lru = "0.12.3"
34-
parking_lot = "0.12.1"
3534
pkarr = { version = "2.2.0", features = [ "async", "relay", "dht"], default-features = false }
3635
rcgen = "0.13"
3736
redb = "2.0.0"

iroh-net-report/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
//! etc and reachability to the configured relays.
66
// Based on <https://github.com/tailscale/tailscale/blob/main/net/netcheck/netcheck.go>
77

8+
#![cfg_attr(iroh_docsrs, feature(doc_auto_cfg))]
9+
#![deny(missing_docs, rustdoc::broken_intra_doc_links)]
10+
#![cfg_attr(not(test), deny(clippy::unwrap_used))]
11+
812
use std::{
913
collections::{BTreeMap, HashMap},
1014
fmt::{self, Debug},

iroh-net-report/src/ping.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl Pinger {
5454
fn get_client(&self, kind: ICMP) -> Result<Client> {
5555
let client = match kind {
5656
ICMP::V4 => {
57-
let mut opt_client = self.0.client_v4.lock().unwrap();
57+
let mut opt_client = self.0.client_v4.lock().expect("poisoned");
5858
match *opt_client {
5959
Some(ref client) => client.clone(),
6060
None => {
@@ -66,7 +66,7 @@ impl Pinger {
6666
}
6767
}
6868
ICMP::V6 => {
69-
let mut opt_client = self.0.client_v6.lock().unwrap();
69+
let mut opt_client = self.0.client_v6.lock().expect("poisoned");
7070
match *opt_client {
7171
Some(ref client) => client.clone(),
7272
None => {

iroh-relay/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ iroh-metrics = { version = "0.29.0", default-features = false }
4343
libc = "0.2.139"
4444
num_enum = "0.7"
4545
once_cell = "1.18.0"
46-
parking_lot = "0.12.1"
4746
pin-project = "1"
4847
postcard = { version = "1", default-features = false, features = [
4948
"alloc",

iroh-relay/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

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

3233
pub mod client;
3334
pub mod defaults;

iroh-relay/src/quic.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ pub(crate) mod server {
7070
vec![crate::quic::ALPN_QUIC_ADDR_DISC.to_vec()];
7171
let server_config = QuicServerConfig::try_from(quic_config.server_config)?;
7272
let mut server_config = quinn::ServerConfig::with_crypto(Arc::new(server_config));
73-
let transport_config = Arc::get_mut(&mut server_config.transport).unwrap();
73+
let transport_config =
74+
Arc::get_mut(&mut server_config.transport).expect("not used yet");
7475
transport_config
7576
.max_concurrent_uni_streams(0_u8.into())
7677
.max_concurrent_bidi_streams(0_u8.into())

iroh/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ netdev = "0.31.0"
5151
netwatch = { version = "0.2.0" }
5252
num_enum = "0.7"
5353
once_cell = "1.18.0"
54-
parking_lot = "0.12.1"
5554
pin-project = "1"
5655
pkarr = { version = "2", default-features = false, features = [
5756
"async",

iroh/src/discovery.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,12 +441,11 @@ mod tests {
441441
use std::{
442442
collections::{BTreeSet, HashMap},
443443
net::SocketAddr,
444-
sync::Arc,
444+
sync::{Arc, Mutex},
445445
time::SystemTime,
446446
};
447447

448448
use iroh_base::SecretKey;
449-
use parking_lot::Mutex;
450449
use rand::Rng;
451450
use tokio_util::task::AbortOnDropHandle;
452451

@@ -499,6 +498,7 @@ mod tests {
499498
self.shared
500499
.nodes
501500
.lock()
501+
.unwrap()
502502
.insert(self.node_id, (url.cloned(), addrs.clone(), now));
503503
}
504504

@@ -508,7 +508,7 @@ mod tests {
508508
node_id: NodeId,
509509
) -> Option<BoxStream<Result<DiscoveryItem>>> {
510510
let addr_info = match self.resolve_wrong {
511-
false => self.shared.nodes.lock().get(&node_id).cloned(),
511+
false => self.shared.nodes.lock().unwrap().get(&node_id).cloned(),
512512
true => {
513513
let ts = system_time_now() - 100_000;
514514
let port: u16 = rand::thread_rng().gen_range(10_000..20_000);

iroh/src/discovery/pkarr/dht.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,11 @@ impl Builder {
180180

181181
/// Builds the discovery mechanism.
182182
pub fn build(self) -> anyhow::Result<DhtDiscovery> {
183-
let pkarr = self
184-
.client
185-
.unwrap_or_else(|| PkarrClient::new(Default::default()).unwrap())
186-
.as_async();
183+
let pkarr = match self.client {
184+
Some(client) => client,
185+
None => PkarrClient::new(Default::default())?,
186+
};
187+
let pkarr = pkarr.as_async();
187188
let ttl = self.ttl.unwrap_or(DEFAULT_PKARR_TTL);
188189
let relay_url = self.pkarr_relay;
189190
let dht = self.dht;
@@ -259,8 +260,8 @@ impl DhtDiscovery {
259260
let relay_publish = async {
260261
if let Some(relay) = this.0.pkarr_relay.as_ref() {
261262
tracing::info!(
262-
"publishing to relay: {}",
263-
this.0.relay_url.as_ref().unwrap().to_string()
263+
"publishing to relay: {:?}",
264+
this.0.relay_url.as_ref().map(|r| r.to_string())
264265
);
265266
match relay.publish(&signed_packet).await {
266267
Ok(_) => {
@@ -286,8 +287,11 @@ impl DhtDiscovery {
286287
let Some(relay) = &self.0.pkarr_relay else {
287288
return;
288289
};
289-
let url = self.0.relay_url.as_ref().unwrap();
290-
tracing::info!("resolving {} from relay {}", pkarr_public_key.to_z32(), url);
290+
tracing::info!(
291+
"resolving {} from relay {:?}",
292+
pkarr_public_key.to_z32(),
293+
self.0.relay_url
294+
);
291295
let response = relay.resolve(&pkarr_public_key).await;
292296
match response {
293297
Ok(Some(signed_packet)) => {
@@ -382,7 +386,7 @@ impl Discovery for DhtDiscovery {
382386
};
383387
let this = self.clone();
384388
let curr = tokio::spawn(this.publish_loop(keypair.clone(), signed_packet));
385-
let mut task = self.0.task.lock().unwrap();
389+
let mut task = self.0.task.lock().expect("poisoned");
386390
*task = Some(AbortOnDropHandle::new(curr));
387391
}
388392

0 commit comments

Comments
 (0)