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

Commit 0c9c31a

Browse files
committed
Replace tokio_core with tokio.
* Remove `tokio-core` and replace with `tokio` in - `ethcore/stratum` - `secret_store` - `util/fetch` - `util/reactor` * Bump hyper to 0.12 in - `miner` - `util/fake-fetch` - `util/fetch` * Bump `jsonrpc-***` to 0.9 in - `parity` - `ethcore/stratum` - `ipfs` - `rpc` - `rpc_client` - `whisper` * Bump `ring` to 0.13
1 parent 6b286a5 commit 0c9c31a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1306
-986
lines changed

Cargo.lock

Lines changed: 538 additions & 421 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ futures = "0.1"
3131
futures-cpupool = "0.1"
3232
fdlimit = "0.1"
3333
ctrlc = { git = "https://github.com/paritytech/rust-ctrlc.git" }
34-
jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.11" }
34+
jsonrpc-core = { git = "https://github.com/c0gent/jsonrpc.git", branch = "c0gent-hyper" }
3535
ethcore = { path = "ethcore", features = ["parity"] }
3636
parity-bytes = "0.1"
3737
ethcore-io = { path = "util/io" }
@@ -137,7 +137,4 @@ members = [
137137
"util/keccak-hasher",
138138
"util/patricia-trie-ethereum",
139139
"util/fastmap",
140-
]
141-
142-
[patch.crates-io]
143-
ring = { git = "https://github.com/paritytech/ring" }
140+
]

ethcore/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ hashdb = "0.2.1"
2020
memorydb = "0.2.1"
2121
patricia-trie = "0.2"
2222
patricia-trie-ethereum = { path = "../util/patricia-trie-ethereum" }
23-
parity-crypto = "0.1"
23+
parity-crypto = "0.2"
2424
error-chain = { version = "0.12", default-features = false }
2525
ethcore-io = { path = "../util/io" }
2626
ethcore-logger = { path = "../logger" }

ethcore/private-tx/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ethabi-derive = "6.0"
1212
ethabi-contract = "6.0"
1313
ethcore = { path = ".." }
1414
parity-bytes = "0.1"
15-
parity-crypto = "0.1"
15+
parity-crypto = "0.2"
1616
ethcore-io = { path = "../../util/io" }
1717
ethcore-logger = { path = "../../logger" }
1818
ethcore-miner = { path = "../../miner" }

ethcore/private-tx/src/encryptor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ impl SecretStoreEncryptor {
125125

126126
// send HTTP request
127127
let method = if use_post {
128-
Method::Post
128+
Method::POST
129129
} else {
130-
Method::Get
130+
Method::GET
131131
};
132132

133133
let url = Url::from_str(&url).map_err(|e| ErrorKind::Encrypt(e.to_string()))?;

ethcore/res/ethereum/tests

Submodule tests updated 19584 files

ethcore/stratum/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ authors = ["Parity Technologies <[email protected]>"]
88
[dependencies]
99
ethereum-types = "0.4"
1010
keccak-hash = "0.1"
11-
jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.11" }
12-
jsonrpc-macros = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.11" }
13-
jsonrpc-tcp-server = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.11" }
11+
jsonrpc-core = { git = "https://github.com/c0gent/jsonrpc.git", branch = "c0gent-hyper" }
12+
jsonrpc-macros = { git = "https://github.com/c0gent/jsonrpc.git", branch = "c0gent-hyper" }
13+
jsonrpc-tcp-server = { git = "https://github.com/c0gent/jsonrpc.git", branch = "c0gent-hyper" }
1414
log = "0.4"
1515
parking_lot = "0.6"
1616

1717
[dev-dependencies]
1818
env_logger = "0.5"
19-
tokio-core = "0.1"
19+
tokio = "0.1"
2020
tokio-io = "0.1"
2121
ethcore-logger = { path = "../../logger" }

ethcore/stratum/src/lib.rs

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extern crate parking_lot;
2525

2626
#[macro_use] extern crate log;
2727

28-
#[cfg(test)] extern crate tokio_core;
28+
#[cfg(test)] extern crate tokio;
2929
#[cfg(test)] extern crate tokio_io;
3030
#[cfg(test)] extern crate ethcore_logger;
3131

@@ -323,12 +323,10 @@ impl MetaExtractor<SocketMetadata> for PeerMetaExtractor {
323323
#[cfg(test)]
324324
mod tests {
325325
use super::*;
326-
use std::net::SocketAddr;
326+
use std::net::{SocketAddr, Shutdown};
327327
use std::sync::Arc;
328328

329-
use tokio_core::reactor::{Core, Timeout};
330-
use tokio_core::net::TcpStream;
331-
use tokio_io::io;
329+
use tokio::{io, runtime::Runtime, timer::timeout::{self, Timeout}, net::TcpStream};
332330
use jsonrpc_core::futures::{Future, future};
333331

334332
use ethcore_logger::init_log;
@@ -342,23 +340,23 @@ mod tests {
342340
}
343341

344342
fn dummy_request(addr: &SocketAddr, data: &str) -> Vec<u8> {
345-
let mut core = Core::new().expect("Tokio Core should be created with no errors");
346-
let mut buffer = vec![0u8; 2048];
343+
let mut runtime = Runtime::new().expect("Tokio Runtime should be created with no errors");
347344

348345
let mut data_vec = data.as_bytes().to_vec();
349346
data_vec.extend(b"\n");
350347

351-
let stream = TcpStream::connect(addr, &core.handle())
352-
.and_then(|stream| {
353-
io::write_all(stream, &data_vec)
348+
let stream = TcpStream::connect(addr)
349+
.and_then(move |stream| {
350+
io::write_all(stream, data_vec)
354351
})
355352
.and_then(|(stream, _)| {
356-
io::read(stream, &mut buffer)
353+
stream.shutdown(Shutdown::Write).unwrap();
354+
io::read_to_end(stream, Vec::with_capacity(2048))
357355
})
358-
.and_then(|(_, read_buf, len)| {
359-
future::ok(read_buf[0..len].to_vec())
356+
.and_then(|(_stream, read_buf)| {
357+
future::ok(read_buf)
360358
});
361-
let result = core.run(stream).expect("Core should run with no errors");
359+
let result = runtime.block_on(stream).expect("Runtime should run with no errors");
362360

363361
result
364362
}
@@ -417,7 +415,7 @@ mod tests {
417415
}
418416

419417
#[test]
420-
fn receives_initial_paylaod() {
418+
fn receives_initial_payload() {
421419
let addr = "127.0.0.1:19975".parse().unwrap();
422420
let _stratum = Stratum::start(&addr, DummyManager::new(), None).expect("There should be no error starting stratum");
423421
let request = r#"{"jsonrpc": "2.0", "method": "mining.subscribe", "params": [], "id": 2}"#;
@@ -460,40 +458,43 @@ mod tests {
460458
.to_vec();
461459
auth_request.extend(b"\n");
462460

463-
let mut core = Core::new().expect("Tokio Core should be created with no errors");
464-
let timeout1 = Timeout::new(::std::time::Duration::from_millis(100), &core.handle())
465-
.expect("There should be a timeout produced in message test");
466-
let timeout2 = Timeout::new(::std::time::Duration::from_millis(100), &core.handle())
467-
.expect("There should be a timeout produced in message test");
468-
let mut buffer = vec![0u8; 2048];
469-
let mut buffer2 = vec![0u8; 2048];
470-
let stream = TcpStream::connect(&addr, &core.handle())
471-
.and_then(|stream| {
472-
io::write_all(stream, &auth_request)
461+
let auth_response = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}\n";
462+
463+
let mut runtime = Runtime::new().expect("Tokio Runtime should be created with no errors");
464+
let read_buf0 = vec![0u8; auth_response.len()];
465+
let read_buf1 = Vec::with_capacity(2048);
466+
let stream = TcpStream::connect(&addr)
467+
.and_then(move |stream| {
468+
io::write_all(stream, auth_request)
473469
})
474470
.and_then(|(stream, _)| {
475-
io::read(stream, &mut buffer)
471+
io::read_exact(stream, read_buf0)
476472
})
477-
.and_then(|(stream, _, _)| {
473+
.map_err(|err| panic!("{:?}", err))
474+
.and_then(move |(stream, read_buf0)| {
475+
assert_eq!(String::from_utf8(read_buf0).unwrap(), auth_response);
478476
trace!(target: "stratum", "Received authorization confirmation");
479-
timeout1.join(future::ok(stream))
477+
Timeout::new(future::ok(stream), ::std::time::Duration::from_millis(100))
480478
})
481-
.and_then(|(_, stream)| {
479+
.map_err(|err: timeout::Error<()>| panic!("Timeout: {:?}", err))
480+
.and_then(move |stream| {
482481
trace!(target: "stratum", "Pusing work to peers");
483482
stratum.push_work_all(r#"{ "00040008", "100500" }"#.to_owned())
484483
.expect("Pushing work should produce no errors");
485-
timeout2.join(future::ok(stream))
484+
Timeout::new(future::ok(stream), ::std::time::Duration::from_millis(100))
486485
})
487-
.and_then(|(_, stream)| {
486+
.map_err(|err: timeout::Error<()>| panic!("Timeout: {:?}", err))
487+
.and_then(|stream| {
488488
trace!(target: "stratum", "Ready to read work from server");
489-
io::read(stream, &mut buffer2)
489+
stream.shutdown(Shutdown::Write).unwrap();
490+
io::read_to_end(stream, read_buf1)
490491
})
491-
.and_then(|(_, read_buf, len)| {
492+
.and_then(|(_, read_buf1)| {
492493
trace!(target: "stratum", "Received work from server");
493-
future::ok(read_buf[0..len].to_vec())
494+
future::ok(read_buf1)
494495
});
495496
let response = String::from_utf8(
496-
core.run(stream).expect("Core should run with no errors")
497+
runtime.block_on(stream).expect("Runtime should run with no errors")
497498
).expect("Response should be utf-8");
498499

499500
assert_eq!(

ethkey/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ authors = ["Parity Technologies <[email protected]>"]
66
[dependencies]
77
byteorder = "1.0"
88
edit-distance = "2.0"
9-
parity-crypto = "0.1"
9+
parity-crypto = "0.2"
1010
eth-secp256k1 = { git = "https://github.com/paritytech/rust-secp256k1" }
1111
ethereum-types = "0.4"
1212
lazy_static = "1.0"

ethstore/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ tiny-keccak = "1.4"
1616
time = "0.1.34"
1717
itertools = "0.5"
1818
parking_lot = "0.6"
19-
parity-crypto = "0.1"
19+
parity-crypto = "0.2"
2020
ethereum-types = "0.4"
2121
dir = { path = "../util/dir" }
2222
smallvec = "0.6"

ipfs/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ authors = ["Parity Technologies <[email protected]>"]
99
ethcore = { path = "../ethcore" }
1010
parity-bytes = "0.1"
1111
ethereum-types = "0.4"
12-
jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.11" }
13-
jsonrpc-http-server = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.11" }
12+
jsonrpc-core = { git = "https://github.com/c0gent/jsonrpc.git", branch = "c0gent-hyper" }
13+
jsonrpc-http-server = { git = "https://github.com/c0gent/jsonrpc.git", branch = "c0gent-hyper" }
1414
rlp = { version = "0.2.4", features = ["ethereum"] }
15-
cid = "0.2"
16-
multihash = "0.7"
15+
cid = "0.3"
16+
multihash = "0.8"
1717
unicase = "2.0"
1818

1919
[dev-dependencies]

ipfs/src/error.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,11 @@ impl From<ServerError> for String {
9595
}
9696
}
9797
}
98+
99+
impl ::std::fmt::Display for ServerError {
100+
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
101+
write!(f, "{:?}", self)
102+
}
103+
}
104+
105+
impl ::std::error::Error for ServerError {}

ipfs/src/lib.rs

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ use std::net::{SocketAddr, IpAddr};
3535
use core::futures::future::{self, FutureResult};
3636
use core::futures::{self, Future};
3737
use ethcore::client::BlockChainClient;
38-
use http::hyper::header::{self, Vary, ContentType};
39-
use http::hyper::{Method, StatusCode};
40-
use http::hyper::{self, server};
41-
use unicase::Ascii;
38+
use http::hyper::{self, server, Method, StatusCode, Body,
39+
header::{self, HeaderValue},
40+
};
4241

4342
use error::ServerError;
4443
use route::Out;
@@ -67,18 +66,18 @@ impl IpfsHandler {
6766
client: client,
6867
}
6968
}
70-
pub fn on_request(&self, req: hyper::Request) -> (Option<header::AccessControlAllowOrigin>, Out) {
69+
pub fn on_request(&self, req: hyper::Request<Body>) -> (Option<HeaderValue>, Out) {
7170
match *req.method() {
72-
Method::Get | Method::Post => {},
71+
Method::GET | Method::POST => {},
7372
_ => return (None, Out::Bad("Invalid Request")),
7473
}
7574

7675
if !http::is_host_allowed(&req, &self.allowed_hosts) {
7776
return (None, Out::Bad("Disallowed Host header"));
7877
}
7978

80-
let cors_header = http::cors_header(&req, &self.cors_domains);
81-
if cors_header == http::CorsHeader::Invalid {
79+
let cors_header = http::cors_allow_origin(&req, &self.cors_domains);
80+
if cors_header == http::AllowCors::Invalid {
8281
return (None, Out::Bad("Disallowed Origin header"));
8382
}
8483

@@ -88,39 +87,39 @@ impl IpfsHandler {
8887
}
8988
}
9089

91-
impl server::Service for IpfsHandler {
92-
type Request = hyper::Request;
93-
type Response = hyper::Response;
90+
impl hyper::service::Service for IpfsHandler {
91+
type ReqBody = Body;
92+
type ResBody = Body;
9493
type Error = hyper::Error;
95-
type Future = FutureResult<hyper::Response, hyper::Error>;
94+
type Future = FutureResult<hyper::Response<Body>, Self::Error>;
9695

97-
fn call(&self, request: Self::Request) -> Self::Future {
96+
fn call(&mut self, request: hyper::Request<Self::ReqBody>) -> Self::Future {
9897
let (cors_header, out) = self.on_request(request);
9998

10099
let mut res = match out {
101100
Out::OctetStream(bytes) => {
102-
hyper::Response::new()
103-
.with_status(StatusCode::Ok)
104-
.with_header(ContentType::octet_stream())
105-
.with_body(bytes)
101+
hyper::Response::builder()
102+
.status(StatusCode::OK)
103+
.header("content-type", HeaderValue::from_static("application/octet-stream"))
104+
.body(bytes.into())
106105
},
107106
Out::NotFound(reason) => {
108-
hyper::Response::new()
109-
.with_status(StatusCode::NotFound)
110-
.with_header(ContentType::plaintext())
111-
.with_body(reason)
107+
hyper::Response::builder()
108+
.status(StatusCode::NOT_FOUND)
109+
.header("content-type", HeaderValue::from_static("text/plain; charset=utf-8"))
110+
.body(reason.into())
112111
},
113112
Out::Bad(reason) => {
114-
hyper::Response::new()
115-
.with_status(StatusCode::BadRequest)
116-
.with_header(ContentType::plaintext())
117-
.with_body(reason)
113+
hyper::Response::builder()
114+
.status(StatusCode::BAD_REQUEST)
115+
.header("content-type", HeaderValue::from_static("text/plain; charset=utf-8"))
116+
.body(reason.into())
118117
}
119-
};
118+
}.expect("Response builder: Parsing 'content-type' header name will not fail; qed");
120119

121120
if let Some(cors_header) = cors_header {
122-
res.headers_mut().set(cors_header);
123-
res.headers_mut().set(Vary::Items(vec![Ascii::new("Origin".into())]));
121+
res.headers_mut().append(header::ACCESS_CONTROL_ALLOW_ORIGIN, cors_header);
122+
res.headers_mut().append(header::VARY, HeaderValue::from_static("origin"));
124123
}
125124

126125
future::ok(res)
@@ -164,23 +163,32 @@ pub fn start_server(
164163
let hosts: DomainsValidation<_> = hosts.map(move |hosts| include_current_interface(hosts, interface, port)).into();
165164

166165
let (close, shutdown_signal) = futures::sync::oneshot::channel::<()>();
167-
let (tx, rx) = mpsc::sync_channel(1);
166+
let (tx, rx) = mpsc::sync_channel::<Result<(), ServerError>>(1);
168167
let thread = thread::spawn(move || {
169168
let send = |res| tx.send(res).expect("rx end is never dropped; qed");
170-
let server = match server::Http::new().bind(&addr, move || {
171-
Ok(IpfsHandler::new(cors.clone(), hosts.clone(), client.clone()))
172-
}) {
173-
Ok(server) => {
174-
send(Ok(()));
175-
server
176-
},
169+
170+
let server_bldr = match server::Server::try_bind(&addr) {
171+
Ok(s) => s,
177172
Err(err) => {
178-
send(Err(err));
173+
send(Err(ServerError::from(err)));
179174
return;
180175
}
181176
};
182177

183-
let _ = server.run_until(shutdown_signal.map_err(|_| {}));
178+
let new_service = move || {
179+
Ok::<_, ServerError>(
180+
IpfsHandler::new(cors.clone(), hosts.clone(), client.clone())
181+
)
182+
};
183+
184+
let server = server_bldr
185+
.serve(new_service)
186+
.map_err(|_| ())
187+
.select(shutdown_signal.map_err(|_| ()))
188+
.then(|_| Ok(()));
189+
190+
hyper::rt::run(server);
191+
send(Ok(()));
184192
});
185193

186194
// Wait for server to start successfuly.

miner/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ authors = ["Parity Technologies <[email protected]>"]
1010
# Only work_notify, consider a separate crate
1111
ethash = { path = "../ethash", optional = true }
1212
fetch = { path = "../util/fetch", optional = true }
13-
hyper = { version = "0.11", optional = true }
13+
hyper = { version = "0.12", optional = true }
1414
parity-reactor = { path = "../util/reactor", optional = true }
1515
url = { version = "1", optional = true }
1616

0 commit comments

Comments
 (0)