[libp2p-dns] Use trust-dns-resolver (with either async-std or tokio). Remove thread pool. (#1927)

* [libp2p-dns] Use trust-dns-resolver.

Use the `trust-dns-resolver` library for DNS resolution,
thereby removing current use of the thread pool.

Since `trust-dns-resolver` and related crates already
provide support for both `async-std` and `tokio`, we
make use of that here in our own feature flags.

Since `trust-dns-resolver` provides many useful
configuration options and error detail, central
types of `trust-dns-resolver` like `ResolverConfig`,
`ResolverOpts` and `ResolveError` are re-exposed
in the API of `libp2p-dns`. Full encapsulation
does not seem preferable in this case.

* Cleanup

* Fix two intra-doc links.

* Simplify slightly.

* Incorporate review feedback.

* Remove git dependency and fix example.

* Update version and changelogs.
This commit is contained in:
Roman Borschel
2021-03-16 11:48:48 +01:00
committed by GitHub
parent 9dbc90efe7
commit cd15bc9c62
12 changed files with 334 additions and 211 deletions

View File

@@ -43,7 +43,8 @@ use futures::{future, prelude::*};
use libp2p::{identity, PeerId, ping::{Ping, PingConfig}, Swarm};
use std::{error::Error, task::{Context, Poll}};
fn main() -> Result<(), Box<dyn Error>> {
#[async_std::main]
async fn main() -> Result<(), Box<dyn Error>> {
env_logger::init();
// Create a random PeerId.
@@ -52,7 +53,7 @@ fn main() -> Result<(), Box<dyn Error>> {
println!("Local peer id: {:?}", peer_id);
// Create a transport.
let transport = libp2p::build_development_transport(id_keys)?;
let transport = libp2p::development_transport(id_keys).await?;
// Create a ping network behaviour.
//