Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Idealpeers in log #1563

Merged
merged 3 commits into from
Jul 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions parity/informant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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<Message>(&self, client: &Client, maybe_sync: Option<(&EthSync, &NetworkService<Message>)>) where Message: Send + Sync + Clone + 'static {
let elapsed = self.last_tick.read().unwrap().elapsed();
if elapsed < Duration::from_secs(5) {
return;
Expand Down Expand Up @@ -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)))),
)
}
Expand All @@ -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))))
}
Expand Down
4 changes: 3 additions & 1 deletion parity/io_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ impl IoHandler<NetSyncMessage> for ClientIoHandler {

fn timeout(&self, _io: &IoContext<NetSyncMessage>, 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)));
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion parity/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions util/src/network/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ impl<Message> NetworkService<Message> 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<String> {
let host = self.host.read().unwrap();
Expand Down