-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: resolve domains in enode strings
- Loading branch information
Showing
18 changed files
with
355 additions
and
36 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//! Resolves a [DNSNodeRecord] to a [NodeRecord] by looking up the record in the DNS system. | ||
|
||
use reth_network_types::{DNSNodeRecord, NodeRecord}; | ||
use std::io::Error; | ||
use url::Host; | ||
|
||
/// Resolves the host in a [DNSNodeRecord] to an IP address, returning a [NodeRecord]. If the domain | ||
/// cannot be resolved, an error is returned. | ||
/// | ||
/// If the host is already an IP address, the [NodeRecord] is returned immediately. | ||
pub async fn resolve_dns_node_record(node_record: DNSNodeRecord) -> Result<NodeRecord, Error> { | ||
let domain = match node_record.host { | ||
Host::Ipv4(ip) => { | ||
let id = node_record.id; | ||
let tcp_port = node_record.tcp_port; | ||
let udp_port = node_record.udp_port; | ||
|
||
return Ok(NodeRecord { address: ip.into(), id, tcp_port, udp_port }) | ||
} | ||
Host::Ipv6(ip) => { | ||
let id = node_record.id; | ||
let tcp_port = node_record.tcp_port; | ||
let udp_port = node_record.udp_port; | ||
|
||
return Ok(NodeRecord { address: ip.into(), id, tcp_port, udp_port }) | ||
} | ||
Host::Domain(domain) => domain, | ||
}; | ||
|
||
let mut ips = tokio::net::lookup_host(domain).await?; | ||
let ip = ips | ||
.next() | ||
.ok_or_else(|| Error::new(std::io::ErrorKind::AddrNotAvailable, "No IP found"))?; | ||
|
||
Ok(NodeRecord { | ||
address: ip.ip(), | ||
id: node_record.id, | ||
tcp_port: node_record.tcp_port, | ||
udp_port: node_record.udp_port, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.