Skip to content

feat!: update to edition 2024 and update deps to latest #3386

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,153 changes: 584 additions & 569 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions iroh-base/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "iroh-base"
version = "0.90.0"
edition = "2021"
edition = "2024"
readme = "README.md"
description = "base type and utilities for Iroh"
license = "MIT OR Apache-2.0"
Expand All @@ -18,7 +18,7 @@ workspace = true
curve25519-dalek = { version = "4.1.3", features = ["serde", "rand_core", "zeroize"], optional = true }
data-encoding = { version = "2.3.3", optional = true }
ed25519-dalek = { version = "2.1.1", features = ["serde", "rand_core", "zeroize"], optional = true }
derive_more = { version = "1.0.0", features = ["display"], optional = true }
derive_more = { version = "2.0.1", features = ["display"], optional = true }
url = { version = "2.5.3", features = ["serde"], optional = true }
postcard = { version = "1", default-features = false, features = ["alloc", "use-std", "experimental-derive"], optional = true }
rand_core = { version = "0.6.4", optional = true }
Expand Down
6 changes: 3 additions & 3 deletions iroh-dns-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "iroh-dns-server"
version = "0.90.0"
edition = "2021"
edition = "2024"
description = "A pkarr relay and DNS server"
license = "MIT OR Apache-2.0"
authors = ["Frando <franz@n0.computer>", "n0 team"]
Expand All @@ -16,7 +16,7 @@ axum-server = { version = "0.7", features = ["tls-rustls-no-provider"] }
base64-url = "3.0"
bytes = "1.7"
clap = { version = "4.5.1", features = ["derive"] }
derive_more = { version = "1.0.0", features = [
derive_more = { version = "2.0.1", features = [
"debug",
"display",
"into",
Expand Down Expand Up @@ -50,7 +50,7 @@ tokio-rustls = { version = "0.26", default-features = false, features = [
tokio-rustls-acme = { version = "0.7.1", features = ["axum"] }
tokio-stream = "0.1.14"
tokio-util = "0.7"
toml = "0.8.10"
toml = "0.9.2"
tower-http = { version = "0.6.1", features = ["cors", "trace"] }
tower_governor = "0.7"
tracing = "0.1"
Expand Down
6 changes: 3 additions & 3 deletions iroh-dns-server/benches/write.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::sync::Arc;

use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use iroh::{discovery::pkarr::PkarrRelayClient, node_info::NodeInfo, SecretKey};
use iroh_dns_server::{config::Config, metrics::Metrics, server::Server, ZoneStore};
use criterion::{BenchmarkId, Criterion, Throughput, criterion_group, criterion_main};
use iroh::{SecretKey, discovery::pkarr::PkarrRelayClient, node_info::NodeInfo};
use iroh_dns_server::{ZoneStore, config::Config, metrics::Metrics, server::Server};
use n0_snafu::Result;
use rand_chacha::rand_core::SeedableRng;
use tokio::runtime::Runtime;
Expand Down
8 changes: 4 additions & 4 deletions iroh-dns-server/examples/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use std::{net::SocketAddr, str::FromStr};

use clap::{Parser, ValueEnum};
use iroh::{
NodeId, SecretKey,
discovery::{
dns::{N0_DNS_NODE_ORIGIN_PROD, N0_DNS_NODE_ORIGIN_STAGING},
pkarr::{PkarrRelayClient, N0_DNS_PKARR_RELAY_PROD, N0_DNS_PKARR_RELAY_STAGING},
UserData,
dns::{N0_DNS_NODE_ORIGIN_PROD, N0_DNS_NODE_ORIGIN_STAGING},
pkarr::{N0_DNS_PKARR_RELAY_PROD, N0_DNS_PKARR_RELAY_STAGING, PkarrRelayClient},
},
node_info::{NodeIdExt, NodeInfo, IROH_TXT_NAME},
NodeId, SecretKey,
node_info::{IROH_TXT_NAME, NodeIdExt, NodeInfo},
};
use n0_snafu::{Result, ResultExt};
use url::Url;
Expand Down
2 changes: 1 addition & 1 deletion iroh-dns-server/examples/resolve.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use clap::{Parser, ValueEnum};
use iroh::{
NodeId,
discovery::dns::{N0_DNS_NODE_ORIGIN_PROD, N0_DNS_NODE_ORIGIN_STAGING},
dns::DnsResolver,
NodeId,
};
use n0_snafu::{Result, ResultExt};

Expand Down
4 changes: 2 additions & 2 deletions iroh-dns-server/src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ use hickory_server::{
self,
op::ResponseCode,
rr::{
rdata::{self},
LowerName, Name, RData, Record, RecordSet, RecordType, RrKey,
rdata::{self},
},
serialize::{binary::BinEncoder, txt::RDataParser},
xfer::Protocol,
},
server::{Request, RequestHandler, ResponseHandler, ResponseInfo},
store::in_memory::InMemoryAuthority,
};
use n0_snafu::{format_err, Result, ResultExt};
use n0_snafu::{Result, ResultExt, format_err};
use serde::{Deserialize, Serialize};
use tokio::{
net::{TcpListener, UdpSocket},
Expand Down
2 changes: 1 addition & 1 deletion iroh-dns-server/src/dns/node_authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use tracing::{debug, trace};

use crate::{
store::ZoneStore,
util::{record_set_append_origin, PublicKeyBytes},
util::{PublicKeyBytes, record_set_append_origin},
};

#[derive(derive_more::Debug)]
Expand Down
4 changes: 2 additions & 2 deletions iroh-dns-server/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use std::{
};

use axum::{
Router,
extract::{ConnectInfo, Request, State},
handler::Handler,
http::Method,
middleware::{self, Next},
response::IntoResponse,
routing::get,
Router,
};
use n0_snafu::{Result, ResultExt};
use serde::{Deserialize, Serialize};
Expand All @@ -22,7 +22,7 @@ use tower_http::{
cors::{self, CorsLayer},
trace::TraceLayer,
};
use tracing::{info, span, warn, Level};
use tracing::{Level, info, span, warn};

mod doh;
mod error;
Expand Down
4 changes: 2 additions & 2 deletions iroh-dns-server/src/http/doh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
// https://github.com/fission-codes/fission-server/blob/main/fission-server/src/routes/doh.rs

use axum::{
Json,
extract::State,
response::{IntoResponse, Response},
Json,
};
use hickory_server::proto::{
serialize::binary::BinDecodable,
{self},
};
use http::{
header::{CACHE_CONTROL, CONTENT_TYPE},
HeaderValue, StatusCode,
header::{CACHE_CONTROL, CONTENT_TYPE},
};
use n0_snafu::ResultExt;

Expand Down
2 changes: 1 addition & 1 deletion iroh-dns-server/src/http/doh/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use hickory_server::{
},
server::Request as DNSRequest,
};
use http::{header, request::Parts, HeaderValue, StatusCode};
use http::{HeaderValue, StatusCode, header, request::Parts};
use serde::Deserialize;
use tracing::info;

Expand Down
4 changes: 2 additions & 2 deletions iroh-dns-server/src/http/error.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use axum::{
Json,
extract::rejection::{ExtensionRejection, QueryRejection},
http::StatusCode,
response::IntoResponse,
Json,
};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -78,7 +78,7 @@ impl From<ExtensionRejection> for AppError {
/// We could have used http_serde, but it encodes the status code as a NUMBER.
pub mod serde_status_code {
use http::StatusCode;
use serde::{de::Unexpected, Deserialize, Deserializer, Serialize, Serializer};
use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Unexpected};

/// Serialize [StatusCode]s.
pub fn serialize<S: Serializer>(status: &StatusCode, ser: S) -> Result<S::Ok, S::Error> {
Expand Down
2 changes: 1 addition & 1 deletion iroh-dns-server/src/http/pkarr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use axum::{
response::IntoResponse,
};
use bytes::Bytes;
use http::{header, StatusCode};
use http::{StatusCode, header};
use tracing::info;

use super::error::AppError;
Expand Down
12 changes: 7 additions & 5 deletions iroh-dns-server/src/http/rate_limiting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use std::{sync::Arc, time::Duration};
use governor::{clock::QuantaInstant, middleware::NoOpMiddleware};
use serde::{Deserialize, Serialize};
use tower_governor::{
GovernorLayer,
governor::GovernorConfigBuilder,
key_extractor::{PeerIpKeyExtractor, SmartIpKeyExtractor},
GovernorLayer,
};

/// Config for http server rate limit.
Expand Down Expand Up @@ -71,10 +71,12 @@ pub fn create(
// The governor needs a background task for garbage collection (to clear expired records)
let gc_interval = Duration::from_secs(60);
let governor_limiter = governor_conf.limiter().clone();
std::thread::spawn(move || loop {
std::thread::sleep(gc_interval);
tracing::debug!("rate limiting storage size: {}", governor_limiter.len());
governor_limiter.retain_recent();
std::thread::spawn(move || {
loop {
std::thread::sleep(gc_interval);
tracing::debug!("rate limiting storage size: {}", governor_limiter.len());
governor_limiter.retain_recent();
}
});

Some(GovernorLayer {
Expand Down
6 changes: 3 additions & 3 deletions iroh-dns-server/src/http/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ use axum_server::{
accept::Accept,
tls_rustls::{RustlsAcceptor, RustlsConfig},
};
use n0_future::{future::Boxed as BoxFuture, FutureExt};
use n0_future::{FutureExt, future::Boxed as BoxFuture};
use n0_snafu::{Result, ResultExt};
use serde::{Deserialize, Serialize};
use snafu::whatever;
use tokio::io::{AsyncRead, AsyncWrite};
use tokio_rustls_acme::{axum::AxumAcceptor, caches::DirCache, AcmeConfig};
use tokio_rustls_acme::{AcmeConfig, axum::AxumAcceptor, caches::DirCache};
use tokio_stream::StreamExt;
use tracing::{debug, error, info_span, Instrument};
use tracing::{Instrument, debug, error, info_span};

/// The mode how SSL certificates should be created.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, strum::Display)]
Expand Down
6 changes: 3 additions & 3 deletions iroh-dns-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ mod tests {
};

use iroh::{
discovery::pkarr::PkarrRelayClient, dns::DnsResolver, node_info::NodeInfo, RelayUrl,
SecretKey,
RelayUrl, SecretKey, discovery::pkarr::PkarrRelayClient, dns::DnsResolver,
node_info::NodeInfo,
};
use n0_snafu::{Result, ResultExt};
use pkarr::{SignedPacket, Timestamp};
use tracing_test::traced_test;

use crate::{
ZoneStore,
config::BootstrapOption,
server::Server,
store::{PacketSource, ZoneStoreOptions},
util::PublicKeyBytes,
ZoneStore,
};

const DNS_TIMEOUT: Duration = Duration::from_secs(1);
Expand Down
2 changes: 1 addition & 1 deletion iroh-dns-server/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use self::signed_packets::SignedPacketStore;
use crate::{
config::BootstrapOption,
metrics::Metrics,
util::{signed_packet_to_hickory_records_without_origin, PublicKeyBytes},
util::{PublicKeyBytes, signed_packet_to_hickory_records_without_origin},
};

mod signed_packets;
Expand Down
26 changes: 14 additions & 12 deletions iroh-dns-server/src/store/signed_packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use std::{
time::{Duration, SystemTime},
};

use n0_snafu::{format_err, Result, ResultExt};
use n0_snafu::{Result, ResultExt, format_err};
use pkarr::{SignedPacket, Timestamp};
use redb::{
backends::InMemoryBackend, Database, MultimapTableDefinition, ReadableTable, TableDefinition,
Database, MultimapTableDefinition, ReadableTable, TableDefinition, backends::InMemoryBackend,
};
use tokio::sync::{mpsc, oneshot};
use tokio_util::sync::CancellationToken;
Expand Down Expand Up @@ -151,7 +151,7 @@ impl Actor {
Message::Upsert { packet, res } => {
let key = PublicKeyBytes::from_signed_packet(&packet);
trace!("upsert {}", key);
let replaced = if let Some(existing) = get_packet(&tables.signed_packets, &key)? {
let replaced = match get_packet(&tables.signed_packets, &key)? { Some(existing) => {
if existing.more_recent_than(&packet) {
res.send(false).ok();
continue;
Expand All @@ -160,9 +160,9 @@ impl Actor {
tables.update_time.remove(&existing.timestamp().to_bytes(), key.as_bytes()).e()?;
true
}
} else {
} _ => {
false
};
}};
let value = packet.serialize();
tables.signed_packets
.insert(key.as_bytes(), &value[..]).e()?;
Expand All @@ -177,14 +177,14 @@ impl Actor {
}
Message::Remove { key, res } => {
trace!("remove {}", key);
let updated = if let Some(row) = tables.signed_packets.remove(key.as_bytes()).e()? {
let updated = match tables.signed_packets.remove(key.as_bytes()).e()? { Some(row) => {
let packet = SignedPacket::deserialize(row.value()).e()?;
tables.update_time.remove(&packet.timestamp().to_bytes(), key.as_bytes()).e()?;
self.metrics.store_packets_removed.inc();
true
} else {
} _ => {
false
};
}};
res.send(updated).ok();
}
Message::Snapshot { res } => {
Expand All @@ -193,7 +193,7 @@ impl Actor {
}
Message::CheckExpired { key, time } => {
trace!("check expired {} at {}", key, fmt_time(time));
if let Some(packet) = get_packet(&tables.signed_packets, &key)? {
match get_packet(&tables.signed_packets, &key)? { Some(packet) => {
let expired = Timestamp::now() - expiry_us;
if packet.timestamp() < expired {
tables.update_time.remove(&time.to_bytes(), key.as_bytes()).e()?;
Expand All @@ -204,10 +204,10 @@ impl Actor {
debug!("packet {key} is no longer expired, removing obsolete expiry entry");
tables.update_time.remove(&time.to_bytes(), key.as_bytes()).e()?;
}
} else {
} _ => {
debug!("expired packet {key} not found, remove from expiry table");
tables.update_time.remove(&time.to_bytes(), key.as_bytes()).e()?;
}
}}
}
}
}
Expand Down Expand Up @@ -365,7 +365,9 @@ fn get_packet(
buf.extend(data);
match SignedPacket::deserialize(&buf) {
Ok(packet) => Ok(Some(packet)),
Err(err2) => Err(format_err!("Failed to decode as pkarr v3: {err:#}. Also failed to decode as pkarr v2: {err2:#}"))
Err(err2) => Err(format_err!(
"Failed to decode as pkarr v3: {err:#}. Also failed to decode as pkarr v2: {err2:#}"
)),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions iroh-dns-server/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use core::fmt;
use std::{
collections::{btree_map, BTreeMap},
collections::{BTreeMap, btree_map},
str::FromStr,
sync::Arc,
};

use hickory_server::proto::{
op::Message,
rr::{
domain::{IntoLabel, Label},
Name, Record, RecordSet, RecordType, RrKey,
domain::{IntoLabel, Label},
},
serialize::binary::BinDecodable,
};
Expand Down
Loading
Loading