summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorebroto <ebroto@tutanota.com>2020-01-10 21:06:08 +0100
committerGitHub <noreply@github.com>2020-01-10 21:06:08 +0100
commitc14bdf76736f0587b19118a4dabc26401838b6cf (patch)
treeb714213f30f8a38c18dc07441eb93cabea5049f1
parent51ff9ac0a2ddda333d4cd290bc0ace4fa1631390 (diff)
parent457efb6810181d65f465c3b4ea07ef6e701b0f5d (diff)
Merge pull request #105 from bigtoast/trust
Upgraded trust-dns-resolver (#92)
-rw-r--r--CONTRIBUTING.md2
-rw-r--r--Cargo.lock12
-rw-r--r--Cargo.toml2
-rw-r--r--src/network/dns/client.rs6
-rw-r--r--src/network/dns/resolver.rs13
-rw-r--r--src/os/shared.rs6
-rw-r--r--src/tests/fakes/fake_input.rs17
7 files changed, 24 insertions, 34 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 287ddf0..ff82cca 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -6,6 +6,8 @@ To set up your development environment:
To run tests: `cargo test`
+After tests, check the formatting: `cargo fmt -- --check`
+
Note that at the moment the tests do not test the os layer (anything in the `os` folder).
If you are stuck, unsure about how to approach an issue or would like some guidance, you are welcome to contact: aram@poor.dev
diff --git a/Cargo.lock b/Cargo.lock
index 87629ae..4605165 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -99,7 +99,7 @@ dependencies = [
"structopt 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"termion 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "trust-dns-resolver 0.18.0-alpha.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "trust-dns-resolver 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)",
"tui 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -1588,7 +1588,7 @@ dependencies = [
[[package]]
name = "trust-dns-proto"
-version = "0.18.0-alpha.2"
+version = "0.18.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"async-trait 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1607,7 +1607,7 @@ dependencies = [
[[package]]
name = "trust-dns-resolver"
-version = "0.18.0-alpha.2"
+version = "0.18.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1620,7 +1620,7 @@ dependencies = [
"resolv-conf 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "trust-dns-proto 0.18.0-alpha.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "trust-dns-proto 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -2005,8 +2005,8 @@ dependencies = [
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"
"checksum tokio 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2e765bf9f550bd9b8a970633ca3b56b8120c4b6c5dcbe26a93744cb02fee4b17"
-"checksum trust-dns-proto 0.18.0-alpha.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2a7f3a2ab8a919f5eca52a468866a67ed7d3efa265d48a652a9a3452272b413f"
-"checksum trust-dns-resolver 0.18.0-alpha.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6f90b1502b226f8b2514c6d5b37bafa8c200d7ca4102d57dc36ee0f3b7a04a2f"
+"checksum trust-dns-proto 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)" = "253a722ff22a1217b7af6199cb2ec5824a19c5110e0db21d3fcb28d5f6e1b0ee"
+"checksum trust-dns-resolver 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)" = "72d7df08b45f4d6d124cdae3c303f9908159a17b39e633e524349e91bc798d32"
"checksum tui 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ff64c925f5e20d7a393c598a33b6afc9c9942e7ebc530085588f5b7667ea559"
"checksum typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9"
"checksum ucd-trie 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8f00ed7be0c1ff1e24f46c3d2af4859f7e863672ba3a6e92e7cff702bf9f06c2"
diff --git a/Cargo.toml b/Cargo.toml
index 8f9b4e4..1dc2b8e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -29,7 +29,7 @@ chrono = "0.4"
regex = "1.3.1"
lazy_static = "1.4.0"
tokio = { version = "0.2", features = ["rt-core", "sync"] }
-trust-dns-resolver = "=0.18.0-alpha.2"
+trust-dns-resolver = "0.18.1"
async-trait = "0.1.21"
[target.'cfg(target_os="linux")'.dependencies]
diff --git a/src/network/dns/client.rs b/src/network/dns/client.rs
index 1f3fe17..f9d12ed 100644
--- a/src/network/dns/client.rs
+++ b/src/network/dns/client.rs
@@ -1,7 +1,6 @@
use crate::network::dns::{resolver::Lookup, IpTable};
use std::{
collections::HashSet,
- future::Future,
net::Ipv4Addr,
sync::{Arc, Mutex},
thread::{Builder, JoinHandle},
@@ -23,14 +22,12 @@ pub struct Client {
}
impl Client {
- pub fn new<R, B>(resolver: R, background: B) -> Result<Self, failure::Error>
+ pub fn new<R>(resolver: R, mut runtime: Runtime) -> Result<Self, failure::Error>
where
R: Lookup + Send + Sync + 'static,
- B: Future<Output = ()> + Send + 'static,
{
let cache = Arc::new(Mutex::new(IpTable::new()));
let pending = Arc::new(Mutex::new(PendingAddrs::new()));
- let mut runtime = Runtime::new()?;
let (tx, mut rx) = mpsc::channel::<Vec<Ipv4Addr>>(CHANNEL_SIZE);
let handle = Builder::new().name("resolver".into()).spawn({
@@ -39,7 +36,6 @@ impl Client {
move || {
runtime.block_on(async {
let resolver = Arc::new(resolver);
- tokio::spawn(background);
while let Some(ips) = rx.recv().await {
for ip in ips {
diff --git a/src/network/dns/resolver.rs b/src/network/dns/resolver.rs
index 69f6308..007c485 100644
--- a/src/network/dns/resolver.rs
+++ b/src/network/dns/resolver.rs
@@ -1,18 +1,19 @@
use async_trait::async_trait;
-use std::{future::Future, net::Ipv4Addr};
-use trust_dns_resolver::{error::ResolveErrorKind, AsyncResolver};
+use std::net::Ipv4Addr;
+use tokio::runtime::Handle;
+use trust_dns_resolver::{error::ResolveErrorKind, TokioAsyncResolver};
#[async_trait]
pub trait Lookup {
async fn lookup(&self, ip: Ipv4Addr) -> Option<String>;
}
-pub struct Resolver(AsyncResolver);
+pub struct Resolver(TokioAsyncResolver);
impl Resolver {
- pub fn new() -> Result<(Self, impl Future<Output = ()>), failure::Error> {
- let (resolver, background) = AsyncResolver::from_system_conf()?;
- Ok((Self(resolver), background))
+ pub async fn new(runtime: Handle) -> Result<Self, failure::Error> {
+ let resolver = TokioAsyncResolver::from_system_conf(runtime).await?;
+ Ok(Self(resolver))
}
}
diff --git a/src/os/shared.rs b/src/os/shared.rs
index ec6a294..385f253 100644
--- a/src/os/shared.rs
+++ b/src/os/shared.rs
@@ -4,6 +4,7 @@ use ::pnet_bandwhich_fork::datalink::{self, Config, NetworkInterface};
use ::std::io::{self, stdin, Write};
use ::termion::event::Event;
use ::termion::input::TermRead;
+use ::tokio::runtime::Runtime;
use ::std::io::ErrorKind;
use ::std::time;
@@ -123,8 +124,9 @@ pub fn get_input(
let write_to_stdout = create_write_to_stdout();
let (on_winch, cleanup) = sigwinch();
let dns_client = if resolve {
- let (resolver, background) = dns::Resolver::new()?;
- let dns_client = dns::Client::new(resolver, background)?;
+ let mut runtime = Runtime::new()?;
+ let resolver = runtime.block_on(dns::Resolver::new(runtime.handle().clone()))?;
+ let dns_client = dns::Client::new(resolver, runtime)?;
Some(dns_client)
} else {
None
diff --git a/src/tests/fakes/fake_input.rs b/src/tests/fakes/fake_input.rs
index 92042df..253082e 100644
--- a/src/tests/fakes/fake_input.rs
+++ b/src/tests/fakes/fake_input.rs
@@ -3,12 +3,10 @@ use ::ipnetwork::IpNetwork;
use ::pnet_bandwhich_fork::datalink::DataLinkReceiver;
use ::pnet_bandwhich_fork::datalink::NetworkInterface;
use ::std::collections::HashMap;
-use ::std::future::Future;
use ::std::net::{IpAddr, Ipv4Addr, SocketAddr};
-use ::std::pin::Pin;
-use ::std::task::{Context, Poll};
use ::std::{thread, time};
use ::termion::event::Event;
+use ::tokio::runtime::Runtime;
use crate::{
network::{
@@ -172,7 +170,8 @@ pub fn create_fake_on_winch(should_send_winch_event: bool) -> Box<OnSigWinch> {
}
pub fn create_fake_dns_client(ips_to_hosts: HashMap<IpAddr, String>) -> Option<dns::Client> {
- let dns_client = dns::Client::new(FakeResolver(ips_to_hosts), FakeBackground {}).unwrap();
+ let runtime = Runtime::new().unwrap();
+ let dns_client = dns::Client::new(FakeResolver(ips_to_hosts), runtime).unwrap();
Some(dns_client)
}
@@ -185,13 +184,3 @@ impl Lookup for FakeResolver {
self.0.get(&ip).cloned()
}
}
-
-struct FakeBackground {}
-
-impl Future for FakeBackground {
- type Output = ();
-
- fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
- Poll::Ready(())
- }
-}