Skip to content
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
26 changes: 26 additions & 0 deletions src/dns/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,32 @@ mod tests {
assert!(!records[1].has_ttl);
}

#[test]
fn test_platform_records_deduplicate_addresses_in_first_seen_order() {
let records = records_from_ip_addrs([
"2001:db8::2".parse().unwrap(),
"192.0.2.2".parse().unwrap(),
"2001:db8::1".parse().unwrap(),
"192.0.2.2".parse().unwrap(),
"192.0.2.1".parse().unwrap(),
"2001:db8::2".parse().unwrap(),
]);

let actual: Vec<_> = records
.iter()
.map(|record| (record.typ.as_str(), record.value.as_str()))
.collect();
assert_eq!(
actual,
[
("AAAA", "2001:db8::2"),
("A", "192.0.2.2"),
("AAAA", "2001:db8::1"),
("A", "192.0.2.1"),
]
);
}

#[test]
fn test_render_shows_unavailable_ttl_per_record() {
let out = render(&Inspection {
Expand Down
2 changes: 1 addition & 1 deletion src/dns/inspect/rdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const DNS_TYPE_HTTPS: u16 = wire::TYPE_HTTPS;
const DNS_TYPE_CAA: u16 = wire::TYPE_CAA;

pub(super) fn records_from_ip_addrs(addrs: impl IntoIterator<Item = IpAddr>) -> Vec<Record> {
addrs
crate::dns::ordered_unique_ip_addrs(addrs)
.into_iter()
.map(|ip| {
let typ = if ip.is_ipv4() { "A" } else { "AAAA" };
Expand Down
12 changes: 12 additions & 0 deletions src/dns/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::net::IpAddr;

pub(crate) mod custom;
pub mod doh;
pub(crate) mod error;
Expand All @@ -7,3 +9,13 @@ pub(crate) mod svcb;
pub(crate) mod transport;
pub(crate) mod util;
pub(crate) mod wire;

pub(crate) fn ordered_unique_ip_addrs(addrs: impl IntoIterator<Item = IpAddr>) -> Vec<IpAddr> {
let mut unique = Vec::new();
for addr in addrs {
if !unique.contains(&addr) {
unique.push(addr);
}
}
unique
}
16 changes: 3 additions & 13 deletions src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ async fn resolve_dns_for_client_inner(
)
.await?;
let https_records = https_lookup.records;
let timing_addrs = dns_timing_addrs(addrs.iter().copied());
let timing_addrs = crate::dns::ordered_unique_ip_addrs(addrs.iter().copied());
let socket_addrs = custom::socket_addrs_for_override(&addrs);
let auto_http3_config = auto_http3_config_for_records(
&https_records,
Expand Down Expand Up @@ -459,7 +459,7 @@ async fn resolve_dns_for_client_inner(
.await?;
let effective_host = https_records.fallback_target;
let https_records = https_records.records;
let addrs = dns_timing_addrs(socket_addrs.iter().map(|addr| addr.ip()));
let addrs = crate::dns::ordered_unique_ip_addrs(socket_addrs.iter().map(|addr| addr.ip()));
let auto_http3_config =
auto_http3_config_for_records(&https_records, &effective_host, &socket_addrs);
if auto_http3 && https_lookup_succeeded {
Expand Down Expand Up @@ -702,16 +702,6 @@ fn auto_http3_optional_lookup_timeout_for_remaining(
}
}

fn dns_timing_addrs(addrs: impl IntoIterator<Item = IpAddr>) -> Vec<IpAddr> {
let mut unique = Vec::new();
for addr in addrs {
if !unique.contains(&addr) {
unique.push(addr);
}
}
unique
}

fn configure_dns_resolution(
builder: ClientBuilder,
host: Option<&str>,
Expand Down Expand Up @@ -1246,7 +1236,7 @@ mod tests {
"::2".parse().unwrap(),
];

let display_addrs = dns_timing_addrs(addrs);
let display_addrs = crate::dns::ordered_unique_ip_addrs(addrs);

assert_eq!(
display_addrs,
Expand Down
12 changes: 1 addition & 11 deletions src/http/transport/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,22 +760,12 @@ pub(super) fn record_dns_addrs_trace(
socket_addrs: addrs.to_vec(),
timing: Some(DnsTiming {
host: host.to_string(),
addrs: dns_timing_addrs(addrs.iter().map(|addr| addr.ip())),
addrs: crate::dns::ordered_unique_ip_addrs(addrs.iter().map(|addr| addr.ip())),
duration,
}),
});
}

fn dns_timing_addrs(addrs: impl IntoIterator<Item = IpAddr>) -> Vec<IpAddr> {
let mut unique = Vec::new();
for addr in addrs {
if !unique.contains(&addr) {
unique.push(addr);
}
}
unique
}

pub(super) fn alpn_for_config(config: &ClientConfig) -> Vec<Vec<u8>> {
match config.mode {
Some(HttpVersion::Http1) => vec![b"http/1.1".to_vec()],
Expand Down
Loading