Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Remove dependency on hyper-tls
Browse files Browse the repository at this point in the history
This removes one of the dependencies on native-tls, and thus on OpenSSL.
I will remove the other in a separate commit.
  • Loading branch information
Demi-Marie committed Nov 6, 2019
1 parent a0d368b commit b9a0835
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
32 changes: 27 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/offchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 4 additions & 12 deletions core/offchain/src/api/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -554,9 +554,7 @@ 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>),
Https(hyper::Client<hyper_rustls::HttpsConnector<hyper::client::HttpConnector>, hyper::Body>),
}

impl HyperClient {
Expand All @@ -565,13 +563,8 @@ impl HyperClient {
/// 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())
},
}
let tls = hyper_rustls::HttpsConnector::new(1);
HyperClient::Https(hyper::Client::builder().build(tls))
}
}

Expand Down Expand Up @@ -687,7 +680,6 @@ impl Future for HttpWorker {
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),
});
debug_assert!(me.requests.iter().all(|(i, _)| *i != id));
Expand Down

0 comments on commit b9a0835

Please sign in to comment.