Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump rand version to 0.8 and some other minor changes #688

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 34 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,37 @@ members = [
"test",
"ws",
]

[workspace.package]
version = "18.0.1"
authors = ["Parity Technologies <admin@parity.io>"]
repository = "https://github.com/paritytech/jsonrpc"
homepage = "https://github.com/paritytech/jsonrpc"
license = "MIT"
edition = "2018"
keywords = ["jsonrpc", "json-rpc", "json", "rpc", "serde"]

[workspace.dependencies]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding workspace dependencies and also keeping mentions to crates in the workspace in the workspace dependencies.

# local projects
jsonrpc-core = { version = "18.0.1", path = "./core" }
jsonrpc-core-client = { version = "18.0.1", path = "./core-client" }
jsonrpc-http-server = { version = "18.0.1", path = "./http" }
jsonrpc-ipc-server = { version = "18.0.1", path = "./ipc" }
jsonrpc-pubsub = { version = "18.0.1", path = "./pubsub" }
jsonrpc-server-utils = { version = "18.0.1", path = "./server-utils" }
jsonrpc-tcp-server = { version = "18.0.1", path = "./tcp" }

assert_matches = "1.3"
env_logger = "0.7"
futures = "0.3"
lazy_static = "1.0"
log = "0.4"
hyper = "0.14"
parking_lot = "0.11.0"
parity-tokio-ipc = "0.9"
serde = "1.0"
serde_json = "1.0"
tokio = "1"
tokio-util = "0.6"
tower-service = "0.3"
unicase = "2.0"
17 changes: 8 additions & 9 deletions core-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
[package]
authors = ["Parity Technologies <admin@parity.io>"]
description = "Transport agnostic JSON-RPC 2.0 client implementation."
documentation = "https://docs.rs/jsonrpc-core-client/"
edition = "2018"
homepage = "https://github.com/paritytech/jsonrpc"
keywords = ["jsonrpc", "json-rpc", "json", "rpc", "serde"]
license = "MIT"
name = "jsonrpc-core-client"
repository = "https://github.com/paritytech/jsonrpc"
version = "18.0.0"
version.workspace = true
authors.workspace = true
repository.workspace = true
homepage.workspace = true
license.workspace = true
edition.workspace = true

categories = [
"asynchronous",
Expand All @@ -27,7 +26,7 @@ arbitrary_precision = ["jsonrpc-client-transports/arbitrary_precision"]

[dependencies]
jsonrpc-client-transports = { version = "18.0.0", path = "./transports", default-features = false }
futures = { version = "0.3", features = [ "compat" ] }
futures = { version = "0.3", features = ["compat"] }

[badges]
travis-ci = { repository = "paritytech/jsonrpc", branch = "master"}
travis-ci = { repository = "paritytech/jsonrpc", branch = "master" }
49 changes: 24 additions & 25 deletions core-client/transports/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,39 @@ categories = [
default = ["http", "tls", "ws"]
tls = ["hyper-tls", "http"]
http = ["hyper", "tokio/full"]
ws = [
"websocket",
"tokio",
"futures/compat"
ws = ["websocket", "tokio", "futures/compat"]
ipc = ["parity-tokio-ipc", "jsonrpc-server-utils", "tokio"]
arbitrary_precision = [
"serde_json/arbitrary_precision",
"jsonrpc-core/arbitrary_precision",
]
ipc = [
"parity-tokio-ipc",
"jsonrpc-server-utils",
"tokio",
]
arbitrary_precision = ["serde_json/arbitrary_precision", "jsonrpc-core/arbitrary_precision"]

[dependencies]
derive_more = "0.99"
futures = "0.3"
jsonrpc-core = { version = "18.0.0", path = "../../core" }
jsonrpc-pubsub = { version = "18.0.0", path = "../../pubsub" }
log = "0.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
futures.workspace = true
jsonrpc-core.workspace = true
jsonrpc-pubsub.workspace = true
log.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true

hyper = { version = "0.14", features = ["client", "http1", "tcp"], optional = true }
hyper = { workspace = true, features = [
"client",
"http1",
"tcp",
], optional = true }
hyper-tls = { version = "0.5", optional = true }
jsonrpc-server-utils = { version = "18.0.0", path = "../../server-utils", optional = true }
parity-tokio-ipc = { version = "0.9", optional = true }
tokio = { version = "1", optional = true }
jsonrpc-server-utils = { workspace = true, optional = true }
parity-tokio-ipc = { workspace = true, optional = true }
tokio = { workspace = true, optional = true }
websocket = { version = "0.26", optional = true }

[dev-dependencies]
assert_matches = "1.1"
jsonrpc-http-server = { version = "18.0.0", path = "../../http" }
jsonrpc-ipc-server = { version = "18.0.0", path = "../../ipc" }
lazy_static = "1.0"
env_logger = "0.7"
assert_matches.workspace = true
jsonrpc-http-server.workspace = true
jsonrpc-ipc-server.workspace = true
lazy_static.workspace = true
env_logger.workspace = true

[badges]
travis-ci = { repository = "paritytech/jsonrpc", branch = "master" }
2 changes: 1 addition & 1 deletion core-client/transports/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl RawClient {
};
let result = self.0.send(msg.into());
async move {
let () = result.map_err(|e| RpcError::Other(Box::new(e)))?;
result.map_err(|e| RpcError::Other(Box::new(e)))?;

receiver.await.map_err(|e| RpcError::Other(Box::new(e)))?
}
Expand Down
147 changes: 68 additions & 79 deletions core-client/transports/src/transports/duplex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,9 @@ where
fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
// Handle requests from the client.
log::debug!("handle requests from client");
loop {
// Check that the client channel is open
let channel = match self.channel.as_mut() {
Some(channel) => channel,
None => break,
};

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaner loop.

// Check that the client channel is open
while let Some(channel) = self.channel.as_mut() {
let msg = match channel.poll_next_unpin(cx) {
Poll::Ready(Some(msg)) => msg,
Poll::Ready(None) => {
Expand Down Expand Up @@ -185,87 +182,79 @@ where

// Handle incoming queue.
log::debug!("handle incoming");
loop {
match self.incoming.pop_front() {
Some((id, result, method, sid)) => {
let sid_and_method = sid.and_then(|sid| method.map(|method| (sid, method)));
// Handle the response to a pending request.
match self.pending_requests.remove(&id) {
// It's a regular Req-Res call, so just answer.
Some(PendingRequest::Call(tx)) => {
tx.send(result)
.map_err(|_| RpcError::Client("oneshot channel closed".into()))?;
continue;
}
// It was a subscription request,
// turn it into a proper subscription.
Some(PendingRequest::Subscription(mut subscription)) => {
let sid = result.as_ref().ok().and_then(|res| SubscriptionId::parse_value(res));
let method = subscription.notification.clone();
while let Some((id, result, method, sid)) = self.incoming.pop_front() {
let sid_and_method = sid.and_then(|sid| method.map(|method| (sid, method)));
// Handle the response to a pending request.
match self.pending_requests.remove(&id) {
// It's a regular Req-Res call, so just answer.
Some(PendingRequest::Call(tx)) => {
tx.send(result)
.map_err(|_| RpcError::Client("oneshot channel closed".into()))?;
continue;
}
// It was a subscription request,
// turn it into a proper subscription.
Some(PendingRequest::Subscription(mut subscription)) => {
let sid = result.as_ref().ok().and_then(SubscriptionId::parse_value);
let method = subscription.notification.clone();

if let Some(sid) = sid {
subscription.id = Some(sid.clone());
if self
.subscriptions
.insert((sid.clone(), method.clone()), subscription)
.is_some()
{
log::warn!(
"Overwriting existing subscription under {:?} ({:?}). \
if let Some(sid) = sid {
subscription.id = Some(sid.clone());
if self
.subscriptions
.insert((sid.clone(), method.clone()), subscription)
.is_some()
{
log::warn!(
"Overwriting existing subscription under {:?} ({:?}). \
Seems that server returned the same subscription id.",
sid,
method,
);
}
} else {
let err = RpcError::Client(format!(
"Subscription {:?} ({:?}) rejected: {:?}",
id, method, result,
));

if subscription.channel.unbounded_send(result).is_err() {
log::warn!("{}, but the reply channel has closed.", err);
}
}
continue;
}
// It's not a pending request nor a notification
None if sid_and_method.is_none() => {
log::warn!("Got unexpected response with id {:?} ({:?})", id, sid_and_method);
continue;
sid,
method,
);
}
// just fall-through in case it's a notification
None => {}
};

let sid_and_method = if let Some(x) = sid_and_method {
x
} else {
continue;
};
let err =
RpcError::Client(format!("Subscription {:?} ({:?}) rejected: {:?}", id, method, result,));

if let Some(subscription) = self.subscriptions.get_mut(&sid_and_method) {
let res = subscription.channel.unbounded_send(result);
if res.is_err() {
let subscription = self
.subscriptions
.remove(&sid_and_method)
.expect("Subscription was just polled; qed");
let sid = subscription.id.expect(
"Every subscription that ends up in `self.subscriptions` has id already \
assigned; assignment happens during response to subscribe request.",
);
let (_id, request_str) =
self.request_builder.unsubscribe_request(subscription.unsubscribe, sid);
log::debug!("outgoing: {}", request_str);
self.outgoing.push_back(request_str);
log::debug!("unsubscribed from {:?}", sid_and_method);
if subscription.channel.unbounded_send(result).is_err() {
log::warn!("{}, but the reply channel has closed.", err);
}
} else {
log::warn!("Received unexpected subscription notification: {:?}", sid_and_method);
}
continue;
}
None => break,
// It's not a pending request nor a notification
None if sid_and_method.is_none() => {
log::warn!("Got unexpected response with id {:?} ({:?})", id, sid_and_method);
continue;
}
// just fall-through in case it's a notification
None => {}
};

let sid_and_method = if let Some(x) = sid_and_method {
x
} else {
continue;
};

if let Some(subscription) = self.subscriptions.get_mut(&sid_and_method) {
let res = subscription.channel.unbounded_send(result);
if res.is_err() {
let subscription = self
.subscriptions
.remove(&sid_and_method)
.expect("Subscription was just polled; qed");
let sid = subscription.id.expect(
"Every subscription that ends up in `self.subscriptions` has id already \
assigned; assignment happens during response to subscribe request.",
);
let (_id, request_str) = self.request_builder.unsubscribe_request(subscription.unsubscribe, sid);
log::debug!("outgoing: {}", request_str);
self.outgoing.push_back(request_str);
log::debug!("unsubscribed from {:?}", sid_and_method);
}
} else {
log::warn!("Received unexpected subscription notification: {:?}", sid_and_method);
}
}

Expand Down
3 changes: 2 additions & 1 deletion core-client/transports/src/transports/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ pub mod ws;
pub use duplex::duplex;

/// Creates JSON-RPC requests
#[derive(Default)]
pub struct RequestBuilder {
id: u64,
}

impl RequestBuilder {
/// Create a new RequestBuilder
pub fn new() -> Self {
RequestBuilder { id: 0 }
Self::default()
}

fn next_id(&mut self) -> Id {
Expand Down
23 changes: 11 additions & 12 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
[package]
authors = ["Parity Technologies <admin@parity.io>"]
description = "Transport agnostic rust implementation of JSON-RPC 2.0 Specification."
documentation = "https://docs.rs/jsonrpc-core/"
edition = "2018"
homepage = "https://github.com/paritytech/jsonrpc"
keywords = ["jsonrpc", "json-rpc", "json", "rpc", "serde"]
license = "MIT"
name = "jsonrpc-core"
repository = "https://github.com/paritytech/jsonrpc"
version = "18.0.0"
version.workspace = true
authors.workspace = true
repository.workspace = true
homepage.workspace = true
license.workspace = true
edition.workspace = true

categories = [
"asynchronous",
Expand All @@ -19,20 +18,20 @@ categories = [
]

[dependencies]
log = "0.4"
log.workspace = true
# FIXME: Currently a lot of jsonrpc-* crates depend on entire `futures` being
# re-exported but it's not strictly required for this crate. Either adapt the
# remaining crates or settle for this re-export to be a single, common dependency
futures = { version = "0.3", optional = true }
futures = { workspace = true, optional = true }
futures-util = { version = "0.3", default-features = false, features = ["std"] }
futures-executor = { version = "0.3", optional = true }
serde = "1.0"
serde_json = "1.0"
serde.workspace = true
serde_json.workspace = true
serde_derive = "1.0"

[features]
default = ["futures-executor", "futures"]
arbitrary_precision = ["serde_json/arbitrary_precision"]

[badges]
travis-ci = { repository = "paritytech/jsonrpc", branch = "master"}
travis-ci = { repository = "paritytech/jsonrpc", branch = "master" }