diff --git a/src/bin/client.rs b/src/bin/client.rs index 3dda6fc22..a862737be 100644 --- a/src/bin/client.rs +++ b/src/bin/client.rs @@ -4,13 +4,15 @@ extern crate rustc_serialize; extern crate log; extern crate env_logger; -use std::io::*; +use std::io::stdin; use std::env; use log::{LogLevelFilter}; use env_logger::LogBuilder; -use util::hash::*; +use util::*; +use ethcore::client::*; use ethcore::service::ClientService; use ethcore::ethereum; +use ethcore::sync::*; fn setup_log() { let mut builder = LogBuilder::new(); @@ -26,7 +28,9 @@ fn setup_log() { fn main() { setup_log(); let spec = ethereum::new_frontier(); - let mut _service = ClientService::start(spec).unwrap(); + let mut service = ClientService::start(spec).unwrap(); + let io_handler = Box::new(ClientIoHandler { client: service.client(), timer: 0 }); + service.io().register_handler(io_handler).expect("Error registering IO handler"); loop { let mut cmd = String::new(); stdin().read_line(&mut cmd).unwrap(); @@ -36,3 +40,21 @@ fn main() { } } + +struct ClientIoHandler { + client: Arc>, + timer: TimerToken, +} + +impl IoHandler for ClientIoHandler { + fn initialize<'s>(&'s mut self, io: &mut IoContext<'s, NetSyncMessage>) { + self.timer = io.register_timer(5000).expect("Error registering timer"); + } + + fn timeout<'s>(&'s mut self, _io: &mut IoContext<'s, NetSyncMessage>, timer: TimerToken) { + if self.timer == timer { + println!("Chain info: {:?}", self.client.read().unwrap().deref().chain_info()); + } + } +} + diff --git a/src/client.rs b/src/client.rs index 6e74f21a0..3ee84ccd7 100644 --- a/src/client.rs +++ b/src/client.rs @@ -14,6 +14,7 @@ use verification::*; use block::*; /// General block status +#[derive(Debug)] pub enum BlockStatus { /// Part of the blockchain. InChain, @@ -26,6 +27,7 @@ pub enum BlockStatus { } /// Information about the blockchain gthered together. +#[derive(Debug)] pub struct BlockChainInfo { /// Blockchain difficulty. pub total_difficulty: U256, @@ -40,6 +42,7 @@ pub struct BlockChainInfo { } /// Block queue status +#[derive(Debug)] pub struct BlockQueueStatus { pub full: bool, } diff --git a/src/service.rs b/src/service.rs index d6df3cf0a..3bc137c9c 100644 --- a/src/service.rs +++ b/src/service.rs @@ -7,7 +7,8 @@ use client::Client; /// Client service setup. Creates and registers client and network services with the IO subsystem. pub struct ClientService { - _net_service: NetworkService, + net_service: NetworkService, + client: Arc>, } impl ClientService { @@ -22,14 +23,23 @@ impl ClientService { let client = Arc::new(RwLock::new(try!(Client::new(spec, &dir, net_service.io().channel())))); EthSync::register(&mut net_service, client.clone()); let client_io = Box::new(ClientIoHandler { - client: client + client: client.clone() }); try!(net_service.io().register_handler(client_io)); Ok(ClientService { - _net_service: net_service, + net_service: net_service, + client: client, }) } + + pub fn io(&mut self) -> &mut IoService { + self.net_service.io() + } + + pub fn client(&self) -> Arc> { + self.client.clone() + } } /// IO interface for the Client handler