Skip to content

Commit ed23295

Browse files
authored
fix(autonat): dial first address in multi-address DialRequest
Fixes #6482. The AutoNAT v2 server selected the last address via `addrs.pop()` but always reported `addr_idx = 0`. Selection now uses the first priority-ordered address and reports its index. **Attestation**: - [x] I have read every line of this diff, understand what it does, and can explain it in review. Pull-Request: #6514.
1 parent 8293360 commit ed23295

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

protocols/autonat/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## 0.16.0
22

3+
- Fix AutoNAT v2 server preserving the selected address index for multi-address `DialRequest`s.
4+
See [PR 6514](https://github.com/libp2p/rust-libp2p/pull/6514).
5+
36
- Use `futures-timer` instead of tokio's timer for stream timeouts so the bounded `Delay` works on
47
`wasm32`; tokio's timer has no driver in the browser and panics at runtime.
58
See [PR 6488](https://github.com/libp2p/rust-libp2p/pull/6488).

protocols/autonat/src/v2/server/handler/dial_request.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,9 @@ where
273273
}
274274
};
275275
all_addrs.clone_from(&addrs);
276-
let idx = 0;
277-
let addr = addrs.pop().ok_or(HandleFail::DialRefused)?;
276+
let idx = addrs.len().checked_sub(1).ok_or(HandleFail::DialRefused)?;
277+
let addr = addrs.remove(idx);
278+
278279
*tested_addrs = Some(addr.clone());
279280
*data_amount = 0;
280281
if addr != observed_multiaddr {

0 commit comments

Comments
 (0)