Skip to content

Commit

Permalink
resolve DNS addresses in P2P behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
sistemd committed Nov 25, 2024
1 parent c45b23d commit eb36a40
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion crates/p2p/src/behaviour.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::collections::{HashMap, VecDeque};
use std::net::IpAddr;
use std::net::{IpAddr, ToSocketAddrs};
use std::time::{Duration, Instant};
use std::{cmp, task};

Expand Down Expand Up @@ -707,6 +707,19 @@ impl Behaviour {
.find_map(|p| match p {
Protocol::Ip4(ip) => Some(IpAddr::V4(ip)),
Protocol::Ip6(ip) => Some(IpAddr::V6(ip)),
Protocol::Dns4(dns) | Protocol::Dns6(dns) => {
// We only care about resolving to an IP address so any port is fine.
let dns_with_port = format!("{}:0", dns);
match dns_with_port.to_socket_addrs() {
Ok(mut addrs) => addrs
.find(|addr| addr.is_ipv4() || addr.is_ipv6())
.map(|addr| addr.ip()),
Err(e) => {
tracing::info!("Failed to resolve DNS address '{}': {}", dns, e);
None
}
}
}
_ => None,
})
.ok_or_else(|| {
Expand Down

0 comments on commit eb36a40

Please sign in to comment.