Skip to content

Commit a8ee257

Browse files
committed
fix(iroh): when ports change for the current best address, use it
1 parent a00644a commit a8ee257

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

iroh/src/magicsock/node_map/best_addr.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,19 @@ impl BestAddr {
121121
}
122122
Some(state) => {
123123
let candidate = AddrLatency { addr, latency };
124+
// If the current address has exceeded its trust interval, or if the new address has lower latency,
125+
// use the new address.
124126
if !state.is_trusted(confirmed_at) || candidate.is_better_than(&state.addr) {
125127
self.insert(addr, latency, source, confirmed_at);
128+
// If the new address is equal to the current address, mark it as reconfirmed now and expand its trust
129+
// interval.
126130
} else if state.addr.addr == addr {
127131
state.confirmed_at = confirmed_at;
128132
state.trust_until = Some(source.trust_until(confirmed_at));
133+
// If we receive a pong on a different port but the same IP address as the current best addr,
134+
// we assume that the endpoint has rebound, and thus use the new port.
135+
} else if state.addr.addr.ip() == addr.ip() {
136+
self.insert(addr, latency, source, confirmed_at)
129137
}
130138
}
131139
}

0 commit comments

Comments
 (0)