From e5fb6adbb4bc5d74ea5a9f0d9340eaada853f3d3 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Mon, 7 Jul 2025 23:46:46 +0100 Subject: [PATCH] fix(connlib): always signal server-reflexive candidates (#9802) When we create a new connection, we seed the local ICE agent with all known local candidates, i.e. host addresses and allocations on relays. Server-reflexive candidates are never added to the local agent because you cannot send directly from a server-reflexive addresses. Instead, an agent sends from the _base_ of a server-reflexive candidate which in turn is known as a host candidate. The server-reflexive candidate is however signaled to the remote so it can try and send packets to it. Those will then be mapped by the NAT to our host candidate. In case we have just performed a network reset, our own server-reflexive candidate may not be known yet and therefore the seeding doesn't add an candidates. With no candidates being seeded, we also can't signal them to the remote. For candidates discovered later in this process, the signalling happens as part of adding them to the local agent. Because server-reflexive candidates are not added to the local agent, we currently miss out on signaling those to the remote IF they weren't already present when the ICE agent got created. This scenario can happen right after a network reset. In practice, it shouldn't be much of an issue though. As soon as we start sending from our host candidate, the remote will create a peer-reflexive candidate for it. It is however cleaner to directly send the server-reflexive candidate once we discover it. --- rust/connlib/snownet/src/node.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rust/connlib/snownet/src/node.rs b/rust/connlib/snownet/src/node.rs index 9aeb7ae34..f6280416a 100644 --- a/rust/connlib/snownet/src/node.rs +++ b/rust/connlib/snownet/src/node.rs @@ -950,7 +950,14 @@ where allocation::Event::New(candidate) if candidate.kind() == CandidateKind::ServerReflexive => { - self.shared_candidates.insert(candidate); + if !self.shared_candidates.insert(candidate.clone()) { + continue; + } + + for (cid, agent, _span) in self.connections.connecting_agents_by_relay_mut(rid) + { + add_local_candidate(cid, agent, candidate.clone(), &mut self.pending_events) + } } allocation::Event::New(candidate) => { for (cid, agent, _span) in self.connections.connecting_agents_by_relay_mut(rid)