Deduplication for dns records

This commit is contained in:
Slatian 2023-02-25 12:08:46 +01:00
parent c1cd66782f
commit 9f3b6d0c17
2 changed files with 6 additions and 6 deletions

View File

@ -41,13 +41,13 @@ pub struct DnsLookupResult {
timeout: bool, timeout: bool,
} }
#[derive(serde::Deserialize, serde::Serialize, Clone)] #[derive(serde::Deserialize, serde::Serialize, Clone, PartialEq)]
pub struct MxRecord { pub struct MxRecord {
preference: u16, preference: u16,
exchange: String, exchange: String,
} }
#[derive(serde::Deserialize, serde::Serialize, Clone)] #[derive(serde::Deserialize, serde::Serialize, Clone, PartialEq)]
pub struct SoaRecord { pub struct SoaRecord {
mname: String, mname: String,
rname: String, rname: String,
@ -58,7 +58,7 @@ pub struct SoaRecord {
minimum: u32, minimum: u32,
} }
#[derive(serde::Deserialize, serde::Serialize, Clone)] #[derive(serde::Deserialize, serde::Serialize, Clone, PartialEq)]
pub struct SrvRecord { pub struct SrvRecord {
priority: u16, priority: u16,
weight: u16, weight: u16,
@ -95,12 +95,12 @@ pub async fn reverse_lookup(
} }
} }
pub fn opush<T>(opt_vec: &mut Option<Vec<T>>, data: T) { pub fn opush<T: std::cmp::PartialEq>(opt_vec: &mut Option<Vec<T>>, data: T) {
if opt_vec.is_none() { if opt_vec.is_none() {
*opt_vec = Some(Default::default()); *opt_vec = Some(Default::default());
} }
match opt_vec { match opt_vec {
Some(vec) => vec.push(data), Some(vec) => if !vec.contains(&data) { vec.push(data) },
None => {}, None => {},
} }
} }

View File

@ -41,7 +41,7 @@
{% if r.cname %} {% if r.cname %}
<p>This domain has a cname set, this means its contents are full replaced by the linked record.</p> <p>This domain has a cname set, this means its contents are full replaced by the linked record.</p>
<p class="button-paragraph">{{ helper::dig(extra=extra, name=r.cname[1]) }}</p> <p class="button-paragraph">{{ helper::dig(extra=extra, name=r.cname[0]) }}</p>
</p>Usually you get the <code>A</code> and <code>AAAA</code> records for the linked record to avoid uneccessary requests. If anything else resolves, that is a violation of the DNS specification.</p> </p>Usually you get the <code>A</code> and <code>AAAA</code> records for the linked record to avoid uneccessary requests. If anything else resolves, that is a violation of the DNS specification.</p>