Skip to content

Commit 1a7a88b

Browse files
authored
refactor: remove Endpoint::path_selection (#3668)
## Description Remove the test-only `Endpoint::path_selection` API and instead use `Endpoint::clear_ip_transports` for `PathSelection::RelayOnly `, now that this public API was added in #3651. ## Breaking Changes <!-- Optional, if there are any breaking changes document them, including how to migrate older code. --> ## Notes & open questions <!-- Any notes, remarks or open questions you have to make about the PR. --> ## Change checklist <!-- Remove any that are not relevant. --> - [ ] 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. - [ ] List all breaking changes in the above "Breaking Changes" section. - [ ] Open an issue or PR on any number0 repos that are affected by this breaking change. Give guidance on how the updates should be handled or do the actual updates themselves. The major ones are: - [ ] [`quic-rpc`](https://github.com/n0-computer/quic-rpc) - [ ] [`iroh-gossip`](https://github.com/n0-computer/iroh-gossip) - [ ] [`iroh-blobs`](https://github.com/n0-computer/iroh-blobs) - [ ] [`dumbpipe`](https://github.com/n0-computer/dumbpipe) - [ ] [`sendme`](https://github.com/n0-computer/sendme)
1 parent 7f17d98 commit 1a7a88b

File tree

6 files changed

+9
-71
lines changed

6 files changed

+9
-71
lines changed

iroh/bench/src/iroh.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ pub fn server_endpoint(
3434
#[cfg(feature = "local-relay")]
3535
{
3636
builder = builder.insecure_skip_relay_cert_verify(relay_url.is_some());
37-
let path_selection = match opt.only_relay {
38-
true => iroh::endpoint::PathSelection::RelayOnly,
39-
false => iroh::endpoint::PathSelection::default(),
40-
};
41-
builder = builder.path_selection(path_selection);
37+
if opt.only_relay {
38+
builder = builder.clear_ip_transports();
39+
}
4240
}
4341
let ep = builder
4442
.alpns(vec![ALPN.to_vec()])
@@ -95,11 +93,9 @@ pub async fn connect_client(
9593
#[cfg(feature = "local-relay")]
9694
{
9795
builder = builder.insecure_skip_relay_cert_verify(relay_url.is_some());
98-
let path_selection = match opt.only_relay {
99-
true => iroh::endpoint::PathSelection::RelayOnly,
100-
false => iroh::endpoint::PathSelection::default(),
101-
};
102-
builder = builder.path_selection(path_selection);
96+
if opt.only_relay {
97+
builder = builder.clear_ip_transports();
98+
}
10399
}
104100
let endpoint = builder
105101
.alpns(vec![ALPN.to_vec()])

iroh/examples/transfer.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -242,16 +242,7 @@ impl EndpointArgs {
242242
}
243243

244244
if self.relay_only {
245-
#[cfg(feature = "test-utils")]
246-
{
247-
builder = builder.path_selection(iroh::endpoint::PathSelection::RelayOnly)
248-
}
249-
#[cfg(not(feature = "test-utils"))]
250-
{
251-
n0_error::bail_any!(
252-
"Must have the `discovery-local-network` enabled when using the `--mdns` flag"
253-
);
254-
}
245+
builder = builder.clear_ip_transports();
255246
}
256247

257248
if let Some(host) = self.dns_server {
@@ -280,7 +271,7 @@ impl EndpointArgs {
280271
#[cfg(not(feature = "discovery-local-network"))]
281272
{
282273
n0_error::bail_any!(
283-
"Must have the `test-utils` feature enabled when using the `--relay-only` flag"
274+
"Must have the `discovery-local-network` enabled when using the `--mdns` flag"
284275
);
285276
}
286277
}

iroh/src/endpoint.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,6 @@ pub use crate::magicsock::transports::TransportConfig;
8181
/// is still no connection the configured [`crate::discovery::Discovery`] will be used however.
8282
const DISCOVERY_WAIT_PERIOD: Duration = Duration::from_millis(500);
8383

84-
/// Defines the mode of path selection for all traffic flowing through
85-
/// the endpoint.
86-
#[cfg(any(test, feature = "test-utils"))]
87-
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
88-
pub enum PathSelection {
89-
/// Uses all available paths
90-
#[default]
91-
All,
92-
/// Forces all traffic to go exclusively through relays
93-
RelayOnly,
94-
}
95-
9684
/// Builder for [`Endpoint`].
9785
///
9886
/// By default the endpoint will generate a new random [`SecretKey`], which will result in a
@@ -113,8 +101,6 @@ pub struct Builder {
113101
#[cfg(any(test, feature = "test-utils"))]
114102
insecure_skip_relay_cert_verify: bool,
115103
transports: Vec<TransportConfig>,
116-
#[cfg(any(test, feature = "test-utils"))]
117-
path_selection: PathSelection,
118104
max_tls_tickets: usize,
119105
}
120106

@@ -176,8 +162,6 @@ impl Builder {
176162
dns_resolver: None,
177163
#[cfg(any(test, feature = "test-utils"))]
178164
insecure_skip_relay_cert_verify: false,
179-
#[cfg(any(test, feature = "test-utils"))]
180-
path_selection: PathSelection::default(),
181165
max_tls_tickets: DEFAULT_MAX_TLS_TICKETS,
182166
transports,
183167
}
@@ -224,8 +208,6 @@ impl Builder {
224208
server_config,
225209
#[cfg(any(test, feature = "test-utils"))]
226210
insecure_skip_relay_cert_verify: self.insecure_skip_relay_cert_verify,
227-
// #[cfg(any(test, feature = "test-utils"))]
228-
// path_selection: self.path_selection,
229211
metrics,
230212
};
231213

@@ -471,14 +453,6 @@ impl Builder {
471453
self
472454
}
473455

474-
/// This implies we only use the relay to communicate
475-
/// and do not attempt to do any hole punching.
476-
#[cfg(any(test, feature = "test-utils"))]
477-
pub fn path_selection(mut self, path_selection: PathSelection) -> Self {
478-
self.path_selection = path_selection;
479-
self
480-
}
481-
482456
/// Set the maximum number of TLS tickets to cache.
483457
///
484458
/// Set this to a larger value if you want to do 0rtt connections to a large

iroh/src/magicsock.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ use self::{
5353
};
5454
#[cfg(not(wasm_browser))]
5555
use crate::dns::DnsResolver;
56-
// #[cfg(any(test, feature = "test-utils"))]
57-
// use crate::endpoint::PathSelection;
5856
#[cfg(not(wasm_browser))]
5957
use crate::net_report::QuicConfig;
6058
use crate::{
@@ -136,10 +134,6 @@ pub(crate) struct Options {
136134
/// May only be used in tests.
137135
#[cfg(any(test, feature = "test-utils"))]
138136
pub(crate) insecure_skip_relay_cert_verify: bool,
139-
140-
// /// Configuration for what path selection to use
141-
// #[cfg(any(test, feature = "test-utils"))]
142-
// pub(crate) path_selection: PathSelection,
143137
pub(crate) metrics: EndpointMetrics,
144138
}
145139

@@ -936,8 +930,6 @@ impl Handle {
936930
server_config,
937931
#[cfg(any(test, feature = "test-utils"))]
938932
insecure_skip_relay_cert_verify,
939-
// #[cfg(any(test, feature = "test-utils"))]
940-
// path_selection,
941933
metrics,
942934
} = opts;
943935

@@ -1026,8 +1018,6 @@ impl Handle {
10261018
let endpoint_map = {
10271019
EndpointMap::new(
10281020
secret_key.public(),
1029-
// #[cfg(any(test, feature = "test-utils"))]
1030-
// path_selection,
10311021
metrics.magicsock.clone(),
10321022
direct_addrs.addrs.watch(),
10331023
disco.clone(),
@@ -1856,12 +1846,9 @@ mod tests {
18561846

18571847
use super::{EndpointIdMappedAddr, Options, endpoint_map::Source, mapped_addrs::MappedAddr};
18581848
use crate::{
1859-
Endpoint,
1860-
RelayMode,
1861-
SecretKey,
1849+
Endpoint, RelayMode, SecretKey,
18621850
discovery::static_provider::StaticProvider,
18631851
dns::DnsResolver,
1864-
// endpoint::PathSelection,
18651852
magicsock::{Handle, MagicSock, TransportConfig},
18661853
tls::{self, DEFAULT_MAX_TLS_TICKETS},
18671854
};
@@ -1883,7 +1870,6 @@ mod tests {
18831870
#[cfg(any(test, feature = "test-utils"))]
18841871
insecure_skip_relay_cert_verify: false,
18851872
#[cfg(any(test, feature = "test-utils"))]
1886-
// path_selection: PathSelection::default(),
18871873
discovery_user_data: None,
18881874
metrics: Default::default(),
18891875
}
@@ -2319,7 +2305,6 @@ mod tests {
23192305
proxy_url: None,
23202306
server_config,
23212307
insecure_skip_relay_cert_verify: false,
2322-
// path_selection: PathSelection::default(),
23232308
metrics: Default::default(),
23242309
};
23252310
let msock = MagicSock::spawn(opts).await?;

iroh/src/magicsock/endpoint_map.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ use serde::{Deserialize, Serialize};
1212
use tokio::sync::mpsc;
1313
use tracing::warn;
1414

15-
// #[cfg(any(test, feature = "test-utils"))]
16-
// use crate::endpoint::PathSelection;
1715
pub(super) use self::endpoint_state::EndpointStateMessage;
1816
pub(crate) use self::endpoint_state::PathsWatcher;
1917
use self::endpoint_state::{EndpointStateActor, EndpointStateHandle};
@@ -69,8 +67,6 @@ impl EndpointMap {
6967
/// Creates a new [`EndpointMap`].
7068
pub(super) fn new(
7169
local_endpoint_id: EndpointId,
72-
// TODO:
73-
// #[cfg(any(test, feature = "test-utils"))] path_selection: PathSelection,
7470
metrics: Arc<MagicsockMetrics>,
7571

7672
local_addrs: n0_watcher::Direct<BTreeSet<DirectAddr>>,

iroh/src/magicsock/endpoint_map/endpoint_state.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ use crate::{
3535
util::MaybeFuture,
3636
};
3737

38-
// TODO: Use this
39-
// #[cfg(any(test, feature = "test-utils"))]
40-
// use crate::endpoint::PathSelection;
41-
4238
mod guarded_channel;
4339

4440
// TODO: use this

0 commit comments

Comments
 (0)