diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 34f369729..d35a01be7 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -35,7 +35,7 @@ use util::rlp::{RlpStream, Rlp, UntrustedRlp}; use util::journaldb; use util::journaldb::JournalDB; use util::kvdb::*; -use util::{Stream, View, PerfTimer, Itertools, Colour}; +use util::{Stream, View, PerfTimer, Itertools}; use util::{Mutex, RwLock}; // other @@ -608,18 +608,6 @@ impl Client { } } } - - /// Notify us that the network has been started. - pub fn network_started(&self, url: &str) { - let mut previous_enode = self.previous_enode.lock(); - if let Some(ref u) = *previous_enode { - if u == url { - return; - } - } - *previous_enode = Some(url.into()); - info!(target: "mode", "Public node URL: {}", Colour::White.bold().paint(url)); - } } #[derive(Ipc)] @@ -687,7 +675,7 @@ impl BlockChainClient for Client { fn block(&self, id: BlockID) -> Option { if let &BlockID::Pending = &id { - if let Some(block) = self.miner.pending_block() { + if let Some(block) = self.miner.pending_block() { return Some(block.rlp_bytes(Seal::Without)); } } @@ -708,7 +696,7 @@ impl BlockChainClient for Client { if let &BlockID::Pending = &id { if let Some(block) = self.miner.pending_block() { return Some(*block.header.difficulty() + self.block_total_difficulty(BlockID::Latest).expect("blocks in chain have details; qed")); - } + } } Self::block_hash(&self.chain, id).and_then(|hash| self.chain.block_details(&hash)).map(|d| d.total_difficulty) } diff --git a/util/src/network/service.rs b/util/src/network/service.rs index d95db5842..df9c50ef4 100644 --- a/util/src/network/service.rs +++ b/util/src/network/service.rs @@ -21,10 +21,25 @@ use network::error::NetworkError; use network::host::{Host, NetworkContext, NetworkIoMessage, ProtocolId}; use network::stats::NetworkStats; use io::*; - -use std::sync::Arc; - use parking_lot::RwLock; +use std::sync::Arc; +use ansi_term::Colour; + +struct HostHandler { + public_url: RwLock> +} + +impl IoHandler for HostHandler { + fn message(&self, _io: &IoContext, message: &NetworkIoMessage) { + if let NetworkIoMessage::NetworkStarted(ref public_url) = *message { + let mut url = self.public_url.write(); + if url.as_ref().map(|uref| uref != public_url).unwrap_or(true) { + info!(target: "network", "Public node URL: {}", Colour::White.bold().paint(public_url.as_ref())); + } + *url = Some(public_url.to_owned()); + } + } +} /// IO Service with networking /// `Message` defines a notification data type. @@ -34,12 +49,14 @@ pub struct NetworkService { host: RwLock>>, stats: Arc, panic_handler: Arc, + host_handler: Arc, config: NetworkConfiguration, } impl NetworkService { /// Starts IO event loop pub fn new(config: NetworkConfiguration) -> Result { + let host_handler = Arc::new(HostHandler { public_url: RwLock::new(None) }); let panic_handler = PanicHandler::new_in_arc(); let io_service = try!(IoService::::start()); panic_handler.forward_from(&io_service); @@ -53,6 +70,7 @@ impl NetworkService { panic_handler: panic_handler, host: RwLock::new(None), config: config, + host_handler: host_handler, }) } @@ -106,6 +124,11 @@ impl NetworkService { try!(self.io_service.register_handler(h.clone())); *host = Some(h); } + + if self.host_handler.public_url.read().is_none() { + try!(self.io_service.register_handler(self.host_handler.clone())); + } + Ok(()) }