-
Notifications
You must be signed in to change notification settings - Fork 173
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
clients: feature gate tls
#545
Changes from all commits
050dfac
fab8e24
0c64dd8
2d9020a
41b2121
6b10b43
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 |
---|---|---|
|
@@ -13,16 +13,19 @@ documentation = "https://docs.rs/jsonrpsee-http-client" | |
async-trait = "0.1" | ||
fnv = "1" | ||
hyper = { version = "0.14.10", features = ["client", "http1", "http2", "tcp"] } | ||
hyper-rustls = { version = "0.23", features = ["webpki-tokio"] } | ||
hyper-rustls = { version = "0.23", optional = true } | ||
jsonrpsee-types = { path = "../types", version = "0.6.0" } | ||
jsonrpsee-utils = { path = "../utils", version = "0.6.0", features = ["client", "http-helpers"] } | ||
serde = { version = "1.0", default-features = false, features = ["derive"] } | ||
serde_json = "1.0" | ||
thiserror = "1.0" | ||
tokio = { version = "1.8", features = ["time"] } | ||
tracing = "0.1" | ||
url = "2.2" | ||
|
||
[dev-dependencies] | ||
jsonrpsee-test-utils = { path = "../test-utils" } | ||
tokio = { version = "1.8", features = ["net", "rt-multi-thread", "macros"] } | ||
|
||
[features] | ||
default = ["tls"] | ||
tls = ["hyper-rustls/webpki-tokio"] | ||
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. TIL |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,30 +32,29 @@ use futures::{ | |
}; | ||
use pin_project::pin_project; | ||
use std::{io::Error as IoError, pin::Pin, task::Context, task::Poll}; | ||
use tokio::net::TcpStream; | ||
use tokio_util::compat::{TokioAsyncReadCompatExt, TokioAsyncWriteCompatExt}; | ||
|
||
/// Stream to represent either a unencrypted or encrypted socket stream. | ||
#[pin_project(project = EitherStreamProj)] | ||
#[derive(Debug, Copy, Clone)] | ||
pub enum EitherStream<S, T> { | ||
#[derive(Debug)] | ||
pub enum EitherStream { | ||
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. I did this but I realized I can just used placeholder type such as Unless we plan to support any transport using |
||
/// Unencrypted socket stream. | ||
Plain(#[pin] S), | ||
Plain(#[pin] TcpStream), | ||
/// Encrypted socket stream. | ||
Tls(#[pin] T), | ||
#[cfg(feature = "tls")] | ||
Tls(#[pin] tokio_rustls::client::TlsStream<TcpStream>), | ||
} | ||
|
||
impl<S, T> AsyncRead for EitherStream<S, T> | ||
where | ||
S: TokioAsyncReadCompatExt, | ||
T: TokioAsyncReadCompatExt, | ||
{ | ||
impl AsyncRead for EitherStream { | ||
fn poll_read(self: Pin<&mut Self>, cx: &mut Context, buf: &mut [u8]) -> Poll<Result<usize, IoError>> { | ||
match self.project() { | ||
EitherStreamProj::Plain(s) => { | ||
let compat = s.compat(); | ||
futures::pin_mut!(compat); | ||
AsyncRead::poll_read(compat, cx, buf) | ||
} | ||
#[cfg(feature = "tls")] | ||
EitherStreamProj::Tls(t) => { | ||
let compat = t.compat(); | ||
futures::pin_mut!(compat); | ||
|
@@ -75,6 +74,7 @@ where | |
futures::pin_mut!(compat); | ||
AsyncRead::poll_read_vectored(compat, cx, bufs) | ||
} | ||
#[cfg(feature = "tls")] | ||
EitherStreamProj::Tls(t) => { | ||
let compat = t.compat(); | ||
futures::pin_mut!(compat); | ||
|
@@ -84,18 +84,15 @@ where | |
} | ||
} | ||
|
||
impl<S, T> AsyncWrite for EitherStream<S, T> | ||
where | ||
S: TokioAsyncWriteCompatExt, | ||
T: TokioAsyncWriteCompatExt, | ||
{ | ||
impl AsyncWrite for EitherStream { | ||
fn poll_write(self: Pin<&mut Self>, cx: &mut Context, buf: &[u8]) -> Poll<Result<usize, IoError>> { | ||
match self.project() { | ||
EitherStreamProj::Plain(s) => { | ||
let compat = s.compat_write(); | ||
futures::pin_mut!(compat); | ||
AsyncWrite::poll_write(compat, cx, buf) | ||
} | ||
#[cfg(feature = "tls")] | ||
EitherStreamProj::Tls(t) => { | ||
let compat = t.compat_write(); | ||
futures::pin_mut!(compat); | ||
|
@@ -111,6 +108,7 @@ where | |
futures::pin_mut!(compat); | ||
AsyncWrite::poll_write_vectored(compat, cx, bufs) | ||
} | ||
#[cfg(feature = "tls")] | ||
EitherStreamProj::Tls(t) => { | ||
let compat = t.compat_write(); | ||
futures::pin_mut!(compat); | ||
|
@@ -126,6 +124,7 @@ where | |
futures::pin_mut!(compat); | ||
AsyncWrite::poll_flush(compat, cx) | ||
} | ||
#[cfg(feature = "tls")] | ||
EitherStreamProj::Tls(t) => { | ||
let compat = t.compat_write(); | ||
futures::pin_mut!(compat); | ||
|
@@ -141,6 +140,7 @@ where | |
futures::pin_mut!(compat); | ||
AsyncWrite::poll_close(compat, cx) | ||
} | ||
#[cfg(feature = "tls")] | ||
EitherStreamProj::Tls(t) => { | ||
let compat = t.compat_write(); | ||
futures::pin_mut!(compat); | ||
|
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.
This will close #554