Report the average network bandwidth (#1551)

* Report the average network bandwidth

* Fix concerns
This commit is contained in:
Pierre Krieger
2019-01-25 11:34:34 +01:00
committed by Gav Wood
parent aeb6aa8b48
commit a1586df41b
7 changed files with 342 additions and 9 deletions
+12
View File
@@ -173,6 +173,18 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> Service<B, S,
Ok(service)
}
/// Returns the downloaded bytes per second averaged over the past few seconds.
#[inline]
pub fn average_download_per_sec(&self) -> u64 {
self.network.lock().average_download_per_sec()
}
/// Returns the uploaded bytes per second averaged over the past few seconds.
#[inline]
pub fn average_upload_per_sec(&self) -> u64 {
self.network.lock().average_upload_per_sec()
}
/// Called when a new block is imported by the client.
pub fn on_block_imported(&self, hash: B::Hash, header: &B::Header) {
self.handler.on_block_imported(&mut NetSyncIo::new(&self.network, self.protocol_id), hash, header)