temporary implementation of trust-dns-https for Tokio 0.3

This commit is contained in:
Benjamin Fry 2020-11-10 09:13:33 -08:00
parent 2d0a3d0461
commit 1b535dfd3b
9 changed files with 87 additions and 48 deletions

49
Cargo.lock generated
View File

@ -62,9 +62,9 @@ dependencies = [
[[package]]
name = "async-executor"
version = "1.3.0"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d373d78ded7d0b3fa8039375718cde0aace493f2e34fb60f51cbf567562ca801"
checksum = "eb877970c7b440ead138f6321a3b5395d6061183af779340b65e20c0fede9146"
dependencies = [
"async-task",
"concurrent-queue",
@ -629,7 +629,26 @@ dependencies = [
"indexmap",
"slab",
"tokio 0.2.22",
"tokio-util",
"tokio-util 0.3.1",
"tracing",
"tracing-futures",
]
[[package]]
name = "h2"
version = "0.3.0"
source = "git+https://github.com/hyperium/h2.git#cbbdd305b1afc1eaf19f2e3b26f9419048041e7d"
dependencies = [
"bytes 0.5.6",
"fnv",
"futures-core",
"futures-sink",
"futures-util",
"http",
"indexmap",
"slab",
"tokio 0.3.3",
"tokio-util 0.4.0",
"tracing",
"tracing-futures",
]
@ -879,9 +898,9 @@ dependencies = [
[[package]]
name = "native-tls"
version = "0.2.5"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a1cda389c26d6b88f3d2dc38aa1b750fe87d298cc5d795ec9e975f402f00372"
checksum = "6fcc7939b5edc4e4f86b1b4a04bb1498afaaf871b1a6691838ed06fcb48d3a3f"
dependencies = [
"lazy_static",
"libc",
@ -1643,6 +1662,20 @@ dependencies = [
"tokio 0.2.22",
]
[[package]]
name = "tokio-util"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24793699f4665ba0416ed287dc794fe6b11a4aa5e4e95b58624f45f6c46b97d4"
dependencies = [
"bytes 0.5.6",
"futures-core",
"futures-sink",
"log",
"pin-project-lite",
"tokio 0.3.3",
]
[[package]]
name = "toml"
version = "0.5.7"
@ -1755,13 +1788,13 @@ dependencies = [
"env_logger",
"futures",
"futures-util",
"h2",
"h2 0.3.0",
"http",
"log",
"rustls",
"thiserror",
"tokio 0.3.3",
"tokio-rustls 0.14.1",
"tokio-rustls 0.20.0",
"trust-dns-proto",
"trust-dns-rustls",
"webpki",
@ -1904,7 +1937,7 @@ dependencies = [
"env_logger",
"futures-executor",
"futures-util",
"h2",
"h2 0.2.7",
"http",
"log",
"openssl",

View File

@ -13,6 +13,7 @@ members = ["crates/proto",
"tests/compatibility-tests",
"tests/integration-tests"]
# [patch.crates-io]
[patch.crates-io]
# tokio = { path = "../tokio/tokio" }
# mio = { git = "https://github.com/tokio-rs/mio.git" }
# mio = { git = "https://github.com/tokio-rs/mio.git" }
h2 = { git = "https://github.com/hyperium/h2.git" }

View File

@ -51,13 +51,13 @@ cfg-if = "1"
bytes = "0.5"
data-encoding = "2.2.0"
futures-util = { version = "0.3.5", default-features = false, features = ["std"] }
h2 = { version = "0.2.6", features = ["stream"] }
h2 = { version = "0.3.0", features = ["stream"] }
http = "0.2"
log = "0.4"
rustls = "0.18"
thiserror = "1.0.20"
tokio = { version = "0.3.0", features = ["io-util", "net", "rt"] }
tokio-rustls = "0.14"
tokio = { version = "0.3", features = ["io-util", "net", "rt"] }
tokio-rustls = "0.20.0"
# disables default features, i.e. openssl...
trust-dns-proto = { version = "0.20.0-alpha.3", path = "../proto", features = ["tokio-runtime"], default-features = false }
trust-dns-rustls = { version = "0.20.0-alpha.3", path = "../rustls", default-features = false }

View File

@ -31,7 +31,7 @@ use tokio_rustls::{
use webpki::DNSNameRef;
use trust_dns_proto::error::ProtoError;
use trust_dns_proto::iocompat::AsyncIo03As02;
use trust_dns_proto::iocompat::AsyncIoStdAsTokio;
use trust_dns_proto::tcp::Connect;
use trust_dns_proto::xfer::{
DnsRequest, DnsRequestSender, DnsResponse, DnsResponseFuture, SerialMessage,
@ -381,7 +381,7 @@ where
},
TlsConnecting {
// FIXME: also abstract away Tokio TLS in RuntimeProvider.
tls: TokioTlsConnect<AsyncIo03As02<S>>,
tls: TokioTlsConnect<AsyncIoStdAsTokio<S>>,
name_server_name: Arc<str>,
name_server: SocketAddr,
},
@ -392,7 +392,7 @@ where
Output = Result<
(
SendRequest<Bytes>,
Connection<TokioTlsClientStream<AsyncIo03As02<S>>, Bytes>,
Connection<TokioTlsClientStream<AsyncIoStdAsTokio<S>>, Bytes>,
),
h2::Error,
>,
@ -444,7 +444,7 @@ where
match DNSNameRef::try_from_ascii_str(&dns_name) {
Ok(dns_name) => {
let tls = TlsConnector::from(tls.client_config);
let tls = tls.connect(dns_name, AsyncIo03As02(tcp));
let tls = tls.connect(dns_name, AsyncIoStdAsTokio(tcp));
HttpsClientConnectState::TlsConnecting {
name_server_name,
name_server,
@ -533,7 +533,7 @@ mod tests {
use webpki_roots;
use tokio::net::TcpStream as TokioTcpStream;
use trust_dns_proto::iocompat::AsyncIo02As03;
use trust_dns_proto::iocompat::AsyncIoTokioAsStd;
use trust_dns_proto::op::{Message, Query, ResponseCode};
use trust_dns_proto::rr::{Name, RData, RecordType};
@ -562,11 +562,11 @@ mod tests {
client_config.key_log = Arc::new(KeyLogFile::new());
let https_builder = HttpsClientStreamBuilder::with_client_config(Arc::new(client_config));
let connect =
https_builder.build::<AsyncIo02As03<TokioTcpStream>>(google, "dns.google".to_string());
let connect = https_builder
.build::<AsyncIoTokioAsStd<TokioTcpStream>>(google, "dns.google".to_string());
// tokio runtime stuff...
let mut runtime = Runtime::new().expect("could not start runtime");
let runtime = Runtime::new().expect("could not start runtime");
let mut https = runtime.block_on(connect).expect("https connect failed");
let response = runtime
@ -637,11 +637,13 @@ mod tests {
client_config.alpn_protocols.push(ALPN_H2.to_vec());
let https_builder = HttpsClientStreamBuilder::with_client_config(Arc::new(client_config));
let connect = https_builder
.build::<AsyncIo02As03<TokioTcpStream>>(cloudflare, "cloudflare-dns.com".to_string());
let connect = https_builder.build::<AsyncIoTokioAsStd<TokioTcpStream>>(
cloudflare,
"cloudflare-dns.com".to_string(),
);
// tokio runtime stuff...
let mut runtime = Runtime::new().expect("could not start runtime");
let runtime = Runtime::new().expect("could not start runtime");
let mut https = runtime.block_on(connect).expect("https connect failed");
let response = runtime

View File

@ -84,10 +84,10 @@ pub mod iocompat {
use tokio::io::{AsyncRead as TokioAsyncRead, AsyncWrite as TokioAsyncWrite, ReadBuf};
/// Conversion from `tokio::io::{AsyncRead, AsyncWrite}` to `std::io::{AsyncRead, AsyncWrite}`
pub struct AsyncIo02As03<T>(pub T);
pub struct AsyncIoTokioAsStd<T: TokioAsyncRead + TokioAsyncWrite>(pub T);
impl<T> Unpin for AsyncIo02As03<T> {}
impl<R: TokioAsyncRead + Unpin> AsyncRead for AsyncIo02As03<R> {
impl<T: TokioAsyncRead + TokioAsyncWrite> Unpin for AsyncIoTokioAsStd<T> {}
impl<R: TokioAsyncRead + TokioAsyncWrite + Unpin> AsyncRead for AsyncIoTokioAsStd<R> {
fn poll_read(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
@ -100,7 +100,7 @@ pub mod iocompat {
}
}
impl<W: TokioAsyncWrite + Unpin> AsyncWrite for AsyncIo02As03<W> {
impl<W: TokioAsyncRead + TokioAsyncWrite + Unpin> AsyncWrite for AsyncIoTokioAsStd<W> {
fn poll_write(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
@ -117,9 +117,9 @@ pub mod iocompat {
}
/// Conversion from `std::io::{AsyncRead, AsyncWrite}` to `tokio::io::{AsyncRead, AsyncWrite}`
pub struct AsyncIo03As02<T>(pub T);
pub struct AsyncIoStdAsTokio<T: AsyncRead + AsyncWrite>(pub T);
impl<R: AsyncRead + Unpin> TokioAsyncRead for AsyncIo03As02<R> {
impl<R: AsyncRead + AsyncWrite + Unpin> TokioAsyncRead for AsyncIoStdAsTokio<R> {
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
@ -132,7 +132,7 @@ pub mod iocompat {
}
}
impl<W: AsyncWrite + Unpin> TokioAsyncWrite for AsyncIo03As02<W> {
impl<W: AsyncRead + AsyncWrite + Unpin> TokioAsyncWrite for AsyncIoStdAsTokio<W> {
fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
@ -140,9 +140,11 @@ pub mod iocompat {
) -> Poll<Result<usize, io::Error>> {
Pin::new(&mut self.get_mut().0).poll_write(cx, buf)
}
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
Pin::new(&mut self.get_mut().0).poll_flush(cx)
}
fn poll_shutdown(
self: Pin<&mut Self>,
cx: &mut Context<'_>,

View File

@ -20,7 +20,7 @@ use log::warn;
use crate::error::ProtoError;
#[cfg(feature = "tokio-runtime")]
use crate::iocompat::AsyncIo02As03;
use crate::iocompat::AsyncIoTokioAsStd;
use crate::tcp::{Connect, DnsTcpStream, TcpStream};
use crate::xfer::{DnsClientStream, SerialMessage};
#[cfg(feature = "tokio-runtime")]
@ -139,7 +139,7 @@ impl<S: DnsTcpStream> Future for TcpClientConnect<S> {
use tokio::net::TcpStream as TokioTcpStream;
#[cfg(feature = "tokio-runtime")]
impl<T> DnsTcpStream for AsyncIo02As03<T>
impl<T> DnsTcpStream for AsyncIoTokioAsStd<T>
where
T: tokio::io::AsyncRead + tokio::io::AsyncWrite + Unpin + Send + Sync + Sized + 'static,
{
@ -148,16 +148,16 @@ where
#[cfg(feature = "tokio-runtime")]
#[async_trait]
impl Connect for AsyncIo02As03<TokioTcpStream> {
impl Connect for AsyncIoTokioAsStd<TokioTcpStream> {
async fn connect(addr: SocketAddr) -> io::Result<Self> {
super::tokio::connect(&addr).await.map(AsyncIo02As03)
super::tokio::connect(&addr).await.map(AsyncIoTokioAsStd)
}
}
#[cfg(test)]
#[cfg(feature = "tokio-runtime")]
mod tests {
use super::AsyncIo02As03;
use super::AsyncIoTokioAsStd;
#[cfg(not(target_os = "linux"))]
use std::net::Ipv6Addr;
use std::net::{IpAddr, Ipv4Addr};
@ -169,7 +169,7 @@ mod tests {
#[test]
fn test_tcp_stream_ipv4() {
let io_loop = Runtime::new().expect("failed to create tokio runtime");
tcp_client_stream_test::<AsyncIo02As03<TokioTcpStream>, Runtime, TokioTime>(
tcp_client_stream_test::<AsyncIoTokioAsStd<TokioTcpStream>, Runtime, TokioTime>(
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
io_loop,
)
@ -179,7 +179,7 @@ mod tests {
#[cfg(not(target_os = "linux"))] // ignored until Travis-CI fixes IPv6
fn test_tcp_stream_ipv6() {
let io_loop = Runtime::new().expect("failed to create tokio runtime");
tcp_client_stream_test::<AsyncIo02As03<TokioTcpStream>, Runtime, TokioTime>(
tcp_client_stream_test::<AsyncIoTokioAsStd<TokioTcpStream>, Runtime, TokioTime>(
IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)),
io_loop,
)

View File

@ -436,14 +436,14 @@ mod tests {
use tokio::net::TcpStream as TokioTcpStream;
use tokio::runtime::Runtime;
use crate::iocompat::AsyncIo02As03;
use crate::iocompat::AsyncIoTokioAsStd;
use crate::TokioTime;
use crate::tests::tcp_stream_test;
#[test]
fn test_tcp_stream_ipv4() {
let io_loop = Runtime::new().expect("failed to create tokio runtime");
tcp_stream_test::<AsyncIo02As03<TokioTcpStream>, Runtime, TokioTime>(
tcp_stream_test::<AsyncIoTokioAsStd<TokioTcpStream>, Runtime, TokioTime>(
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
io_loop,
)
@ -453,7 +453,7 @@ mod tests {
#[cfg(not(target_os = "linux"))] // ignored until Travis-CI fixes IPv6
fn test_tcp_stream_ipv6() {
let io_loop = Runtime::new().expect("failed to create tokio runtime");
tcp_stream_test::<AsyncIo02As03<TokioTcpStream>, Runtime, TokioTime>(
tcp_stream_test::<AsyncIoTokioAsStd<TokioTcpStream>, Runtime, TokioTime>(
IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)),
io_loop,
)

View File

@ -17,7 +17,7 @@ use rustls::ClientConfig;
use tokio::net::TcpStream as TokioTcpStream;
use trust_dns_proto::error::ProtoError;
use trust_dns_proto::iocompat::AsyncIo02As03;
use trust_dns_proto::iocompat::AsyncIoTokioAsStd;
use trust_dns_proto::tcp::TcpClientStream;
use trust_dns_proto::xfer::BufDnsStreamHandle;
@ -25,7 +25,7 @@ use crate::tls_stream::tls_connect;
/// Type of TlsClientStream used with Rustls
pub type TlsClientStream =
TcpClientStream<AsyncIo02As03<tokio_rustls::client::TlsStream<TokioTcpStream>>>;
TcpClientStream<AsyncIoTokioAsStd<tokio_rustls::client::TlsStream<TokioTcpStream>>>;
/// Creates a new TlsStream to the specified name_server
///

View File

@ -20,7 +20,7 @@ use tokio::net::TcpStream as TokioTcpStream;
use tokio_rustls::TlsConnector;
use webpki::{DNSName, DNSNameRef};
use trust_dns_proto::iocompat::AsyncIo02As03;
use trust_dns_proto::iocompat::AsyncIoTokioAsStd;
use trust_dns_proto::tcp::{self, DnsTcpStream, TcpStream};
use trust_dns_proto::xfer::{BufStreamHandle, StreamReceiver};
@ -78,8 +78,9 @@ pub fn tls_connect(
) -> (
Pin<
Box<
dyn Future<Output = Result<TlsStream<AsyncIo02As03<TokioTlsClientStream>>, io::Error>>
+ Send,
dyn Future<
Output = Result<TlsStream<AsyncIoTokioAsStd<TokioTlsClientStream>>, io::Error>,
> + Send,
>,
>,
BufStreamHandle,
@ -105,7 +106,7 @@ async fn connect_tls(
name_server: SocketAddr,
dns_name: String,
outbound_messages: StreamReceiver,
) -> io::Result<TcpStream<AsyncIo02As03<TokioTlsClientStream>>> {
) -> io::Result<TcpStream<AsyncIoTokioAsStd<TokioTlsClientStream>>> {
let tcp = tcp::tokio::connect(&name_server).await?;
let dns_name = DNSNameRef::try_from_ascii_str(&dns_name)
@ -123,7 +124,7 @@ async fn connect_tls(
.await?;
Ok(TcpStream::from_stream_with_receiver(
AsyncIo02As03(s),
AsyncIoTokioAsStd(s),
name_server,
outbound_messages,
))