diff --git a/substrate/core/network-libp2p/src/transport.rs b/substrate/core/network-libp2p/src/transport.rs
index 66fd40584c..c095602a11 100644
--- a/substrate/core/network-libp2p/src/transport.rs
+++ b/substrate/core/network-libp2p/src/transport.rs
@@ -15,14 +15,15 @@
// along with Substrate. If not, see .
use futures::prelude::*;
-use libp2p::{InboundUpgradeExt, OutboundUpgradeExt, PeerId, Transport, mplex, secio, yamux, tcp, dns, websocket};
+use libp2p::{
+ InboundUpgradeExt, OutboundUpgradeExt, PeerId, Transport,
+ mplex, secio, yamux, tcp, dns, websocket, bandwidth
+};
use libp2p::core::{self, transport::boxed::Boxed, muxing::StreamMuxerBox};
use std::{io, sync::Arc, time::Duration, usize};
pub use self::bandwidth::BandwidthSinks;
-mod bandwidth;
-
/// Builds the transport that serves as a common ground for all connections.
///
/// Returns a `BandwidthSinks` object that allows querying the average bandwidth produced by all
@@ -37,7 +38,7 @@ pub fn build_transport(
let transport = tcp::TcpConfig::new();
let transport = websocket::WsConfig::new(transport.clone()).or_transport(transport);
let transport = dns::DnsConfig::new(transport);
- let (transport, sinks) = bandwidth::BandwidthLogging::new(transport, 5);
+ let (transport, sinks) = bandwidth::BandwidthLogging::new(transport, Duration::from_secs(5));
// TODO: rework the transport creation (https://github.com/libp2p/rust-libp2p/issues/783)
let transport = transport
diff --git a/substrate/core/network-libp2p/src/transport/bandwidth.rs b/substrate/core/network-libp2p/src/transport/bandwidth.rs
deleted file mode 100644
index 23ec064918..0000000000
--- a/substrate/core/network-libp2p/src/transport/bandwidth.rs
+++ /dev/null
@@ -1,262 +0,0 @@
-// Copyright 2019 Parity Technologies (UK) Ltd.
-// This file is part of Substrate.
-
-// Substrate is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Substrate is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Substrate. If not, see .
-
-use futures::{prelude::*, try_ready};
-use lazy_static::lazy_static;
-use libp2p::{Multiaddr, core::Transport, core::transport::TransportError};
-use parking_lot::Mutex;
-use smallvec::{smallvec, SmallVec};
-use std::{io, io::Read, io::Write, sync::Arc, time::Instant};
-
-/// Wraps around a `Transport` and logs the bandwidth that goes through all the opened connections.
-#[derive(Clone)]
-pub struct BandwidthLogging {
- inner: TInner,
- sinks: Arc,
-}
-
-impl BandwidthLogging {
- /// Creates a new `BandwidthLogging` around the transport.
- #[inline]
- pub fn new(inner: TInner, period_seconds: u32) -> (Self, Arc) {
- let sink = Arc::new(BandwidthSinks {
- download: Mutex::new(BandwidthSink::new(period_seconds)),
- upload: Mutex::new(BandwidthSink::new(period_seconds)),
- });
-
- let trans = BandwidthLogging {
- inner,
- sinks: sink.clone(),
- };
-
- (trans, sink)
- }
-}
-
-impl Transport for BandwidthLogging
-where
- TInner: Transport,
-{
- type Output = BandwidthConnecLogging;
- type Error = TInner::Error;
- type Listener = BandwidthListener;
- type ListenerUpgrade = BandwidthFuture;
- type Dial = BandwidthFuture;
-
- fn listen_on(self, addr: Multiaddr) -> Result<(Self::Listener, Multiaddr), TransportError> {
- let sinks = self.sinks;
- self.inner
- .listen_on(addr)
- .map(|(inner, new_addr)| (BandwidthListener { inner, sinks }, new_addr))
- }
-
- fn dial(self, addr: Multiaddr) -> Result> {
- let sinks = self.sinks;
- self.inner
- .dial(addr)
- .map(move |fut| BandwidthFuture {
- inner: fut,
- sinks,
- })
- }
-
- fn nat_traversal(&self, server: &Multiaddr, observed: &Multiaddr) -> Option {
- self.inner.nat_traversal(server, observed)
- }
-}
-
-/// Wraps around a `Stream` that produces connections. Wraps each connection around a bandwidth
-/// counter.
-pub struct BandwidthListener {
- inner: TInner,
- sinks: Arc,
-}
-
-impl Stream for BandwidthListener
-where TInner: Stream,
-{
- type Item = (BandwidthFuture, Multiaddr);
- type Error = TInner::Error;
-
- fn poll(&mut self) -> Poll