Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dns: Resolve DNS address to multiple IP addresses to make dialing more robust #241

Open
lexnv opened this issue Sep 9, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@lexnv
Copy link
Collaborator

lexnv commented Sep 9, 2024

The current DNS implementation extracts the first IP address from the DNS translation.
In practice, this works most of the time, however the DNS translation can produce multiple IP addresses.

let lookup =
match TokioAsyncResolver::tokio(ResolverConfig::default(), ResolverOpts::default())
.lookup_ip(url.clone())
.await

Returns a list of resolved IP addresses from the DNS component.

This helps improve the dialing attempts made by TCP and WebSocket transports.
When the transport fails to dial the first IP, it can move on to the next one until addresses are exhausted (or limit reached).

This is the code where we take into account the first address we find:

let Some(ip) = lookup.iter().find(|ip| match dns_type {
DnsType::Dns => true,
DnsType::Dns4 => ip.is_ipv4(),
DnsType::Dns6 => ip.is_ipv6(),
}) else {
tracing::debug!(
target: LOG_TARGET,
"Multiaddr DNS type does not match IP version `{}`",
url
);
return Err(DnsError::IpVersionMismatch);
};
Ok(SocketAddr::new(ip, port))

@lexnv lexnv added the enhancement New feature or request label Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant