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

Add transport support for dnsaddr #1450

Closed
wants to merge 8 commits into from

Conversation

ackintosh
Copy link
Contributor

@ackintosh ackintosh commented Feb 12, 2020

@@ -170,7 +176,56 @@ where
})
.next()
.ok_or_else(|| DnsErr::ResolveFail(name))
}.left_future()
}.boxed().left_future()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You normally don't have to box the future. Just put an async block around the entire code instead of having two distinct async blocks.

Since this is a lot of code, it might be worth moving it to a separate freestanding function.

assert_eq!(addr.len(), 3);
// TODO: ipfs
// match addr[2] {
// Protocol::Ipfs(_) => (),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll file another PR to add the ipfs support.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@tomaka tomaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, there's obviously quite a lot of TODOs

transports/dns/src/lib.rs Outdated Show resolved Hide resolved
use trust_dns_client::udp::UdpClientConnection;
use trust_dns_client::client::{SyncClient, Client};
use trust_dns_proto::rr::domain::Name;
use futures::stream::FuturesOrdered;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please merge with the use futures:: above.

@@ -238,6 +225,90 @@ where TErr: error::Error + 'static
}
}

async fn resolve_dns<T>(p: Protocol<'_>, suffix: Multiaddr) -> Result<Multiaddr, DnsErr<T::Error>>
where
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These where bounds shouldn't be necessary.

Suggested change
where

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated at fcc3d6a .

If T: Transport is removed we'll get the error:

error[E0220]: associated type `Error` not found for `T`
   --> transports/dns/src/lib.rs:228:89
    |
228 | async fn resolve_dns<T>(p: Protocol<'_>, suffix: Multiaddr) -> Result<Multiaddr, DnsErr<T::Error>>
    |                                                                                         ^^^^^^^^ associated type `Error` not found

{
match p {
Protocol::Dns4(ref n) | Protocol::Dns6(ref n) => {
let name = n.to_string();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let name = n.to_string();

T::Dial: Send
{
match p {
Protocol::Dns4(ref n) | Protocol::Dns6(ref n) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Protocol::Dns4(ref n) | Protocol::Dns6(ref n) => {
Protocol::Dns4(ref name) | Protocol::Dns6(ref name) => {

Err(e) => Err(e)
}.map_err(|_| {
error!("DNS resolver crashed");
DnsErr::ResolveFail(name.clone())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DnsErr::ResolveFail(name.clone())
DnsErr::ResolveFail(name.to_string())

if suffix.len() == 0 {
Ok(resolved_addrs[0].clone())
} else {
// TODO: suffix matching
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd that this is out of scope of this function.

}
Protocol::Dnsaddr(ref n) => {
let conn = UdpClientConnection::new("8.8.8.8:53".parse().unwrap()).unwrap(); // TODO: error handling
let client = SyncClient::new(conn); // TODO: should use async client?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// TODO: should use async client?

Yes!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm...

I've added trust-dns in order to query TXT records. I'm trying to switch the SyncClient to AsyncClient but I think AsyncClient can not be used for rust-libp2p because a background future is required for the client. 🤔

https://docs.rs/trust-dns-client/0.19.3/trust_dns_client/#async-usage

// Create a new client, the bg is a background future which handles
//   the multiplexing of the DNS requests to the server.
//   the client is a handle to an unbounded queue for sending requests via the
//   background. The background must be scheduled to run before the client can
//   send any dns requests
let client = AsyncClient::connect(stream);

// await the connection to be established
let (mut client, bg) = runtime.block_on(client).expect("connection failed");

// make sure to run the background task
runtime.spawn(bg);

======

Do you know other library what can query TXT records asynchronously? 💦

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think AsyncClient can not be used for rust-libp2p because a background future is required for the client.

That makes it more difficult to implement, but normally not impossible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is not to run the background future in the background, but to run it alongside with the "front" one. I don't have more precise guidelines without looking deeply into details (which I don't really have the time right now to do) though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've thought for a while about this but I can not come up anything to address the issue... hmm... 🤔💦

@romanb
Copy link
Contributor

romanb commented Jan 25, 2021

Superseded by #1931.

@romanb romanb closed this Jan 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants