Skip to content

Commit

Permalink
prepare for client release (#215)
Browse files Browse the repository at this point in the history
* prep for client release.

* fix nits

* add changelogs

* Update http-client/src/lib.rs

Co-authored-by: David <dvdplm@gmail.com>

* address grumbles: one changelog

* 0.2.0-alpha

* revert rust2018 lint

Co-authored-by: David <dvdplm@gmail.com>
  • Loading branch information
niklasad1 and dvdplm committed Mar 4, 2021
1 parent 50d8bf7 commit 7aeb95d
Show file tree
Hide file tree
Showing 17 changed files with 65 additions and 26 deletions.
12 changes: 6 additions & 6 deletions examples/Cargo.toml
Expand Up @@ -12,10 +12,10 @@ async-std = "1.9"
env_logger = "0.8"
futures = "0.3"
log = "0.4"
jsonrpsee-types = { path = "../types", version = "0.1" }
jsonrpsee-http-client = { path = "../http-client", version = "0.1" }
jsonrpsee-ws-client = { path = "../ws-client", version = "0.1" }
jsonrpsee-ws-server = { path = "../ws-server", version = "0.1" }
jsonrpsee-http-server = { path = "../http-server", version = "0.1" }
jsonrpsee-proc-macros = { path = "../proc-macros", version = "0.2" }
jsonrpsee-types = { path = "../types" }
jsonrpsee-http-client = { path = "../http-client" }
jsonrpsee-ws-client = { path = "../ws-client" }
jsonrpsee-ws-server = { path = "../ws-server" }
jsonrpsee-http-server = { path = "../http-server" }
jsonrpsee-proc-macros = { path = "../proc-macros" }
tokio = { version = "1", features = ["full"] }
6 changes: 3 additions & 3 deletions http-client/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "jsonrpsee-http-client"
version = "0.1.0"
version = "0.2.0-alpha"
authors = ["Parity Technologies <admin@parity.io>", "Pierre Krieger <pierre.krieger1708@gmail.com>"]
description = "HTTP client for JSON-RPC"
edition = "2018"
Expand All @@ -11,8 +11,8 @@ async-trait = "0.1"
futures = "0.3"
hyper14 = { package = "hyper", version = "0.14", features = ["client", "http1", "http2", "tcp"], optional = true }
hyper13 = { package = "hyper", version = "0.13", optional = true }
jsonrpsee-types = { path = "../types", version = "0.1" }
jsonrpsee-utils = { path = "../utils", version = "0.1", default-features = false, optional = true }
jsonrpsee-types = { path = "../types", version = "0.2.0-alpha" }
jsonrpsee-utils = { path = "../utils", version = "0.2.0-alpha", default-features = false, optional = true }
log = "0.4"
serde = { version = "1.0", default-features = false, features = ["derive"] }
serde_json = "1.0"
Expand Down
3 changes: 1 addition & 2 deletions http-client/src/client.rs
Expand Up @@ -7,8 +7,7 @@ use std::convert::TryInto;
use std::sync::atomic::{AtomicU64, Ordering};

/// JSON-RPC HTTP Client that provides functionality to perform method calls and notifications.
///
/// WARNING: The async methods must be executed on [Tokio 1.0](https://docs.rs/tokio/1.0.1/tokio).
#[derive(Debug)]
pub struct HttpClient {
/// HTTP transport client.
transport: HttpTransportClient,
Expand Down
22 changes: 22 additions & 0 deletions http-client/src/lib.rs
@@ -1,3 +1,25 @@
#![warn(missing_debug_implementations, missing_docs, unreachable_pub)]

//! # jsonrpsee-http-client
//!
//! `jsonrpsee-http-client` is [JSON RPC](https://www.jsonrpc.org/specification) HTTP client library that's is built for `async/await`.
//!
//! It is tightly-coupled to [`tokio`](https://docs.rs/tokio) because [`hyper`](https://docs.rs/hyper) is used as transport client,
//! which is not compatible with other async runtimes such as
//! [`async-std`](https://docs.rs/async-std/), [`smol`](https://docs.rs/smol) and similar.
//!
//! It supports both [`tokio 1.0`](https://docs.rs/tokio/1.2.0/tokio/) and [`tokio 0.2`](https://docs.rs/tokio/0.2.25/tokio/index.html)
//! via [Optional features](#optional-features).
//!
//! # Optional Features
//!
//! `jsonrpsee-http-client` uses the following [feature flags]:
//!
//! - `tokio1`: Enable to use the library with [`tokio 1.0`](https://docs.rs/tokio/1.2.0/tokio/) (mutually exclusive with `tokio02`)
//! - `tokio0.2`: Enable to use the library with [`tokio 0.2`](https://docs.rs/tokio/0.2.25/tokio/index.html) (mutually exclusive with `tokio1`)
//!
//! [feature flags]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section

#[cfg(all(feature = "tokio1", feature = "tokio02"))]
compile_error!("feature `tokio1` and `tokio02` are mutably exclusive");

Expand Down
6 changes: 3 additions & 3 deletions http-server/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "jsonrpsee-http-server"
version = "0.1.0"
version = "0.2.0-alpha"
authors = ["Parity Technologies <admin@parity.io>", "Pierre Krieger <pierre.krieger1708@gmail.com>"]
description = "HTTP server for JSON-RPC"
edition = "2018"
Expand All @@ -11,8 +11,8 @@ async-std = "1.8"
futures = "0.3"
fnv = "1"
hyper = { version = "0.14", features = ["stream", "client", "server", "http1", "http2", "tcp"] }
jsonrpsee-types = { path = "../types", version = "0.1" }
jsonrpsee-utils = { path = "../utils", version = "0.1" }
jsonrpsee-types = { path = "../types", version = "0.2.0-alpha" }
jsonrpsee-utils = { path = "../utils", version = "0.2.0-alpha" }
log = "0.4"
serde = { version = "1", default-features = false, features = ["derive"] }
serde_json = "1"
Expand Down
4 changes: 2 additions & 2 deletions proc-macros/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "jsonrpsee-proc-macros"
description = "JSON-RPC crate"
version = "0.2.0"
description = "Procedueral macros for jsonrpsee"
version = "0.2.0-alpha"
authors = ["Parity Technologies <admin@parity.io>", "Pierre Krieger <pierre.krieger1708@gmail.com>"]
license = "MIT"
edition = "2018"
Expand Down
2 changes: 1 addition & 1 deletion types/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "jsonrpsee-types"
version = "0.1.0"
version = "0.2.0-alpha"
authors = ["Parity Technologies <admin@parity.io>"]
description = "Shared types for jsonrpsee"
edition = "2018"
Expand Down
1 change: 1 addition & 0 deletions types/src/client.rs
Expand Up @@ -17,6 +17,7 @@ pub struct Subscription<Notif> {
}

/// Message that the Client can send to the background task.
#[derive(Debug)]
pub enum FrontToBack {
/// Send a one-shot notification to the server. The server doesn't give back any feedback.
Notification {
Expand Down
4 changes: 2 additions & 2 deletions utils/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "jsonrpsee-utils"
version = "0.1.0"
version = "0.2.0-alpha"
authors = ["Parity Technologies <admin@parity.io>"]
description = "Utilities for jsonrpsee"
edition = "2018"
Expand All @@ -11,7 +11,7 @@ futures = "0.3"
globset = "0.4"
hyper13 = { package = "hyper", version = "0.13", default-features = false, features = ["stream"], optional = true }
hyper14 = { package = "hyper", version = "0.14", default-features = false, features = ["stream"], optional = true }
jsonrpsee-types = { path = "../types", version = "0.1" }
jsonrpsee-types = { path = "../types", version = "0.2.0-alpha" }
lazy_static = "1.4"
log = "0.4"
unicase = "2.6"
Expand Down
4 changes: 2 additions & 2 deletions ws-client/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "jsonrpsee-ws-client"
version = "0.1.0"
version = "0.2.0-alpha"
authors = ["Parity Technologies <admin@parity.io>", "Pierre Krieger <pierre.krieger1708@gmail.com>"]
description = "WebSocket client for JSON-RPC"
edition = "2018"
Expand All @@ -12,7 +12,7 @@ async-std = { version = "1.8", features = ["attributes"] }
async-tls = "0.11"
fnv = "1"
futures = "0.3"
jsonrpsee-types = { path = "../types", version = "0.1" }
jsonrpsee-types = { path = "../types", version = "0.2.0-alpha" }
log = "0.4"
serde = { version = "1", default-features = false, features = ["derive"] }
serde_json = "1"
Expand Down
2 changes: 1 addition & 1 deletion ws-client/src/client.rs
Expand Up @@ -46,7 +46,7 @@ use std::{io, marker::PhantomData};
/// Client that can be cloned.
///
/// > **Note**: This struct is designed to be easy to use, but it works by maintaining a background task running in parallel.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct WsClient {
/// Channel to send requests to the background task.
to_back: mpsc::Sender<FrontToBack>,
Expand Down
2 changes: 2 additions & 0 deletions ws-client/src/jsonrpc_transport.rs
Expand Up @@ -16,6 +16,7 @@ pub async fn websocket_connection(config: WsConfig<'_>) -> Result<(Sender, Recei

/// JSONRPC WebSocket sender.
/// It's a wrapper over `WebSocket sender` with additional `JSONRPC request_id`.
#[derive(Debug)]
pub struct Sender {
request_id: u64,
transport: transport::Sender,
Expand Down Expand Up @@ -93,6 +94,7 @@ impl Sender {
}

/// JSONRPC WebSocket receiver.
#[derive(Debug)]
pub struct Receiver {
transport: transport::Receiver,
}
Expand Down
6 changes: 6 additions & 0 deletions ws-client/src/lib.rs
@@ -1,3 +1,9 @@
#![warn(missing_debug_implementations, missing_docs, unreachable_pub)]

//! # jsonrpsee-ws-client
//!
//! `jsonrpsee-ws-client` is a [JSON RPC](https://www.jsonrpc.org/specification) WebSocket client library that's is built for `async/await`.

/// WebSocket Client.
pub mod client;
/// JSONRPC WebSocket transport.
Expand Down
6 changes: 5 additions & 1 deletion ws-client/src/manager.rs
Expand Up @@ -14,12 +14,14 @@ use jsonrpsee_types::{
};
use std::collections::hash_map::{Entry, HashMap};

#[derive(Debug)]
enum Kind {
PendingMethodCall(PendingCallOneshot),
PendingSubscription((PendingSubscriptionOneshot, UnsubscribeMethod)),
Subscription((SubscriptionSink, UnsubscribeMethod)),
}

#[derive(Debug)]
/// Indicates the status of a given request/response.
pub enum RequestStatus {
/// The method call is waiting for a response,
Expand All @@ -38,6 +40,7 @@ type SubscriptionSink = mpsc::Sender<JsonValue>;
type UnsubscribeMethod = String;
type RequestId = u64;

#[derive(Debug, Default)]
/// Manages and monitors JSONRPC v2 method calls and subscriptions.
pub struct RequestManager {
/// List of requests that are waiting for a response from the server.
Expand All @@ -48,8 +51,9 @@ pub struct RequestManager {
}

impl RequestManager {
/// Create an empty `RequestManager`.
pub fn new() -> Self {
Self { requests: FnvHashMap::default(), subscriptions: HashMap::new() }
Self::default()
}

/// Tries to insert a new pending call.
Expand Down
1 change: 1 addition & 0 deletions ws-client/src/stream.rs
Expand Up @@ -33,6 +33,7 @@ use futures::{
use pin_project::pin_project;
use std::{io::Error as IoError, pin::Pin, task::Context, task::Poll};

/// Stream to represent either a unencrypted or encrypted socket stream.
#[pin_project(project = EitherStreamProj)]
#[derive(Debug, Copy, Clone)]
pub enum EitherStream<S, T> {
Expand Down
6 changes: 5 additions & 1 deletion ws-client/src/transport.rs
Expand Up @@ -42,22 +42,26 @@ type TlsOrPlain = crate::stream::EitherStream<TcpStream, TlsStream<TcpStream>>;
pub struct Host(String);

impl Host {
/// Extracts a string slice from the inner String.
pub fn as_str(&self) -> &str {
self.0.as_str()
}
}

/// Sending end of WebSocket transport.
#[derive(Debug)]
pub struct Sender {
inner: connection::Sender<BufReader<BufWriter<TlsOrPlain>>>,
}

/// Receiving end of WebSocket transport.
#[derive(Debug)]
pub struct Receiver {
inner: connection::Receiver<BufReader<BufWriter<TlsOrPlain>>>,
}

/// Builder for a WebSocket transport [`Sender`] and [`Receiver`] pair.
/// Builder for a WebSocket transport [`Sender`] and ['Receiver`] pair.
#[derive(Debug)]
pub struct WsTransportClientBuilder<'a> {
/// Socket addresses to try to connect to.
sockaddrs: Vec<SocketAddr>,
Expand Down
4 changes: 2 additions & 2 deletions ws-server/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "jsonrpsee-ws-server"
version = "0.1.0"
version = "0.2.0-alpha"
authors = ["Parity Technologies <admin@parity.io>", "Pierre Krieger <pierre.krieger1708@gmail.com>"]
description = "WebSocket server for JSON-RPC"
edition = "2018"
Expand All @@ -13,7 +13,7 @@ beef = "0.5"
bs58 = "0.4"
fnv = "1"
futures = "0.3"
jsonrpsee-types = { path = "../types", version = "0.1" }
jsonrpsee-types = { path = "../types", version = "0.2.0-alpha" }
log = "0.4"
parking_lot = "0.11"
rand = "0.8"
Expand Down

0 comments on commit 7aeb95d

Please sign in to comment.