mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-29 01:31:33 +00:00
Support /dns protocol in multiaddr (#1575)
* Add /dns protocol support to multiaddr The /dns protocol has been added to the spec and has had a de-facto meaning for years. See https://github.com/multiformats/multiaddr/pull/100 This adds address parsing and encoding support for /dns to the multiaddr format library. * Cover Dns protocol in multiaddr property tests * transports/dns: Support the /dns protocol * Support /dns protocol in address translation * Translate an FQDN URL into a /dns multiaddr * transports/websocket: Support /dns multiaddr * Use the /dns protocol in websocket redirects The whole thing with back-translating from an redirect URL looks a bit baroque, but at least now the transport does not completely ignore IPv6 addresses resolved from a hostname in a redirect URL. * Add CHANGELOG entry Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
This commit is contained in:
@ -37,9 +37,14 @@ use multiaddr::{Multiaddr, Protocol};
|
||||
/// If the first [`Protocol`]s are not IP addresses, `None` is returned instead.
|
||||
pub fn address_translation(original: &Multiaddr, observed: &Multiaddr) -> Option<Multiaddr> {
|
||||
original.replace(0, move |proto| match proto {
|
||||
Protocol::Ip4(_) | Protocol::Ip6(_) | Protocol::Dns4(_) | Protocol::Dns6(_) => match observed.iter().next() {
|
||||
Protocol::Ip4(_)
|
||||
| Protocol::Ip6(_)
|
||||
| Protocol::Dns(_)
|
||||
| Protocol::Dns4(_)
|
||||
| Protocol::Dns6(_) => match observed.iter().next() {
|
||||
x @ Some(Protocol::Ip4(_)) => x,
|
||||
x @ Some(Protocol::Ip6(_)) => x,
|
||||
x @ Some(Protocol::Dns(_)) => x,
|
||||
x @ Some(Protocol::Dns4(_)) => x,
|
||||
x @ Some(Protocol::Dns6(_)) => x,
|
||||
_ => None,
|
||||
|
Reference in New Issue
Block a user