diff --git a/ethcore/light/src/net/mod.rs b/ethcore/light/src/net/mod.rs index 968b98281..bd9e3e1fd 100644 --- a/ethcore/light/src/net/mod.rs +++ b/ethcore/light/src/net/mod.rs @@ -899,7 +899,7 @@ impl LightProtocol { // the maximum amount of requests we'll fill in a single packet. const MAX_REQUESTS: usize = 256; - use ::request::RequestBuilder; + use ::request::Builder; use ::request::CompleteRequest; let peers = self.peers.read(); @@ -914,7 +914,7 @@ impl LightProtocol { let peer: &mut Peer = &mut *peer; let req_id: u64 = raw.val_at(0)?; - let mut request_builder = RequestBuilder::default(); + let mut request_builder = Builder::default(); trace!(target: "pip", "Received requests (id: {}) from peer {}", req_id, peer_id); diff --git a/ethcore/light/src/net/request_set.rs b/ethcore/light/src/net/request_set.rs index 7ec668884..e535d3b5d 100644 --- a/ethcore/light/src/net/request_set.rs +++ b/ethcore/light/src/net/request_set.rs @@ -147,7 +147,7 @@ fn compute_timeout(reqs: &Requests) -> Duration { #[cfg(test)] mod tests { use net::ReqId; - use request::RequestBuilder; + use request::Builder; use time::{SteadyTime, Duration}; use super::{RequestSet, compute_timeout}; @@ -156,7 +156,7 @@ mod tests { let test_begin = SteadyTime::now(); let mut req_set = RequestSet::default(); - let the_req = RequestBuilder::default().build(); + let the_req = Builder::default().build(); let req_time = compute_timeout(&the_req); req_set.insert(ReqId(0), the_req.clone(), 0.into(), test_begin); req_set.insert(ReqId(1), the_req, 0.into(), test_begin + Duration::seconds(1)); @@ -173,7 +173,7 @@ mod tests { #[test] fn cumulative_cost() { - let the_req = RequestBuilder::default().build(); + let the_req = Builder::default().build(); let test_begin = SteadyTime::now(); let test_end = test_begin + Duration::seconds(1); let mut req_set = RequestSet::default(); diff --git a/ethcore/light/src/net/tests/mod.rs b/ethcore/light/src/net/tests/mod.rs index 539a60ffb..af0a02c3e 100644 --- a/ethcore/light/src/net/tests/mod.rs +++ b/ethcore/light/src/net/tests/mod.rs @@ -41,7 +41,7 @@ use std::sync::Arc; // helper for encoding a single request into a packet. // panics on bad backreference. fn encode_single(request: Request) -> NetworkRequests { - let mut builder = RequestBuilder::default(); + let mut builder = Builder::default(); builder.push(request).unwrap(); builder.build() } @@ -344,7 +344,7 @@ fn get_block_bodies() { proto.handle_packet(&Expect::Nothing, &1, packet::STATUS, &my_status); } - let mut builder = RequestBuilder::default(); + let mut builder = Builder::default(); let mut bodies = Vec::new(); for i in 0..10 { @@ -400,7 +400,7 @@ fn get_block_receipts() { .take(10) .collect(); - let mut builder = RequestBuilder::default(); + let mut builder = Builder::default(); let mut receipts = Vec::new(); for hash in block_hashes.iter().cloned() { builder.push(Request::Receipts(IncompleteReceiptsRequest { hash: hash.into() })).unwrap(); @@ -448,7 +448,7 @@ fn get_state_proofs() { let key1: H256 = U256::from(11223344).into(); let key2: H256 = U256::from(99988887).into(); - let mut builder = RequestBuilder::default(); + let mut builder = Builder::default(); builder.push(Request::Account(IncompleteAccountRequest { block_hash: H256::default().into(), address_hash: key1.into(), diff --git a/ethcore/light/src/on_demand/mod.rs b/ethcore/light/src/on_demand/mod.rs index 6a9ecb4d1..40da12348 100644 --- a/ethcore/light/src/on_demand/mod.rs +++ b/ethcore/light/src/on_demand/mod.rs @@ -74,8 +74,8 @@ impl Peer { // Attempted request info and sender to put received value. struct Pending { - requests: basic_request::Requests, - net_requests: basic_request::Requests, + requests: basic_request::Batch, + net_requests: basic_request::Batch, required_capabilities: Capabilities, responses: Vec, sender: oneshot::Sender>, @@ -151,7 +151,7 @@ impl Pending { fn update_net_requests(&mut self) { use request::IncompleteRequest; - let mut builder = basic_request::RequestBuilder::default(); + let mut builder = basic_request::Builder::default(); let num_answered = self.requests.num_answered(); let mut mapping = move |idx| idx - num_answered; @@ -281,7 +281,7 @@ impl OnDemand { return Ok(receiver); } - let mut builder = basic_request::RequestBuilder::default(); + let mut builder = basic_request::Builder::default(); let responses = Vec::with_capacity(requests.len()); diff --git a/ethcore/light/src/types/request/builder.rs b/ethcore/light/src/types/request/builder.rs index 74503f54f..df9dad1ad 100644 --- a/ethcore/light/src/types/request/builder.rs +++ b/ethcore/light/src/types/request/builder.rs @@ -25,23 +25,23 @@ use request::{ }; /// Build chained requests. Push them onto the series with `push`, -/// and produce a `Requests` object with `build`. Outputs are checked for consistency. +/// and produce a `Batch` object with `build`. Outputs are checked for consistency. #[derive(Debug, Clone, PartialEq, Eq)] -pub struct RequestBuilder { +pub struct Builder { output_kinds: HashMap<(usize, usize), OutputKind>, requests: Vec, } -impl Default for RequestBuilder { +impl Default for Builder { fn default() -> Self { - RequestBuilder { + Builder { output_kinds: HashMap::new(), requests: Vec::new(), } } } -impl RequestBuilder { +impl Builder { /// Attempt to push a request onto the request chain. Fails if the request /// references a non-existent output of a prior request. pub fn push(&mut self, request: T) -> Result<(), NoSuchOutput> { @@ -62,9 +62,9 @@ impl RequestBuilder { &self.output_kinds } - /// Convert this into a "requests" object. - pub fn build(self) -> Requests { - Requests { + /// Convert this into a "batch" object. + pub fn build(self) -> Batch { + Batch { outputs: HashMap::new(), requests: self.requests, answered: 0, @@ -74,13 +74,13 @@ impl RequestBuilder { /// Requests pending responses. #[derive(Debug, Clone, PartialEq, Eq)] -pub struct Requests { +pub struct Batch { outputs: HashMap<(usize, usize), Output>, requests: Vec, answered: usize, } -impl Requests { +impl Batch { /// Get access to the underlying slice of requests. // TODO: unimplemented -> Vec, // do we _have to_ allocate? pub fn requests(&self) -> &[T] { &self.requests } @@ -94,10 +94,10 @@ impl Requests { } /// Map requests from one type into another. - pub fn map_requests(self, f: F) -> Requests + pub fn map_requests(self, f: F) -> Batch where F: FnMut(T) -> U, U: IncompleteRequest { - Requests { + Batch { outputs: self.outputs, requests: self.requests.into_iter().map(f).collect(), answered: self.answered, @@ -105,7 +105,7 @@ impl Requests { } } -impl Requests { +impl Batch { /// Get the next request as a filled request. Returns `None` when all requests answered. pub fn next_complete(&self) -> Option { if self.is_complete() { @@ -113,7 +113,7 @@ impl Requests { } else { Some(self.requests[self.answered].clone() .complete() - .expect("All outputs checked as invariant of `Requests` object; qed")) + .expect("All outputs checked as invariant of `Batch` object; qed")) } } @@ -149,7 +149,7 @@ impl Requests { } } -impl Requests { +impl Batch { /// Supply a response for the next request. /// Fails on: wrong request kind, all requests answered already. pub fn supply_response(&mut self, env: &T::Environment, response: &T::Response) @@ -170,7 +170,7 @@ impl Requests { } } -impl Requests { +impl Batch { /// For each request, produce a response. /// The responses vector produced goes up to the point where the responder /// first returns `None`, an invalid response, or until all requests have been responded to. @@ -193,7 +193,7 @@ impl Requests { } } -impl Deref for Requests { +impl Deref for Batch { type Target = [T]; fn deref(&self) -> &[T] { @@ -201,7 +201,7 @@ impl Deref for Requests { } } -impl DerefMut for Requests { +impl DerefMut for Batch { fn deref_mut(&mut self) -> &mut [T] { &mut self.requests[..] } @@ -210,12 +210,12 @@ impl DerefMut for Requests { #[cfg(test)] mod tests { use request::*; - use super::RequestBuilder; + use super::Builder; use bigint::hash::H256; #[test] fn all_scalar() { - let mut builder = RequestBuilder::default(); + let mut builder = Builder::default(); builder.push(Request::HeaderProof(IncompleteHeaderProofRequest { num: 100.into(), })).unwrap(); @@ -227,7 +227,7 @@ mod tests { #[test] #[should_panic] fn missing_backref() { - let mut builder = RequestBuilder::default(); + let mut builder = Builder::default(); builder.push(Request::HeaderProof(IncompleteHeaderProofRequest { num: Field::BackReference(100, 3), })).unwrap(); @@ -236,7 +236,7 @@ mod tests { #[test] #[should_panic] fn wrong_kind() { - let mut builder = RequestBuilder::default(); + let mut builder = Builder::default(); assert!(builder.push(Request::HeaderProof(IncompleteHeaderProofRequest { num: 100.into(), })).is_ok()); @@ -247,7 +247,7 @@ mod tests { #[test] fn good_backreference() { - let mut builder = RequestBuilder::default(); + let mut builder = Builder::default(); builder.push(Request::HeaderProof(IncompleteHeaderProofRequest { num: 100.into(), // header proof puts hash at output 0. })).unwrap(); diff --git a/ethcore/light/src/types/request/mod.rs b/ethcore/light/src/types/request/mod.rs index c762f5d04..03f8b92be 100644 --- a/ethcore/light/src/types/request/mod.rs +++ b/ethcore/light/src/types/request/mod.rs @@ -73,7 +73,7 @@ pub use self::epoch_signal::{ Response as SignalResponse, }; -pub use self::builder::{RequestBuilder, Requests}; +pub use self::builder::{Builder, Requests}; /// Error indicating a reference to a non-existent or wrongly-typed output. #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -241,7 +241,7 @@ impl Encodable for HashOrNumber { } /// Type alias for "network requests". -pub type NetworkRequests = Requests; +pub type NetworkRequests = Batch; /// All request types, as they're sent over the network. /// They may be incomplete, with back-references to outputs diff --git a/sync/src/light_sync/mod.rs b/sync/src/light_sync/mod.rs index 54f8a26c0..05a104607 100644 --- a/sync/src/light_sync/mod.rs +++ b/sync/src/light_sync/mod.rs @@ -522,7 +522,7 @@ impl LightSync { rng.shuffle(&mut peer_ids); let request = { - let mut builder = request::RequestBuilder::default(); + let mut builder = request::Builder::default(); builder.push(request::Request::Headers(request::IncompleteHeadersRequest { start: req.start.into(), skip: req.skip,