light: max requests as 0 on unknown peer
This commit is contained in:
parent
2a01b43bd1
commit
484023b171
@ -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.
|
||||
|
@ -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<usize>;
|
||||
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<usize> {
|
||||
fn max_requests(&self, peer: PeerId, kind: request::Kind) -> usize {
|
||||
self.proto.max_requests(peer, kind)
|
||||
}
|
||||
|
||||
|
@ -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<usize> {
|
||||
/// 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.
|
||||
|
Loading…
Reference in New Issue
Block a user