Skip to content

Commit

Permalink
Make net not include tokio-rustls. (#305)
Browse files Browse the repository at this point in the history
This PR removes tokio-rustls as a dependency of the net feature so you only
get TLS if you ask for it.
  • Loading branch information
partim authored Apr 29, 2024
1 parent 4cab467 commit bf163e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ serde = ["dep:serde", "octseq/serde"]
sign = ["std"]
smallvec = ["dep:smallvec", "octseq/smallvec"]
std = ["bytes?/std", "octseq/std", "time/std"]
net = ["bytes", "futures-util", "rand", "std", "tokio", "tokio-rustls"]
net = ["bytes", "futures-util", "rand", "std", "tokio"]
tsig = ["bytes", "ring", "smallvec"]
validate = ["std", "ring"]
zonefile = ["bytes", "serde", "std"]

# Unstable features
unstable-client-transport = [ "moka", "tracing" ]
unstable-server-transport = ["arc-swap", "chrono/clock", "hex", "libc", "tracing"]
unstable-client-transport = [ "moka", "net", "tracing" ]
unstable-server-transport = ["arc-swap", "chrono/clock", "hex", "libc", "net", "tracing"]
unstable-zonetree = ["futures", "parking_lot", "serde", "tokio", "tracing"]

# Test features
Expand Down
28 changes: 15 additions & 13 deletions src/net/client/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@ use pin_project_lite::pin_project;
use std::boxed::Box;
use std::io;
use std::net::SocketAddr;
use std::sync::Arc;
use std::task::{Context, Poll};
use tokio::io::ReadBuf;
use tokio::net::{TcpStream, UdpSocket};
use tokio_rustls::client::TlsStream;
use tokio_rustls::rustls::pki_types::ServerName;
use tokio_rustls::rustls::ClientConfig;
use tokio_rustls::TlsConnector;

/// How many times do we try a new random port if we get ‘address in use.’
const RETRY_RANDOM_PORT: usize = 10;
Expand Down Expand Up @@ -72,25 +67,30 @@ impl AsyncConnect for TcpConnect {
//------------ TlsConnect -----------------------------------------------------

/// Create new TLS connections
#[cfg(feature = "tokio-rustls")]
#[derive(Clone, Debug)]
pub struct TlsConnect {
/// Configuration for setting up a TLS connection.
client_config: Arc<ClientConfig>,
client_config: std::sync::Arc<tokio_rustls::rustls::ClientConfig>,

/// Server name for certificate verification.
server_name: ServerName<'static>,
server_name: tokio_rustls::rustls::pki_types::ServerName<'static>,

/// Remote address to connect to.
addr: SocketAddr,
}

#[cfg(feature = "tokio-rustls")]
impl TlsConnect {
/// Function to create a new TLS connection stream
pub fn new(
client_config: impl Into<Arc<ClientConfig>>,
server_name: ServerName<'static>,
pub fn new<Conf>(
client_config: Conf,
server_name: tokio_rustls::rustls::pki_types::ServerName<'static>,
addr: SocketAddr,
) -> Self {
) -> Self
where
Conf: Into<std::sync::Arc<tokio_rustls::rustls::ClientConfig>>,
{
Self {
client_config: client_config.into(),
server_name,
Expand All @@ -99,8 +99,9 @@ impl TlsConnect {
}
}

#[cfg(feature = "tokio-rustls")]
impl AsyncConnect for TlsConnect {
type Connection = TlsStream<TcpStream>;
type Connection = tokio_rustls::client::TlsStream<TcpStream>;
type Fut = Pin<
Box<
dyn Future<Output = Result<Self::Connection, std::io::Error>>
Expand All @@ -110,7 +111,8 @@ impl AsyncConnect for TlsConnect {
>;

fn connect(&self) -> Self::Fut {
let tls_connection = TlsConnector::from(self.client_config.clone());
let tls_connection =
tokio_rustls::TlsConnector::from(self.client_config.clone());
let server_name = self.server_name.clone();
let addr = self.addr;
Box::pin(async move {
Expand Down

0 comments on commit bf163e1

Please sign in to comment.