-
Notifications
You must be signed in to change notification settings - Fork 1k
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
inject_connected
and inject_disconnected
might introduce small inefficiencies in NetworkBehaviour
implementers
#2434
Comments
I don't think the fact that we have both I do agree that having both |
implementation wise, protocols typically store information in a |
inject_connected
and inject_disconnected
introduce small inefficienciesinject_connected
and inject_disconnected
might introduce small inefficiencies in NetworkBehaviour
implementors
inject_connected
and inject_disconnected
might introduce small inefficiencies in NetworkBehaviour
implementorsinject_connected
and inject_disconnected
might introduce small inefficiencies in NetworkBehaviour
implementers
fixed title to make the point more clear. On one hand it may be a bit confusing the existence of both methods; but beyond this it also splits the logic required to handle new and closed connections/peers in a two step process in each protocol. Doing what protocols require to "unify" back this logic is what typically will produce a small inefficiency. I also see as an advantage to removing the It also aligns nicely with |
This has historical reasons because originally, |
@divagant-martian do you want to propose a patch combining the four methods into two? |
That's my suggestion. If you ask if I would be giving a PR for this, yes. But I'd like to first gather thoughts on the matter. I guess that's the reason for opening this issue |
Checking the implemented protocols (gossipsub, kad, relay, req/resp and floodsub, mdns and identify) all but floodsub and mdns implement at least a pair of the coupled methods:
inject_connection_(closed|establised)
and the correspondinginject_(disconnected|connected)
from theNetworkBehaviour
trait.This seems to be because the protocols require pieces of information that are not given together: i.e connection direction and whether this connection is the last/first. In the general case the means the protocol implementing the trait retrieves the same
Peer_id
twice for every first connection and final disconnection. This could be avoided removinginject_disconnected
andinject_connected
and simply passing the number of connections as a parameter. If a protocol cares to check for the conditions for disconnections/connections it would mean to move the check that the swarm already does about the number of connections to the protocol.The text was updated successfully, but these errors were encountered: