[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

@ -58,14 +58,15 @@ use libp2p::{
NetworkBehaviour,
PeerId,
Swarm,
build_development_transport,
development_transport,
identity,
mdns::{Mdns, MdnsConfig, MdnsEvent},
swarm::NetworkBehaviourEventProcess
};
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 key for ourselves.
@ -73,7 +74,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let local_peer_id = PeerId::from(local_key.public());
// Set up a an encrypted DNS-enabled TCP Transport over the Mplex protocol.
let transport = build_development_transport(local_key)?;
let transport = development_transport(local_key).await?;
// We create a custom network behaviour that combines Kademlia and mDNS.
#[derive(NetworkBehaviour)]