Skip to content
Merged
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
5552d9a
refactor: convert iroh-base to n0-error
Frando Oct 20, 2025
93fb21c
fixup
Frando Oct 20, 2025
82f4bbd
refactor: convert iroh-relay
Frando Oct 20, 2025
0b4c014
wip
Frando Oct 20, 2025
9650632
wip: converting iroh
Frando Oct 20, 2025
54fef34
fmt
Frando Oct 20, 2025
39a5935
fixup
Frando Oct 20, 2025
3cd15f9
fixup
Frando Oct 20, 2025
f4ec732
fixup
Frando Oct 20, 2025
923694c
codex is converting iroh
Frando Oct 20, 2025
9d39c78
fixes
Frando Oct 20, 2025
4e830d1
wip
Frando Oct 20, 2025
894ff10
codex did it
Frando Oct 20, 2025
47064a3
fix & fmt
Frando Oct 20, 2025
8afe0b7
chore: clippy fix & cargo fix & fmt
Frando Oct 20, 2025
4365e91
fixup
Frando Oct 20, 2025
099e2b0
fixup
Frando Oct 20, 2025
7f59c66
fixup
Frando Oct 20, 2025
587c5c6
fixup
Frando Oct 21, 2025
35fa204
fixup
Frando Oct 21, 2025
383ed04
fixup
Frando Oct 21, 2025
7e9b997
fixup
Frando Oct 21, 2025
6969f68
fixup
Frando Oct 21, 2025
ea9b541
fixup
Frando Oct 21, 2025
8c5694e
update n0-error
Frando Oct 27, 2025
ad783e3
wip
Frando Oct 27, 2025
836e80a
fix: adapt to n0-error API changes
Frando Oct 27, 2025
e8b7690
cleanup
Frando Oct 27, 2025
b466519
more cleanup
Frando Oct 27, 2025
d94e61c
cleanup
Frando Oct 27, 2025
40b8123
updates and cleanups
Frando Oct 27, 2025
9fd0040
Merge remote-tracking branch 'origin/main' into Frando/n0-error
Frando Oct 27, 2025
b8564dd
self-review
Frando Oct 27, 2025
19aab31
more self-review
Frando Oct 27, 2025
83b6459
self review
Frando Oct 27, 2025
83934ea
bump n0-error
Frando Oct 27, 2025
b2f2975
adapt for changes in n0-error
Frando Oct 27, 2025
2aa1031
refactor: bump n0-error, rename #display to #error
Frando Oct 27, 2025
b249b7b
wip: bail -> bail_any
Frando Oct 28, 2025
649482b
bump n0-error and adapt for changes
Frando Oct 28, 2025
315afaf
bump n0-error
Frando Oct 28, 2025
ad42cf1
bump n0-error, rename e() to anyerr()
Frando Oct 28, 2025
e0eb6aa
fixup
Frando Oct 28, 2025
db2c9fd
bump n0-error
Frando Oct 28, 2025
35eaf79
Merge remote-tracking branch 'origin/main' into Frando/n0-error
Frando Oct 30, 2025
d194524
bump n0-error
Frando Oct 30, 2025
304525b
fixup
Frando Oct 30, 2025
a1dbd6c
bump n0-error
Frando Oct 30, 2025
69ae70e
bump to released n0-error
Frando Oct 31, 2025
1998994
deps: remove nested_enum_utils
Frando Oct 31, 2025
8eef317
refactor: use ensure more
dignifiedquire Nov 1, 2025
0f78cc8
refactor(iroh-dns-server): use concrete erros in utils
dignifiedquire Nov 1, 2025
1f12fd3
fix: use imports more
Frando Nov 3, 2025
ad6e742
refactor: simplify line in tests
Frando Nov 3, 2025
9667f8b
refactor(iroh-dns-server): move block from `select!` to fn (#3597)
Frando Nov 3, 2025
24aeb24
bump n0-watcher, iroh-metrics, and add git dep for portmapper and net…
Frando Nov 3, 2025
49848b8
fix: less std errors
Frando Nov 3, 2025
a9875ed
update portmapper and netwatch
Frando Nov 3, 2025
10a8558
address some nits
Frando Nov 3, 2025
ea6f85f
Merge remote-tracking branch 'origin/main' into Frando/n0-error
Frando Nov 3, 2025
c9b5aef
Merge remote-tracking branch 'origin/main' into Frando/n0-error
Frando Nov 3, 2025
5924089
tests: mark integration_mainline as flaky
Frando Nov 3, 2025
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
231 changes: 51 additions & 180 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ unexpected_cfgs = { level = "warn", check-cfg = ["cfg(iroh_docsrs)", "cfg(iroh_l

[workspace.lints.clippy]
unused-async = "warn"

[patch.crates-io]
netwatch = { git = "https://github.com/n0-computer/net-tools", branch = "Frando/n0-snafu" }
portmapper = { git = "https://github.com/n0-computer/net-tools", branch = "Frando/n0-snafu" }
6 changes: 1 addition & 5 deletions iroh-base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ derive_more = { version = "2.0.1", features = ["display"], optional = true }
url = { version = "2.5.3", features = ["serde"], optional = true }
rand_core = { version = "0.9.3", optional = true }
serde = { version = "1", features = ["derive", "rc"] }
snafu = { version = "0.8.5", features = ["rust_1_81"], optional = true }
n0-snafu = "0.2.2"
nested_enum_utils = "0.2.0"
n0-error = "0.1.0"
zeroize = { version = "1.8.2", optional = true, features = ["derive"] }
zeroize_derive = { version = "1.4.2", optional = true } # needed for minimal versions

Expand All @@ -44,7 +42,6 @@ key = [
"dep:ed25519-dalek",
"dep:url",
"dep:derive_more",
"dep:snafu",
"dep:data-encoding",
"dep:rand_core",
"dep:zeroize",
Expand All @@ -54,7 +51,6 @@ key = [
relay = [
"dep:url",
"dep:derive_more",
"dep:snafu",
]

[package.metadata.docs.rs]
Expand Down
47 changes: 20 additions & 27 deletions iroh-base/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ use std::{

use curve25519_dalek::edwards::CompressedEdwardsY;
use ed25519_dalek::{SigningKey, VerifyingKey};
use nested_enum_utils::common_fields;
use n0_error::{ensure, stack_error};
use rand_core::CryptoRng;
use serde::{Deserialize, Serialize, de, ser};
use snafu::{Backtrace, Snafu};

/// A public key.
///
Expand Down Expand Up @@ -128,7 +127,7 @@ impl PublicKey {
pub fn verify(&self, message: &[u8], signature: &Signature) -> Result<(), SignatureError> {
self.as_verifying_key()
.verify_strict(message, &signature.0)
.map_err(|_| SignatureSnafu.build())
.map_err(|_| SignatureError::new())
}

/// Convert to a hex string limited to the first 5 bytes for a friendly string
Expand Down Expand Up @@ -204,26 +203,18 @@ impl Display for PublicKey {
}

/// Error when deserialising a [`PublicKey`] or a [`SecretKey`].
#[common_fields({
backtrace: Option<Backtrace>,
#[snafu(implicit)]
span_trace: n0_snafu::SpanTrace,
})]
#[derive(Snafu, Debug)]
#[stack_error(derive, add_meta, from_sources, std_sources)]
#[allow(missing_docs)]
#[snafu(visibility(pub(crate)))]
pub enum KeyParsingError {
/// Error when decoding.
#[snafu(transparent)]
Decode { source: data_encoding::DecodeError },
#[error(transparent)]
Decode(data_encoding::DecodeError),
/// Error when decoding the public key.
#[snafu(transparent)]
Key {
source: ed25519_dalek::SignatureError,
},
#[error(transparent)]
Key(ed25519_dalek::SignatureError),
/// The encoded information had the wrong length.
#[snafu(display("invalid length"))]
DecodeInvalidLength {},
#[error("invalid length")]
DecodeInvalidLength,
}

/// Deserialises the [`PublicKey`] from it's base32 encoding.
Expand Down Expand Up @@ -420,9 +411,9 @@ impl Signature {
}

/// Verification of a signature failed.
#[derive(Debug, Snafu)]
#[snafu(display("Invalid signature"))]
pub struct SignatureError;
#[stack_error(derive, add_meta)]
#[error("Invalid signature")]
pub struct SignatureError {}

fn decode_base32_hex(s: &str) -> Result<[u8; 32], KeyParsingError> {
let mut bytes = [0u8; 32];
Expand All @@ -433,16 +424,18 @@ fn decode_base32_hex(s: &str) -> Result<[u8; 32], KeyParsingError> {
} else {
let input = s.to_ascii_uppercase();
let input = input.as_bytes();
if data_encoding::BASE32_NOPAD.decode_len(input.len())? != bytes.len() {
return Err(DecodeInvalidLengthSnafu.build());
}
ensure!(
data_encoding::BASE32_NOPAD.decode_len(input.len())? == bytes.len(),
KeyParsingError::DecodeInvalidLength
);
data_encoding::BASE32_NOPAD.decode_mut(input, &mut bytes)
};
match res {
Ok(len) => {
if len != PublicKey::LENGTH {
return Err(DecodeInvalidLengthSnafu.build());
}
ensure!(
len == PublicKey::LENGTH,
KeyParsingError::DecodeInvalidLength
);
}
Err(partial) => return Err(partial.error.into()),
}
Expand Down
13 changes: 5 additions & 8 deletions iroh-base/src/relay_url.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{fmt, ops::Deref, str::FromStr, sync::Arc};

use n0_error::stack_error;
use serde::{Deserialize, Serialize};
use snafu::{Backtrace, ResultExt, Snafu};
use url::Url;

/// A URL identifying a relay server.
Expand Down Expand Up @@ -39,12 +39,9 @@ impl From<Url> for RelayUrl {
}

/// Can occur when parsing a string into a [`RelayUrl`].
#[derive(Debug, Snafu)]
#[snafu(display("Failed to parse"))]
pub struct RelayUrlParseError {
source: url::ParseError,
backtrace: Option<Backtrace>,
}
#[stack_error(derive, add_meta)]
#[error("Failed to parse relay URL")]
pub struct RelayUrlParseError(#[error(std_err)] url::ParseError);

/// Support for parsing strings directly.
///
Expand All @@ -54,7 +51,7 @@ impl FromStr for RelayUrl {
type Err = RelayUrlParseError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let inner = Url::from_str(s).context(RelayUrlParseSnafu)?;
let inner = Url::from_str(s).map_err(|err| RelayUrlParseError::new(err))?;
Ok(RelayUrl::from(inner))
}
}
Expand Down
5 changes: 2 additions & 3 deletions iroh-dns-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ hickory-server = { version = "0.25.1", features = ["https-ring"] }
http = "1.0.0"
humantime = "2.2.0"
humantime-serde = "1.1.1"
iroh-metrics = { version = "0.36", features = ["service"] }
iroh-metrics = { version = "0.37", features = ["service"] }
lru = "0.16"
n0-future = "0.3.0"
n0-snafu = "0.2.2"
pkarr = { version = "5", features = ["relays", "dht"], default-features = false }
rcgen = "0.14"
redb = "3.1.0"
Expand All @@ -40,7 +39,7 @@ rustls = { version = "0.23.33", default-features = false, features = ["ring"] }
rustls-pemfile = { version = "2.1" }
serde = { version = "1", features = ["derive"] }
struct_iterable = "0.1.1"
snafu = { version = "0.8.5", features = ["rust_1_81"] }
n0-error = "0.1.0"
strum = { version = "0.27", features = ["derive"] }
tokio = { version = "1", features = ["full"] }
tokio-rustls = { version = "0.26", default-features = false, features = [
Expand Down
2 changes: 1 addition & 1 deletion iroh-dns-server/benches/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use criterion::{BenchmarkId, Criterion, Throughput, criterion_group, criterion_main};
use iroh::{SecretKey, discovery::pkarr::PkarrRelayClient, endpoint_info::EndpointInfo};
use iroh_dns_server::{ZoneStore, config::Config, metrics::Metrics, server::Server};
use n0_snafu::Result;
use n0_error::Result;
use rand_chacha::rand_core::SeedableRng;
use tokio::runtime::Runtime;

Expand Down
8 changes: 4 additions & 4 deletions iroh-dns-server/examples/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::str::FromStr;

use clap::Parser;
use iroh::EndpointId;
use n0_snafu::{Result, ResultExt};
use n0_error::{Result, StdResultExt};

#[derive(Debug, Parser)]
struct Cli {
Expand All @@ -21,12 +21,12 @@ fn main() -> Result<()> {
match args.command {
Command::EndpointToPkarr { endpoint_id } => {
let endpoint_id = EndpointId::from_str(&endpoint_id)?;
let public_key = pkarr::PublicKey::try_from(endpoint_id.as_bytes()).e()?;
let public_key = pkarr::PublicKey::try_from(endpoint_id.as_bytes()).anyerr()?;
println!("{}", public_key.to_z32())
}
Command::PkarrToEndpoint { z32_pubkey } => {
let public_key = pkarr::PublicKey::try_from(z32_pubkey.as_str()).e()?;
let endpoint_id = EndpointId::from_bytes(public_key.as_bytes()).e()?;
let public_key = pkarr::PublicKey::try_from(z32_pubkey.as_str()).anyerr()?;
let endpoint_id = EndpointId::from_bytes(public_key.as_bytes())?;
println!("{endpoint_id}")
}
}
Expand Down
2 changes: 1 addition & 1 deletion iroh-dns-server/examples/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use iroh::{
},
endpoint_info::{EndpointIdExt, EndpointInfo, IROH_TXT_NAME},
};
use n0_snafu::{Result, ResultExt};
use n0_error::{Result, StackResultExt};
use url::Url;

const DEV_PKARR_RELAY_URL: &str = "http://localhost:8080/pkarr";
Expand Down
4 changes: 2 additions & 2 deletions iroh-dns-server/examples/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use iroh::{
discovery::dns::{N0_DNS_ENDPOINT_ORIGIN_PROD, N0_DNS_ENDPOINT_ORIGIN_STAGING},
dns::DnsResolver,
};
use n0_snafu::{Result, ResultExt};
use n0_error::{Result, StackResultExt, StdResultExt};

const DEV_DNS_SERVER: &str = "127.0.0.1:5300";
const DEV_DNS_ORIGIN_DOMAIN: &str = "irohdns.example";
Expand Down Expand Up @@ -49,7 +49,7 @@ async fn main() -> Result<()> {
let resolver = if let Some(host) = args.dns_server {
let addr = tokio::net::lookup_host(host)
.await
.e()?
.anyerr()?
.next()
.context("failed to resolve DNS server address")?;
DnsResolver::with_nameserver(addr)
Expand Down
8 changes: 4 additions & 4 deletions iroh-dns-server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
time::Duration,
};

use n0_snafu::{Result, ResultExt};
use n0_error::{Result, StdResultExt};
use serde::{Deserialize, Serialize};
use tracing::info;

Expand Down Expand Up @@ -162,8 +162,8 @@ impl Config {
);
let s = tokio::fs::read_to_string(path.as_ref())
.await
.with_context(|| format!("failed to read {}", path.as_ref().to_string_lossy()))?;
let config: Config = toml::from_str(&s).e()?;
.with_std_context(|_| format!("failed to read {}", path.as_ref().to_string_lossy()))?;
let config: Config = toml::from_str(&s).anyerr()?;
Ok(config)
}

Expand All @@ -173,7 +173,7 @@ impl Config {
PathBuf::from(val)
} else {
let path = dirs_next::data_dir()
.context("operating environment provides no directory for application data")?;
.std_context("operating environment provides no directory for application data")?;

path.join("iroh-dns")
};
Expand Down
24 changes: 12 additions & 12 deletions iroh-dns-server/src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use hickory_server::{
server::{Request, RequestHandler, ResponseHandler, ResponseInfo},
store::in_memory::InMemoryAuthority,
};
use n0_snafu::{Result, ResultExt, format_err};
use n0_error::{Result, StdResultExt, anyerr};
use serde::{Deserialize, Serialize};
use tokio::{
net::{TcpListener, UdpSocket},
Expand Down Expand Up @@ -82,12 +82,12 @@ impl DnsServer {
config.port,
);

let socket = UdpSocket::bind(bind_addr).await.e()?;
let socket = UdpSocket::bind(bind_addr).await.anyerr()?;

let socket_addr = socket.local_addr().e()?;
let socket_addr = socket.local_addr().anyerr()?;

server.register_socket(socket);
server.register_listener(TcpListener::bind(bind_addr).await.e()?, TCP_TIMEOUT);
server.register_listener(TcpListener::bind(bind_addr).await.anyerr()?, TCP_TIMEOUT);
info!("DNS server listening on {}", bind_addr);

Ok(Self {
Expand All @@ -103,15 +103,15 @@ impl DnsServer {

/// Shutdown the server an wait for all tasks to complete.
pub async fn shutdown(mut self) -> Result<()> {
self.server.shutdown_gracefully().await.e()?;
self.server.shutdown_gracefully().await.anyerr()?;
Ok(())
}

/// Wait for all tasks to complete.
///
/// Runs forever unless tasks fail.
pub async fn run_until_done(mut self) -> Result<()> {
self.server.block_until_done().await.e()?;
self.server.block_until_done().await.anyerr()?;
Ok(())
}
}
Expand All @@ -133,7 +133,7 @@ impl DnsHandler {
.iter()
.map(Name::from_utf8)
.collect::<Result<Vec<_>, _>>()
.e()?;
.anyerr()?;

let (static_authority, serial) = create_static_authority(&origins, config)?;
let authority = Arc::new(NodeAuthority::new(
Expand All @@ -159,7 +159,7 @@ impl DnsHandler {
let (tx, mut rx) = broadcast::channel(1);
let response_handle = Handle(tx);
self.handle_request(&request, response_handle).await;
rx.recv().await.e()
rx.recv().await.anyerr()
}
}

Expand Down Expand Up @@ -234,9 +234,9 @@ fn create_static_authority(
config.default_soa.split_ascii_whitespace(),
None,
)
.e()?
.anyerr()?
.into_soa()
.map_err(|_| format_err!("Couldn't parse SOA: {}", config.default_soa))?;
.map_err(|_| anyerr!("Couldn't parse SOA: {}", config.default_soa))?;
let serial = soa.serial();
let mut records = BTreeMap::new();
for name in origins {
Expand All @@ -260,7 +260,7 @@ fn create_static_authority(
);
}
if let Some(ns) = &config.rr_ns {
let ns = Name::parse(ns, Some(&Name::root())).e()?;
let ns = Name::parse(ns, Some(&Name::root())).anyerr()?;
push_record(
&mut records,
serial,
Expand All @@ -270,7 +270,7 @@ fn create_static_authority(
}

let static_authority = InMemoryAuthority::new(Name::root(), records, ZoneType::Primary, false)
.map_err(|e| format_err!("new authority: {e}"))?;
.map_err(|e| anyerr!("new authority: {e}"))?;

Ok((static_authority, serial))
}
Expand Down
Loading
Loading