-
Notifications
You must be signed in to change notification settings - Fork 998
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/: Support generic connection management #2824
Comments
I am currently working on proposal (2), i.e. extending |
How is (2) going to work in terms of composing behaviours? One |
Correct. |
Draft implementation of (2) is happening on #2828. Still work in progress, but might help understand the idea behind (2). Happy to expand on any of this in written form. No need to dig through the code in case you don't want to. |
Going to start on this once #3011 is merged to avoid the churn. |
I think we should design this with a concrete use-case in mind. @divagant-martian would you volunteer overseeing @thomaseizinger can you keep @divagant-martian in the loop? |
@mxinden for sure! I'm also relatively familiar with substrate's peer management and can probably get in touch with the iroh guys to check what needs we have in common and where do those differ |
So here is an alternative idea: Make
|
The proposal would work very well for us and save a lot of time spent on disconnecting peers we were not interested in having in the first place 👍 |
I am in favor of getting rid of
It would be wonderful to have a single mechanism only to create a new handler.
In my eyes this is the way to go. We also achieved consensus on this in #2118 (comment). |
I've put up a draft PR here that aims to build the foundation for the above idea. |
A note on this: From the other party's perspective, it is still a regular disconnect, it just happens automatically within the |
We do still need a mechanism for a (In #2828 that happens via new methods on |
@mxinden wouldn't it be enough making the new handler function fallible? I as I understand this is part of the proposal. Am I missing something? |
Unless I am missing something, the only thing not possible with my proposal is blocking a new incoming connection before the upgrade process is finished. For any policy that purely operates on the number of connections, these upgrades would be wasted (plus they consume resources). |
We could retain a prototype-based system where creating a handler is a two-step process for inbound connections:
The first failure point can be used for pending inbound connections before the upgrade. |
Right, that makes sense and would tackle both cases. Would that be reasonable to add to your current work @thomaseizinger or do you think it should be an effort for a second iteration? |
But that second failure point needs some synchronization mechanism back to a single point of truth, likely living in the Removing the |
Counting policies would use the first failure point, data driven policies like allow/ban lists would use the latter one. List-based policies don't need synchronisation.
The argument for synchronisation with NB stems from it having more knowledge right? But a pending connection doesn't provide any information apart from the incoming multiaddress. This makes me think that policies that need to take into account pending connections are likely going to be resource-based, i.e. RAM usage, number of connections etc. Pushing these policies into NB doesn't feel right.
This makes me think that policing pending connections should either happen in the |
Removing I am tempted to build a version of this that doesn't remove @divagant-martian Would that be sufficient for your usecase? A connection management behaviour would have to create For example, if you have a list of banned peers, you'd copy this list into the prototype upon constructing it in |
I put up a draft PR here for what this could look like: #3118 |
I now have a fully working version of the current codebase without the I think this can be merged as an independent improvement. We can then later decide how we want to manage pending connections. |
Previously, we used the full reference to the `OutEvent` of the `ConnectionHandler` in all implementations of `NetworkBehaviour`. Not only is this very verbose, it is also more brittle to changes. With the current implementation plan for #2824, we will be removing the `IntoConnectionHandler` abstraction. Using a type-alias to refer to the `OutEvent` makes the migration much easier.
Previously, a `ConnectionHandler` was immediately requested from the `NetworkBehaviour` as soon as a new dial was initiated or a new incoming connection accepted. With this patch, we delay the creation of the handler until the connection is actually established and fully upgraded, i.e authenticated and multiplexed. As a consequence, `NetworkBehaviour::new_handler` is now deprecated in favor of a new set of callbacks: - `NetworkBehaviour::handle_pending_inbound_connection` - `NetworkBehaviour::handle_pending_outbound_connection` - `NetworkBehaviour::handle_established_inbound_connection` - `NetworkBehaviour::handle_established_outbound_connection` All callbacks are fallible, allowing the `NetworkBehaviour` to abort the connection either immediately or after it is fully established. All callbacks also receive a `ConnectionId` parameter which uniquely identifies the connection. For example, in case a `NetworkBehaviour` issues a dial via `NetworkBehaviourAction::Dial`, it can unambiguously detect this dial in these lifecycle callbacks via the `ConnectionId`. Finally, `NetworkBehaviour::handle_pending_outbound_connection` also replaces `NetworkBehaviour::addresses_of_peer` by allowing the behaviour to return more addresses to be used for the dial. Resolves #2824. Pull-Request: #3254.
We had multiple requests for rust-libp2p to be able to prevent dialing any private IP addresses. Thus far we have pointed them to the following https://github.com/mxinden/kademlia-exporter/blob/master/src/exporter/client/global_only.rs Somehow I was operating with the assumption that we can now use the generic Unfortunately this is not quite possible. Say that a Should we support the above use-case, e.g. by returning both a set of additional addresses and a set of blocked addresses from I am leaning towards the latter, i.e. not extend the @thomaseizinger any thoughts on this? |
That is something that would be nice to support. It is a bit tricky though. Even if we pass a mutable reference of the existing addresses into the behaviour, you can never guarantee that another behaviour doesn't add more non-global addresses. How effective such a global-ip address management is depends on how you compose your behaviours which is quite the foot-gun. In this case, refusing the dial on the |
Maybe we've mixed too many concerns here by merging |
Agreed with the concerns above. I suggest continuing with the custom |
Currently, banning peers is a first-class feature of `Swarm`. With the new connection management capabilities of `NetworkBehaviour`, we can now implement allow and block lists as a separate module. We introduce a new crate `libp2p-allow-block-list` and deprecate `Swarm::ban_peer_id` in favor of that. Related #2824. Pull-Request: #3590.
Previously, we used the full reference to the `OutEvent` of the `ConnectionHandler` in all implementations of `NetworkBehaviour`. Not only is this very verbose, it is also more brittle to changes. With the current implementation plan for libp2p#2824, we will be removing the `IntoConnectionHandler` abstraction. Using a type-alias to refer to the `OutEvent` makes the migration much easier.
Previously, a `ConnectionHandler` was immediately requested from the `NetworkBehaviour` as soon as a new dial was initiated or a new incoming connection accepted. With this patch, we delay the creation of the handler until the connection is actually established and fully upgraded, i.e authenticated and multiplexed. As a consequence, `NetworkBehaviour::new_handler` is now deprecated in favor of a new set of callbacks: - `NetworkBehaviour::handle_pending_inbound_connection` - `NetworkBehaviour::handle_pending_outbound_connection` - `NetworkBehaviour::handle_established_inbound_connection` - `NetworkBehaviour::handle_established_outbound_connection` All callbacks are fallible, allowing the `NetworkBehaviour` to abort the connection either immediately or after it is fully established. All callbacks also receive a `ConnectionId` parameter which uniquely identifies the connection. For example, in case a `NetworkBehaviour` issues a dial via `NetworkBehaviourAction::Dial`, it can unambiguously detect this dial in these lifecycle callbacks via the `ConnectionId`. Finally, `NetworkBehaviour::handle_pending_outbound_connection` also replaces `NetworkBehaviour::addresses_of_peer` by allowing the behaviour to return more addresses to be used for the dial. Resolves libp2p#2824. Pull-Request: libp2p#3254.
Description
(Taken from #2118 (comment).)
I see 3 ways how we can enable users to do advanced connection management:
pool::ConnectionCounter
generic and allow users to provide their own.Box
ed requires an additional generic parameter.NetworkBehaviour
trait and thus limited in its decision making.NetworkBehaviour
with methods called to review a pending or established connection.NetworkBehaviour
.SwarmEvent::ReviewConnection
requiring the user to manually accept each pending/established connection via e.g.Swarm::accept()
.Motivation
Allows downstream users to do advanced connection management and can simplify existing implementations working around this today.
Are you planning to do it yourself in a pull request?
Yes
The text was updated successfully, but these errors were encountered: