Skip to content

Commit 47064a3

Browse files
committed
fix & fmt
1 parent 894ff10 commit 47064a3

File tree

20 files changed

+171
-128
lines changed

20 files changed

+171
-128
lines changed

iroh-dns-server/src/config.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,8 @@ impl Config {
175175
let dir = if let Some(val) = env::var_os("IROH_DNS_DATA_DIR") {
176176
PathBuf::from(val)
177177
} else {
178-
let path = dirs_next::data_dir().std_context(
179-
"operating environment provides no directory for application data",
180-
)?;
178+
let path = dirs_next::data_dir()
179+
.std_context("operating environment provides no directory for application data")?;
181180

182181
path.join("iroh-dns")
183182
};

iroh-dns-server/src/dns/node_authority.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use hickory_server::{
1313
server::RequestInfo,
1414
store::in_memory::InMemoryAuthority,
1515
};
16-
use n0_error::{Result, StackResultExt, StdResultExt, whatever};
16+
use n0_error::{Result, StdResultExt, whatever};
1717
use tracing::{debug, trace};
1818

1919
use crate::{

iroh-dns-server/src/http.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ impl HttpServer {
111111
.join(config.cert_mode.to_string());
112112
tokio::fs::create_dir_all(&cache_path)
113113
.await
114-
.std_context(format!(
115-
"failed to create cert cache dir at {cache_path:?}"
116-
))?;
114+
.std_context(format!("failed to create cert cache dir at {cache_path:?}"))?;
117115
config
118116
.cert_mode
119117
.build(

iroh-dns-server/src/http/tls.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use axum_server::{
99
accept::Accept,
1010
tls_rustls::{RustlsAcceptor, RustlsConfig},
1111
};
12-
use n0_future::{FutureExt, future::Boxed as BoxFuture};
1312
use n0_error::{Result, StdResultExt, whatever};
13+
use n0_future::{FutureExt, future::Boxed as BoxFuture};
1414
use serde::{Deserialize, Serialize};
1515
use tokio::io::{AsyncRead, AsyncWrite};
1616
use tokio_rustls_acme::{AcmeConfig, axum::AxumAcceptor, caches::DirCache};
@@ -157,7 +157,9 @@ async fn load_secret_key(
157157
let mut reader = std::io::Cursor::new(keyfile);
158158

159159
loop {
160-
match rustls_pemfile::read_one(&mut reader).std_context("cannot parse secret key .pem file")? {
160+
match rustls_pemfile::read_one(&mut reader)
161+
.std_context("cannot parse secret key .pem file")?
162+
{
161163
Some(rustls_pemfile::Item::Pkcs1Key(key)) => {
162164
return Ok(rustls::pki_types::PrivateKeyDer::Pkcs1(key));
163165
}

iroh-dns-server/src/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use std::sync::Arc;
33

44
use iroh_metrics::service::start_metrics_server;
5-
use n0_error::{Result, StdResultExt, StackResultExt};
5+
use n0_error::{Result, StdResultExt};
66
use tracing::info;
77

88
use crate::{

iroh-dns-server/src/store/signed_packets.rs

Lines changed: 76 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
time::{Duration, SystemTime},
77
};
88

9-
use n0_error::{Result, StdResultExt, StackResultExt, format_err};
9+
use n0_error::{Result, StdResultExt, format_err};
1010
use pkarr::{SignedPacket, Timestamp};
1111
use redb::{
1212
Database, MultimapTableDefinition, ReadableTable, TableDefinition, backends::InMemoryBackend,
@@ -128,90 +128,90 @@ impl Actor {
128128
tokio::pin!(timeout);
129129
for _ in 0..self.options.max_batch_size {
130130
tokio::select! {
131-
_ = self.cancel.cancelled() => {
132-
drop(tables);
133-
transaction.commit().e()?;
134-
return Ok(());
135-
}
136-
_ = &mut timeout => break,
137-
Some(msg) = self.recv.recv() => {
138-
match msg {
139-
Message::Get { key, res } => {
140-
match get_packet(&tables.signed_packets, &key) {
141-
Ok(packet) => {
142-
trace!("get {key}: {}", packet.is_some());
143-
res.send(packet).ok();
144-
},
145-
Err(err) => {
146-
warn!("get {key} failed: {err:#}");
147-
return Err(err).std_context(format!("get packet for {key} failed"))
131+
_ = self.cancel.cancelled() => {
132+
drop(tables);
133+
transaction.commit().e()?;
134+
return Ok(());
135+
}
136+
_ = &mut timeout => break,
137+
Some(msg) = self.recv.recv() => {
138+
match msg {
139+
Message::Get { key, res } => {
140+
match get_packet(&tables.signed_packets, &key) {
141+
Ok(packet) => {
142+
trace!("get {key}: {}", packet.is_some());
143+
res.send(packet).ok();
144+
},
145+
Err(err) => {
146+
warn!("get {key} failed: {err:#}");
147+
return Err(err).std_context(format!("get packet for {key} failed"))
148+
}
148149
}
149150
}
150-
}
151-
Message::Upsert { packet, res } => {
152-
let key = PublicKeyBytes::from_signed_packet(&packet);
153-
trace!("upsert {}", key);
154-
let replaced = match get_packet(&tables.signed_packets, &key)? { Some(existing) => {
155-
if existing.more_recent_than(&packet) {
156-
res.send(false).ok();
157-
continue;
151+
Message::Upsert { packet, res } => {
152+
let key = PublicKeyBytes::from_signed_packet(&packet);
153+
trace!("upsert {}", key);
154+
let replaced = match get_packet(&tables.signed_packets, &key)? { Some(existing) => {
155+
if existing.more_recent_than(&packet) {
156+
res.send(false).ok();
157+
continue;
158+
} else {
159+
// remove the old packet from the update time index
160+
tables.update_time.remove(&existing.timestamp().to_bytes(), key.as_bytes()).e()?;
161+
true
162+
}
163+
} _ => {
164+
false
165+
}};
166+
let value = packet.serialize();
167+
tables.signed_packets
168+
.insert(key.as_bytes(), &value[..]).e()?;
169+
tables.update_time
170+
.insert(&packet.timestamp().to_bytes(), key.as_bytes()).e()?;
171+
if replaced {
172+
self.metrics.store_packets_updated.inc();
158173
} else {
159-
// remove the old packet from the update time index
160-
tables.update_time.remove(&existing.timestamp().to_bytes(), key.as_bytes()).e()?;
161-
true
174+
self.metrics.store_packets_inserted.inc();
162175
}
163-
} _ => {
164-
false
165-
}};
166-
let value = packet.serialize();
167-
tables.signed_packets
168-
.insert(key.as_bytes(), &value[..]).e()?;
169-
tables.update_time
170-
.insert(&packet.timestamp().to_bytes(), key.as_bytes()).e()?;
171-
if replaced {
172-
self.metrics.store_packets_updated.inc();
173-
} else {
174-
self.metrics.store_packets_inserted.inc();
176+
res.send(true).ok();
175177
}
176-
res.send(true).ok();
177-
}
178-
Message::Remove { key, res } => {
179-
trace!("remove {}", key);
180-
let updated = match tables.signed_packets.remove(key.as_bytes()).e()? { Some(row) => {
181-
let packet = SignedPacket::deserialize(row.value()).e()?;
182-
tables.update_time.remove(&packet.timestamp().to_bytes(), key.as_bytes()).e()?;
183-
self.metrics.store_packets_removed.inc();
184-
true
185-
} _ => {
186-
false
187-
}};
188-
res.send(updated).ok();
189-
}
190-
Message::Snapshot { res } => {
191-
trace!("snapshot");
192-
res.send(Snapshot::new(&self.db)?).ok();
193-
}
194-
Message::CheckExpired { key, time } => {
195-
trace!("check expired {} at {}", key, fmt_time(time));
196-
match get_packet(&tables.signed_packets, &key)? { Some(packet) => {
197-
let expired = Timestamp::now() - expiry_us;
198-
if packet.timestamp() < expired {
199-
tables.update_time.remove(&time.to_bytes(), key.as_bytes()).e()?;
200-
let _ = tables.signed_packets.remove(key.as_bytes()).e()?;
201-
self.metrics.store_packets_expired.inc();
202-
debug!("removed expired packet {key}");
203-
} else {
204-
debug!("packet {key} is no longer expired, removing obsolete expiry entry");
178+
Message::Remove { key, res } => {
179+
trace!("remove {}", key);
180+
let updated = match tables.signed_packets.remove(key.as_bytes()).e()? { Some(row) => {
181+
let packet = SignedPacket::deserialize(row.value()).e()?;
182+
tables.update_time.remove(&packet.timestamp().to_bytes(), key.as_bytes()).e()?;
183+
self.metrics.store_packets_removed.inc();
184+
true
185+
} _ => {
186+
false
187+
}};
188+
res.send(updated).ok();
189+
}
190+
Message::Snapshot { res } => {
191+
trace!("snapshot");
192+
res.send(Snapshot::new(&self.db)?).ok();
193+
}
194+
Message::CheckExpired { key, time } => {
195+
trace!("check expired {} at {}", key, fmt_time(time));
196+
match get_packet(&tables.signed_packets, &key)? { Some(packet) => {
197+
let expired = Timestamp::now() - expiry_us;
198+
if packet.timestamp() < expired {
199+
tables.update_time.remove(&time.to_bytes(), key.as_bytes()).e()?;
200+
let _ = tables.signed_packets.remove(key.as_bytes()).e()?;
201+
self.metrics.store_packets_expired.inc();
202+
debug!("removed expired packet {key}");
203+
} else {
204+
debug!("packet {key} is no longer expired, removing obsolete expiry entry");
205+
tables.update_time.remove(&time.to_bytes(), key.as_bytes()).e()?;
206+
}
207+
} _ => {
208+
debug!("expired packet {key} not found, remove from expiry table");
205209
tables.update_time.remove(&time.to_bytes(), key.as_bytes()).e()?;
206-
}
207-
} _ => {
208-
debug!("expired packet {key} not found, remove from expiry table");
209-
tables.update_time.remove(&time.to_bytes(), key.as_bytes()).e()?;
210-
}}
210+
}}
211+
}
211212
}
212213
}
213214
}
214-
}
215215
}
216216
drop(tables);
217217
transaction.commit().e()?;

iroh/bench/src/iroh.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use iroh::{
88
Endpoint, EndpointAddr, RelayMode, RelayUrl,
99
endpoint::{Connection, ConnectionError, RecvStream, SendStream, TransportConfig},
1010
};
11-
use n0_error::{Result, StackResultExt, StdResultExt};
11+
use n0_error::{Result, StdResultExt};
1212
use tracing::{trace, warn};
1313

1414
use crate::{

iroh/examples/0rtt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use iroh::{
77
endpoint::{Connecting, Connection},
88
};
99
use iroh_base::ticket::EndpointTicket;
10-
use n0_error::{Result, StdResultExt, StackResultExt, whatever};
10+
use n0_error::{Result, StackResultExt, StdResultExt, whatever};
1111
use n0_future::{StreamExt, future};
1212
use n0_watcher::Watcher;
1313
use tracing::{info, trace};

iroh/examples/locally-discovered-nodes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use iroh::{
1010
discovery::mdns::{DiscoveryEvent, MdnsDiscovery},
1111
endpoint_info::UserData,
1212
};
13-
use n0_future::StreamExt;
1413
use n0_error::Result;
14+
use n0_future::StreamExt;
1515
use tokio::task::JoinSet;
1616

1717
#[tokio::main]

iroh/examples/transfer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use iroh::{
1717
endpoint::ConnectionError,
1818
};
1919
use iroh_base::ticket::EndpointTicket;
20+
use n0_error::{Result, StackResultExt, StdResultExt, whatever};
2021
use n0_future::task::AbortOnDropHandle;
21-
use n0_error::{Result, StdResultExt, StackResultExt, whatever};
2222
use n0_watcher::Watcher as _;
2323
use tokio_stream::StreamExt;
2424
use tracing::{info, warn};

0 commit comments

Comments
 (0)