Skip to content

Commit

Permalink
fix(iroh-net): reconfirm best addr when receiving data on it (#2255)
Browse files Browse the repository at this point in the history
When receiving data via UDP, we were not extending the validity of the
current `best_addr`. This would trigger expiry of the `best_addr`, even
though it was actively being used.

This fix, extends the validity, everytime we successfully receive a UDP
packet on the current `best_addr`.

Closes #2169
  • Loading branch information
dignifiedquire authored Apr 30, 2024
1 parent 5502c5a commit 6fbf4a9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 12 additions & 0 deletions iroh-net/src/magicsock/node_map/best_addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ impl BestAddrInner {
pub(super) enum Source {
ReceivedPong,
BestCandidate,
Udp,
}

impl Source {
Expand All @@ -47,6 +48,7 @@ impl Source {
Source::ReceivedPong => from + TRUST_UDP_ADDR_DURATION,
// TODO: Fix time
Source::BestCandidate => from + Duration::from_secs(60 * 60),
Source::Udp => from + TRUST_UDP_ADDR_DURATION,
}
}
}
Expand Down Expand Up @@ -141,6 +143,16 @@ impl BestAddr {
}
}

/// Reset the expiry, if the passed in addr matches the currently used one.
pub fn reconfirm_if_used(&mut self, addr: SocketAddr, source: Source, confirmed_at: Instant) {
if let Some(state) = self.0.as_mut() {
if state.addr.addr == addr {
state.confirmed_at = confirmed_at;
state.trust_until = Some(source.trust_until(confirmed_at));
}
}
}

fn insert(
&mut self,
addr: SocketAddr,
Expand Down
4 changes: 3 additions & 1 deletion iroh-net/src/magicsock/node_map/node_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::{

use crate::magicsock::{metrics::Metrics as MagicsockMetrics, ActorMessage, QuicMappedAddr};

use super::best_addr::{self, BestAddr, ClearReason};
use super::best_addr::{self, BestAddr, ClearReason, Source};
use super::IpPort;

/// Number of addresses that are not active that we keep around per node.
Expand Down Expand Up @@ -967,6 +967,8 @@ impl NodeState {
};
state.last_payload_msg = Some(now);
self.last_used = Some(now);
self.best_addr
.reconfirm_if_used(addr.into(), Source::Udp, now);
}

pub(super) fn receive_relay(&mut self, url: &RelayUrl, _src: &PublicKey, now: Instant) {
Expand Down

0 comments on commit 6fbf4a9

Please sign in to comment.