mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 18:01:03 +00:00
Remove dependencies on OpenSSL (#4036)
* Remove dependency on hyper-tls This removes one of the dependencies on native-tls, and thus on OpenSSL. I will remove the other in a separate commit. * Remove the `HttpClient` enum It only had one variant. * Apply suggestions from code review Co-Authored-By: Pierre Krieger <pierre.krieger1708@gmail.com>
This commit is contained in:
committed by
Bastian Köcher
parent
dfded93411
commit
5a26696432
Generated
+27
-5
@@ -762,6 +762,14 @@ dependencies = [
|
||||
"memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ct-logs"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"sct 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ctor"
|
||||
version = "0.1.12"
|
||||
@@ -1567,15 +1575,19 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hyper-tls"
|
||||
version = "0.3.2"
|
||||
name = "hyper-rustls"
|
||||
version = "0.17.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ct-logs 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hyper 0.12.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustls 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio-rustls 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"webpki 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"webpki-roots 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -5649,7 +5661,7 @@ dependencies = [
|
||||
"futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures-timer 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hyper 0.12.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hyper-tls 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hyper-rustls 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -7057,6 +7069,14 @@ dependencies = [
|
||||
"untrusted 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webpki-roots"
|
||||
version = "0.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"webpki 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webpki-roots"
|
||||
version = "0.18.0"
|
||||
@@ -7341,6 +7361,7 @@ dependencies = [
|
||||
"checksum crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5"
|
||||
"checksum csv 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "37519ccdfd73a75821cac9319d4fce15a81b9fcf75f951df5b9988aa3a0af87d"
|
||||
"checksum csv-core 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9b5cadb6b25c77aeff80ba701712494213f4a8418fcda2ee11b6560c3ad0bf4c"
|
||||
"checksum ct-logs 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4d3686f5fa27dbc1d76c751300376e167c5a43387f44bb451fd1c24776e49113"
|
||||
"checksum ctor 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "cd8ce37ad4184ab2ce004c33bf6379185d3b1c95801cab51026bd271bf68eedc"
|
||||
"checksum ctr 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "022cd691704491df67d25d006fe8eca083098253c4d43516c2206479c58c6736"
|
||||
"checksum ctrlc 3.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c7dfd2d8b4c82121dfdff120f818e09fc4380b0b7e17a742081a89b94853e87f"
|
||||
@@ -7429,7 +7450,7 @@ dependencies = [
|
||||
"checksum humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f"
|
||||
"checksum hyper 0.10.16 (registry+https://github.com/rust-lang/crates.io-index)" = "0a0652d9a2609a968c14be1a9ea00bf4b1d64e2e1f53a1b51b6fff3a6e829273"
|
||||
"checksum hyper 0.12.35 (registry+https://github.com/rust-lang/crates.io-index)" = "9dbe6ed1438e1f8ad955a4701e9a944938e9519f6888d12d8558b645e247d5f6"
|
||||
"checksum hyper-tls 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3a800d6aa50af4b5850b2b0f659625ce9504df908e9733b635720483be26174f"
|
||||
"checksum hyper-rustls 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)" = "719d85c7df4a7f309a77d145340a063ea929dcb2e025bae46a80345cffec2952"
|
||||
"checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e"
|
||||
"checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9"
|
||||
"checksum impl-codec 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3fa0086251524c50fd53b32e7b05eb6d79e2f97221eaf0c53c0ca9c3096f21d3"
|
||||
@@ -7763,6 +7784,7 @@ dependencies = [
|
||||
"checksum wasmtime-runtime 0.2.0 (git+https://github.com/CraneStation/wasmtime.git?rev=71dd73d6)" = "<none>"
|
||||
"checksum web-sys 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)" = "c84440699cd02ca23bed6f045ffb1497bc18a3c2628bd13e2093186faaaacf6b"
|
||||
"checksum webpki 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d7e664e770ac0110e2384769bcc59ed19e329d81f555916a6e072714957b81b4"
|
||||
"checksum webpki-roots 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a262ae37dd9d60f60dd473d1158f9fbebf110ba7b6a5051c8160460f6043718b"
|
||||
"checksum webpki-roots 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)" = "91cd5736df7f12a964a5067a12c62fa38e1bd8080aff1f80bc29be7c80d19ab4"
|
||||
"checksum websocket 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b255b190f412e45000c35be7fe9b48b39a2ac5eb90d093d421694e5dae8b335c"
|
||||
"checksum weedle 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3bb43f70885151e629e2a19ce9e50bd730fd436cfd4b666894c9ce4de9141164"
|
||||
|
||||
@@ -28,7 +28,7 @@ keystore = { package = "substrate-keystore", path = "../keystore" }
|
||||
|
||||
[target.'cfg(not(target_os = "unknown"))'.dependencies]
|
||||
hyper = "0.12.35"
|
||||
hyper-tls = "0.3.2"
|
||||
hyper-rustls = "0.17.1"
|
||||
|
||||
[dev-dependencies]
|
||||
env_logger = "0.7.0"
|
||||
|
||||
@@ -29,7 +29,7 @@ use crate::api::timestamp;
|
||||
use bytes::Buf as _;
|
||||
use fnv::FnvHashMap;
|
||||
use futures::{prelude::*, channel::mpsc, compat::Compat01As03};
|
||||
use log::{warn, error};
|
||||
use log::error;
|
||||
use primitives::offchain::{HttpRequestId, Timestamp, HttpRequestStatus, HttpError};
|
||||
use std::{fmt, io::Read as _, mem, pin::Pin, task::Context, task::Poll};
|
||||
|
||||
@@ -50,9 +50,7 @@ pub fn http() -> (HttpApi, HttpWorker) {
|
||||
let engine = HttpWorker {
|
||||
to_api,
|
||||
from_api,
|
||||
// TODO: don't unwrap; we should fall back to the HttpConnector if we fail to create the
|
||||
// Https one; there doesn't seem to be any built-in way to do this
|
||||
http_client: HyperClient::new(),
|
||||
http_client: hyper::Client::builder().build(hyper_rustls::HttpsConnector::new(1)),
|
||||
requests: Vec::new(),
|
||||
};
|
||||
|
||||
@@ -551,30 +549,6 @@ enum WorkerToApi {
|
||||
},
|
||||
}
|
||||
|
||||
/// Wraps around a `hyper::Client` with either TLS enabled or disabled.
|
||||
enum HyperClient {
|
||||
/// Everything is ok and HTTPS is available.
|
||||
Https(hyper::Client<hyper_tls::HttpsConnector<hyper::client::HttpConnector>, hyper::Body>),
|
||||
/// We failed to initialize HTTPS and therefore only allow HTTP.
|
||||
Http(hyper::Client<hyper::client::HttpConnector, hyper::Body>),
|
||||
}
|
||||
|
||||
impl HyperClient {
|
||||
/// Creates new hyper client.
|
||||
///
|
||||
/// By default we will try to initialize the `HttpsConnector`,
|
||||
/// If that's not possible we'll fall back to `HttpConnector`.
|
||||
pub fn new() -> Self {
|
||||
match hyper_tls::HttpsConnector::new(1) {
|
||||
Ok(tls) => HyperClient::Https(hyper::Client::builder().build(tls)),
|
||||
Err(e) => {
|
||||
warn!("Unable to initialize TLS client. Falling back to HTTP-only: {:?}", e);
|
||||
HyperClient::Http(hyper::Client::new())
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Must be continuously polled for the [`HttpApi`] to properly work.
|
||||
pub struct HttpWorker {
|
||||
/// Used to sends messages to the `HttpApi`.
|
||||
@@ -582,7 +556,7 @@ pub struct HttpWorker {
|
||||
/// Used to receive messages from the `HttpApi`.
|
||||
from_api: mpsc::UnboundedReceiver<ApiToWorker>,
|
||||
/// The engine that runs HTTP requests.
|
||||
http_client: HyperClient,
|
||||
http_client: hyper::Client<hyper_rustls::HttpsConnector<hyper::client::HttpConnector>, hyper::Body>,
|
||||
/// HTTP requests that are being worked on by the engine.
|
||||
requests: Vec<(HttpRequestId, HttpWorkerRequest)>,
|
||||
}
|
||||
@@ -686,10 +660,7 @@ impl Future for HttpWorker {
|
||||
Poll::Pending => {},
|
||||
Poll::Ready(None) => return Poll::Ready(()), // stops the worker
|
||||
Poll::Ready(Some(ApiToWorker::Dispatch { id, request })) => {
|
||||
let future = Compat01As03::new(match me.http_client {
|
||||
HyperClient::Http(ref mut c) => c.request(request),
|
||||
HyperClient::Https(ref mut c) => c.request(request),
|
||||
});
|
||||
let future = Compat01As03::new(me.http_client.request(request));
|
||||
debug_assert!(me.requests.iter().all(|(i, _)| *i != id));
|
||||
me.requests.push((id, HttpWorkerRequest::Dispatched(future)));
|
||||
cx.waker().wake_by_ref(); // reschedule the task to poll the request
|
||||
|
||||
Reference in New Issue
Block a user