Update jsonrpc dependencies and rewrite dapps to futures. (#6522)

* Bump version.

* Fix RPC crate.

* Fix BoxFuture in crates.

* Compiles and passes tests!

* Get rid of .boxed()

* Fixing issues with the UI.

* Remove minihttp. Support threads.

* Reimplement files serving to do it in chunks.

* Increase chunk size.

* Remove some unecessary copying.

* Fix tests.

* Fix stratum warning and ipfs todo.

* Switch to proper branch of jsonrpc.

* Update Cargo.lock.

* Update docs.

* Include dapps-glue in workspace.

* fixed merge artifacts

* Fix test compilation.
This commit is contained in:
Tomasz Drwięga
2017-10-05 12:35:01 +02:00
committed by Arkadiy Paronyan
parent 492da38d67
commit e8b418ca03
118 changed files with 2090 additions and 2908 deletions

View File

@@ -11,8 +11,7 @@ futures = "0.1"
futures-cpupool = "0.1"
parking_lot = "0.4"
log = "0.3"
reqwest = "0.6"
mime = "0.2"
reqwest = "0.7"
[features]
default = []

View File

@@ -20,11 +20,13 @@ use std::{io, fmt, time};
use std::sync::Arc;
use std::sync::atomic::{self, AtomicBool};
use futures::{self, BoxFuture, Future};
use futures::{self, Future};
use futures_cpupool::{CpuPool, CpuFuture};
use mime::{self, Mime};
use parking_lot::RwLock;
use reqwest;
use reqwest::mime::Mime;
type BoxFuture<A, B> = Box<Future<Item = A, Error = B> + Send>;
/// Fetch abort control
#[derive(Default, Debug, Clone)]
@@ -58,16 +60,19 @@ pub trait Fetch: Clone + Send + Sync + 'static {
I: Send + 'static,
E: Send + 'static,
{
f.boxed()
Box::new(f)
}
/// Spawn the future in context of this `Fetch` thread pool as "fire and forget", i.e. dropping this future without
/// canceling the underlying future.
/// Implementation is optional.
fn forget<F, I, E>(&self, _: F) where
fn process_and_forget<F, I, E>(&self, _: F) where
F: Future<Item=I, Error=E> + Send + 'static,
I: Send + 'static,
E: Send + 'static {}
E: Send + 'static,
{
panic!("Attempting to process and forget future on unsupported Fetch.");
}
/// Fetch URL and get a future for the result.
/// Supports aborting the request in the middle of execution.
@@ -109,9 +114,9 @@ impl Clone for Client {
impl Client {
fn new_client() -> Result<Arc<reqwest::Client>, Error> {
let mut client = reqwest::Client::new()?;
let mut client = reqwest::ClientBuilder::new()?;
client.redirect(reqwest::RedirectPolicy::limited(5));
Ok(Arc::new(client))
Ok(Arc::new(client.build()?))
}
fn with_limit(limit: Option<usize>) -> Result<Self, Error> {
@@ -154,10 +159,10 @@ impl Fetch for Client {
I: Send + 'static,
E: Send + 'static,
{
self.pool.spawn(f).boxed()
Box::new(self.pool.spawn(f))
}
fn forget<F, I, E>(&self, f: F) where
fn process_and_forget<F, I, E>(&self, f: F) where
F: Future<Item=I, Error=E> + Send + 'static,
I: Send + 'static,
E: Send + 'static,
@@ -203,8 +208,8 @@ impl Future for FetchTask {
}
trace!(target: "fetch", "Starting fetch task: {:?}", self.url);
let result = self.client.get(&self.url)
.header(reqwest::header::UserAgent("Parity Fetch".into()))
let result = self.client.get(&self.url)?
.header(reqwest::header::UserAgent::new("Parity Fetch"))
.send()?;
Ok(futures::Async::Ready(Response {
@@ -289,7 +294,7 @@ impl Response {
/// Returns status code of this response.
pub fn status(&self) -> reqwest::StatusCode {
match self.inner {
ResponseInner::Response(ref r) => *r.status(),
ResponseInner::Response(ref r) => r.status(),
ResponseInner::NotFound => reqwest::StatusCode::NotFound,
_ => reqwest::StatusCode::Ok,
}
@@ -303,7 +308,7 @@ impl Response {
/// Returns `true` if content type of this response is `text/html`
pub fn is_html(&self) -> bool {
match self.content_type() {
Some(Mime(mime::TopLevel::Text, mime::SubLevel::Html, _)) => true,
Some(ref mime) if mime.type_() == "text" && mime.subtype() == "html" => true,
_ => false,
}
}

View File

@@ -26,10 +26,9 @@ extern crate futures_cpupool;
extern crate parking_lot;
extern crate reqwest;
pub extern crate mime;
pub mod client;
pub use self::reqwest::StatusCode;
pub use self::mime::Mime;
pub use self::reqwest::mime::Mime;
pub use self::client::{Client, Fetch, Error, Response, Abort};