Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async DNS pipeline (trust-dns 0.23) #27

Merged
merged 17 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,308 changes: 324 additions & 984 deletions Cargo.lock

Large diffs are not rendered by default.

22 changes: 8 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,16 @@ serde_derive = "1.0"
serde_json = "1.0"
url_serde = { version = "0.2", default-features = false }
regex = "1.10"
r2d2 = "0.8"
r2d2_redis = "0.14"
redis = "0.20"
async-trait = "0.1"
bb8-redis = "0.15"
actix-web = { version = "3.3", default-features = false }
actix-web-httpauth = "0.5"
trust-dns = { version = "0.14", default-features = false }
trust-dns-server = { version = "0.14", default-features = false }
trust-dns-proto = { version = "0.4", default-features = false }
trust-dns-resolver = { version = "0.10", default-features = false }
futures = "0.1"
tokio = "0.1"
tokio-tcp = "0.1"
tokio-udp = "0.1"
hickory-server = { version = "0.24", default-features = false }
hickory-proto = { version = "0.24", default-features = false }
hickory-resolver = { version = "0.24", default-features = false, features = [
"tokio-runtime",
] }
tokio = "1.21"
rand = "0.8"
farmhash = "1.1"
http_req = { version = "0.10", features = [
Expand All @@ -49,9 +46,6 @@ tempfile = "3.1"
flate2 = "1.0"
tar = "0.4"

[patch.crates-io]
rusqlite = { git = "https://github.com/rusqlite/rusqlite", rev = "aa64e2fb33755c696337d443ac4e8af93551ad05" }

[profile.dev]
opt-level = 0
debug = true
Expand Down
4 changes: 2 additions & 2 deletions src/dns/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Copyright: 2019, Valerian Saliou <[email protected]>
// License: Mozilla Public License v2.0 (MPL v2.0)

use trust_dns::op::ResponseCode;
use hickory_proto::op::ResponseCode;

#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub enum CodeName {
Expand All @@ -22,7 +22,7 @@ pub enum CodeName {
}

impl CodeName {
pub fn from_trust(response_code: &ResponseCode) -> Option<CodeName> {
pub fn from_hickory(response_code: &ResponseCode) -> Option<CodeName> {
match response_code {
&ResponseCode::NoError => Some(CodeName::NoError),
&ResponseCode::FormErr => Some(CodeName::FormErr),
Expand Down
54 changes: 31 additions & 23 deletions src/dns/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
// Copyright: 2020, Valerian Saliou <[email protected]>
// License: Mozilla Public License v2.0 (MPL v2.0)

use hickory_resolver::config::{NameServerConfig, Protocol, ResolverConfig, ResolverOpts};
use hickory_resolver::error::ResolveError;
use hickory_resolver::Resolver;
use std::collections::HashMap;
use std::net::ToSocketAddrs;
use std::ops::Deref;
use std::sync::RwLock;
use std::thread;
use std::time::{Duration, Instant, SystemTime};
use trust_dns_resolver::config::{NameServerConfig, Protocol, ResolverConfig, ResolverOpts};
use trust_dns_resolver::error::ResolveError;
use trust_dns_resolver::Resolver;

use super::record::{RecordType, RecordValue, RecordValues};
use crate::APP_CONF;
Expand Down Expand Up @@ -86,8 +86,10 @@ impl DNSFlattenBuilder {
for socket_address in socket_addresses {
resolver_config.add_name_server(NameServerConfig {
socket_addr: socket_address,
bind_addr: None,
protocol: Protocol::Udp,
tls_dns_name: None,
trust_negative_responses: true,
});
}
}
Expand Down Expand Up @@ -194,35 +196,41 @@ impl DNSFlatten {
let values: Result<Vec<String>, ResolveError> = match registry_key.1 {
RecordType::A => self
.resolver
.ipv4_lookup(&registry_key.0)
.ipv4_lookup(registry_key.0.to_str())
.map(|values| values.iter().map(|value| value.to_string()).collect()),
RecordType::AAAA => self
.resolver
.ipv6_lookup(&registry_key.0)
.ipv6_lookup(registry_key.0.to_str())
.map(|values| values.iter().map(|value| value.to_string()).collect()),
RecordType::MX => {
// Format as `{priority} {exchange}`, eg. `10 inbound.crisp.email`
self.resolver.mx_lookup(&registry_key.0).map(|values| {
values
.iter()
.map(|value| format!("{} {}", value.preference(), value.exchange()))
.collect()
})
self.resolver
.mx_lookup(registry_key.0.to_str())
.map(|values| {
values
.iter()
.map(|value| format!("{} {}", value.preference(), value.exchange()))
.collect()
})
}
RecordType::TXT => {
// Assemble all TXT data segments
self.resolver.txt_lookup(&registry_key.0).map(|values| {
values
.iter()
.map(|value_chunks| {
value_chunks
.txt_data()
.iter()
.map(|value_chunk| std::str::from_utf8(value_chunk).unwrap_or(""))
.collect()
})
.collect()
})
self.resolver
.txt_lookup(registry_key.0.to_str())
.map(|values| {
values
.iter()
.map(|value_chunks| {
value_chunks
.txt_data()
.iter()
.map(|value_chunk| {
std::str::from_utf8(value_chunk).unwrap_or("")
})
.collect()
})
.collect()
})
}
RecordType::PTR | RecordType::CNAME => Ok(Vec::new()),
};
Expand Down
Loading
Loading