diff --git a/core/src/connection.rs b/core/src/connection.rs index 3a8d54d04a1..425dc5d390d 100644 --- a/core/src/connection.rs +++ b/core/src/connection.rs @@ -230,14 +230,4 @@ impl ConnectedPoint { ConnectedPoint::Listener { send_back_addr, .. } => send_back_addr, } } - - /// Modifies the address of the remote stored in this struct. - /// - /// For `Dialer`, this modifies `address`. For `Listener`, this modifies `send_back_addr`. - pub fn set_remote_address(&mut self, new_address: Multiaddr) { - match self { - ConnectedPoint::Dialer { address, .. } => *address = new_address, - ConnectedPoint::Listener { send_back_addr, .. } => *send_back_addr = new_address, - } - } } diff --git a/core/src/muxing.rs b/core/src/muxing.rs index 68e555e167f..8f16a1b086f 100644 --- a/core/src/muxing.rs +++ b/core/src/muxing.rs @@ -51,7 +51,6 @@ //! implementation of `StreamMuxer` to control everything that happens on the wire. use futures::{task::Context, task::Poll, AsyncRead, AsyncWrite}; -use multiaddr::Multiaddr; use std::io; pub use self::boxed::StreamMuxerBox; @@ -139,22 +138,14 @@ pub trait StreamMuxer { pub enum StreamMuxerEvent { /// Remote has opened a new substream. Contains the substream in question. InboundSubstream(T), - - /// Address to the remote has changed. The previous one is now obsolete. - /// - /// > **Note**: This can for example happen when using the QUIC protocol, where the two nodes - /// > can change their IP address while retaining the same QUIC connection. - AddressChange(Multiaddr), } impl StreamMuxerEvent { /// If `self` is a [`StreamMuxerEvent::InboundSubstream`], returns the content. Otherwise /// returns `None`. pub fn into_inbound_substream(self) -> Option { - if let StreamMuxerEvent::InboundSubstream(s) = self { - Some(s) - } else { - None + match self { + StreamMuxerEvent::InboundSubstream(stream) => Some(stream), } } @@ -164,7 +155,6 @@ impl StreamMuxerEvent { StreamMuxerEvent::InboundSubstream(stream) => { StreamMuxerEvent::InboundSubstream(map(stream)) } - StreamMuxerEvent::AddressChange(addr) => StreamMuxerEvent::AddressChange(addr), } } } diff --git a/core/src/muxing/boxed.rs b/core/src/muxing/boxed.rs index f0e2ff10647..8345f747a0f 100644 --- a/core/src/muxing/boxed.rs +++ b/core/src/muxing/boxed.rs @@ -50,9 +50,6 @@ where ) -> Poll, Self::Error>> { let substream = match self.inner.poll_event(cx) { Poll::Pending => return Poll::Pending, - Poll::Ready(Ok(StreamMuxerEvent::AddressChange(a))) => { - return Poll::Ready(Ok(StreamMuxerEvent::AddressChange(a))) - } Poll::Ready(Ok(StreamMuxerEvent::InboundSubstream(s))) => s, Poll::Ready(Err(err)) => return Poll::Ready(Err(err.into())), }; diff --git a/muxers/mplex/src/lib.rs b/muxers/mplex/src/lib.rs index 80b1db16481..8f692ca4a68 100644 --- a/muxers/mplex/src/lib.rs +++ b/muxers/mplex/src/lib.rs @@ -75,9 +75,6 @@ where } /// Multiplexer. Implements the `StreamMuxer` trait. -/// -/// This implementation isn't capable of detecting when the underlying socket changes its address, -/// and no [`StreamMuxerEvent::AddressChange`] event is ever emitted. pub struct Multiplex { io: Arc>>, } diff --git a/muxers/yamux/src/lib.rs b/muxers/yamux/src/lib.rs index 8eb6fb3e895..f74226b3049 100644 --- a/muxers/yamux/src/lib.rs +++ b/muxers/yamux/src/lib.rs @@ -97,7 +97,6 @@ where pub type YamuxResult = Result; -/// > **Note**: This implementation never emits [`StreamMuxerEvent::AddressChange`] events. impl StreamMuxer for Yamux where S: Stream> + Unpin, diff --git a/protocols/autonat/src/behaviour.rs b/protocols/autonat/src/behaviour.rs index 86c65bb3416..58102932cbe 100644 --- a/protocols/autonat/src/behaviour.rs +++ b/protocols/autonat/src/behaviour.rs @@ -383,29 +383,6 @@ impl NetworkBehaviour for Behaviour { } } - fn inject_address_change( - &mut self, - peer: &PeerId, - conn: &ConnectionId, - old: &ConnectedPoint, - new: &ConnectedPoint, - ) { - self.inner.inject_address_change(peer, conn, old, new); - - if old.is_relayed() && new.is_relayed() { - return; - } - let connections = self.connected.get_mut(peer).expect("Peer is connected."); - let addr = new.get_remote_address(); - let observed_addr = - if !new.is_relayed() && (!self.config.only_global_ips || addr.is_global_ip()) { - Some(addr.clone()) - } else { - None - }; - connections.insert(*conn, observed_addr); - } - fn inject_new_listen_addr(&mut self, id: ListenerId, addr: &Multiaddr) { self.inner.inject_new_listen_addr(id, addr); self.as_client().on_new_address(); diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index 1a633edc534..75585133b1d 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -1,6 +1,10 @@ # 0.37.0 [unreleased] - Update to `libp2p-core` `v0.34.0`. +- Deprecate `NetworkBehaviour::inject_address_change` and + `Connectionhandler::inject_address_change`. See [PR XXXX]. + +[PR XXXX]: https://github.com/libp2p/rust-libp2p/pull/XXXX # 0.36.2 [unreleased] diff --git a/swarm/src/behaviour.rs b/swarm/src/behaviour.rs index d09427fbc6b..f250d38c729 100644 --- a/swarm/src/behaviour.rs +++ b/swarm/src/behaviour.rs @@ -232,6 +232,7 @@ pub trait NetworkBehaviour: 'static { } /// Informs the behaviour that the [`ConnectedPoint`] of an existing connection has changed. + #[deprecated(since = "0.37.0", note = "This function will no longer be called.")] fn inject_address_change( &mut self, _: &PeerId, diff --git a/swarm/src/behaviour/either.rs b/swarm/src/behaviour/either.rs index 479534f6a8f..9f01c451460 100644 --- a/swarm/src/behaviour/either.rs +++ b/swarm/src/behaviour/either.rs @@ -107,19 +107,6 @@ where } } - fn inject_address_change( - &mut self, - peer_id: &PeerId, - connection: &ConnectionId, - old: &ConnectedPoint, - new: &ConnectedPoint, - ) { - match self { - Either::Left(a) => a.inject_address_change(peer_id, connection, old, new), - Either::Right(b) => b.inject_address_change(peer_id, connection, old, new), - } - } - fn inject_event( &mut self, peer_id: PeerId, diff --git a/swarm/src/behaviour/toggle.rs b/swarm/src/behaviour/toggle.rs index 25183b932c7..b5de3a9494c 100644 --- a/swarm/src/behaviour/toggle.rs +++ b/swarm/src/behaviour/toggle.rs @@ -126,18 +126,6 @@ where } } - fn inject_address_change( - &mut self, - peer_id: &PeerId, - connection: &ConnectionId, - old: &ConnectedPoint, - new: &ConnectedPoint, - ) { - if let Some(inner) = self.inner.as_mut() { - inner.inject_address_change(peer_id, connection, old, new) - } - } - fn inject_event( &mut self, peer_id: PeerId, @@ -345,12 +333,6 @@ where .inject_event(event) } - fn inject_address_change(&mut self, addr: &Multiaddr) { - if let Some(inner) = self.inner.as_mut() { - inner.inject_address_change(addr) - } - } - fn inject_dial_upgrade_error( &mut self, info: Self::OutboundOpenInfo, diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index e53701699e2..432acc96bca 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -59,8 +59,6 @@ pub struct Connected { pub enum Event { /// Event generated by the [`ConnectionHandler`]. Handler(T), - /// Address of the remote has changed. - AddressChange(Multiaddr), } /// A multiplexed connection to a peer with an associated [`ConnectionHandler`]. @@ -166,10 +164,6 @@ where self.handler.inject_substream(substream, endpoint); continue; } - Poll::Ready(Ok(SubstreamEvent::AddressChange(address))) => { - self.handler.inject_address_change(&address); - return Poll::Ready(Ok(Event::AddressChange(address))); - } Poll::Ready(Err(err)) => return Poll::Ready(Err(ConnectionError::IO(err))), } diff --git a/swarm/src/connection/handler_wrapper.rs b/swarm/src/connection/handler_wrapper.rs index 77eb1d79bbf..da040d69178 100644 --- a/swarm/src/connection/handler_wrapper.rs +++ b/swarm/src/connection/handler_wrapper.rs @@ -32,7 +32,6 @@ use instant::Instant; use libp2p_core::{ muxing::SubstreamBox, upgrade::{self, InboundUpgradeApply, OutboundUpgradeApply, UpgradeError}, - Multiaddr, }; use libp2p_core::{ConnectedPoint, PeerId}; use std::{error, fmt, pin::Pin, task::Context, task::Poll, time::Duration}; @@ -317,10 +316,6 @@ where self.handler.inject_event(event); } - pub fn inject_address_change(&mut self, new_address: &Multiaddr) { - self.handler.inject_address_change(new_address); - } - fn handle_connection_handler_event( &mut self, handler_event: ConnectionHandlerEvent< diff --git a/swarm/src/connection/pool.rs b/swarm/src/connection/pool.rs index 10fc29a8120..2aa24240219 100644 --- a/swarm/src/connection/pool.rs +++ b/swarm/src/connection/pool.rs @@ -236,16 +236,6 @@ where /// The produced event. event: THandlerOutEvent, }, - - /// The connection to a node has changed its address. - AddressChange { - id: ConnectionId, - peer_id: PeerId, - /// The new endpoint. - new_endpoint: ConnectedPoint, - /// The old endpoint. - old_endpoint: ConnectedPoint, - }, } impl Pool @@ -542,29 +532,6 @@ where Poll::Ready(Some(task::EstablishedConnectionEvent::Notify { id, peer_id, event })) => { return Poll::Ready(PoolEvent::ConnectionEvent { peer_id, id, event }); } - Poll::Ready(Some(task::EstablishedConnectionEvent::AddressChange { - id, - peer_id, - new_address, - })) => { - let connection = self - .established - .get_mut(&peer_id) - .expect("Receive `AddressChange` event for established peer.") - .get_mut(&id) - .expect("Receive `AddressChange` event from established connection"); - let mut new_endpoint = connection.endpoint.clone(); - new_endpoint.set_remote_address(new_address); - let old_endpoint = - std::mem::replace(&mut connection.endpoint, new_endpoint.clone()); - - return Poll::Ready(PoolEvent::AddressChange { - peer_id, - id, - new_endpoint, - old_endpoint, - }); - } Poll::Ready(Some(task::EstablishedConnectionEvent::Closed { id, peer_id, diff --git a/swarm/src/connection/pool/task.rs b/swarm/src/connection/pool/task.rs index 866049e50da..06c69f40f15 100644 --- a/swarm/src/connection/pool/task.rs +++ b/swarm/src/connection/pool/task.rs @@ -73,12 +73,6 @@ where #[derive(Debug)] pub enum EstablishedConnectionEvent { - /// A node we are connected to has changed its address. - AddressChange { - id: ConnectionId, - peer_id: PeerId, - new_address: Multiaddr, - }, /// Notify the manager of an event from the connection. Notify { id: ConnectionId, @@ -225,15 +219,6 @@ pub async fn new_for_established_connection( }) .await; } - Ok(connection::Event::AddressChange(new_address)) => { - let _ = events - .send(EstablishedConnectionEvent::AddressChange { - id: connection_id, - peer_id, - new_address, - }) - .await; - } Err(error) => { command_receiver.close(); let (handler, _closing_muxer) = connection.close(); diff --git a/swarm/src/connection/substream.rs b/swarm/src/connection/substream.rs index 50714585366..d0c9c564c34 100644 --- a/swarm/src/connection/substream.rs +++ b/swarm/src/connection/substream.rs @@ -19,7 +19,6 @@ // DEALINGS IN THE SOFTWARE. use futures::prelude::*; -use libp2p_core::multiaddr::Multiaddr; use libp2p_core::muxing::{StreamMuxer, StreamMuxerEvent}; use smallvec::SmallVec; use std::sync::Arc; @@ -75,12 +74,6 @@ where /// destroyed or `close_graceful` is called. substream: TMuxer::Substream, }, - - /// Address to the remote has changed. The previous one is now obsolete. - /// - /// > **Note**: This can for example happen when using the QUIC protocol, where the two nodes - /// > can change their IP address while retaining the same QUIC connection. - AddressChange(Multiaddr), } /// Identifier for a substream being opened. @@ -140,9 +133,6 @@ where Poll::Ready(Ok(StreamMuxerEvent::InboundSubstream(substream))) => { return Poll::Ready(Ok(SubstreamEvent::InboundSubstream { substream })); } - Poll::Ready(Ok(StreamMuxerEvent::AddressChange(addr))) => { - return Poll::Ready(Ok(SubstreamEvent::AddressChange(addr))) - } Poll::Ready(Err(err)) => return Poll::Ready(Err(err.into())), Poll::Pending => {} } @@ -243,10 +233,6 @@ where .field("user_data", user_data) .field("substream", substream) .finish(), - SubstreamEvent::AddressChange(address) => f - .debug_struct("SubstreamEvent::AddressChange") - .field("address", address) - .finish(), } } } diff --git a/swarm/src/handler.rs b/swarm/src/handler.rs index 2a301b70889..8fe307184f9 100644 --- a/swarm/src/handler.rs +++ b/swarm/src/handler.rs @@ -136,6 +136,7 @@ pub trait ConnectionHandler: Send + 'static { fn inject_event(&mut self, event: Self::InEvent); /// Notifies the handler of a change in the address of the remote. + #[deprecated(since = "0.37.0", note = "This handler will no longer be called.")] fn inject_address_change(&mut self, _new_address: &Multiaddr) {} /// Indicates to the handler that upgrading an outbound substream to the given protocol has failed. diff --git a/swarm/src/handler/either.rs b/swarm/src/handler/either.rs index 21d386ec56a..a29ce915312 100644 --- a/swarm/src/handler/either.rs +++ b/swarm/src/handler/either.rs @@ -26,7 +26,7 @@ use crate::upgrade::{InboundUpgradeSend, OutboundUpgradeSend, SendWrapper}; use either::Either; use libp2p_core::either::{EitherError, EitherOutput}; use libp2p_core::upgrade::{EitherUpgrade, UpgradeError}; -use libp2p_core::{ConnectedPoint, Multiaddr, PeerId}; +use libp2p_core::{ConnectedPoint, PeerId}; use std::task::{Context, Poll}; pub enum IntoEitherHandler { @@ -134,13 +134,6 @@ where } } - fn inject_address_change(&mut self, addr: &Multiaddr) { - match self { - Either::Left(handler) => handler.inject_address_change(addr), - Either::Right(handler) => handler.inject_address_change(addr), - } - } - fn inject_dial_upgrade_error( &mut self, info: Self::OutboundOpenInfo, diff --git a/swarm/src/handler/map_in.rs b/swarm/src/handler/map_in.rs index a209225045e..18e2b4c57de 100644 --- a/swarm/src/handler/map_in.rs +++ b/swarm/src/handler/map_in.rs @@ -23,7 +23,6 @@ use crate::handler::{ SubstreamProtocol, }; use crate::upgrade::{InboundUpgradeSend, OutboundUpgradeSend}; -use libp2p_core::Multiaddr; use std::{fmt::Debug, marker::PhantomData, task::Context, task::Poll}; /// Wrapper around a protocol handler that turns the input event into something else. @@ -86,10 +85,6 @@ where } } - fn inject_address_change(&mut self, addr: &Multiaddr) { - self.inner.inject_address_change(addr) - } - fn inject_dial_upgrade_error( &mut self, info: Self::OutboundOpenInfo, diff --git a/swarm/src/handler/map_out.rs b/swarm/src/handler/map_out.rs index 2eb0c2f9bdc..43c7954eeeb 100644 --- a/swarm/src/handler/map_out.rs +++ b/swarm/src/handler/map_out.rs @@ -23,7 +23,6 @@ use crate::handler::{ SubstreamProtocol, }; use crate::upgrade::{InboundUpgradeSend, OutboundUpgradeSend}; -use libp2p_core::Multiaddr; use std::fmt::Debug; use std::task::{Context, Poll}; @@ -79,10 +78,6 @@ where self.inner.inject_event(event) } - fn inject_address_change(&mut self, addr: &Multiaddr) { - self.inner.inject_address_change(addr) - } - fn inject_dial_upgrade_error( &mut self, info: Self::OutboundOpenInfo, diff --git a/swarm/src/handler/multi.rs b/swarm/src/handler/multi.rs index f7e4d7ed1b4..0b9410f6e8c 100644 --- a/swarm/src/handler/multi.rs +++ b/swarm/src/handler/multi.rs @@ -29,7 +29,7 @@ use crate::upgrade::{InboundUpgradeSend, OutboundUpgradeSend, UpgradeInfoSend}; use crate::NegotiatedSubstream; use futures::{future::BoxFuture, prelude::*}; use libp2p_core::upgrade::{NegotiationError, ProtocolError, ProtocolName, UpgradeError}; -use libp2p_core::{ConnectedPoint, Multiaddr, PeerId}; +use libp2p_core::{ConnectedPoint, PeerId}; use rand::Rng; use std::{ cmp, @@ -155,12 +155,6 @@ where } } - fn inject_address_change(&mut self, addr: &Multiaddr) { - for h in self.handlers.values_mut() { - h.inject_address_change(addr) - } - } - fn inject_dial_upgrade_error( &mut self, (key, arg): Self::OutboundOpenInfo, diff --git a/swarm/src/handler/select.rs b/swarm/src/handler/select.rs index 70a6f3c26f6..92573bfb86d 100644 --- a/swarm/src/handler/select.rs +++ b/swarm/src/handler/select.rs @@ -27,7 +27,7 @@ use crate::upgrade::{InboundUpgradeSend, OutboundUpgradeSend, SendWrapper}; use libp2p_core::{ either::{EitherError, EitherOutput}, upgrade::{EitherUpgrade, NegotiationError, ProtocolError, SelectUpgrade, UpgradeError}, - ConnectedPoint, Multiaddr, PeerId, + ConnectedPoint, PeerId, }; use std::{cmp, task::Context, task::Poll}; @@ -169,11 +169,6 @@ where } } - fn inject_address_change(&mut self, new_address: &Multiaddr) { - self.proto1.inject_address_change(new_address); - self.proto2.inject_address_change(new_address) - } - fn inject_dial_upgrade_error( &mut self, info: Self::OutboundOpenInfo, diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index c5ef1b0aa88..a4dcd3c97b9 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -810,21 +810,6 @@ where self.behaviour.inject_event(peer_id, id, event); } } - PoolEvent::AddressChange { - peer_id, - id, - new_endpoint, - old_endpoint, - } => { - if !self.banned_peer_connections.contains(&id) { - self.behaviour.inject_address_change( - &peer_id, - &id, - &old_endpoint, - &new_endpoint, - ); - } - } } None