-
Notifications
You must be signed in to change notification settings - Fork 1k
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: add support for Offline Usage with libp2p::SwarmBuilder with_dns #5903
Comments
Just playing with it a bit I came up with this hacky solution. Though I would also note it might be better to introduce a jsut higher-order function, such as This function would attempt to apply the system DNS configuration, but if an error occur whether from system_conf it would seamlessly fall back to localhost DNS settings without logging a warning, keeping the main logic concise and maintainable.
...
pub fn system(inner: T) -> Result<Transport<T>, std::io::Error> {
let (cfg, opts) = system_conf::read_system_conf().unwrap_or_else(|_| {
tracing::warn!("Unable to read /etc/resolv.conf, using localhost DNS");
(Self::localhost_resolver_config(), ResolverOpts::default())
});
Ok(Self::custom(inner, cfg, opts))
}
fn localhost_resolver_config() -> ResolverConfig {
ResolverConfig::from_parts(
None,
vec![],
vec![
NameServerConfig {
socket_addr: SocketAddr::new(
std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST),
53,
),
protocol: hickory_resolver::proto::xfer::Protocol::Udp,
tls_dns_name: None,
http_endpoint: None,
trust_negative_responses: false,
bind_addr: None,
},
NameServerConfig {
socket_addr: SocketAddr::new(
std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST),
53,
),
protocol: hickory_resolver::proto::xfer::Protocol::Tcp,
tls_dns_name: None,
http_endpoint: None,
trust_negative_responses: false,
bind_addr: None,
},
],
)
}
... |
HI @LVivona, thanks for your detailed report. There is already a function Generally I am wondering: wouldn't it be easier in your scenario to just add a feature flag that handles the case of a offline node, and build the transport with and without dns depending on that feature flag? |
Thanks for the reply, @elenaf9 You're right using custom setting with I guess my follow-up, is whether localhost should still be considered within the scope of |
What do you mean with local DNS resolution? Requests to the OS dns cache? Or are you running a local DNS resolver? |
Description
I was running a local build and had with_dns enabled, but I didn't have Wi-Fi in this instance, which it understandably threw me the error.
I'd like to avoid un-commenting it if possible and just have the function with_dns downgrade back to the previous step builder phase in the small case of testing within the builder SawmBuilder with_dns within a local environment without a connection to the internet.
Motivation
Current Implementation
There exist not current implementation as I am aware. without commentating it in the instance to which I have no internet
Are you planning to do it yourself in a pull request?
Yes
The text was updated successfully, but these errors were encountered: