Documentation

This commit is contained in:
arkpar 2016-01-15 01:03:29 +01:00
parent e5a51707ec
commit f6dff48312
2 changed files with 9 additions and 13 deletions

View File

@ -105,6 +105,7 @@ pub struct Client {
} }
impl Client { impl Client {
/// Create a new client with given spec and DB path.
pub fn new(spec: Spec, path: &Path, message_channel: IoChannel<NetSyncMessage> ) -> Result<Client, Error> { pub fn new(spec: Spec, path: &Path, message_channel: IoChannel<NetSyncMessage> ) -> Result<Client, Error> {
let chain = Arc::new(RwLock::new(BlockChain::new(&spec.genesis_block(), path))); let chain = Arc::new(RwLock::new(BlockChain::new(&spec.genesis_block(), path)));
let engine = Arc::new(try!(spec.to_engine())); let engine = Arc::new(try!(spec.to_engine()));
@ -123,7 +124,7 @@ impl Client {
}) })
} }
/// This is triggered by a message coming from a block queue when the block is ready for insertion
pub fn import_verified_block(&mut self, bytes: Bytes) { pub fn import_verified_block(&mut self, bytes: Bytes) {
let block = BlockView::new(&bytes); let block = BlockView::new(&bytes);
let header = block.header(); let header = block.header();
@ -173,7 +174,7 @@ impl Client {
return; return;
} }
} }
info!(target: "client", "Imported {}", header.hash()); info!(target: "client", "Imported #{} ({})", header.number(), header.hash());
} }
} }

View File

@ -1,10 +1,3 @@
//! Client service.
//!
//!
//!
//!
//!
use util::*; use util::*;
use sync::*; use sync::*;
use spec::Spec; use spec::Spec;
@ -12,11 +5,13 @@ use error::*;
use std::env; use std::env;
use client::Client; use client::Client;
/// Client service setup. Creates and registers client and network services with the IO subsystem.
pub struct ClientService { pub struct ClientService {
_net_service: NetworkService<SyncMessage>, _net_service: NetworkService<SyncMessage>,
} }
impl ClientService { impl ClientService {
/// Start the service in a separate thread.
pub fn start(spec: Spec) -> Result<ClientService, Error> { pub fn start(spec: Spec) -> Result<ClientService, Error> {
let mut net_service = try!(NetworkService::start()); let mut net_service = try!(NetworkService::start());
info!("Starting {}", net_service.host_info()); info!("Starting {}", net_service.host_info());
@ -37,13 +32,13 @@ impl ClientService {
} }
} }
/// IO interface for the Client handler
struct ClientIoHandler { struct ClientIoHandler {
client: Arc<RwLock<Client>> client: Arc<RwLock<Client>>
} }
impl IoHandler<NetSyncMessage> for ClientIoHandler { impl IoHandler<NetSyncMessage> for ClientIoHandler {
fn initialize<'s>(&'s mut self, _io: &mut IoContext<'s, NetSyncMessage>) { fn initialize<'s>(&'s mut self, _io: &mut IoContext<'s, NetSyncMessage>) { }
}
fn message<'s>(&'s mut self, _io: &mut IoContext<'s, NetSyncMessage>, net_message: &'s mut NetSyncMessage) { fn message<'s>(&'s mut self, _io: &mut IoContext<'s, NetSyncMessage>, net_message: &'s mut NetSyncMessage) {
match net_message { match net_message {
@ -52,11 +47,11 @@ impl IoHandler<NetSyncMessage> for ClientIoHandler {
&mut SyncMessage::BlockVerified(ref mut bytes) => { &mut SyncMessage::BlockVerified(ref mut bytes) => {
self.client.write().unwrap().import_verified_block(mem::replace(bytes, Bytes::new())); self.client.write().unwrap().import_verified_block(mem::replace(bytes, Bytes::new()));
}, },
_ => {}, _ => {}, // ignore other messages
} }
} }
_ => {}, _ => {}, // ignore other messages
} }
} }