Update to libp2p-0.23. (#6870)

* Update to libp2p-0.23.

Thereby incorporate bandwidth measurement along the
lines previously done by libp2p itself.

* Tweak dependencies for wasm32 compilation.

For wasm32 we need to enable unstable features to
make `task::Builder::local` available.

* Simplify dependencies.

* Simplify.

Leave the calculation of bytes sent/received per second
to the outer layers of the code, subject to their own
individual update intervals.

* Cleanup

* Re-add lost dev dependency.

* Avoid division by zero.

* Remove redundant metric.

* Enable sending of noise legacy handshakes.

* Add comment about monotonic gauge.

* CI
This commit is contained in:
Roman Borschel
2020-08-14 10:41:47 +02:00
committed by GitHub
parent f94aae1d2d
commit 327e02942c
18 changed files with 129 additions and 75 deletions
+27 -5
View File
@@ -45,6 +45,10 @@ pub struct InformantDisplay<B: BlockT> {
last_number: Option<NumberFor<B>>,
/// The last time `display` or `new` has been called.
last_update: Instant,
/// The last seen total of bytes received.
last_total_bytes_inbound: u64,
/// The last seen total of bytes sent.
last_total_bytes_outbound: u64,
/// The format to print output in.
format: OutputFormat,
}
@@ -55,6 +59,8 @@ impl<B: BlockT> InformantDisplay<B> {
InformantDisplay {
last_number: None,
last_update: Instant::now(),
last_total_bytes_inbound: 0,
last_total_bytes_outbound: 0,
format,
}
}
@@ -66,9 +72,25 @@ impl<B: BlockT> InformantDisplay<B> {
let finalized_number = info.chain.finalized_number;
let num_connected_peers = net_status.num_connected_peers;
let speed = speed::<B>(best_number, self.last_number, self.last_update);
self.last_update = Instant::now();
let total_bytes_inbound = net_status.total_bytes_inbound;
let total_bytes_outbound = net_status.total_bytes_outbound;
let now = Instant::now();
let elapsed = (now - self.last_update).as_secs();
self.last_update = now;
self.last_number = Some(best_number);
let diff_bytes_inbound = total_bytes_inbound - self.last_total_bytes_inbound;
let diff_bytes_outbound = total_bytes_outbound - self.last_total_bytes_outbound;
let (avg_bytes_per_sec_inbound, avg_bytes_per_sec_outbound) =
if elapsed > 0 {
self.last_total_bytes_inbound = total_bytes_inbound;
self.last_total_bytes_outbound = total_bytes_outbound;
(diff_bytes_inbound / elapsed, diff_bytes_outbound / elapsed)
} else {
(diff_bytes_inbound, diff_bytes_outbound)
};
let (level, status, target) = match (net_status.sync_state, net_status.best_seen_block) {
(SyncState::Idle, _) => ("💤", "Idle".into(), "".into()),
(SyncState::Downloading, None) => ("⚙️ ", format!("Preparing{}", speed), "".into()),
@@ -92,8 +114,8 @@ impl<B: BlockT> InformantDisplay<B> {
best_hash,
Colour::White.bold().paint(format!("{}", finalized_number)),
info.chain.finalized_hash,
Colour::Green.paint(format!("{}", TransferRateFormat(net_status.average_download_per_sec))),
Colour::Red.paint(format!("{}", TransferRateFormat(net_status.average_upload_per_sec))),
Colour::Green.paint(format!("{}", TransferRateFormat(avg_bytes_per_sec_inbound))),
Colour::Red.paint(format!("{}", TransferRateFormat(avg_bytes_per_sec_outbound))),
)
} else {
info!(
@@ -108,8 +130,8 @@ impl<B: BlockT> InformantDisplay<B> {
best_hash,
finalized_number,
info.chain.finalized_hash,
TransferRateFormat(net_status.average_download_per_sec),
TransferRateFormat(net_status.average_upload_per_sec),
TransferRateFormat(avg_bytes_per_sec_inbound),
TransferRateFormat(avg_bytes_per_sec_outbound),
)
}
}