Releases: paritytech/jsonrpsee
v0.22.1
[v0.22.1] - 2024-02-19
This is a small patch release that internally changes AtomicU64
to AtomicUsize
to support more targets.
[Fixed]
v0.22.0
[v0.22.0] - 2024-02-07
Another breaking release where a new ResponsePayload
type is introduced in order
to make it possible to determine whether a response has been processed.
Unfortunately, the IntoResponse trait
was modified to enable that
and some minor changes were made to make more fields private to avoid further
breakage.
Example of the async ResponsePayload API
#[rpc(server)]
pub trait Api {
#[method(name = "x")]
fn x(&self) -> ResponsePayload<'static, String>;
}
impl RpcServer for () {
fn x(&self) -> ResponsePayload<'static, String> {
let (rp, rp_done) = ResponsePayload::success("ehheeheh".to_string()).notify_on_completion();
tokio::spawn(async move {
if rp_done.await.is_ok() {
do_task_that_depend_x();
}
});
rp
}
}
Roadmap
We are getting closer to releasing jsonrpsee v1.0 and
the following work is planned:
- Native async traits
- Upgrade hyper to v1.0
- Better subscription API for the client.
Thanks to the external contributor @dan-starkware who contributed to this release.
[Added]
- feat(server): add
TowerService::on_session_close
(#1284) - feat(server): async API when
Response
has been processed. (#1281)
[Changed]
v0.21.0
[v0.21.0] - 2023-12-13
This release contains big changes and let's go over the main ones:
JSON-RPC specific middleware
After getting plenty of feedback regarding a JSON-RPC specific middleware,
this release introduces a composable "tower-like" middleware that applies per JSON-RPC method call.
The new middleware also replaces the old RpcLogger
which may break some use-cases, such as if
JSON-RPC was made on a WebSocket or HTTP transport, but it's possible to implement that by
using jsonrpsee as a tower service
or the low-level server API
.
An example how write such middleware:
#[derive(Clone)]
pub struct ModifyRequestIf<S>(S);
impl<'a, S> RpcServiceT<'a> for ModifyRequestIf<S>
where
S: Send + Sync + RpcServiceT<'a>,
{
type Future = S::Future;
fn call(&self, mut req: Request<'a>) -> Self::Future {
// Example how to modify the params in the call.
if req.method == "say_hello" {
// It's a bit awkward to create new params in the request
// but this shows how to do it.
let raw_value = serde_json::value::to_raw_value("myparams").unwrap();
req.params = Some(StdCow::Owned(raw_value));
}
// Re-direct all calls that isn't `say_hello` to `say_goodbye`
else if req.method != "say_hello" {
req.method = "say_goodbye".into();
}
self.0.call(req)
}
}
async fn run_server() {
// Construct our middleware and build the server.
let rpc_middleware = RpcServiceBuilder::new().layer_fn(|service| ModifyRequestIf(service));
let server = Server::builder().set_rpc_middleware(rpc_middleware).build("127.0.0.1:0").await.unwrap();
// Start the server.
let mut module = RpcModule::new(());
module.register_method("say_hello", |_, _| "lo").unwrap();
module.register_method("say_goodbye", |_, _| "goodbye").unwrap();
let handle = server.start(module);
handle.stopped().await;
}
jsonrpsee server as a tower service
For users who want to get full control of the HTTP request, it's now possible to utilize jsonrpsee as a tower service
example here
jsonrpsee server low-level API
For users who want to get low-level access and for example to disconnect
misbehaving peers that is now possible as well example here
Logging in the server
Logging of RPC calls has been disabled by default,
but it's possible to enable that with the RPC logger middleware or provide
your own middleware for that.
let rpc_middleware = RpcServiceBuilder::new().rpc_logger(1024);
let server = Server::builder().set_rpc_middleware(rpc_middleware).build("127.0.0.1:0").await?;
WebSocket ping/pong API
The WebSocket ping/pong APIs have been refactored to be able
to disconnect inactive connections both by from the server and client-side.
Thanks to the external contributors @oleonardolima
and @venugopv who contributed to this release.
[Changed]
- chore(deps): update tokio-rustls requirement from 0.24 to 0.25 (#1256)
- chore(deps): update gloo-net requirement from 0.4.0 to 0.5.0 (#1260)
- chore(deps): update async-lock requirement from 2.4 to 3.0 (#1226)
- chore(deps): update proc-macro-crate requirement from 1 to 2 (#1211)
- chore(deps): update console-subscriber requirement from 0.1.8 to 0.2.0 (#1210)
- refactor: split client and server errors (#1122)
- refactor(ws client): impl tokio:{AsyncRead, AsyncWrite} for EitherStream (#1249)
- refactor(http client): enable all http versions (#1252)
- refactor(server): change ws ping API (#1248)
- refactor(ws client): generic over data stream (#1168)
- refactor(client): unify ws ping/pong API with the server (#1258
- refactor: set
tcp_nodelay == true
by default ([#1263])(#1263)
[Added]
- feat(client): add
disconnect_reason
API (#1246) - feat(server): jsonrpsee as
service
andlow-level API for more fine-grained API to disconnect peers etc
(#1224) - feat(server): JSON-RPC specific middleware (#1215)
- feat(middleware): add
HostFilterLayer::disable
(#1213)
[Fixed]
- fix(host filtering): support hosts with multiple ports (#1227)
v0.20.3
[v0.20.3] - 2023-10-24
This release fixes a cancel-safety issue in the server's graceful shutdown which could lead to high CPU usage.
[Fixed]
v0.20.2
[v0.20.2] - 2023-10-13
This release removes the bounded buffer check which was intended to provide
backpressure all the way down to the TCP layer but it didn't work well.
For subscriptions the backpressure will be handled by implementation itself
and just rely on that.
[Changed]
- server: remove bounded channel check (#1209)
v0.20.1
[v0.20.1] - 2023-09-15
This release adds support for synchronous subscriptions
and fixes a leak in WebSocket server
where FuturesUnordered was not getting polled until shutdown, so it was accumulating tasks forever.
[Changed]
- client: downgrade log for unknown subscription to DEBUG (#1185)
- refactor(http client): use HTTP connector on http URLs (#1187)
- refactor(server): less alloc per method call (#1188)
[Fixed]
- fix: remove needless clone in ws background task (#1203)
- async client: save latest Waker (#1198)
- chore(deps): bump actions/checkout from 3.6.0 to 4.0.0 (#1197)
- fix(server): fix leak in FuturesUnordered (#1204)
[Added]
- feat(server): add sync subscription API
register_subscription_raw
(#1182)
v0.16.3
[v0.16.3] - 2023-08-23
This release fixes https://rustsec.org/advisories/RUSTSEC-2023-0052.
v0.20.0
[v0.20.0] - 2023-08-11
Another breaking release where the major changes are:
host filtering
has been moved to tower middleware instead of the server API.- the clients now supports default port number such
wss://my.server.com
- the background task for the async client has been refactored to multiplex send and read operations.
Regarding host filtering prior to this release one had to do:
let acl = AllowHosts::Only(vec!["http://localhost:*".into(), "http://127.0.0.1:*".into()]);
let server = ServerBuilder::default().set_host_filtering(acl).build("127.0.0.1:0").await.unwrap();
After this release then one have to do:
let middleware = tower::ServiceBuilder::new().layer(HostFilterLayer::new(["example.com"]).unwrap());
let server = Server::builder().set_middleware(middleware).build("127.0.0.1:0".parse::<SocketAddr>()?).await?;
Thanks to the external contributors @polachok, @bobs4462 and @aj3n that contributed to this release.
[Added]
- feat(server): add
SubscriptionMessage::new
(#1176) - feat(server): add
SubscriptionSink::connection_id
(#1175) - feat(server): add
Params::get
(#1173) - feat(server): add
PendingSubscriptionSink::connection_id
(#1163)
[Fixed]
- fix(server): host filtering URI read authority (#1178)
[Changed]
- refactor: make ErrorObject::borrowed accept
&str
(#1160) - refactor(client): support default port number (#1172)
- refactor(server): server host filtering (#1174)
- refactor(client): refactor background task (#1145)
- refactor: use
RootCertStore::add_trust_anchors
(#1165) - chore(deps): update criterion v0.5 and pprof 0.12 (#1161)
- chore(deps): update webpki-roots requirement from 0.24 to 0.25 (#1158)
- refactor(server): move host filtering to tower middleware (#1179)