Skip to content

Commit f8a8841

Browse files
committed
build: Clean up "proxy" feature
Before, the the `client` module was gated on the "proxy" feature, which caused unnecessary coupling since proxy is only required for the Socks5 client type. This commit removes feature gating of the `client` module in favor of more precise feature gating of the Socks5 client type as well as functions which call into the `socks` module.
1 parent 92f3567 commit f8a8841

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

src/client.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ use std::convert::TryFrom;
1717
/// [`RawClient`](client/struct.RawClient.html) and provides a more user-friendly
1818
/// constructor that can choose the right backend based on the url prefix.
1919
///
20-
/// **This is available only with the `default` features, or if `proxy` and one ssl implementation are enabled**
20+
/// **Note the `Socks5` client type requires the "proxy" feature to be enabled.
2121
pub enum ClientType {
2222
#[allow(missing_docs)]
2323
TCP(RawClient<ElectrumPlaintextStream>),
2424
#[allow(missing_docs)]
2525
SSL(RawClient<ElectrumSslStream>),
2626
#[allow(missing_docs)]
27+
#[cfg(feature = "proxy")]
2728
Socks5(RawClient<ElectrumProxyStream>),
2829
}
2930

@@ -44,6 +45,7 @@ macro_rules! impl_inner_call {
4445
let res = match &*read_client {
4546
ClientType::TCP(inner) => inner.$name( $($args, )* ),
4647
ClientType::SSL(inner) => inner.$name( $($args, )* ),
48+
#[cfg(feature = "proxy")]
4749
ClientType::Socks5(inner) => inner.$name( $($args, )* ),
4850
};
4951
drop(read_client);
@@ -110,6 +112,7 @@ impl ClientType {
110112
pub fn from_config(url: &str, config: &Config) -> Result<Self, Error> {
111113
if url.starts_with("ssl://") {
112114
let url = url.replacen("ssl://", "", 1);
115+
#[cfg(feature = "proxy")]
113116
let client = match config.socks5() {
114117
Some(socks5) => RawClient::new_proxy_ssl(
115118
url.as_str(),
@@ -121,19 +124,28 @@ impl ClientType {
121124
RawClient::new_ssl(url.as_str(), config.validate_domain(), config.timeout())?
122125
}
123126
};
127+
#[cfg(not(feature = "proxy"))]
128+
let client =
129+
RawClient::new_ssl(url.as_str(), config.validate_domain(), config.timeout())?;
124130

125131
Ok(ClientType::SSL(client))
126132
} else {
127133
let url = url.replacen("tcp://", "", 1);
128134

129-
Ok(match config.socks5().as_ref() {
130-
None => ClientType::TCP(RawClient::new(url.as_str(), config.timeout())?),
135+
#[cfg(feature = "proxy")]
136+
let client = match config.socks5() {
131137
Some(socks5) => ClientType::Socks5(RawClient::new_proxy(
132138
url.as_str(),
133139
socks5,
134140
config.timeout(),
135141
)?),
136-
})
142+
None => ClientType::TCP(RawClient::new(url.as_str(), config.timeout())?),
143+
};
144+
145+
#[cfg(not(feature = "proxy"))]
146+
let client = ClientType::TCP(RawClient::new(url.as_str(), config.timeout())?);
147+
148+
Ok(client)
137149
}
138150
}
139151
}

src/lib.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,20 @@ extern crate serde_json;
4343
))]
4444
extern crate webpki_roots;
4545

46-
#[cfg(any(feature = "default", feature = "proxy"))]
46+
#[cfg(feature = "proxy")]
4747
extern crate byteorder;
4848

49-
#[cfg(all(unix, any(feature = "default", feature = "proxy")))]
49+
#[cfg(all(unix, feature = "proxy"))]
5050
extern crate libc;
51-
#[cfg(all(windows, any(feature = "default", feature = "proxy")))]
51+
#[cfg(all(windows, feature = "proxy"))]
5252
extern crate winapi;
5353

54-
#[cfg(any(feature = "default", feature = "proxy"))]
54+
#[cfg(feature = "proxy")]
5555
pub mod socks;
5656

5757
mod api;
5858
mod batch;
5959

60-
#[cfg(any(
61-
all(feature = "proxy", feature = "use-openssl"),
62-
all(feature = "proxy", feature = "use-rustls"),
63-
all(feature = "proxy", 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-
all(feature = "proxy", feature = "use-openssl"),
78-
all(feature = "proxy", feature = "use-rustls"),
79-
all(feature = "proxy", feature = "use-rustls-ring")
80-
))]
8171
pub use client::*;
8272
pub use config::{Config, ConfigBuilder, Socks5Config};
8373
pub use types::*;

src/raw_client.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,10 @@ impl RawClient<ElectrumSslStream> {
470470
}
471471
}
472472

473-
#[cfg(any(feature = "default", feature = "proxy"))]
473+
#[cfg(feature = "proxy")]
474474
/// Transport type used to establish a connection to a server through a socks proxy
475475
pub type ElectrumProxyStream = Socks5Stream;
476-
#[cfg(any(feature = "default", feature = "proxy"))]
476+
#[cfg(feature = "proxy")]
477477
impl RawClient<ElectrumProxyStream> {
478478
/// Creates a new socks client and tries to connect to `target_addr` using `proxy_addr` as a
479479
/// socks proxy server. The DNS resolution of `target_addr`, if required, is done
@@ -499,10 +499,13 @@ impl RawClient<ElectrumProxyStream> {
499499
Ok(stream.into())
500500
}
501501

502-
#[cfg(any(
503-
feature = "use-openssl",
504-
feature = "use-rustls",
505-
feature = "use-rustls-ring"
502+
#[cfg(all(
503+
feature = "proxy",
504+
any(
505+
feature = "use-openssl",
506+
feature = "use-rustls",
507+
feature = "use-rustls-ring",
508+
)
506509
))]
507510
/// Creates a new TLS client that connects to `target_addr` using `proxy_addr` as a socks proxy
508511
/// server. The DNS resolution of `target_addr`, if required, is done through the proxy. This

0 commit comments

Comments
 (0)