mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-14 10:31:21 +00:00
[libp2p-dns] Implement /dnsaddr
resolution. (#1931)
* Implement `/dnsaddr` support on `libp2p-dns`. To that end, since resolving `/dnsaddr` addresses needs "fully qualified" multiaddresses when dialing, i.e. those that end with the `/p2p/...` protocol, we make sure that dialing always uses such fully qualified addresses by appending the `/p2p` protocol as necessary. As a side-effect, this adds support for dialing peers via "fully qualified" addresses, as an alternative to using a `PeerId` together with a `Multiaddr` with or without the `/p2p` protocol. * Adapt libp2p-relay. * Update versions, changelogs and small cleanups.
This commit is contained in:
@ -113,6 +113,7 @@ use libp2p_core::{
|
||||
transport::{self, TransportError},
|
||||
muxing::StreamMuxerBox,
|
||||
network::{
|
||||
self,
|
||||
ConnectionLimits,
|
||||
Network,
|
||||
NetworkInfo,
|
||||
@ -359,11 +360,11 @@ where TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
|
||||
}
|
||||
|
||||
/// Initiates a new dialing attempt to the given address.
|
||||
pub fn dial_addr(me: &mut Self, addr: Multiaddr) -> Result<(), ConnectionLimit> {
|
||||
pub fn dial_addr(me: &mut Self, addr: Multiaddr) -> Result<(), DialError> {
|
||||
let handler = me.behaviour.new_handler()
|
||||
.into_node_handler_builder()
|
||||
.with_substream_upgrade_protocol_override(me.substream_upgrade_protocol_override);
|
||||
me.network.dial(&addr, handler).map(|_id| ())
|
||||
Ok(me.network.dial(&addr, handler).map(|_id| ())?)
|
||||
}
|
||||
|
||||
/// Initiates a new dialing attempt to the given peer.
|
||||
@ -386,7 +387,7 @@ where TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
|
||||
me.network.peer(*peer_id)
|
||||
.dial(first, addrs, handler)
|
||||
.map(|_| ())
|
||||
.map_err(DialError::ConnectionLimit)
|
||||
.map_err(DialError::from)
|
||||
} else {
|
||||
Err(DialError::NoAddresses)
|
||||
};
|
||||
@ -1053,16 +1054,28 @@ pub enum DialError {
|
||||
/// The configured limit for simultaneous outgoing connections
|
||||
/// has been reached.
|
||||
ConnectionLimit(ConnectionLimit),
|
||||
/// The address given for dialing is invalid.
|
||||
InvalidAddress(Multiaddr),
|
||||
/// [`NetworkBehaviour::addresses_of_peer`] returned no addresses
|
||||
/// for the peer to dial.
|
||||
NoAddresses
|
||||
}
|
||||
|
||||
impl From<network::DialError> for DialError {
|
||||
fn from(err: network::DialError) -> DialError {
|
||||
match err {
|
||||
network::DialError::ConnectionLimit(l) => DialError::ConnectionLimit(l),
|
||||
network::DialError::InvalidAddress(a) => DialError::InvalidAddress(a),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for DialError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
DialError::ConnectionLimit(err) => write!(f, "Dial error: {}", err),
|
||||
DialError::NoAddresses => write!(f, "Dial error: no addresses for peer."),
|
||||
DialError::InvalidAddress(a) => write!(f, "Dial error: invalid address: {}", a),
|
||||
DialError::Banned => write!(f, "Dial error: peer is banned.")
|
||||
}
|
||||
}
|
||||
@ -1072,6 +1085,7 @@ impl error::Error for DialError {
|
||||
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
||||
match self {
|
||||
DialError::ConnectionLimit(err) => Some(err),
|
||||
DialError::InvalidAddress(_) => None,
|
||||
DialError::NoAddresses => None,
|
||||
DialError::Banned => None
|
||||
}
|
||||
|
Reference in New Issue
Block a user