@@ -21,7 +21,8 @@ use std::io;
|
||||
use std::sync::Arc;
|
||||
|
||||
use ethsync::ManageNetwork;
|
||||
use fetch::Fetch;
|
||||
use fetch::{self, Fetch};
|
||||
use futures_cpupool::CpuPool;
|
||||
use hash::keccak_buffer;
|
||||
|
||||
use jsonrpc_core::{Result, BoxFuture};
|
||||
@@ -36,15 +37,17 @@ pub struct ParitySetClient<F> {
|
||||
net: Arc<ManageNetwork>,
|
||||
dapps: Option<Arc<DappsService>>,
|
||||
fetch: F,
|
||||
pool: CpuPool,
|
||||
}
|
||||
|
||||
impl<F: Fetch> ParitySetClient<F> {
|
||||
/// Creates new `ParitySetClient` with given `Fetch`.
|
||||
pub fn new(net: Arc<ManageNetwork>, dapps: Option<Arc<DappsService>>, fetch: F) -> Self {
|
||||
pub fn new(net: Arc<ManageNetwork>, dapps: Option<Arc<DappsService>>, fetch: F, p: CpuPool) -> Self {
|
||||
ParitySetClient {
|
||||
net: net,
|
||||
dapps: dapps,
|
||||
fetch: fetch,
|
||||
pool: p,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -125,14 +128,16 @@ impl<F: Fetch> ParitySet for ParitySetClient<F> {
|
||||
}
|
||||
|
||||
fn hash_content(&self, url: String) -> BoxFuture<H256> {
|
||||
self.fetch.process(self.fetch.fetch(&url).then(move |result| {
|
||||
let future = self.fetch.fetch(&url, Default::default()).then(move |result| {
|
||||
result
|
||||
.map_err(errors::fetch)
|
||||
.and_then(|response| {
|
||||
keccak_buffer(&mut io::BufReader::new(response)).map_err(errors::fetch)
|
||||
.and_then(move |response| {
|
||||
let mut reader = io::BufReader::new(fetch::BodyReader::new(response));
|
||||
keccak_buffer(&mut reader).map_err(errors::fetch)
|
||||
})
|
||||
.map(Into::into)
|
||||
}))
|
||||
});
|
||||
Box::new(self.pool.spawn(future))
|
||||
}
|
||||
|
||||
fn dapps_refresh(&self) -> Result<bool> {
|
||||
|
||||
@@ -23,6 +23,7 @@ use ethcore::client::MiningBlockChainClient;
|
||||
use ethcore::mode::Mode;
|
||||
use ethsync::ManageNetwork;
|
||||
use fetch::{self, Fetch};
|
||||
use futures_cpupool::CpuPool;
|
||||
use hash::keccak_buffer;
|
||||
use updater::{Service as UpdateService};
|
||||
|
||||
@@ -41,6 +42,7 @@ pub struct ParitySetClient<C, M, U, F = fetch::Client> {
|
||||
net: Arc<ManageNetwork>,
|
||||
dapps: Option<Arc<DappsService>>,
|
||||
fetch: F,
|
||||
pool: CpuPool,
|
||||
eip86_transition: u64,
|
||||
}
|
||||
|
||||
@@ -55,6 +57,7 @@ impl<C, M, U, F> ParitySetClient<C, M, U, F>
|
||||
net: &Arc<ManageNetwork>,
|
||||
dapps: Option<Arc<DappsService>>,
|
||||
fetch: F,
|
||||
pool: CpuPool,
|
||||
) -> Self {
|
||||
ParitySetClient {
|
||||
client: client.clone(),
|
||||
@@ -63,6 +66,7 @@ impl<C, M, U, F> ParitySetClient<C, M, U, F>
|
||||
net: net.clone(),
|
||||
dapps: dapps,
|
||||
fetch: fetch,
|
||||
pool: pool,
|
||||
eip86_transition: client.eip86_transition(),
|
||||
}
|
||||
}
|
||||
@@ -166,14 +170,16 @@ impl<C, M, U, F> ParitySet for ParitySetClient<C, M, U, F> where
|
||||
}
|
||||
|
||||
fn hash_content(&self, url: String) -> BoxFuture<H256> {
|
||||
self.fetch.process(self.fetch.fetch(&url).then(move |result| {
|
||||
let future = self.fetch.fetch(&url, Default::default()).then(move |result| {
|
||||
result
|
||||
.map_err(errors::fetch)
|
||||
.and_then(|response| {
|
||||
keccak_buffer(&mut io::BufReader::new(response)).map_err(errors::fetch)
|
||||
.and_then(move |response| {
|
||||
let mut reader = io::BufReader::new(fetch::BodyReader::new(response));
|
||||
keccak_buffer(&mut reader).map_err(errors::fetch)
|
||||
})
|
||||
.map(Into::into)
|
||||
}))
|
||||
});
|
||||
Box::new(self.pool.spawn(future))
|
||||
}
|
||||
|
||||
fn dapps_refresh(&self) -> Result<bool> {
|
||||
|
||||
@@ -16,9 +16,10 @@
|
||||
|
||||
//! Test implementation of fetch client.
|
||||
|
||||
use std::{io, thread};
|
||||
use std::thread;
|
||||
use jsonrpc_core::futures::{self, Future};
|
||||
use fetch::{self, Fetch};
|
||||
use fetch::{self, Fetch, Url};
|
||||
use hyper;
|
||||
|
||||
/// Test implementation of fetcher. Will always return the same file.
|
||||
#[derive(Default, Clone)]
|
||||
@@ -27,15 +28,12 @@ pub struct TestFetch;
|
||||
impl Fetch for TestFetch {
|
||||
type Result = Box<Future<Item = fetch::Response, Error = fetch::Error> + Send + 'static>;
|
||||
|
||||
fn new() -> Result<Self, fetch::Error> where Self: Sized {
|
||||
Ok(TestFetch)
|
||||
}
|
||||
|
||||
fn fetch_with_abort(&self, _url: &str, _abort: fetch::Abort) -> Self::Result {
|
||||
fn fetch(&self, url: &str, abort: fetch::Abort) -> Self::Result {
|
||||
let u = Url::parse(url).unwrap();
|
||||
let (tx, rx) = futures::oneshot();
|
||||
thread::spawn(move || {
|
||||
let cursor = io::Cursor::new(b"Some content");
|
||||
tx.send(fetch::Response::from_reader(cursor)).unwrap();
|
||||
let r = hyper::Response::new().with_body(&b"Some content"[..]);
|
||||
tx.send(fetch::Response::new(u, r, abort)).unwrap();
|
||||
});
|
||||
|
||||
Box::new(rx.map_err(|_| fetch::Error::Aborted))
|
||||
|
||||
@@ -22,6 +22,7 @@ use ethereum_types::{U256, Address};
|
||||
use ethcore::miner::MinerService;
|
||||
use ethcore::client::TestBlockChainClient;
|
||||
use ethsync::ManageNetwork;
|
||||
use futures_cpupool::CpuPool;
|
||||
|
||||
use jsonrpc_core::IoHandler;
|
||||
use v1::{ParitySet, ParitySetClient};
|
||||
@@ -53,7 +54,8 @@ fn parity_set_client(
|
||||
net: &Arc<TestManageNetwork>,
|
||||
) -> TestParitySetClient {
|
||||
let dapps_service = Arc::new(TestDappsService);
|
||||
ParitySetClient::new(client, miner, updater, &(net.clone() as Arc<ManageNetwork>), Some(dapps_service), TestFetch::default())
|
||||
let pool = CpuPool::new(1);
|
||||
ParitySetClient::new(client, miner, updater, &(net.clone() as Arc<ManageNetwork>), Some(dapps_service), TestFetch::default(), pool)
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user