Trait libp2p::TransportExt

source ·
pub trait TransportExt: Transport {
    // Provided method
    fn with_bandwidth_logging<S>(
        self
    ) -> (Boxed<(PeerId, StreamMuxerBox)>, Arc<BandwidthSinks>)
       where Self: Sized + Send + Unpin + 'static,
             Self::Dial: Send + 'static,
             Self::ListenerUpgrade: Send + 'static,
             Self::Error: Send + Sync,
             Self::Output: Into<(PeerId, S)>,
             S: StreamMuxer + Send + 'static,
             S::Substream: Send + 'static,
             S::Error: Send + Sync + 'static { ... }
}
Expand description

Trait automatically implemented on all objects that implement Transport. Provides some additional utilities.

Provided Methods§

source

fn with_bandwidth_logging<S>( self ) -> (Boxed<(PeerId, StreamMuxerBox)>, Arc<BandwidthSinks>)
where Self: Sized + Send + Unpin + 'static, Self::Dial: Send + 'static, Self::ListenerUpgrade: Send + 'static, Self::Error: Send + Sync, Self::Output: Into<(PeerId, S)>, S: StreamMuxer + Send + 'static, S::Substream: Send + 'static, S::Error: Send + Sync + 'static,

👎Deprecated: Use libp2p::SwarmBuilder::with_bandwidth_metrics or libp2p_metrics::BandwidthTransport instead.

Adds a layer on the Transport that logs all trafic that passes through the streams created by it.

This method returns an Arc<BandwidthSinks> that can be used to retrieve the total number of bytes transferred through the streams.

Example
use libp2p_yamux as yamux;
use libp2p_noise as noise;
use libp2p_tcp as tcp;
use libp2p::{
    core::upgrade,
    identity,
    TransportExt,
    Transport,
};

let id_keys = identity::Keypair::generate_ed25519();

let transport = tcp::tokio::Transport::new(tcp::Config::default().nodelay(true))
    .upgrade(upgrade::Version::V1)
    .authenticate(
        noise::Config::new(&id_keys)
            .expect("Signing libp2p-noise static DH keypair failed."),
    )
    .multiplex(yamux::Config::default())
    .boxed();

let (transport, sinks) = transport.with_bandwidth_logging();

Implementors§

source§

impl<TTransport> TransportExt for TTransport
where TTransport: Transport,