Skip to content

Commit

Permalink
Merge pull request #2406 from eqlabs/sistemd/resolve-dns-address-in-p2p
Browse files Browse the repository at this point in the history
feat(p2p): resolve DNS addresses in P2P behaviour
  • Loading branch information
sistemd authored Nov 26, 2024
2 parents c45b23d + eb36a40 commit dd9bb0b
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 dd9bb0b

Please sign in to comment.