Skip to content

Commit 34f52c6

Browse files
Frandoflub
andauthored
refactor(multipath): rename EndpointMap/EndpointState to RemoteMap/RemoteState (#3673)
## Description Renames: * renamed `endpoint_map` -> `remote_map`, `EndpointMap` -> `RemoteMap`, `endpoint_state` -> `remote_state`, `EndpointStateActor` -> `RemoteStateActor` Moved: * moved `path_state` module under `remote_state` (prev `endpoint_state`), its items are used only there and nowhere else ## 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) --------- Co-authored-by: Floris Bruynooghe <flub@n0.computer>
1 parent 1a7a88b commit 34f52c6

File tree

10 files changed

+132
-139
lines changed

10 files changed

+132
-139
lines changed

iroh/src/discovery.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ use tokio::sync::oneshot;
124124
use tracing::{Instrument, debug, error_span, warn};
125125

126126
pub use crate::endpoint_info::{EndpointData, EndpointInfo, ParseError, UserData};
127-
use crate::{Endpoint, magicsock::endpoint_map::Source};
127+
use crate::{Endpoint, magicsock::remote_map::Source};
128128

129129
#[cfg(not(wasm_browser))]
130130
pub mod dns;

iroh/src/endpoint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use url::Url;
2626

2727
pub use super::magicsock::{
2828
AddEndpointAddrError, DirectAddr, DirectAddrType, PathInfo,
29-
endpoint_map::{PathInfoList, Source},
29+
remote_map::{PathInfoList, Source},
3030
};
3131
#[cfg(wasm_browser)]
3232
use crate::discovery::pkarr::PkarrResolver;

iroh/src/endpoint/connection.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ use crate::{
4242
Endpoint,
4343
discovery::DiscoveryTask,
4444
magicsock::{
45-
EndpointStateActorStoppedError,
46-
endpoint_map::{PathInfoList, PathsWatcher},
45+
RemoteStateActorStoppedError,
46+
remote_map::{PathInfoList, PathsWatcher},
4747
},
4848
};
4949

@@ -208,9 +208,9 @@ pub enum AuthenticationError {
208208
NoAlpn {},
209209
}
210210

211-
impl From<EndpointStateActorStoppedError> for ConnectingError {
211+
impl From<RemoteStateActorStoppedError> for ConnectingError {
212212
#[track_caller]
213-
fn from(_value: EndpointStateActorStoppedError) -> Self {
213+
fn from(_value: RemoteStateActorStoppedError) -> Self {
214214
e!(Self::InternalConsistencyError)
215215
}
216216
}
@@ -221,15 +221,15 @@ impl From<EndpointStateActorStoppedError> for ConnectingError {
221221
/// or if the remote did not set an ALPN.
222222
///
223223
/// Otherwise returns a future that completes once the connection has been registered with the
224-
/// magicsock. This future can return an [`EndpointStateActorStoppedError`], which will only be
224+
/// magicsock. This future can return an [`RemoteStateActorStoppedError`], which will only be
225225
/// emitted if the endpoint is closing.
226226
///
227227
/// The returned future is `'static`, so it can be stored without being lifetime-bound on `&ep`.
228228
fn conn_from_quinn_conn(
229229
conn: quinn::Connection,
230230
ep: &Endpoint,
231231
) -> Result<
232-
impl Future<Output = Result<Connection, EndpointStateActorStoppedError>> + Send + 'static,
232+
impl Future<Output = Result<Connection, RemoteStateActorStoppedError>> + Send + 'static,
233233
ConnectingError,
234234
> {
235235
let (remote_id, alpn) = match static_info_from_conn(&conn) {
@@ -328,7 +328,7 @@ pub struct Connecting {
328328
_discovery_drop_guard: Option<DiscoveryTask>,
329329
}
330330

331-
type RegisterWithMagicsockFut = BoxFuture<Result<Connection, EndpointStateActorStoppedError>>;
331+
type RegisterWithMagicsockFut = BoxFuture<Result<Connection, RemoteStateActorStoppedError>>;
332332

333333
/// In-progress connection attempt future
334334
#[derive(derive_more::Debug)]
@@ -370,7 +370,7 @@ pub enum ConnectingError {
370370
},
371371
#[error("Failure finalizing the handshake")]
372372
HandshakeFailure { source: AuthenticationError },
373-
#[error("internal consistency error: EndpointStateActor stopped")]
373+
#[error("internal consistency error: RemoteStateActor stopped")]
374374
InternalConsistencyError,
375375
}
376376

iroh/src/magicsock.rs

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ use transports::{LocalAddrsWatch, MagicTransport, TransportConfig};
4747
use url::Url;
4848

4949
use self::{
50-
endpoint_map::{EndpointMap, EndpointStateMessage},
5150
metrics::Metrics as MagicsockMetrics,
51+
remote_map::{RemoteMap, RemoteStateMessage},
5252
transports::{RelayActorConfig, Transports, TransportsSender},
5353
};
5454
#[cfg(not(wasm_browser))]
@@ -60,22 +60,22 @@ use crate::{
6060
disco::{self, SendAddr},
6161
discovery::{ConcurrentDiscovery, Discovery, EndpointData, UserData},
6262
key::{DecryptionError, SharedSecret, public_ed_box, secret_ed_box},
63-
magicsock::endpoint_map::PathsWatcher,
63+
magicsock::remote_map::PathsWatcher,
6464
metrics::EndpointMetrics,
6565
net_report::{self, IfStateDetails, Report},
6666
};
6767

6868
mod metrics;
6969

70-
pub(crate) mod endpoint_map;
7170
pub(crate) mod mapped_addrs;
71+
pub(crate) mod remote_map;
7272
pub(crate) mod transports;
7373

74-
pub use self::{endpoint_map::PathInfo, metrics::Metrics};
7574
use self::{
7675
mapped_addrs::{EndpointIdMappedAddr, MappedAddr},
7776
transports::Addr,
7877
};
78+
pub use self::{metrics::Metrics, remote_map::PathInfo};
7979

8080
// TODO: Use this
8181
// /// How long we consider a QAD-derived endpoint valid for. UDP NAT mappings typically
@@ -102,7 +102,7 @@ pub(crate) const MAX_MULTIPATH_PATHS: u32 = 16;
102102
/// Error returned when the endpoint state actor stopped while waiting for a reply.
103103
#[stack_error(derive)]
104104
#[error("endpoint state actor stopped")]
105-
pub(crate) struct EndpointStateActorStoppedError;
105+
pub(crate) struct RemoteStateActorStoppedError;
106106

107107
/// Contains options for `MagicSock::listen`.
108108
#[derive(derive_more::Debug)]
@@ -183,7 +183,7 @@ pub(crate) struct MagicSock {
183183
/// If the last net_report report, reports IPv6 to be available.
184184
ipv6_reported: Arc<AtomicBool>,
185185
/// Tracks the networkmap endpoint entity for each endpoint discovery key.
186-
pub(crate) endpoint_map: EndpointMap,
186+
pub(crate) remote_map: RemoteMap,
187187

188188
/// Local addresses
189189
local_addrs_watch: LocalAddrsWatch,
@@ -252,7 +252,7 @@ impl MagicSock {
252252
self.local_addrs_watch.clone().get()
253253
}
254254

255-
/// Registers the connection in the `EndpointStateActor`.
255+
/// Registers the connection in the `RemoteStateActor`.
256256
///
257257
/// The actor is responsible for holepunching and opening additional paths to this
258258
/// connection.
@@ -264,16 +264,16 @@ impl MagicSock {
264264
&self,
265265
remote: EndpointId,
266266
conn: WeakConnectionHandle,
267-
) -> impl Future<Output = Result<PathsWatcher, EndpointStateActorStoppedError>> + Send + 'static
267+
) -> impl Future<Output = Result<PathsWatcher, RemoteStateActorStoppedError>> + Send + 'static
268268
{
269269
let (tx, rx) = oneshot::channel();
270-
let sender = self.endpoint_map.endpoint_state_actor(remote);
270+
let sender = self.remote_map.remote_state_actor(remote);
271271
async move {
272272
sender
273-
.send(EndpointStateMessage::AddConnection(conn, tx))
273+
.send(RemoteStateMessage::AddConnection(conn, tx))
274274
.await
275-
.map_err(|_| EndpointStateActorStoppedError)?;
276-
rx.await.map_err(|_| EndpointStateActorStoppedError)
275+
.map_err(|_| RemoteStateActorStoppedError)?;
276+
rx.await.map_err(|_| RemoteStateActorStoppedError)
277277
}
278278
}
279279

@@ -290,9 +290,9 @@ impl MagicSock {
290290

291291
/// Returns `true` if we have at least one candidate address where we can send packets to.
292292
pub(crate) async fn has_send_address(&self, eid: EndpointId) -> bool {
293-
let actor = self.endpoint_map.endpoint_state_actor(eid);
293+
let actor = self.remote_map.remote_state_actor(eid);
294294
let (tx, rx) = oneshot::channel();
295-
if actor.send(EndpointStateMessage::CanSend(tx)).await.is_err() {
295+
if actor.send(RemoteStateMessage::CanSend(tx)).await.is_err() {
296296
return false;
297297
}
298298
rx.await.unwrap_or(false)
@@ -379,21 +379,21 @@ impl MagicSock {
379379
// TODO: Build better info to expose to the user about remote nodes. We probably want
380380
// to expose this as part of path information instead.
381381
pub(crate) async fn latency(&self, eid: EndpointId) -> Option<Duration> {
382-
let endpoint_state = self.endpoint_map.endpoint_state_actor(eid);
382+
let remote_state = self.remote_map.remote_state_actor(eid);
383383
let (tx, rx) = oneshot::channel();
384-
endpoint_state
385-
.send(EndpointStateMessage::Latency(tx))
384+
remote_state
385+
.send(RemoteStateMessage::Latency(tx))
386386
.await
387387
.ok();
388388
rx.await.unwrap_or_default()
389389
}
390390

391391
/// Returns the socket address which can be used by the QUIC layer to dial this endpoint.
392392
pub(crate) fn get_endpoint_mapped_addr(&self, eid: EndpointId) -> EndpointIdMappedAddr {
393-
self.endpoint_map.endpoint_mapped_addr(eid)
393+
self.remote_map.endpoint_mapped_addr(eid)
394394
}
395395

396-
/// Add potential addresses for a endpoint to the `EndpointStateActor`.
396+
/// Add potential addresses for a endpoint to the `RemoteStateActor`.
397397
///
398398
/// This is used to add possible paths that the remote endpoint might be reachable on. They
399399
/// will be used when there is no active connection to the endpoint to attempt to establish
@@ -402,7 +402,7 @@ impl MagicSock {
402402
pub(crate) async fn add_endpoint_addr(
403403
&self,
404404
mut addr: EndpointAddr,
405-
source: endpoint_map::Source,
405+
source: remote_map::Source,
406406
) -> Result<(), AddEndpointAddrError> {
407407
let mut pruned: usize = 0;
408408
for my_addr in self.direct_addrs.sockaddrs() {
@@ -412,8 +412,8 @@ impl MagicSock {
412412
}
413413
}
414414
if !addr.is_empty() {
415-
// Add addr to the internal EndpointMap
416-
self.endpoint_map
415+
// Add addr to the internal RemoteMap
416+
self.remote_map
417417
.add_endpoint_addr(addr.clone(), source)
418418
.await;
419419
Ok(())
@@ -522,8 +522,8 @@ impl MagicSock {
522522
// result in the wrong address family and Windows trips up on that.
523523
//
524524
// What should be done is that this dst_ip from the RecvMeta is stored in the
525-
// EndpointState/PathState. Then on the send path it should be retrieved from the
526-
// EndpointState/PathSate together with the send address and substituted at send time.
525+
// RemoteState/PathState. Then on the send path it should be retrieved from the
526+
// RemoteState/PathState together with the send address and substituted at send time.
527527
// This is relevant for IPv6 link-local addresses where the OS otherwise does not
528528
// know which interface to send from.
529529
#[cfg(not(windows))]
@@ -605,7 +605,7 @@ impl MagicSock {
605605
}
606606
transports::Addr::Relay(src_url, src_endpoint) => {
607607
let mapped_addr = self
608-
.endpoint_map
608+
.remote_map
609609
.relay_mapped_addrs
610610
.get(&(src_url.clone(), *src_endpoint));
611611
quinn_meta.addr = mapped_addr.private_socket_addr();
@@ -679,15 +679,15 @@ impl MagicSock {
679679
match dm {
680680
disco::Message::Ping(ping) => {
681681
self.metrics.magicsock.recv_disco_ping.inc();
682-
self.endpoint_map.handle_ping(ping, sender, src.clone());
682+
self.remote_map.handle_ping(ping, sender, src.clone());
683683
}
684684
disco::Message::Pong(pong) => {
685685
self.metrics.magicsock.recv_disco_pong.inc();
686-
self.endpoint_map.handle_pong(pong, sender, src.clone());
686+
self.remote_map.handle_pong(pong, sender, src.clone());
687687
}
688688
disco::Message::CallMeMaybe(cm) => {
689689
self.metrics.magicsock.recv_disco_call_me_maybe.inc();
690-
self.endpoint_map
690+
self.remote_map
691691
.handle_call_me_maybe(cm, sender, src.clone());
692692
}
693693
}
@@ -1015,8 +1015,8 @@ impl Handle {
10151015
let direct_addrs = DiscoveredDirectAddrs::default();
10161016
let (disco, disco_receiver) = DiscoState::new(&secret_key);
10171017

1018-
let endpoint_map = {
1019-
EndpointMap::new(
1018+
let remote_map = {
1019+
RemoteMap::new(
10201020
secret_key.public(),
10211021
metrics.magicsock.clone(),
10221022
direct_addrs.addrs.watch(),
@@ -1032,7 +1032,7 @@ impl Handle {
10321032
disco,
10331033
actor_sender: actor_sender.clone(),
10341034
ipv6_reported,
1035-
endpoint_map,
1035+
remote_map,
10361036
discovery,
10371037
relay_map: relay_map.clone(),
10381038
discovery_user_data: RwLock::new(discovery_user_data),
@@ -1358,8 +1358,8 @@ impl Actor {
13581358
// ensure we are doing an initial publish of our addresses
13591359
self.msock.publish_my_addr();
13601360

1361-
// Interval timer to remove closed `EndpointStateActor` handles from the endpoint map.
1362-
let mut endpoint_map_gc = time::interval(endpoint_map::ENDPOINT_MAP_GC_INTERVAL);
1361+
// Interval timer to remove closed `RemoteStateActor` handles from the endpoint map.
1362+
let mut remote_map_gc = time::interval(remote_map::REMOTE_MAP_GC_INTERVAL);
13631363

13641364
loop {
13651365
self.msock.metrics.magicsock.actor_tick_main.inc();
@@ -1472,8 +1472,8 @@ impl Actor {
14721472
warn!(%dst, endpoint = %dst_key.fmt_short(), ?err, "failed to send disco message (UDP)");
14731473
}
14741474
}
1475-
_ = endpoint_map_gc.tick() => {
1476-
self.msock.endpoint_map.remove_closed_endpoint_state_actors();
1475+
_ = remote_map_gc.tick() => {
1476+
self.msock.remote_map.remove_closed_remote_state_actors();
14771477
}
14781478
}
14791479
}
@@ -1844,7 +1844,7 @@ mod tests {
18441844
use tracing::{Instrument, error, info, info_span, instrument};
18451845
use tracing_test::traced_test;
18461846

1847-
use super::{EndpointIdMappedAddr, Options, endpoint_map::Source, mapped_addrs::MappedAddr};
1847+
use super::{EndpointIdMappedAddr, Options, mapped_addrs::MappedAddr, remote_map::Source};
18481848
use crate::{
18491849
Endpoint, RelayMode, SecretKey,
18501850
discovery::static_provider::StaticProvider,
@@ -2379,7 +2379,7 @@ mod tests {
23792379

23802380
let msock_1 = magicsock_ep(secret_key_1.clone()).await.unwrap();
23812381

2382-
// Generate an address not present in the EndpointMap.
2382+
// Generate an address not present in the RemoteMap.
23832383
let bad_addr = EndpointIdMappedAddr::generate();
23842384

23852385
// 500ms is rather fast here. Running this locally it should always be the correct
@@ -2505,9 +2505,9 @@ mod tests {
25052505
});
25062506
let _accept_task = AbortOnDropHandle::new(accept_task);
25072507

2508-
// Add an empty entry in the EndpointMap of ep_1
2508+
// Add an empty entry in the RemoteMap of ep_1
25092509
msock_1
2510-
.endpoint_map
2510+
.remote_map
25112511
.add_endpoint_addr(
25122512
EndpointAddr {
25132513
id: endpoint_id_2,
@@ -2545,7 +2545,7 @@ mod tests {
25452545

25462546
// Provide correct addressing information
25472547
msock_1
2548-
.endpoint_map
2548+
.remote_map
25492549
.add_endpoint_addr(
25502550
EndpointAddr {
25512551
id: endpoint_id_2,
@@ -2584,6 +2584,6 @@ mod tests {
25842584
.expect("connection timed out");
25852585

25862586
// TODO: could remove the addresses again, send, add it back and see it recover.
2587-
// But we don't have that much private access to the EndpointMap. This will do for now.
2587+
// But we don't have that much private access to the RemoteMap. This will do for now.
25882588
}
25892589
}

0 commit comments

Comments
 (0)