Update trust-dns
This commit is contained in:
parent
7211eee4e8
commit
84816c2d14
|
@ -11,7 +11,7 @@ futures-io = "0.3.21"
|
|||
jive = { git = "https://git.asonix.dog/safe-async/jive", features = [
|
||||
"futures-io-compat",
|
||||
] }
|
||||
trust-dns-proto = { version = "0.22.0", default-features = false }
|
||||
trust-dns-resolver = { version = "0.22.0", default-features = false, features = [
|
||||
trust-dns-proto = { version = "0.23.0", default-features = false }
|
||||
trust-dns-resolver = { version = "0.23.0", default-features = false, features = [
|
||||
"system-config",
|
||||
] }
|
||||
|
|
86
src/lib.rs
86
src/lib.rs
|
@ -6,16 +6,19 @@ use std::{
|
|||
};
|
||||
use trust_dns_resolver::config::{ResolverConfig, ResolverOpts};
|
||||
|
||||
pub fn resolver(
|
||||
config: ResolverConfig,
|
||||
options: ResolverOpts,
|
||||
) -> Result<JiveResolver, trust_dns_resolver::error::ResolveError> {
|
||||
JiveResolver::new(config, options, JiveRuntimeHandle)
|
||||
pub fn resolver(config: ResolverConfig, options: ResolverOpts) -> JiveResolver {
|
||||
JiveResolver::new(
|
||||
config,
|
||||
options,
|
||||
trust_dns_resolver::name_server::GenericConnector::new(JiveRuntime),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn resolver_from_system_conf() -> Result<JiveResolver, trust_dns_resolver::error::ResolveError>
|
||||
{
|
||||
JiveResolver::from_system_conf(JiveRuntimeHandle)
|
||||
JiveResolver::from_system_conf(trust_dns_resolver::name_server::GenericConnector::new(
|
||||
JiveRuntime,
|
||||
))
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -29,11 +32,10 @@ pub struct JiveUdpSocket {
|
|||
io: jive::io::Async<jive::net::UdpSocket>,
|
||||
}
|
||||
|
||||
pub type JiveResolver = trust_dns_resolver::AsyncResolver<JiveConnection, JiveConnectionProvider>;
|
||||
pub type JiveResolver = trust_dns_resolver::AsyncResolver<JiveConnectionProvider>;
|
||||
|
||||
pub type JiveConnection = trust_dns_resolver::name_server::GenericConnection;
|
||||
pub type JiveConnectionProvider =
|
||||
trust_dns_resolver::name_server::GenericConnectionProvider<JiveRuntime>;
|
||||
pub type JiveConnectionProvider = trust_dns_resolver::name_server::GenericConnector<JiveRuntime>;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct JiveRuntimeHandle;
|
||||
|
@ -55,6 +57,33 @@ impl trust_dns_resolver::name_server::RuntimeProvider for JiveRuntime {
|
|||
type Tcp = JiveTcpStream;
|
||||
type Timer = JiveTimer;
|
||||
type Udp = JiveUdpSocket;
|
||||
|
||||
fn create_handle(&self) -> Self::Handle {
|
||||
JiveRuntimeHandle
|
||||
}
|
||||
|
||||
fn connect_tcp(
|
||||
&self,
|
||||
server_addr: std::net::SocketAddr,
|
||||
) -> Pin<Box<dyn Send + Future<Output = std::io::Result<Self::Tcp>>>> {
|
||||
Box::pin(async move {
|
||||
Ok(JiveTcpStream {
|
||||
io: jive::io::Async::<jive::net::TcpStream>::connect(server_addr).await?,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn bind_udp(
|
||||
&self,
|
||||
local_addr: std::net::SocketAddr,
|
||||
_server_addr: std::net::SocketAddr,
|
||||
) -> Pin<Box<dyn Send + Future<Output = std::io::Result<Self::Udp>>>> {
|
||||
Box::pin(async move {
|
||||
Ok(JiveUdpSocket {
|
||||
io: jive::io::Async::<jive::net::UdpSocket>::bind(local_addr).await?,
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl trust_dns_resolver::name_server::Spawn for JiveRuntimeHandle {
|
||||
|
@ -115,9 +144,29 @@ impl AsyncWrite for JiveTcpStream {
|
|||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl trust_dns_proto::udp::UdpSocket for JiveUdpSocket {
|
||||
impl trust_dns_proto::udp::DnsUdpSocket for JiveUdpSocket {
|
||||
type Time = JiveTimer;
|
||||
|
||||
fn poll_send_to(
|
||||
&self,
|
||||
cx: &mut Context<'_>,
|
||||
buf: &[u8],
|
||||
target: std::net::SocketAddr,
|
||||
) -> Poll<std::io::Result<usize>> {
|
||||
self.io.poll_send_to(cx, buf, target)
|
||||
}
|
||||
|
||||
fn poll_recv_from(
|
||||
&self,
|
||||
cx: &mut Context<'_>,
|
||||
buf: &mut [u8],
|
||||
) -> Poll<std::io::Result<(usize, std::net::SocketAddr)>> {
|
||||
self.io.poll_recv_from(cx, buf)
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl trust_dns_proto::udp::UdpSocket for JiveUdpSocket {
|
||||
async fn connect(addr: std::net::SocketAddr) -> std::io::Result<Self> {
|
||||
let bind_addr: std::net::SocketAddr = match addr {
|
||||
std::net::SocketAddr::V4(_) => (std::net::Ipv4Addr::UNSPECIFIED, 0).into(),
|
||||
|
@ -139,23 +188,6 @@ impl trust_dns_proto::udp::UdpSocket for JiveUdpSocket {
|
|||
|
||||
Ok(JiveUdpSocket { io })
|
||||
}
|
||||
|
||||
fn poll_send_to(
|
||||
&self,
|
||||
cx: &mut Context<'_>,
|
||||
buf: &[u8],
|
||||
target: std::net::SocketAddr,
|
||||
) -> Poll<std::io::Result<usize>> {
|
||||
self.io.poll_send_to(cx, buf, target)
|
||||
}
|
||||
|
||||
fn poll_recv_from(
|
||||
&self,
|
||||
cx: &mut Context<'_>,
|
||||
buf: &mut [u8],
|
||||
) -> Poll<std::io::Result<(usize, std::net::SocketAddr)>> {
|
||||
self.io.poll_recv_from(cx, buf)
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
|
|
Loading…
Reference in a new issue