Skip to content
Open
Changes from 1 commit
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
23 changes: 15 additions & 8 deletions ts_runtime/src/route_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub struct RouteUpdater {
derp_transport_map: DerpTransportMap,
peer_state: Arc<PeerState>,
env: Env,
/// Prevents building routes until the first `DerpTransportMap` has been processed.
is_initialized: bool,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could derp_transport_map be an Option rather than adding a bool here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my original approach, but all the self.derp_transport_map ref sites went from self.derp_transport_map.0.get(...) to self.derp_transport_map.as_ref().unwrap().0.get(...), which felt...overly complex/boilerplate-ish? I don't think the extra bool on RouteUpdater matters perf-wise, but if I'm being too precious here and Option<DerpTransportMap> is the more idiomatic approach (or if I'm missing something else), happy to change it!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate point: perhaps call this seen_derp or similar? This isn't the unique thing that decides that this actor is done initializing, the peer state is equally important imo (it just happens to not cause this logging issue)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@npry good point, renamed to seen_derp - still open to moving to Option<> if that's better though.

}

impl RouteUpdater {
Expand All @@ -26,8 +28,11 @@ impl RouteUpdater {
"reconstructing routes for peer update"
);

let mut overlay_out = ts_bart::Table::default();
let mut underlay_out = HashMap::default();
let mut routes = PeerRoutesInner::default();
if !self.is_initialized {
tracing::debug!("not building routes, derp map unpopulated");
return routes;
}

for (id, peer) in self.peer_state.peers.peers() {
let span = tracing::trace_span!(
Expand All @@ -46,7 +51,7 @@ impl RouteUpdater {
match self.derp_transport_map.0.get(&region) {
Some(&transport_id) => {
span.record("underlay_transport", tracing::field::debug(transport_id));
underlay_out.insert(*id, transport_id);
routes.underlay_routes.insert(*id, transport_id);
}
None => {
tracing::error!("no region stored in multiderp, no underlay route");
Expand All @@ -56,14 +61,13 @@ impl RouteUpdater {
tracing::trace!(routes = ?peer.accepted_routes);

for route in &peer.accepted_routes {
overlay_out.insert(*route, OutboundRouteAction::Wireguard(*id));
routes
.overlay_out_routes
.insert(*route, OutboundRouteAction::Wireguard(*id));
}
}

PeerRoutesInner {
underlay_routes: underlay_out,
overlay_out_routes: overlay_out,
}
routes
}
}

Expand All @@ -86,6 +90,7 @@ impl kameo::Actor for RouteUpdater {
derp_transport_map: DerpTransportMap::default(),
peer_state: Default::default(),
env,
is_initialized: false,
})
}
}
Expand All @@ -100,6 +105,7 @@ pub struct PeerRouteUpdate {
pub inner: Arc<PeerRoutesInner>,
}

#[derive(Default)]
pub struct PeerRoutesInner {
pub underlay_routes: HashMap<PeerId, UnderlayTransportId>,
pub overlay_out_routes: ts_bart::Table<OutboundRouteAction>,
Expand Down Expand Up @@ -136,6 +142,7 @@ impl Message<DerpTransportMap> for RouteUpdater {
tracing::debug!("derp transport map changed, building new routes");

self.derp_transport_map = msg;
self.is_initialized = true;

let new_routes = self.build_routes();
if let Err(e) = self
Expand Down