Updating JSON-RPC crates (#4934)

* New version of jsonrpc.

* Better invalid encoding messages

* Fixing deprecated methods of tokio_core

* Using dedicated branch for jsonrpc

* Bump
This commit is contained in:
Tomasz Drwięga
2017-03-22 07:02:14 +01:00
committed by Marek Kotewicz
parent d530cc86f3
commit 7e87e9e8ad
48 changed files with 847 additions and 677 deletions

View File

@@ -11,10 +11,9 @@ ethcore-ipc-codegen = { path = "../ipc/codegen" }
[dependencies]
log = "0.3"
jsonrpc-core = { git = "https://github.com/ethcore/jsonrpc.git", branch = "parity-1.6" }
jsonrpc-macros = { git = "https://github.com/ethcore/jsonrpc.git", branch = "parity-1.6" }
jsonrpc-tcp-server = { git = "https://github.com/ethcore/jsonrpc.git", branch = "parity-1.6" }
mio = { git = "https://github.com/ethcore/mio", branch = "v0.5.x" }
jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.7" }
jsonrpc-macros = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.7" }
jsonrpc-tcp-server = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.7" }
ethcore-util = { path = "../util" }
ethcore-devtools = { path = "../devtools" }
lazy_static = "0.2"

View File

@@ -45,8 +45,8 @@ pub use traits::{
};
use jsonrpc_tcp_server::{
Server as JsonRpcServer, RequestContext, MetaExtractor, Dispatcher,
PushMessageError
Server as JsonRpcServer, ServerBuilder as JsonRpcServerBuilder,
RequestContext, MetaExtractor, Dispatcher, PushMessageError,
};
use jsonrpc_core::{MetaIoHandler, Params, to_value, Value, Metadata, Compatibility};
use jsonrpc_macros::IoDelegate;
@@ -58,6 +58,8 @@ use util::{H256, Hashable, RwLock, RwLockReadGuard};
type RpcResult = BoxFuture<jsonrpc_core::Value, jsonrpc_core::Error>;
const NOTIFY_COUNTER_INITIAL: u32 = 16;
struct StratumRpc {
stratum: RwLock<Option<Arc<Stratum>>>,
}
@@ -113,7 +115,7 @@ impl MetaExtractor<SocketMetadata> for PeerMetaExtractor {
}
pub struct Stratum {
rpc_server: JsonRpcServer<SocketMetadata>,
rpc_server: Option<JsonRpcServer>,
/// Subscribed clients
subscribers: RwLock<Vec<SocketAddr>>,
/// List of workers supposed to receive job update
@@ -130,7 +132,11 @@ pub struct Stratum {
tcp_dispatcher: Dispatcher,
}
const NOTIFY_COUNTER_INITIAL: u32 = 16;
impl Drop for Stratum {
fn drop(&mut self) {
self.rpc_server.take().map(|server| server.close());
}
}
impl Stratum {
pub fn start(
@@ -149,12 +155,14 @@ impl Stratum {
let mut handler = MetaIoHandler::<SocketMetadata>::with_compatibility(Compatibility::Both);
handler.extend_with(delegate);
let server = JsonRpcServer::new(addr.clone(), Arc::new(handler))
.extractor(Arc::new(PeerMetaExtractor) as Arc<MetaExtractor<SocketMetadata>>);
let server = JsonRpcServerBuilder::new(handler)
.session_meta_extractor(PeerMetaExtractor);
let tcp_dispatcher = server.dispatcher();
let server = server.start(addr)?;
let stratum = Arc::new(Stratum {
tcp_dispatcher: server.dispatcher(),
rpc_server: server,
tcp_dispatcher: tcp_dispatcher,
rpc_server: Some(server),
subscribers: RwLock::new(Vec::new()),
job_que: RwLock::new(HashSet::new()),
dispatcher: dispatcher,
@@ -163,10 +171,6 @@ impl Stratum {
notify_counter: RwLock::new(NOTIFY_COUNTER_INITIAL),
});
*rpc.stratum.write() = Some(stratum.clone());
let running_stratum = stratum.clone();
::std::thread::spawn(move || running_stratum.rpc_server.run());
Ok(stratum)
}