Merge pull request #4036 from ethcore/on-demand-les-request
On demand LES request
This commit is contained in:
@@ -30,6 +30,7 @@ use util::{Bytes, Mutex, RwLock, U256};
|
||||
use time::{Duration, SteadyTime};
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
@@ -123,6 +124,12 @@ mod timeout {
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct ReqId(usize);
|
||||
|
||||
impl fmt::Display for ReqId {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "Request #{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
// A pending peer: one we've sent our status to but
|
||||
// may not have received one for.
|
||||
struct PendingPeer {
|
||||
@@ -186,12 +193,12 @@ pub trait Handler: Send + Sync {
|
||||
fn on_block_headers(&self, _ctx: &EventContext, _req_id: ReqId, _headers: &[Bytes]) { }
|
||||
/// Called when a peer responds with block receipts.
|
||||
fn on_receipts(&self, _ctx: &EventContext, _req_id: ReqId, _receipts: &[Vec<Receipt>]) { }
|
||||
/// Called when a peer responds with state proofs. Each proof is a series of trie
|
||||
/// Called when a peer responds with state proofs. Each proof should be a series of trie
|
||||
/// nodes in ascending order by distance from the root.
|
||||
fn on_state_proofs(&self, _ctx: &EventContext, _req_id: ReqId, _proofs: &[Vec<Bytes>]) { }
|
||||
/// Called when a peer responds with contract code.
|
||||
fn on_code(&self, _ctx: &EventContext, _req_id: ReqId, _codes: &[Bytes]) { }
|
||||
/// Called when a peer responds with header proofs. Each proof is a block header coupled
|
||||
/// Called when a peer responds with header proofs. Each proof should be a block header coupled
|
||||
/// with a series of trie nodes is ascending order by distance from the root.
|
||||
fn on_header_proofs(&self, _ctx: &EventContext, _req_id: ReqId, _proofs: &[(Bytes, Vec<Bytes>)]) { }
|
||||
/// Called to "tick" the handler periodically.
|
||||
|
||||
@@ -158,6 +158,16 @@ pub struct Status {
|
||||
pub last_head: Option<(H256, u64)>,
|
||||
}
|
||||
|
||||
impl Status {
|
||||
/// Update the status from an announcement.
|
||||
pub fn update_from(&mut self, announcement: &Announcement) {
|
||||
self.last_head = Some((self.head_hash, announcement.reorg_depth));
|
||||
self.head_td = announcement.head_td;
|
||||
self.head_hash = announcement.head_hash;
|
||||
self.head_num = announcement.head_num;
|
||||
}
|
||||
}
|
||||
|
||||
/// Peer capabilities.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Capabilities {
|
||||
|
||||
Reference in New Issue
Block a user