Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Suggestion
With this pull request I would like to suggest removing the ability of a
NetworkBehaviour
to notify allProtocolHandler
s for a given peer with a singleNetworkBehaviourActionEvent
. More concretely I am suggesting to removeNotifyHandler::All
. Animplementor of
NetworkBehaviour
can still notify allProtocolHandler
s for a given peer by emitting oneNotifyHandler
event per connection to that peer.Reasoning
The general ability to notify all handlers for a peer forces events send from the behaviour to the handler to be
Clone
. Reason is that the swarm needs to forward a clone of the event to each handler. A behaviour that always sends events to a single peer only still has to guarantee that that event isClone
.Example
As a concrete example #1838 implementing the libp2p relay spec needs to send substreams between
ProtocolHandler
s. Substreams are always send to concreteProtocolHandler
s, never to allProtocolHandler
s. Today a substream needs to be wrapped in anArc<Mutex<_>>
(or similar) in order to beClone
before one can send it to anotherProtocolHandler
. Removing the ability to send to allProtocolHandler
s would relief the relay implementation of having to wrap each substream before sending.Alternative
Today the
ExpandedSwarm
requiresTInEvent
to beClone
in order to be able to notify all handlers for a given peer. Instead of removing the feature one could as well introduce a secondTInEvent2
which would not require clone, using the former to notify all handlers and the latter to notify specific handlers. A behaviour only requiring the latter could set the former to()
. In my eyes this alternative would not be worth the complexity it introduces.Users
As far as I can tell
NotifyHandler::All
is not used in rust-libp2p nor Substrate. Does anyone know of any users ofNotifyHandler::All
?Is anyone objecting to this change or has alternative suggestions?