mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-25 15:51:34 +00:00
Allow StreamMuxer to notify changes in the address (#1621)
* Allow StreamMuxer to notify changes in the address * Fix doc link * Revert accidental rename * Other accidental rename Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
This commit is contained in:
@ -101,6 +101,15 @@ pub trait NetworkBehaviour: Send + 'static {
|
||||
fn inject_connection_closed(&mut self, _: &PeerId, _: &ConnectionId, _: &ConnectedPoint)
|
||||
{}
|
||||
|
||||
/// Informs the behaviour that the [`ConnectedPoint`] of an existing connection has changed.
|
||||
fn inject_address_change(
|
||||
&mut self,
|
||||
_: &PeerId,
|
||||
_: &ConnectionId,
|
||||
_old: &ConnectedPoint,
|
||||
_new: &ConnectedPoint
|
||||
) {}
|
||||
|
||||
/// Informs the behaviour about an event generated by the handler dedicated to the peer identified by `peer_id`.
|
||||
/// for the behaviour.
|
||||
///
|
||||
|
@ -496,6 +496,11 @@ where TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
|
||||
let connection = connection.id();
|
||||
this.behaviour.inject_event(peer, connection, event);
|
||||
},
|
||||
Poll::Ready(NetworkEvent::AddressChange { connection, new_endpoint, old_endpoint }) => {
|
||||
let peer = connection.peer_id();
|
||||
let connection = connection.id();
|
||||
this.behaviour.inject_address_change(&peer, &connection, &old_endpoint, &new_endpoint);
|
||||
},
|
||||
Poll::Ready(NetworkEvent::ConnectionEstablished { connection, num_established }) => {
|
||||
let peer_id = connection.peer_id().clone();
|
||||
let endpoint = connection.endpoint().clone();
|
||||
|
@ -53,6 +53,7 @@ pub use crate::upgrade::{
|
||||
|
||||
use libp2p_core::{
|
||||
ConnectedPoint,
|
||||
Multiaddr,
|
||||
PeerId,
|
||||
upgrade::{self, UpgradeError},
|
||||
};
|
||||
@ -140,6 +141,9 @@ pub trait ProtocolsHandler: Send + 'static {
|
||||
/// Injects an event coming from the outside in the handler.
|
||||
fn inject_event(&mut self, event: Self::InEvent);
|
||||
|
||||
/// Notifies the handler of a change in the address of the remote.
|
||||
fn inject_address_change(&mut self, _new_address: &Multiaddr) {}
|
||||
|
||||
/// Indicates to the handler that upgrading an outbound substream to the given protocol has failed.
|
||||
fn inject_dial_upgrade_error(
|
||||
&mut self,
|
||||
|
@ -29,6 +29,7 @@ use crate::protocols_handler::{
|
||||
|
||||
use futures::prelude::*;
|
||||
use libp2p_core::{
|
||||
Multiaddr,
|
||||
PeerId,
|
||||
ConnectionInfo,
|
||||
Connected,
|
||||
@ -220,6 +221,10 @@ where
|
||||
self.handler.inject_event(event);
|
||||
}
|
||||
|
||||
fn inject_address_change(&mut self, new_address: &Multiaddr) {
|
||||
self.handler.inject_address_change(new_address);
|
||||
}
|
||||
|
||||
fn poll(&mut self, cx: &mut Context) -> Poll<
|
||||
Result<ConnectionHandlerEvent<Self::OutboundOpenInfo, Self::OutEvent>, Self::Error>
|
||||
> {
|
||||
|
Reference in New Issue
Block a user