Skip to content

Commit e8ece7c

Browse files
author
Thomas Luijken
committed
Replaced tokio_from_system_conf with a custom configuration
Now we use Cloudflare DNS (by default) for resolving instead of using the OS /etc/resolv.conf file and bypassing system timeouts and slow or failing name servers.
1 parent 8616851 commit e8ece7c

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

.github/workflows/BUILD_AND_DEPLOY.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ jobs:
3333
password: ${{ secrets.BASEFLOW_ACR_PASSWORD }}
3434
push: ${{ github.event_name != 'pull_request' }}
3535
vulnerability_scan: ${{ github.event_name != 'pull_request' }}
36-
version: 1.8
36+
version: 1.9
3737
context: ./oxybox

oxybox/src/main.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH};
44

55
use tokio::time::sleep;
66
use tokio_native_tls::TlsConnector as TokioTlsConnector;
7-
use trust_dns_resolver::AsyncResolver;
7+
use trust_dns_resolver::{config::{NameServerConfigGroup, ResolverConfig, ResolverOpts}, TokioAsyncResolver};
88

99
pub mod mimir;
1010
use mimir::{client::send_to_mimir, create_probe_metrics};
@@ -23,6 +23,7 @@ fn to_fixed_width(input: &str, width: usize) -> String {
2323
async fn main() {
2424
let config_file_location = std::env::var("CONFIG_FILE").unwrap_or_else(|_| "config.yml".to_string());
2525
let config_str = std::fs::read_to_string(config_file_location).expect("Failed to read config.yaml");
26+
let dns_host = std::env::var("DNS_HOST").unwrap_or_else(|_| "1.1.1.1".to_string());
2627
let config: Config = serde_yaml::from_str(&config_str).expect("Invalid YAML");
2728

2829

@@ -31,7 +32,19 @@ async fn main() {
3132

3233
let tls_connector = builder.build().expect("Failed to build TLS connector");
3334
let tls_connector = TokioTlsConnector::from(tls_connector);
34-
let resolver = AsyncResolver::tokio_from_system_conf().expect("DNS resolver failed");
35+
let mut opts = ResolverOpts::default();
36+
opts.attempts = 3; // Retry up to 3 times
37+
opts.timeout = std::time::Duration::from_millis(500); // Fast timeout
38+
39+
let name_servers = NameServerConfigGroup::from_ips_clear(
40+
&[std::net::IpAddr::V4(dns_host.parse().unwrap())],
41+
53,
42+
true,
43+
);
44+
45+
let resolver_config = ResolverConfig::from_parts(None, vec![], name_servers);
46+
47+
let resolver = TokioAsyncResolver::tokio(resolver_config, opts);
3548

3649
let max_org_width = config
3750
.keys()

0 commit comments

Comments
 (0)