Skip to content

Commit

Permalink
fix(iroh-net): reconfirm best addr when receiving data on it
Browse files Browse the repository at this point in the history
Closes #2169
  • Loading branch information
dignifiedquire committed Apr 30, 2024
1 parent 5502c5a commit 375a2f2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
18 changes: 18 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,22 @@ 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) {
match self.0.as_mut() {
None => {
// Nothing to do
// TODO: do we want to store this regardless?
}
Some(state) => {
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 375a2f2

Please sign in to comment.