Skip to content

Commit d9fb470

Browse files
refactor(iroh)!: improve reexport structure (#3023)
## Description Currently this simply normalizes `iroh_base` based reexports, but this shows that a lot of the types in `iroh-base` are not very pleasant to import ## Breaking Changes - `iroh-base` - `key` -> `iroh_base::NodeId` etc - `hash` -> `iroh_base::Hash` etc - `node_addr` -> `iroh_base::NodeAddr` - `relay_url` -> `iroh_base::RelayUrl` - `relay_map` -> use `iroh_relay::relay_map` - `iroh` - `hash` -> `iroh_base` - `ticket` -> `iroh_base::ticket`) - `relay` -> removed, use `iroh_relay` directly if needed - `key` -> `NodeId`, etc top level now - `endpoint::Bytes` removed use `bytes::Bytes` - `endpoint::NodeAddr`, use `iroh::NodeAddr` ## Notes & open questions <!-- Any notes, remarks or open questions you have to make about the PR. --> ## Change checklist - [ ] Self-review. - [ ] 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. - [ ] Tests if relevant. - [ ] All breaking changes documented.
1 parent 6e009a8 commit d9fb470

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+224
-212
lines changed

iroh-base/Cargo.toml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,24 @@ serde_test = "1"
4848
[features]
4949
default = ["hash", "ticket", "relay"]
5050
hash = ["dep:blake3", "dep:data-encoding", "dep:postcard", "dep:derive_more", "base32"]
51-
ticket = ["base32", "key"]
51+
ticket = ["base32", "key", "hash"]
5252
base32 = ["dep:data-encoding", "dep:postcard"]
5353
redb = ["dep:redb"]
54-
key = ["dep:ed25519-dalek", "dep:once_cell", "dep:rand", "dep:rand_core", "dep:ssh-key", "dep:ttl_cache", "dep:aead", "dep:crypto_box", "dep:zeroize", "dep:url", "dep:derive_more", "dep:getrandom"]
54+
key = [
55+
"dep:ed25519-dalek",
56+
"dep:once_cell",
57+
"dep:rand",
58+
"dep:rand_core",
59+
"dep:ssh-key",
60+
"dep:ttl_cache",
61+
"dep:aead",
62+
"dep:crypto_box",
63+
"dep:zeroize",
64+
"dep:url",
65+
"dep:derive_more",
66+
"dep:getrandom",
67+
"base32",
68+
]
5569
wasm = ["getrandom?/js"]
5670
relay = ["dep:url", "dep:derive_more"]
5771

iroh-base/src/lib.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
//! Base types and utilities for Iroh
22
#![cfg_attr(iroh_docsrs, feature(doc_auto_cfg))]
33

4+
// TODO: remove
45
#[cfg(feature = "base32")]
56
pub mod base32;
7+
8+
// TODO: move to own crate
9+
#[cfg(feature = "ticket")]
10+
pub mod ticket;
11+
612
#[cfg(feature = "hash")]
7-
pub mod hash;
13+
mod hash;
814
#[cfg(feature = "key")]
9-
pub mod key;
15+
mod key;
1016
#[cfg(feature = "key")]
11-
pub mod node_addr;
12-
#[cfg(feature = "relay")]
13-
pub mod relay_map;
17+
mod node_addr;
1418
#[cfg(feature = "relay")]
1519
mod relay_url;
16-
#[cfg(feature = "ticket")]
17-
pub mod ticket;
20+
21+
#[cfg(feature = "hash")]
22+
pub use self::hash::{BlobFormat, Hash, HashAndFormat};
23+
#[cfg(feature = "key")]
24+
pub use self::key::{
25+
KeyParsingError, NodeId, PublicKey, SecretKey, SharedSecret, Signature, PUBLIC_KEY_LENGTH,
26+
};
27+
#[cfg(feature = "key")]
28+
pub use self::node_addr::NodeAddr;
29+
#[cfg(feature = "relay")]
30+
pub use self::relay_url::RelayUrl;

iroh-base/src/node_addr.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ use std::{collections::BTreeSet, net::SocketAddr};
1010

1111
use serde::{Deserialize, Serialize};
1212

13-
use crate::key::{NodeId, PublicKey};
14-
pub use crate::relay_url::RelayUrl;
13+
use crate::{NodeId, PublicKey, RelayUrl};
1514

1615
/// Network-level addressing information for an iroh node.
1716
///

iroh-dns-server/benches/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use anyhow::Result;
22
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
3-
use iroh::{discovery::pkarr::PkarrRelayClient, dns::node_info::NodeInfo, key::SecretKey};
3+
use iroh::{discovery::pkarr::PkarrRelayClient, dns::node_info::NodeInfo, SecretKey};
44
use iroh_dns_server::{config::Config, server::Server, ZoneStore};
55
use tokio::runtime::Runtime;
66

iroh-dns-server/examples/publish.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ use iroh::{
88
pkarr::{PkarrRelayClient, N0_DNS_PKARR_RELAY_PROD, N0_DNS_PKARR_RELAY_STAGING},
99
},
1010
dns::node_info::{to_z32, NodeInfo, IROH_TXT_NAME},
11-
key::SecretKey,
12-
NodeId,
11+
NodeId, SecretKey,
1312
};
1413
use url::Url;
1514

iroh-dns-server/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ mod tests {
3030
use iroh::{
3131
discovery::pkarr::PkarrRelayClient,
3232
dns::{node_info::NodeInfo, DnsResolver, ResolverExt},
33-
key::SecretKey,
33+
SecretKey,
3434
};
3535
use pkarr::{PkarrClient, SignedPacket};
3636
use testresult::TestResult;

iroh-net-report/src/defaults.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Default values used in net_report.
22
3-
pub(crate) use iroh_base::relay_map::{DEFAULT_RELAY_QUIC_PORT, DEFAULT_STUN_PORT};
4-
53
/// Contains all timeouts that we use in `iroh-net-report`.
64
pub(crate) mod timeouts {
75
use std::time::Duration;

iroh-net-report/src/lib.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ use std::{
1515
use anyhow::{anyhow, Context as _, Result};
1616
use bytes::Bytes;
1717
use hickory_resolver::TokioResolver as DnsResolver;
18-
use iroh_base::relay_map::{RelayMap, RelayNode, RelayUrl};
18+
use iroh_base::RelayUrl;
1919
#[cfg(feature = "metrics")]
2020
use iroh_metrics::inc;
21-
use iroh_relay::protos::stun;
21+
use iroh_relay::{protos::stun, RelayMap};
2222
use netwatch::{IpFamily, UdpSocket};
2323
use tokio::{
2424
sync::{self, mpsc, oneshot},
@@ -808,16 +808,13 @@ mod test_utils {
808808
809809
use std::sync::Arc;
810810

811-
use iroh_base::relay_map::QuicConfig;
812-
use iroh_relay::server;
813-
814-
use crate::RelayNode;
811+
use iroh_relay::{server, RelayNode, RelayQuicConfig};
815812

816813
pub(crate) async fn relay() -> (server::Server, Arc<RelayNode>) {
817814
let server = server::Server::spawn(server::testing::server_config())
818815
.await
819816
.expect("should serve relay");
820-
let quic = Some(QuicConfig {
817+
let quic = Some(RelayQuicConfig {
821818
port: server.quic_addr().expect("server should run quic").port(),
822819
});
823820
let node_desc = RelayNode {
@@ -864,14 +861,15 @@ mod tests {
864861
use std::{net::IpAddr, sync::Arc};
865862

866863
use anyhow::Result;
864+
use iroh_base::RelayUrl;
865+
use iroh_relay::RelayNode;
867866
use tokio::{
868867
net,
869868
sync::{oneshot, Mutex},
870869
};
871870
use tracing::{debug, trace};
872871

873872
use super::*;
874-
use crate::{RelayMap, RelayNode, RelayUrl};
875873

876874
/// A drop guard to clean up test infrastructure.
877875
///

iroh-net-report/src/reportgen.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,15 @@ use std::{
2727

2828
use anyhow::{anyhow, bail, Context as _, Result};
2929
use hickory_resolver::TokioResolver as DnsResolver;
30+
use iroh_base::RelayUrl;
3031
#[cfg(feature = "metrics")]
3132
use iroh_metrics::inc;
32-
use iroh_relay::{http::RELAY_PROBE_PATH, protos::stun};
33+
use iroh_relay::{
34+
defaults::{DEFAULT_RELAY_QUIC_PORT, DEFAULT_STUN_PORT},
35+
http::RELAY_PROBE_PATH,
36+
protos::stun,
37+
RelayMap, RelayNode,
38+
};
3339
use netwatch::{interfaces, UdpSocket};
3440
use rand::seq::IteratorRandom;
3541
use tokio::{
@@ -45,10 +51,9 @@ use url::Host;
4551
use crate::Metrics;
4652
use crate::{
4753
self as net_report,
48-
defaults::{DEFAULT_RELAY_QUIC_PORT, DEFAULT_STUN_PORT},
4954
dns::ResolverExt,
5055
ping::{PingError, Pinger},
51-
RelayMap, RelayNode, RelayUrl, Report,
56+
Report,
5257
};
5358

5459
mod hairpin;

iroh-net-report/src/reportgen/probes.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
use std::{collections::BTreeSet, fmt, sync::Arc};
88

99
use anyhow::{ensure, Result};
10+
use iroh_base::RelayUrl;
11+
use iroh_relay::{RelayMap, RelayNode};
1012
use netwatch::interfaces;
1113
use tokio::time::Duration;
1214

13-
use crate::{RelayMap, RelayNode, RelayUrl, Report};
15+
use crate::Report;
1416

1517
/// The retransmit interval used when net_report first runs.
1618
///

0 commit comments

Comments
 (0)