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
///

iroh-relay/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ http = "1"
3838
http-body-util = "0.1.0"
3939
hyper = { version = "1", features = ["server", "client", "http1"] }
4040
hyper-util = "0.1.1"
41-
iroh-base = { version = "0.29.0", path = "../iroh-base", features = ["key"] }
41+
iroh-base = { version = "0.29.0", path = "../iroh-base", default-features = false, features = ["key", "relay"] }
4242
iroh-metrics = { version = "0.29.0", default-features = false }
4343
libc = "0.2.139"
4444
num_enum = "0.7"

iroh-relay/src/client.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use hyper::{
2424
Request,
2525
};
2626
use hyper_util::rt::TokioIo;
27-
use iroh_base::key::{NodeId, PublicKey, SecretKey};
27+
use iroh_base::{NodeId, PublicKey, RelayUrl, SecretKey};
2828
use rand::Rng;
2929
use rustls::client::Resumption;
3030
use streams::{downcast_upgrade, MaybeTlsStream, ProxyStream};
@@ -46,7 +46,6 @@ use crate::{
4646
defaults::timeouts::*,
4747
http::{Protocol, RELAY_PATH},
4848
protos::relay::DerpCodec,
49-
RelayUrl,
5049
};
5150

5251
pub(crate) mod conn;

iroh-relay/src/client/conn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use futures_util::{
1818
stream::{SplitSink, SplitStream, StreamExt},
1919
SinkExt,
2020
};
21-
use iroh_base::key::{NodeId, SecretKey};
21+
use iroh_base::{NodeId, SecretKey};
2222
use tokio::sync::mpsc;
2323
use tokio_tungstenite_wasm::WebSocketStream;
2424
use tokio_util::{

iroh-relay/src/defaults.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
//! Default values used in the relay.
22
3-
pub use iroh_base::relay_map::{DEFAULT_RELAY_QUIC_PORT, DEFAULT_STUN_PORT};
3+
/// The default STUN port used by the Relay server.
4+
///
5+
/// The STUN port as defined by [RFC 8489](<https://www.rfc-editor.org/rfc/rfc8489#section-18.6>)
6+
pub const DEFAULT_STUN_PORT: u16 = 3478;
7+
8+
/// The default QUIC port used by the Relay server to accept QUIC connections
9+
/// for QUIC address discovery
10+
///
11+
/// The port is "QUIC" typed on a phone keypad.
12+
pub const DEFAULT_RELAY_QUIC_PORT: u16 = 7842;
413

514
/// The default HTTP port used by the Relay server.
615
pub const DEFAULT_HTTP_PORT: u16 = 80;

iroh-relay/src/lib.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,18 @@ pub mod quic;
3737
#[cfg(feature = "server")]
3838
pub mod server;
3939

40+
mod relay_map;
41+
4042
#[cfg(test)]
4143
mod dns;
4244

43-
pub use iroh_base::node_addr::RelayUrl;
4445
pub use protos::relay::MAX_PACKET_SIZE;
4546

46-
pub use self::client::{
47-
conn::{Conn as RelayConn, ReceivedMessage},
48-
Client as HttpClient, ClientBuilder as HttpClientBuilder, ClientError as HttpClientError,
49-
ClientReceiver as HttpClientReceiver,
47+
pub use self::{
48+
client::{
49+
conn::{Conn as RelayConn, ReceivedMessage},
50+
Client as HttpClient, ClientBuilder as HttpClientBuilder, ClientError as HttpClientError,
51+
ClientReceiver as HttpClientReceiver,
52+
},
53+
relay_map::{RelayMap, RelayNode, RelayQuicConfig},
5054
};

iroh-relay/src/protos/relay.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ use std::time::Duration;
1616

1717
use anyhow::{bail, ensure};
1818
use bytes::{Buf, BufMut, Bytes, BytesMut};
19-
#[cfg(feature = "server")]
19+
#[cfg(any(test, feature = "server"))]
2020
use futures_lite::{Stream, StreamExt};
2121
use futures_sink::Sink;
2222
use futures_util::SinkExt;
23-
use iroh_base::key::{PublicKey, SecretKey, Signature, PUBLIC_KEY_LENGTH};
23+
use iroh_base::{PublicKey, SecretKey, Signature, PUBLIC_KEY_LENGTH};
2424
use postcard::experimental::max_size::MaxSize;
2525
use serde::{Deserialize, Serialize};
2626
use tokio_util::codec::{Decoder, Encoder};

iroh-relay/src/quic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl QuicClient {
270270
}
271271
}
272272

273-
#[cfg(test)]
273+
#[cfg(all(test, feature = "server"))]
274274
mod tests {
275275
use std::net::Ipv4Addr;
276276

iroh-base/src/relay_map.rs renamed to iroh-relay/src/relay_map.rs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,10 @@
33
use std::{collections::BTreeMap, fmt, sync::Arc};
44

55
use anyhow::{ensure, Result};
6+
use iroh_base::RelayUrl;
67
use serde::{Deserialize, Serialize};
78

8-
pub use crate::relay_url::RelayUrl;
9-
10-
/// The default STUN port used by the Relay server.
11-
///
12-
/// The STUN port as defined by [RFC 8489](<https://www.rfc-editor.org/rfc/rfc8489#section-18.6>)
13-
pub const DEFAULT_STUN_PORT: u16 = 3478;
14-
15-
/// The default QUIC port used by the Relay server to accept QUIC connections
16-
/// for QUIC address discovery
17-
///
18-
/// The port is "QUIC" typed on a phone keypad.
19-
pub const DEFAULT_RELAY_QUIC_PORT: u16 = 7842;
9+
use crate::defaults::{DEFAULT_RELAY_QUIC_PORT, DEFAULT_STUN_PORT};
2010

2111
/// Configuration of all the relay servers that can be used.
2212
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -77,7 +67,7 @@ impl RelayMap {
7767
url,
7868
stun_only: false,
7969
stun_port,
80-
quic: Some(QuicConfig::default()),
70+
quic: Some(RelayQuicConfig::default()),
8171
}
8272
.into(),
8373
);
@@ -138,21 +128,22 @@ pub struct RelayNode {
138128
/// When `None`, we will not attempt to do QUIC address discovery
139129
/// with this relay server.
140130
#[serde(default = "quic_config")]
141-
pub quic: Option<QuicConfig>,
131+
pub quic: Option<RelayQuicConfig>,
142132
}
143133

144-
fn quic_config() -> Option<QuicConfig> {
145-
Some(QuicConfig::default())
134+
fn quic_config() -> Option<RelayQuicConfig> {
135+
Some(RelayQuicConfig::default())
146136
}
147137

148138
/// Configuration for speaking to the QUIC endpoint on the relay
149139
/// server to do QUIC address discovery.
150140
#[derive(Debug, Deserialize, Serialize, Clone, Eq, PartialEq, PartialOrd, Ord)]
151-
pub struct QuicConfig {
141+
pub struct RelayQuicConfig {
142+
/// The port on which the connection should be bound to.
152143
pub port: u16,
153144
}
154145

155-
impl Default for QuicConfig {
146+
impl Default for RelayQuicConfig {
156147
fn default() -> Self {
157148
Self {
158149
port: DEFAULT_RELAY_QUIC_PORT,

iroh-relay/src/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use http::{
2626
};
2727
use hyper::body::Incoming;
2828
#[cfg(feature = "test-utils")]
29-
use iroh_base::node_addr::RelayUrl;
29+
use iroh_base::RelayUrl;
3030
use iroh_metrics::inc;
3131
use tokio::{
3232
net::{TcpListener, UdpSocket},
@@ -760,7 +760,7 @@ mod tests {
760760

761761
use bytes::Bytes;
762762
use http::header::UPGRADE;
763-
use iroh_base::{key::SecretKey, node_addr::RelayUrl};
763+
use iroh_base::SecretKey;
764764

765765
use super::*;
766766
use crate::{

iroh-relay/src/server/actor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{collections::HashMap, time::Duration};
66

77
use anyhow::{bail, Result};
88
use bytes::Bytes;
9-
use iroh_base::key::NodeId;
9+
use iroh_base::NodeId;
1010
use iroh_metrics::{inc, inc_by};
1111
use time::{Date, OffsetDateTime};
1212
use tokio::sync::mpsc;
@@ -244,7 +244,7 @@ impl ClientCounter {
244244
#[cfg(test)]
245245
mod tests {
246246
use bytes::Bytes;
247-
use iroh_base::key::SecretKey;
247+
use iroh_base::SecretKey;
248248
use tokio::io::DuplexStream;
249249
use tokio_util::codec::Framed;
250250

0 commit comments

Comments
 (0)