-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Return a sequence of Multiaddr
s in listen_on
.
#1028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This is part of the proposed changes to the `Transport` trait as outlined in [1]. To allow transport implementations to listen on multiple addresses we now report all those addresses as a sequence of multi-addresses instead of supporting only a single one. Instead of making `Transport::listen_on` return a generic iterator a concrete type `MultiaddrSeq` is introduced to support non-emptiness. [1]: libp2p#794 (comment)
Why use a |
From #1028 (comment):
By using a concrete type we get more specific semantics and a simpler implementation. Using a |
@@ -104,15 +104,15 @@ where | |||
/// The produced upgrade. | |||
upgrade: TTrans::ListenerUpgrade, | |||
/// Address of the listener which received the connection. | |||
listen_addr: Multiaddr, | |||
listen_addrs: MultiaddrSeq, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, that's clearly wrong. A connection only arrives on a single multiaddress. We need to put the multiaddr a connection arrives on in the ListenerEvent
.
Do we not want to support emptiness? For the |
Currently, pub trait Transport {
type Output;
type Error: error::Error;
type Listener: Stream<Item = ListenerEvent<Self::ListenerUpgrade>, Error = Self::Error>;
type ListenerUpgrade: Future<Item = Self::Output, Error = Self::Error>;
type Dial: Future<Item = Self::Output, Error = Self::Error>;
fn listen_on(self, addr: Multiaddr) -> Result<Self::Listener, TransportError<Self::Error>>;
fn dial(self, addr: Multiaddr) -> Result<Self::Dial, TransportError<Self::Error>>;
}
enum ListenerEvent<T> {
Upgrade {
upgrade: T,
listen_addr: Multiaddr,
remote_addr: Multiaddr
},
AddressExpired(Multiaddr)
} This may also be a good time to revisit the proposal in [2] which got rejected at the time, to use |
The very pragmatic reason is that a lot tests create a transport or a swarm, make it listen on something, then dial the returned address. I'm not sure which decision to take here. In most situations you know your listened addresses immediately, which is why it makes sense to return them immediately and not in the future. |
We still need to know the addresses that we listen on before we receive a connection. The typical process in Substrate is: we start listening, then we dial a bootstrap node, then we indicate to this bootstrap node which addresses we're listening on, and these addresses are then advertised to the rest of the network. |
I have a branch (master...twittner:listener-event-wip) which contains a work in progress of the interface outlined above, except that /// Event produced by [`Transport::Listener`]s
#[derive(Clone, Debug, PartialEq)]
pub enum ListenerEvent<T> {
/// The transport is listening on a new additional [`Multiaddr`].
NewAddress(Multiaddr),
/// An upgrade, consisting of the upgrade future, the listener address and the remote address.
Upgrade {
/// The upgrade.
upgrade: T,
/// The listening address which produced this upgrade.
listen_addr: Multiaddr,
/// The remote address which produced this upgrade.
remote_addr: Multiaddr
},
/// A [`Multiaddr`] is no longer used for listening.
AddressExpired(Multiaddr)
} I do not think we should also have
Most tests can be adjusted with little effort, however I am unsure how to make listen addresses available to users of |
That was my main concern, but if they can be updated then that's good.
That's obviously not great, as the |
I am closing this PR and point to #1032 which has been rebased to not be a continuation of this PR, but to implement the basic interface described above. |
This is part of the proposed changes to the
Transport
trait as outlined in [1].To allow transport implementations to listen on multiple addresses we now report all those addresses as a sequence of multi-addresses instead of supporting only a single one.
Instead of making
Transport::listen_on
return a generic iterator a concrete typeMultiaddrSeq
is introduced to support non-emptiness.