-
Notifications
You must be signed in to change notification settings - Fork 949
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
swarm/: NetworkBehaviour
/ConnectionHandler
cross-communication
#2680
Comments
NetworkBehaviour
cross-communication
Supported protocols are connection-specific so this should likely be reported on a connection-level by I think there is also a nice symmetry here: A peer changing its supported protocols only concerns that one connection so we should only tell that one |
I have never thought about it this way. Thus far in 👍 I think this is worth exploring. |
I just realized that the above may be too rust-libp2p specific. In here, protocols are connection-specific (because bound to a Going back to the specific kademlia example: In theory, a node could be publicly reachable on one transport (i.e. QUIC) but not on another (i.e. TCP) so each |
Do we have any recommendations in the specs for this? cc @MarcoPolo Is a node expected to report (and support) the same set of protocols on each connection? |
I don't think this is specified anywhere.
That was my mind-set thus far, with the exception of relayed connections. All that said, I am in favor of exploring the approach you propose above. |
I opened an issue to discuss this: libp2p/specs#525
Sounds good, I'll work on this next after finishing up generic connection management. |
I think it would be nice to have #2831 for this. |
I've put some more thought into this after looking at the code:
|
In #3579, an idea came up that touches on this issue. In the same way that #3651 immediately re-injects all protocols gathered from the This would allow us to build a standalone address book component that can learn about the addresses of peers from other behaviours such as identify, kademlia or gossipsub. This could make it obsolete for each of these behaviours to participate in storing and emitting addresses upon a new peer being dialed. |
Alternatively, we could add a first-class address book to |
NetworkBehaviour
cross-communicationNetworkBehaviour
/ConnectionHandler
cross-communication
With this patch, implementations of `ConnectionHandler` (which are typically composed in a tree) can exchange information about the supported protocols of a remote with each other via `ConnectionHandlerEvent::ReportRemoteProtocols`. The provided `ProtocolSupport` enum can describe either additions or removals of the remote peer's protocols. This information is aggregated in the connection and passed down to the `ConnectionHandler` via `ConnectionEvent::RemoteProtocolsChange`. Similarly, if the listen protocols of a connection change, all `ConnectionHandler`s on the connection will be notified via `ConnectionEvent::LocalProtocolsChange`. This will allow us to eventually remove `PollParameters` from `NetworkBehaviour`. This pattern allows protocols on a connection to communicate with each other. For example, protocols like identify can share the list of (supposedly) supported protocols by the remote with all other handlers. A protocol like kademlia can accurately add and remove a remote from its routing table as a result. Resolves: #2680. Related: #3124. Pull-Request: #3651.
With #3651, we've merged the necessary support for this to enable kademlia client mode. More importantly, this also sets a direction for how we want to resolve similar problems. In particular, the design to follow is to emit an event and immediately inject it into the component again. Having this concept in place should make it straight-forward to implement the support for other solutions once the need arises. |
Description
Today there is no way to send generic local and remote node information from one
NetworkBehaviour
to anotherNetworkBehaviour
, apart fromNetworkBehaviour::inject_new_external_addr
.Examples of such generic information could be:
Motivation
One example use-case is the exchange of information between
libp2p-identify
andlibp2p-kad
to support Kademlia Client Mode (see #2032).libp2p-kad
needs to know whether a remote peer advertises/ipfs/kad/1.0.0
via the identify protocol to decide whether to include the remote peer in its routing table or not.libp2p-identify
needs to know whether the local node runs in client or in server mode, i.e. supports the/ipfs/kad/1.0.0
or not.See #2521 which is currently blocked on this.
Proposal
Below is an initial action plan proposal based on a meeting with @MarcoPolo.
NetworkBehaviourAction
withNetworkBehaviourAction::ReportRemoteMetaData
, containing a delta update.NetworkBehaviourAction::inject_remote_metadata
.Select
NetworkBehaviour
which takes twoNetworkBehaviour
implementations and passesReportRemoteMetaData
emitted by one behaviour to the other viainject_remote_metadata
.libp2p-kad
can learn supported protocols of remote peers fromlibp2p-identify
.NetworkBehaviourAction
withNetworkBehaviourAction::ReportSupportedProtocol
which eachNetworkBehaviour
emits when it supports a protocol as a listener and which is passed to otherNetworkBehaviour
s via theSelect
NetworkBehaviour
.libp2p-kad
moved from client mode into server mode vialibp2p-identify
.inject_*
methods into singleinject_event
method with a singleenum
. Motivation here is to not have yet anotherinject_***
method onNetworkBehaviour
.Select
behaviour logic inlibp2p-swarm-derive
and merge.Swarm
(e.g.add_remote_metadata
) which would callNetworkBehaviour::inject_event(Event::RemoteMetaData)
on the rootNetworkBehaviour
.AddressBook
type which eachNetworkBehaviour
can instantiate and pass a reference frominject_event
into to track peer metadata.Open questions
Are you planning to do it yourself in a pull request?
No, or at least not any time soon.
The text was updated successfully, but these errors were encountered: