Skip to content

Commit c01956e

Browse files
committed
build: Feature-gate ClientType::SSL
Currently applies to any of - `use-rustls` - `use-rustls-ring` - `use-openssl` and further reduce feature gating of the `client` module.
1 parent 5916edc commit c01956e

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed

src/client.rs

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ pub enum ClientType {
2222
#[allow(missing_docs)]
2323
TCP(RawClient<ElectrumPlaintextStream>),
2424
#[allow(missing_docs)]
25+
#[cfg(any(
26+
feature = "use-rustls",
27+
feature = "use-rustls-ring",
28+
feature = "use-openssl",
29+
))]
2530
SSL(RawClient<ElectrumSslStream>),
2631
#[allow(missing_docs)]
2732
#[cfg(feature = "proxy")]
@@ -44,6 +49,11 @@ macro_rules! impl_inner_call {
4449
let read_client = $self.client_type.read().unwrap();
4550
let res = match &*read_client {
4651
ClientType::TCP(inner) => inner.$name( $($args, )* ),
52+
#[cfg(any(
53+
feature = "use-rustls",
54+
feature = "use-rustls-ring",
55+
feature = "use-openssl",
56+
))]
4757
ClientType::SSL(inner) => inner.$name( $($args, )* ),
4858
#[cfg(feature = "proxy")]
4959
ClientType::Socks5(inner) => inner.$name( $($args, )* ),
@@ -110,8 +120,19 @@ impl ClientType {
110120
/// Constructor that supports multiple backends and allows configuration through
111121
/// the [Config]
112122
pub fn from_config(url: &str, config: &Config) -> Result<Self, Error> {
113-
if url.starts_with("ssl://") {
123+
// TLS.
124+
#[cfg(any(
125+
feature = "use-rustls",
126+
feature = "use-rustls-ring",
127+
feature = "use-openssl",
128+
))]
129+
let client = {
114130
let url = url.replacen("ssl://", "", 1);
131+
132+
#[cfg(not(feature = "proxy"))]
133+
let client =
134+
RawClient::new_ssl(url.as_str(), config.validate_domain(), config.timeout())?;
135+
115136
#[cfg(feature = "proxy")]
116137
let client = match config.socks5() {
117138
Some(socks5) => RawClient::new_proxy_ssl(
@@ -124,12 +145,16 @@ impl ClientType {
124145
RawClient::new_ssl(url.as_str(), config.validate_domain(), config.timeout())?
125146
}
126147
};
127-
#[cfg(not(feature = "proxy"))]
128-
let client =
129-
RawClient::new_ssl(url.as_str(), config.validate_domain(), config.timeout())?;
130148

131-
Ok(ClientType::SSL(client))
132-
} else {
149+
ClientType::SSL(client)
150+
};
151+
// Plain TCP.
152+
#[cfg(not(any(
153+
feature = "use-rustls",
154+
feature = "use-rustls-ring",
155+
feature = "use-openssl",
156+
)))]
157+
let client = {
133158
let url = url.replacen("tcp://", "", 1);
134159

135160
#[cfg(feature = "proxy")]
@@ -145,8 +170,10 @@ impl ClientType {
145170
#[cfg(not(feature = "proxy"))]
146171
let client = ClientType::TCP(RawClient::new(url.as_str(), config.timeout())?);
147172

148-
Ok(client)
149-
}
173+
client
174+
};
175+
176+
Ok(client)
150177
}
151178
}
152179

src/lib.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ pub mod socks;
5757
mod api;
5858
mod batch;
5959

60-
#[cfg(any(
61-
feature = "use-openssl",
62-
feature = "use-rustls",
63-
feature = "use-rustls-ring",
64-
))]
6560
pub mod client;
6661

6762
mod config;
@@ -73,11 +68,6 @@ pub mod utils;
7368

7469
pub use api::ElectrumApi;
7570
pub use batch::Batch;
76-
#[cfg(any(
77-
feature = "use-openssl",
78-
feature = "use-rustls",
79-
feature = "use-rustls-ring",
80-
))]
8171
pub use client::*;
8272
pub use config::{Config, ConfigBuilder, Socks5Config};
8373
pub use types::*;

0 commit comments

Comments
 (0)