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

refactor: crate re-organization with separate crates #177

Merged
merged 5 commits into from
Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ script:
- cargo fmt --all -- --check
- cargo build --verbose --all-features
- cargo test --verbose --all-features
- cargo build --verbose --no-default-features
- cargo build --verbose --features "http"
- cargo build --verbose --features "ws"
- cargo check --benches --all-features
# TODO: add this back when the documentation has been updated.
- RUSTDOCFLAGS="--warn broken_intra_doc_links" cargo doc --verbose --workspace --no-deps --document-private-items
Expand Down
67 changes: 12 additions & 55 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,55 +1,12 @@
[package]
name = "jsonrpsee"
description = "JSON-RPC crate"
version = "2.0.0"
authors = ["Pierre Krieger <pierre.krieger1708@gmail.com>"]
license = "MIT"
edition = "2018"

[dependencies]
async-std = { version = "1.8.0", features = ["attributes"] }
bs58 = "0.4.0"
fnv = "1.0.7"
futures = "0.3.8"
globset = "0.4.6"
hashbrown = "0.9.1"
lazy_static = "1.4.0"
log = "0.4.11"
parking_lot = "0.11.1"
pin-project = "1.0.2"
jsonrpsee-proc-macros = { path = "proc-macros" }
rand = "0.7.3"
serde = { version = "1.0.118", default-features = false, features = ["derive"] }
serde_json = "1.0.60"
smallvec = { version = "1.5.1", default-features = false }
thiserror = "1.0.22"

# used for tests and HTTP/hyper
# the features are used only for tests but enabled because `dev-dependencies` are leaked into dependencies.
tokio = { version = "1.0", features = ["net", "rt-multi-thread", "macros"], optional = true }

# HTTP-related dependencies
hyper = { version = "0.14", features = ["stream", "client", "server", "http1", "http2", "tcp"], optional = true }
unicase = { version = "2.6.0", optional = true }

# WS-related dependencies
async-tls = { version = "0.11.0", optional = true }
bytes = { version = "0.6.0", optional = true }
soketto = { version = "0.4.2", optional = true }
url = { version = "2.2.0", optional = true }
webpki = { version = "0.21.4", optional = true }

[features]
default = ["http", "ws"]
http = ["hyper", "tokio", "unicase"]
ws = ["async-tls", "bytes", "soketto", "url", "webpki"]

[dev-dependencies]
criterion = "0.3.3"
env_logger = "0.8.2"
jsonrpsee-test-utils = { path = "test-utils" }
num_cpus = "1.13.0"

[[bench]]
name = "benches"
harness = false
[workspace]
members = [
"benches",
"http-client",
"http-server",
"test-utils",
"tests",
"types",
"utils",
"ws-client",
"ws-server",
]
23 changes: 23 additions & 0 deletions benches/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "jsonrpsee-benchmarks"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
description = "Benchmarks for jsonrpsee"
edition = "2018"
license = "MIT"

[dev-dependencies]
async-std = "1.8"
criterion = "0.3"
futures = "0.3"
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" }
num_cpus = "1"
tokio = { version = "1", features = ["full"] }

[[bench]]
name = "bench"
harness = false
13 changes: 7 additions & 6 deletions benches/benches.rs → benches/benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use async_std::task::block_on;
use criterion::*;
use futures::channel::oneshot::{self, Sender};
use jsonrpsee::client::{HttpClient, HttpConfig, WsClient, WsConfig};
use jsonrpsee::http::HttpServer;
use jsonrpsee::types::jsonrpc::{JsonValue, Params};
use jsonrpsee::ws::WsServer;
use jsonrpsee_http_client::{HttpClient, HttpConfig};
use jsonrpsee_http_server::HttpServer;
use jsonrpsee_types::jsonrpc::{JsonValue, Params};
use jsonrpsee_ws_client::{WsClient, WsConfig};
use jsonrpsee_ws_server::WsServer;
use std::net::SocketAddr;
use std::sync::Arc;

Expand Down Expand Up @@ -37,7 +38,7 @@ async fn ws_server(tx: Sender<SocketAddr>) {
}

pub fn http_requests(c: &mut criterion::Criterion) {
let mut rt = tokio::runtime::Runtime::new().unwrap();
let rt = tokio::runtime::Runtime::new().unwrap();
let (tx_addr, rx_addr) = oneshot::channel::<SocketAddr>();
async_std::task::spawn(http_server(tx_addr));
let server_addr = block_on(rx_addr).unwrap();
Expand Down Expand Up @@ -73,7 +74,7 @@ pub fn http_requests(c: &mut criterion::Criterion) {
}

pub fn websocket_requests(c: &mut criterion::Criterion) {
let mut rt = tokio::runtime::Runtime::new().unwrap();
let rt = tokio::runtime::Runtime::new().unwrap();
let (tx_addr, rx_addr) = oneshot::channel::<SocketAddr>();
async_std::task::spawn(ws_server(tx_addr));
let server_addr = block_on(rx_addr).unwrap();
Expand Down
1 change: 1 addition & 0 deletions benches/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

23 changes: 23 additions & 0 deletions http-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "jsonrpsee-http-client"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>", "Pierre Krieger <pierre.krieger1708@gmail.com>"]
description = "HTTP client for JSON-RPC"
edition = "2018"
license = "MIT"

[dependencies]
futures = "0.3"
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" }
log = "0.4"
serde = { version = "1.0", default-features = false, features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0"
unicase = "2.6"
url = "2.2"

[dev-dependencies]
jsonrpsee-test-utils = { path = "../test-utils" }
tokio = { version = "1.0", features = ["net", "rt-multi-thread", "macros"] }
10 changes: 6 additions & 4 deletions src/client/http/client.rs → http-client/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::client::http::transport::HttpTransportClient;
use crate::types::error::Error;
use crate::types::http::HttpConfig;
use crate::types::jsonrpc::{self, JsonValue};
use crate::transport::HttpTransportClient;
use jsonrpsee_types::{
error::Error,
http::HttpConfig,
jsonrpc::{self, JsonValue},
};

use std::convert::TryInto;
use std::sync::atomic::{AtomicU64, Ordering};
Expand Down
2 changes: 1 addition & 1 deletion src/client/http/mod.rs → http-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ mod transport;
#[cfg(test)]
mod tests;

pub use crate::types::http::HttpConfig;
pub use client::HttpClient;
pub use jsonrpsee_types::http::HttpConfig;
pub use transport::HttpTransportClient;
9 changes: 6 additions & 3 deletions src/client/http/tests.rs → http-client/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::client::{HttpClient, HttpConfig};
use crate::types::error::Error;
use crate::types::jsonrpc::{self, ErrorCode, JsonValue, Params};
use crate::client::HttpClient;
use jsonrpsee_types::{
error::Error,
http::HttpConfig,
jsonrpc::{self, ErrorCode, JsonValue, Params},
};

use jsonrpsee_test_utils::helpers::*;
use jsonrpsee_test_utils::types::Id;
Expand Down
10 changes: 6 additions & 4 deletions src/client/http/transport.rs → http-client/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// that we need to be guaranteed that hyper doesn't re-use an existing connection if we ever reset
// the JSON-RPC request id to a value that might have already been used.

use crate::types::{error::GenericTransportError, http::HttpConfig, jsonrpc};
use crate::utils::http::hyper_helpers;
use jsonrpsee_types::{error::GenericTransportError, http::HttpConfig, jsonrpc};
use jsonrpsee_utils::http::hyper_helpers;
use thiserror::Error;

const CONTENT_TYPE_JSON: &str = "application/json";
Expand Down Expand Up @@ -132,8 +132,10 @@ where
#[cfg(test)]
mod tests {
use super::{Error, HttpTransportClient};
use crate::types::http::HttpConfig;
use crate::types::jsonrpc::{Call, Id, MethodCall, Params, Request, Version};
use jsonrpsee_types::{
http::HttpConfig,
jsonrpc::{Call, Id, MethodCall, Params, Request, Version},
};

#[test]
fn invalid_http_url_rejected() {
Expand Down
28 changes: 28 additions & 0 deletions http-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "jsonrpsee-http-server"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>", "Pierre Krieger <pierre.krieger1708@gmail.com>"]
description = "HTTP server for JSON-RPC"
edition = "2018"
license = "MIT"

[dependencies]
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" }
log = "0.4"
serde = { version = "1", default-features = false, features = ["derive"] }
serde_json = "1"
parking_lot = "0.11"
thiserror = "1"
# `macros feature` is only used for tests but enabled globally because `dev-dependencies`
# are leaked.
tokio = { version = "1", features = ["net", "rt-multi-thread", "macros"] }
unicase = "2"

[dev-dependencies]
jsonrpsee-test-utils = { path = "../test-utils" }
jsonrpsee-http-client = { path = "../http-client" }
2 changes: 1 addition & 1 deletion src/http/mod.rs → http-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ mod transport;
#[cfg(test)]
mod tests;

pub use crate::types::http::HttpConfig;
pub use jsonrpsee_types::http::HttpConfig;
pub use raw::RawServer as HttpRawServer;
pub use raw::RawServerEvent as HttpRawServerEvent;
pub use raw::TypedResponder as HttpTypedResponder;
Expand Down
8 changes: 5 additions & 3 deletions src/http/raw/core.rs → http-server/src/raw/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

use crate::http::transport::{HttpTransportServer, TransportServerEvent};
use crate::types::jsonrpc;
use crate::types::jsonrpc::wrapped::{batches, Notification, Params};
use crate::transport::{HttpTransportServer, TransportServerEvent};
use jsonrpsee_types::jsonrpc::{
self,
wrapped::{batches, Notification, Params},
};

use core::{fmt, hash::Hash};

Expand Down
File renamed without changes.
7 changes: 3 additions & 4 deletions src/http/raw/tests.rs → http-server/src/raw/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@

#![cfg(test)]

use crate::client::HttpTransportClient;
use crate::http::{HttpRawServer, HttpRawServerEvent, HttpTransportServer};
use crate::types::http::HttpConfig;
use crate::types::jsonrpc::{self, Call, MethodCall, Notification, Params, Request, Version};
use crate::{HttpConfig, HttpRawServer, HttpRawServerEvent, HttpTransportServer};
use jsonrpsee_http_client::HttpTransportClient;
use jsonrpsee_types::jsonrpc::{self, Call, MethodCall, Notification, Params, Request, Version};
use serde_json::Value;

async fn connection_context() -> (HttpTransportClient, HttpRawServer) {
Expand Down
4 changes: 2 additions & 2 deletions src/ws/raw/typed_rp.rs → http-server/src/raw/typed_rp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

use crate::types::jsonrpc;
use crate::ws::raw::RawServerRequest;
use crate::raw::RawServerRequest;
use core::marker::PhantomData;
use jsonrpsee_types::jsonrpc;

/// Allows responding to a server request in a more elegant and strongly-typed fashion.
pub struct TypedResponder<'a, T> {
Expand Down
12 changes: 7 additions & 5 deletions src/http/server.rs → http-server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

use crate::http::raw::{RawServer, RawServerEvent, RawServerRequestId};
use crate::http::transport::HttpTransportServer;
use crate::types::error::Error;
use crate::types::http::HttpConfig;
use crate::types::jsonrpc::{self, JsonValue};
use crate::raw::{RawServer, RawServerEvent, RawServerRequestId};
use crate::transport::HttpTransportServer;
use jsonrpsee_types::{
error::Error,
http::HttpConfig,
jsonrpc::{self, JsonValue},
};

use futures::{channel::mpsc, future::Either, pin_mut, prelude::*};
use parking_lot::Mutex;
Expand Down
5 changes: 2 additions & 3 deletions src/http/tests.rs → http-server/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#![cfg(test)]

use crate::http::HttpServer;
use crate::types::http::HttpConfig;
use crate::types::jsonrpc::JsonValue;
use crate::{HttpConfig, HttpServer};
use futures::channel::oneshot::{self, Sender};
use futures::future::FutureExt;
use futures::{pin_mut, select};
use jsonrpsee_test_utils::helpers::*;
use jsonrpsee_test_utils::types::{Id, StatusCode};
use jsonrpsee_types::jsonrpc::JsonValue;
use std::net::SocketAddr;

async fn server(server_started_tx: Sender<SocketAddr>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

use crate::http::transport::response;
use crate::types::{error::GenericTransportError, http::HttpConfig, jsonrpc};
use crate::utils::http::{access_control::AccessControl, hyper_helpers};
use crate::transport::response;
use futures::{channel::mpsc, channel::oneshot, prelude::*};
use hyper::service::{make_service_fn, service_fn};
use hyper::Error;
use jsonrpsee_types::{error::GenericTransportError, http::HttpConfig, jsonrpc};
use jsonrpsee_utils::http::{access_control::AccessControl, hyper_helpers};
use std::{error, net::SocketAddr, thread};

/// Background thread that serves HTTP requests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ mod background;
#[allow(unused)]
mod response;

use crate::types::http::HttpConfig;
use crate::types::jsonrpc;
use crate::utils::http::access_control::AccessControl;
use jsonrpsee_types::{http::HttpConfig, jsonrpc};
use jsonrpsee_utils::http::access_control::AccessControl;

use fnv::FnvHashMap;
use futures::{channel::oneshot, prelude::*};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

//! Contains common builders for hyper responses.

use crate::types::jsonrpc;
use jsonrpsee_types::jsonrpc;

/// Create a response for plaintext internal error.
pub fn internal_error<T: Into<String>>(msg: T) -> hyper::Response<hyper::Body> {
Expand Down
15 changes: 0 additions & 15 deletions src/client/mod.rs

This file was deleted.

Loading