hickory_proto/rustls/
tls_client_stream.rs1use std::future::Future;
11use std::io;
12use std::net::SocketAddr;
13use std::pin::Pin;
14use std::sync::Arc;
15
16use futures_util::TryFutureExt;
17use rustls::ClientConfig;
18
19use crate::error::ProtoError;
20use crate::iocompat::AsyncIoStdAsTokio;
21use crate::iocompat::AsyncIoTokioAsStd;
22use crate::rustls::tls_stream::{tls_connect_with_bind_addr, tls_connect_with_future};
23use crate::tcp::{Connect, DnsTcpStream, TcpClientStream};
24use crate::xfer::BufDnsStreamHandle;
25
26pub type TlsClientStream<S> =
28 TcpClientStream<AsyncIoTokioAsStd<tokio_rustls::client::TlsStream<AsyncIoStdAsTokio<S>>>>;
29
30#[allow(clippy::type_complexity)]
38pub fn tls_client_connect<S: Connect>(
39 name_server: SocketAddr,
40 dns_name: String,
41 client_config: Arc<ClientConfig>,
42) -> (
43 Pin<Box<dyn Future<Output = Result<TlsClientStream<S>, ProtoError>> + Send + Unpin>>,
44 BufDnsStreamHandle,
45) {
46 tls_client_connect_with_bind_addr(name_server, None, dns_name, client_config)
47}
48
49#[allow(clippy::type_complexity)]
57pub fn tls_client_connect_with_bind_addr<S: Connect>(
58 name_server: SocketAddr,
59 bind_addr: Option<SocketAddr>,
60 dns_name: String,
61 client_config: Arc<ClientConfig>,
62) -> (
63 Pin<Box<dyn Future<Output = Result<TlsClientStream<S>, ProtoError>> + Send + Unpin>>,
64 BufDnsStreamHandle,
65) {
66 let (stream_future, sender) =
67 tls_connect_with_bind_addr(name_server, bind_addr, dns_name, client_config);
68
69 let new_future = Box::pin(
70 stream_future
71 .map_ok(TcpClientStream::from_stream)
72 .map_err(ProtoError::from),
73 );
74
75 (new_future, sender)
76}
77
78#[allow(clippy::type_complexity)]
85pub fn tls_client_connect_with_future<S, F>(
86 future: F,
87 socket_addr: SocketAddr,
88 dns_name: String,
89 client_config: Arc<ClientConfig>,
90) -> (
91 Pin<Box<dyn Future<Output = Result<TlsClientStream<S>, ProtoError>> + Send + Unpin>>,
92 BufDnsStreamHandle,
93)
94where
95 S: DnsTcpStream,
96 F: Future<Output = io::Result<S>> + Send + Unpin + 'static,
97{
98 let (stream_future, sender) =
99 tls_connect_with_future(future, socket_addr, dns_name, client_config);
100
101 let new_future = Box::pin(
102 stream_future
103 .map_ok(TcpClientStream::from_stream)
104 .map_err(ProtoError::from),
105 );
106
107 (new_future, sender)
108}