Skip to content

Commit

Permalink
protocols/request-response: Handle address change on connection (libp…
Browse files Browse the repository at this point in the history
  • Loading branch information
elenaf9 authored and Victor Ermolaev committed Nov 30, 2021
1 parent 89f728d commit c3bb4a0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
23 changes: 23 additions & 0 deletions protocols/request-response/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,29 @@ where
addresses
}

fn inject_address_change(
&mut self,
peer: &PeerId,
conn: &ConnectionId,
_old: &ConnectedPoint,
new: &ConnectedPoint,
) {
let new_address = match new {
ConnectedPoint::Dialer { address } => Some(address.clone()),
ConnectedPoint::Listener { .. } => None,
};
let connections = self
.connected
.get_mut(peer)
.expect("Address change can only happen on an established connection.");

let connection = connections
.iter_mut()
.find(|c| &c.id == conn)
.expect("Address change can only happen on an established connection.");
connection.address = new_address;
}

fn inject_connected(&mut self, peer: &PeerId) {
if let Some(pending) = self.pending_outbound_requests.remove(peer) {
for request in pending {
Expand Down
3 changes: 3 additions & 0 deletions swarm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@

- Migrate to Rust edition 2021 (see [PR 2339]).

- Update `Connection::address` on `inject_address_change` (see [PR 2362]).

[PR 2339]: https://github.com/libp2p/rust-libp2p/pull/2339
[PR 2350]: https://github.com/libp2p/rust-libp2p/pull/2350
[PR 2362]: https://github.com/libp2p/rust-libp2p/pull/2362

# 0.32.0 [2021-11-16]

Expand Down

0 comments on commit c3bb4a0

Please sign in to comment.