From 57c14eedfa861cbde1926595c328c7e8916cf732 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 7 Jul 2016 15:25:58 +0200 Subject: [PATCH] Place ideal peers in the log output. (#1563) --- parity/informant.rs | 12 +++++++----- parity/io_handler.rs | 4 +++- parity/main.rs | 2 +- util/src/network/service.rs | 5 +++++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/parity/informant.rs b/parity/informant.rs index 0eaebe10f..97702f9a6 100644 --- a/parity/informant.rs +++ b/parity/informant.rs @@ -22,7 +22,7 @@ use std::time::{Instant, Duration}; use std::sync::RwLock; use std::ops::{Deref, DerefMut}; use ethsync::{EthSync, SyncProvider}; -use util::Uint; +use util::{Uint, NetworkService}; use ethcore::client::*; use number_prefix::{binary_prefix, Standalone, Prefixed}; @@ -76,7 +76,7 @@ impl Informant { } #[cfg_attr(feature="dev", allow(match_bool))] - pub fn tick(&self, client: &Client, maybe_sync: Option<&EthSync>) { + pub fn tick(&self, client: &Client, maybe_sync: Option<(&EthSync, &NetworkService)>) where Message: Send + Sync + Clone + 'static { let elapsed = self.last_tick.read().unwrap().elapsed(); if elapsed < Duration::from_secs(5) { return; @@ -110,11 +110,13 @@ impl Informant { paint(Yellow.bold(), format!("{:3}", ((report.gas_processed - last_report.gas_processed) / From::from(elapsed.as_milliseconds() * 1000)).low_u64())), match maybe_sync { - Some(sync) => { + Some((sync, net)) => { let sync_info = sync.status(); - format!("{}/{} peers {} ", + let net_config = net.config(); + format!("{}/{}/{} peers {} ", paint(Green.bold(), format!("{:2}", sync_info.num_active_peers)), paint(Green.bold(), format!("{:2}", sync_info.num_peers)), + paint(Green.bold(), format!("{:2}", net_config.ideal_peers)), paint(Cyan.bold(), format!("{:>8}", format!("#{}", sync_info.last_imported_block_number.unwrap_or(chain_info.best_block_number)))), ) } @@ -128,7 +130,7 @@ impl Informant { paint(Purple.bold(), format!("{:>8}", Informant::format_bytes(cache_info.total()))), paint(Purple.bold(), format!("{:>8}", Informant::format_bytes(queue_info.mem_used))), match maybe_sync { - Some(sync) => { + Some((sync, _)) => { let sync_info = sync.status(); format!(" {} sync", paint(Purple.bold(), format!("{:>8}", Informant::format_bytes(sync_info.mem_used)))) } diff --git a/parity/io_handler.rs b/parity/io_handler.rs index 3f0c04fbd..4af630d44 100644 --- a/parity/io_handler.rs +++ b/parity/io_handler.rs @@ -40,7 +40,9 @@ impl IoHandler for ClientIoHandler { fn timeout(&self, _io: &IoContext, timer: TimerToken) { if let INFO_TIMER = timer { - self.info.tick(&self.client, Some(&self.sync)); + if let Some(net) = self.network.upgrade() { + self.info.tick(&self.client, Some((&self.sync, &net))); + } } } diff --git a/parity/main.rs b/parity/main.rs index f54c39ab5..5fe75a134 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -485,7 +485,7 @@ fn execute_import(conf: Configuration) { Err(BlockImportError::Import(ImportError::AlreadyInChain)) => { trace!("Skipping block already in chain."); } Err(e) => die!("Cannot import block: {:?}", e) } - informant.tick(client.deref(), None); + informant.tick::<&'static ()>(client.deref(), None); }; match format { diff --git a/util/src/network/service.rs b/util/src/network/service.rs index 353a24bbe..fdb8c5241 100644 --- a/util/src/network/service.rs +++ b/util/src/network/service.rs @@ -78,6 +78,11 @@ impl NetworkService where Message: Send + Sync + Clone + 'stat &self.stats } + /// Returns network configuration. + pub fn config(&self) -> &NetworkConfiguration { + &self.config + } + /// Returns external url if available. pub fn external_url(&self) -> Option { let host = self.host.read().unwrap();