-
Notifications
You must be signed in to change notification settings - Fork 274
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
bc07cf6
8457ec6
828eea1
f3759ec
09fa00c
ae3db41
6ce77f8
bfee58a
0f19ff2
ca0adf7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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", | ||
|
@@ -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"] } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you're right, I'm fixing it. |
||
|
||
[badges] | ||
travis-ci = { repository = "paritytech/jsonrpc", branch = "master"} | ||
travis-ci = { repository = "paritytech/jsonrpc", branch = "master" } |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
}; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) => { | ||
|
@@ -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); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
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.