diff --git a/ethcore/light/src/client/mod.rs b/ethcore/light/src/client/mod.rs index e56fc115b..32725cc1a 100644 --- a/ethcore/light/src/client/mod.rs +++ b/ethcore/light/src/client/mod.rs @@ -16,13 +16,9 @@ //! Light client implementation. Stores data from light sync -use std::sync::Arc; - -use ethcore::engines::Engine; -use ethcore::ids::BlockId; use ethcore::block_import_error::BlockImportError; use ethcore::block_status::BlockStatus; -use ethcore::verification::queue::{HeaderQueue, QueueInfo, Config as QueueConfig}; +use ethcore::verification::queue::{self, HeaderQueue}; use ethcore::transaction::SignedTransaction; use ethcore::blockchain_info::BlockChainInfo; use ethcore::spec::Spec; @@ -37,12 +33,13 @@ use request; use self::header_chain::HeaderChain; +mod cht; mod header_chain; /// Configuration for the light client. #[derive(Debug, Default, Clone)] pub struct Config { - queue: QueueConfig, + queue: queue::Config, } /// Light client implementation. @@ -79,15 +76,19 @@ impl Client { self.tx_pool.lock().values().cloned().collect() } - /// Inquire about the status of a given block (or header). - pub fn status(&self, id: BlockId) -> BlockStatus { - BlockStatus::Unknown + /// Inquire about the status of a given header. + pub fn status(&self, hash: &H256) -> BlockStatus { + match self.queue.status(hash) { + queue::Status::Unknown => self.chain.status(hash), + other => other.into(), + } } /// Get the header queue info. - pub fn queue_info(&self) -> QueueInfo { + pub fn queue_info(&self) -> queue::QueueInfo { self.queue.queue_info() } + } // dummy implementation -- may draw from canonical cache further on. diff --git a/ethcore/light/src/net/context.rs b/ethcore/light/src/net/context.rs index a7676cdf0..7f55dd229 100644 --- a/ethcore/light/src/net/context.rs +++ b/ethcore/light/src/net/context.rs @@ -95,7 +95,7 @@ pub trait EventContext { /// Find the maximum number of requests of a specific type which can be made from /// supplied peer. - fn max_requests(&self, peer: PeerId, kind: request::Kind) -> Option; + fn max_requests(&self, peer: PeerId, kind: request::Kind) -> usize; /// Disconnect a peer. fn disconnect_peer(&self, peer: PeerId); @@ -132,7 +132,7 @@ impl<'a> EventContext for Ctx<'a> { self.proto.make_announcement(self.io, announcement); } - fn max_requests(&self, peer: PeerId, kind: request::Kind) -> Option { + fn max_requests(&self, peer: PeerId, kind: request::Kind) -> usize { self.proto.max_requests(peer, kind) } diff --git a/ethcore/light/src/net/mod.rs b/ethcore/light/src/net/mod.rs index 02f08a7a9..326c234ca 100644 --- a/ethcore/light/src/net/mod.rs +++ b/ethcore/light/src/net/mod.rs @@ -255,8 +255,9 @@ impl LightProtocol { } /// Check the maximum amount of requests of a specific type - /// which a peer would be able to serve. - pub fn max_requests(&self, peer: PeerId, kind: request::Kind) -> Option { + /// which a peer would be able to serve. Returns zero if the + /// peer is unknown or has no buffer flow parameters. + pub fn max_requests(&self, peer: PeerId, kind: request::Kind) -> usize { self.peers.read().get(&peer).and_then(|peer| { let mut peer = peer.lock(); match peer.remote_flow.as_mut() { @@ -266,7 +267,7 @@ impl LightProtocol { } None => None, } - }) + }).unwrap_or(0) } /// Make a request to a peer.