Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

On demand LES request #4036

Merged
merged 21 commits into from
Jan 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions ethcore/light/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ ethcore-ipc = { path = "../../ipc/rpc", optional = true }
rlp = { path = "../../util/rlp" }
time = "0.1"
smallvec = "0.3.1"
futures = "0.1"
rand = "0.3"

[features]
default = []
Expand Down
3 changes: 3 additions & 0 deletions ethcore/light/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

pub mod client;
pub mod net;
pub mod on_demand;

#[cfg(not(feature = "ipc"))]
pub mod provider;
Expand Down Expand Up @@ -64,6 +65,8 @@ extern crate ethcore_io as io;
extern crate rlp;
extern crate smallvec;
extern crate time;
extern crate futures;
extern crate rand;

#[cfg(feature = "ipc")]
extern crate ethcore_ipc as ipc;
11 changes: 9 additions & 2 deletions ethcore/light/src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions ethcore/light/src/net/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading