mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-22 14:21:33 +00:00
Expand wildcard IP addresses in TCP transport. (#1044)
Wildcard IP addresses (e.g. 0.0.0.0) are used to listen on all host interfaces. To report those addresses such that clients know about them and can actually make use of them we use the `get_if_addrs` crate and maintain a collection of addresses. We report the whole expansion at the very beginning of the listener stream with `ListenerEvent::NewAddress` events and add new addresses should they come to our attention. What remains to be done is to potentially allow users to filter IP addresses, for example the local loopback one, and to detect expired addresses not only if a new address is discovered.
This commit is contained in:
@ -288,6 +288,15 @@ impl<T> ListenerEvent<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if this is an `Upgrade` listener event.
|
||||
pub fn is_upgrade(&self) -> bool {
|
||||
if let ListenerEvent::Upgrade {..} = self {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// Try to turn this listener event into upgrade parts.
|
||||
///
|
||||
/// Returns `None` if the event is not actually an upgrade,
|
||||
@ -300,6 +309,15 @@ impl<T> ListenerEvent<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if this is a `NewAddress` listener event.
|
||||
pub fn is_new_address(&self) -> bool {
|
||||
if let ListenerEvent::NewAddress(_) = self {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// Try to turn this listener event into the `NewAddress` part.
|
||||
///
|
||||
/// Returns `None` if the event is not actually a `NewAddress`,
|
||||
@ -312,6 +330,15 @@ impl<T> ListenerEvent<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if this is an `AddressExpired` listener event.
|
||||
pub fn is_address_expired(&self) -> bool {
|
||||
if let ListenerEvent::AddressExpired(_) = self {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// Try to turn this listener event into the `AddressExpired` part.
|
||||
///
|
||||
/// Returns `None` if the event is not actually a `AddressExpired`,
|
||||
|
Reference in New Issue
Block a user