Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 0 additions & 5 deletions iroh/src/magicsock/remote_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,6 @@ pub enum Source {
_0: Private,
},
/// We established a connection on this address.
///
/// Currently this means the path was in uses as [`PathId::ZERO`] when the a connection
/// was added to the `RemoteStateActor`.
///
/// [`PathId::ZERO`]: quinn_proto::PathId::ZERO
#[strum(serialize = "Connection")]
Connection {
/// private marker
Expand Down
36 changes: 24 additions & 12 deletions iroh/src/magicsock/remote_map/remote_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@ use crate::{
mod guarded_channel;
mod path_state;

// TODO: use this
// /// Number of addresses that are not active that we keep around per endpoint.
// ///
// /// See [`RemoteState::prune_direct_addresses`].
// pub(super) const MAX_INACTIVE_DIRECT_ADDRESSES: usize = 20;

// TODO: use this
// /// How long since an endpoint path was last alive before it might be pruned.
// const LAST_ALIVE_PRUNE_DURATION: Duration = Duration::from_secs(120);

// TODO: use this
// /// The latency at or under which we don't try to upgrade to a better path.
// const GOOD_ENOUGH_LATENCY: Duration = Duration::from_millis(5);
Expand Down Expand Up @@ -442,6 +432,7 @@ impl RemoteStateActor {
self.paths
.insert(path_remote, Source::Connection { _0: Private });
self.select_path();
self.prune_ip_paths();

if path_remote_is_ip {
// We may have raced this with a relay address. Try and add any
Expand Down Expand Up @@ -492,6 +483,9 @@ impl RemoteStateActor {
self.send_disco_message(dst, disco::Message::Ping(ping))
.await;
}
// prune any unused/inactive paths, now that we have added potential
// new ones
self.prune_ip_paths()
}

/// Handles [`RemoteStateMessage::PingReceived`].
Expand Down Expand Up @@ -525,6 +519,7 @@ impl RemoteStateActor {

trace!("ping received, triggering holepunching");
self.trigger_holepunching().await;
self.prune_ip_paths();
}

/// Handles [`RemoteStateMessage::PongReceived`].
Expand All @@ -537,7 +532,8 @@ impl RemoteStateActor {
?src,
txn = ?pong.tx_id,
);

// mark that this path has been holepunched
self.paths.holepunched(&src);
self.open_path(&src);
}
}
Expand Down Expand Up @@ -891,10 +887,12 @@ impl RemoteStateActor {
);
conn_state.add_open_path(path_remote.clone(), path_id);
self.paths
.insert(path_remote, Source::Connection { _0: Private });
.insert(path_remote.clone(), Source::Connection { _0: Private });
self.paths.holepunched(&path_remote);
}

self.select_path();
self.prune_ip_paths();
}
PathEvent::Abandoned { id, path_stats } => {
trace!(?path_stats, "path abandoned");
Expand Down Expand Up @@ -1046,6 +1044,20 @@ impl RemoteStateActor {
}
}
}

/// TODO: fix up docs once review indicates this is actually
/// the criteria for pruning.
fn prune_ip_paths(&mut self) {
let open_paths = self
.connections
.values()
.flat_map(|state| state.open_paths.values());
self.paths.prune_ip_paths(
&self.pending_open_paths,
&self.selected_path.get(),
open_paths,
);
}
}

/// Messages to send to the [`RemoteStateActor`].
Expand Down
Loading
Loading