From 5c7d88073315991249d0c33057ce36d9c34f936e Mon Sep 17 00:00:00 2001 From: Slatian Date: Sat, 5 Aug 2023 23:19:53 +0200 Subject: [PATCH] Aded ranking of resolvers by a weight value --- echoip_test.toml | 1 + src/main.rs | 14 ++++++++++---- src/settings.rs | 2 ++ templates/dig.html | 4 ++-- templates/helpers.html | 2 +- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/echoip_test.toml b/echoip_test.toml index 96dde4c..57fbcf7 100644 --- a/echoip_test.toml +++ b/echoip_test.toml @@ -65,6 +65,7 @@ burst = 15 display_name = "Digitalcourage 3" info_url = "https://digitalcourage.de/support/zensurfreier-dns-server" aliases = ["dc","dc3","digitalcourage3"] +weight = 900 servers = ["5.9.164.112:853","[2a01:4f8:251:554::2]:853"] protocol = "tls" diff --git a/src/main.rs b/src/main.rs index 99778c7..c0a6916 100644 --- a/src/main.rs +++ b/src/main.rs @@ -245,7 +245,8 @@ async fn main() { dns_resolver_selectables.push(Selectable { id: "default".to_string(), - name: "System".to_string() + name: "System".to_string(), + weight: 1000, }); //FIXME: Not release ready,must be configurable and have better error handling. @@ -256,7 +257,8 @@ async fn main() { ).unwrap(); dns_resolver_selectables.push(Selectable { id: "quad9".to_string(), - name: "Quad9".to_string() + name: "Quad9".to_string(), + weight: 500 }); println!("Initalizing Google resolver ..."); let google_resolver = TokioAsyncResolver::tokio( @@ -265,7 +267,8 @@ async fn main() { ).unwrap(); dns_resolver_selectables.push(Selectable { id: "google".to_string(), - name: "Google".to_string() + name: "Google".to_string(), + weight: 10, }); println!("Initalizing Cloudflare resolver ..."); let cloudflare_resolver = TokioAsyncResolver::tokio( @@ -274,7 +277,8 @@ async fn main() { ).unwrap(); dns_resolver_selectables.push(Selectable { id: "cloudflare".to_string(), - name: "Cloudflare".to_string() + name: "Cloudflare".to_string(), + weight: 20, }); let mut dns_resolver_map: HashMap = HashMap::new(); @@ -289,6 +293,7 @@ async fn main() { dns_resolver_selectables.push(Selectable { id: key.clone(), name: resolver_config.display_name.clone(), + weight: resolver_config.weight, }); } @@ -311,6 +316,7 @@ async fn main() { config: config.clone(), }); + dns_resolver_selectables.sort_by(|a,b| b.weight.cmp(&a.weight)); let derived_config = DerivedConfiguration { dns_resolver_selectables: dns_resolver_selectables, }; diff --git a/src/settings.rs b/src/settings.rs index 1806235..39ee983 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -1,4 +1,5 @@ use serde::{Deserialize,Serialize}; + /* Response format */ #[derive(Deserialize, Serialize, Clone, Copy)] @@ -45,5 +46,6 @@ pub struct QuerySettings { pub struct Selectable { pub id: String, pub name: String, + pub weight: i32, } diff --git a/templates/dig.html b/templates/dig.html index 2c17877..a4e0d98 100644 --- a/templates/dig.html +++ b/templates/dig.html @@ -4,7 +4,7 @@ {% block title %}dig {{ data.query }}{% endblock %} {% block og_title %}dig {{ data.query }}{% endblock %} -{% block h1 %}dig {{ helper::breadcrumb_domain(extra=extra, name=data.query) }}{% endblock %} +{% block h1 %}dig {{ helper::breadcrumb_domain(extra=extra, name=data.query) }} via {{data.result.used_dns_resolver}}{% endblock %} {% block og_path %}/dig/{{ data.query | urlencode_strict }}{% endblock %} @@ -24,7 +24,7 @@ {% set r = data.result.records %}
-

DNS Records via {{data.result.used_dns_resolver}}

+

DNS Records

{% if r.nxdomain %}

Our DNS-Server claims that this domain doesn't exist, there shouldn't be any results.

diff --git a/templates/helpers.html b/templates/helpers.html index 931cddc..d45fca7 100644 --- a/templates/helpers.html +++ b/templates/helpers.html @@ -31,7 +31,7 @@ {%- set_global i = i+1 -%} {% endfor %} -{% endmacro breadcrumb_domain %} +{%- endmacro breadcrumb_domain %} {% macro ip_info(ip_info) -%} {{ip_info.scope | title}} {{ip_info.cast | title}} IPv{% if ip_info.is_v6_address %}6{% else %}4{% endif %}