Skip to content
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: Remove NotifyHandler::All #1880

Merged
merged 3 commits into from
Dec 17, 2020
Merged

Conversation

mxinden
Copy link
Member

@mxinden mxinden commented Dec 8, 2020

Suggestion

With this pull request I would like to suggest removing the ability of a NetworkBehaviour to notify all ProtocolHandlers for a given peer with a single NetworkBehaviourActionEvent. More concretely I am suggesting to remove NotifyHandler::All. An
implementor of NetworkBehaviour can still notify all ProtocolHandlers for a given peer by emitting one NotifyHandler 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 is Clone.

Example

As a concrete example #1838 implementing the libp2p relay spec needs to send substreams between ProtocolHandlers. Substreams are always send to concrete ProtocolHandlers, never to all ProtocolHandlers. Today a substream needs to be wrapped in an Arc<Mutex<_>> (or similar) in order to be Clone before one can send it to another ProtocolHandler. Removing the ability to send to all ProtocolHandlers would relief the relay implementation of having to wrap each substream before sending.

Alternative

Today the ExpandedSwarm requires TInEvent to be Clone in order to be able to notify all handlers for a given peer. Instead of removing the feature one could as well introduce a second TInEvent2 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 of NotifyHandler::All?

Is anyone objecting to this change or has alternative suggestions?

Remove `NotifyHandler::All` thus removing the requirement for events
send from a `NetworkBehaviour` to a `ProtocolsHandler` to be `Clone`. An
implementor of `NetworkBehaviour` can still notify all
`ProtocolHandler`s for a given peer by emitting one `NotifyHandler`
event per connection to that peer.
Copy link
Contributor

@romanb romanb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am in favor as this is a good simplification. For the record here, NotifyHandler::All was explicitly introduced for substrate. So if it is no longer used there, that is a good thing. I just hope no-one else relies on it for its protocols and hence needs to adapt the code accordingly.

@romanb
Copy link
Contributor

romanb commented Dec 15, 2020

@mxinden Feel free to go ahead with this PR at your convenience.

@mxinden
Copy link
Member Author

mxinden commented Dec 15, 2020

@tomaka any objections to this change? Are you aware of any (Polkadot) protocols that plan to use NotifyHandler::All?

@tomaka
Copy link
Member

tomaka commented Dec 17, 2020

Go ahead, this is a positive change to me.

@mxinden mxinden merged commit 22817b5 into libp2p:master Dec 17, 2020
@mxinden mxinden mentioned this pull request Sep 5, 2022
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants