Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions core/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}
14 changes: 2 additions & 12 deletions core/src/muxing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -139,22 +138,14 @@ pub trait StreamMuxer {
pub enum StreamMuxerEvent<T> {
/// 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<T> StreamMuxerEvent<T> {
/// If `self` is a [`StreamMuxerEvent::InboundSubstream`], returns the content. Otherwise
/// returns `None`.
pub fn into_inbound_substream(self) -> Option<T> {
if let StreamMuxerEvent::InboundSubstream(s) = self {
Some(s)
} else {
None
match self {
StreamMuxerEvent::InboundSubstream(stream) => Some(stream),
}
}

Expand All @@ -164,7 +155,6 @@ impl<T> StreamMuxerEvent<T> {
StreamMuxerEvent::InboundSubstream(stream) => {
StreamMuxerEvent::InboundSubstream(map(stream))
}
StreamMuxerEvent::AddressChange(addr) => StreamMuxerEvent::AddressChange(addr),
}
}
}
3 changes: 0 additions & 3 deletions core/src/muxing/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ where
) -> Poll<Result<StreamMuxerEvent<Self::Substream>, 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())),
};
Expand Down
3 changes: 0 additions & 3 deletions muxers/mplex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<C> {
io: Arc<Mutex<io::Multiplexed<C>>>,
}
Expand Down
1 change: 0 additions & 1 deletion muxers/yamux/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ where

pub type YamuxResult<T> = Result<T, YamuxError>;

/// > **Note**: This implementation never emits [`StreamMuxerEvent::AddressChange`] events.
impl<S> StreamMuxer for Yamux<S>
where
S: Stream<Item = Result<yamux::Stream, YamuxError>> + Unpin,
Expand Down
23 changes: 0 additions & 23 deletions protocols/autonat/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions swarm/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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]

Expand Down
1 change: 1 addition & 0 deletions swarm/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 0 additions & 13 deletions swarm/src/behaviour/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 0 additions & 18 deletions swarm/src/behaviour/toggle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions swarm/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ pub struct Connected {
pub enum Event<T> {
/// 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`].
Expand Down Expand Up @@ -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))),
}

Expand Down
5 changes: 0 additions & 5 deletions swarm/src/connection/handler_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<
Expand Down
33 changes: 0 additions & 33 deletions swarm/src/connection/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,6 @@ where
/// The produced event.
event: THandlerOutEvent<THandler>,
},

/// 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<THandler, TTrans> Pool<THandler, TTrans>
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 0 additions & 15 deletions swarm/src/connection/pool/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ where

#[derive(Debug)]
pub enum EstablishedConnectionEvent<THandler: ConnectionHandler> {
/// 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,
Expand Down Expand Up @@ -225,15 +219,6 @@ pub async fn new_for_established_connection<THandler>(
})
.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();
Expand Down
14 changes: 0 additions & 14 deletions swarm/src/connection/substream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 => {}
}
Expand Down Expand Up @@ -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(),
}
}
}
1 change: 1 addition & 0 deletions swarm/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 1 addition & 8 deletions swarm/src/handler/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<L, R> {
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 0 additions & 5 deletions swarm/src/handler/map_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
Loading