-
Notifications
You must be signed in to change notification settings - Fork 17
Add peer protection capability (implementation) #36
Conversation
Users can call Protect() to save a peer from pruning, and Unprotect() to remove the protection. Protected peers don't count towards the target quantity to prune during a connection manager cycle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's refcount the protections.
I don’t think we want to do refcounting here as this is intented to behave like a whitelist. Refcounting will be needed for temporary connection locking when we introduce it IMO. |
I can easily see this being used for other purposes. If it is a whitelist, then it should be documented as such and possibly not provide The concern is the application calling |
@vyzo agree that's confusing. I tend to prefer intuitive method signatures. I can add an |
Also slightly reworked the loop that selects candidates to prune to make it better behaved. Before, if we needed to prune N connections, we preselected N and ended up doing nothing if they happened to be in the grace period. Now we skip over them and prune ungraced connections until we meet our target.
@vyzo: I picked @Stebalien's brain yesterday. We definitely expect this API to behave idempotently, so we don't want to do refcounting (there will be an API for locking connections transactionally in the near future). However, we did realise that different subsystems could interfere with each other if they were managing protections. I think this might be what you were getting at. So I've just pushed a new version that scopes protections by tag, both here and in the interface repo: libp2p/go-libp2p-interface-connmgr#14. Also enhanced the docs to explain the behaviour clearly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's acceptable.
Users can call
Protect()
to save a peer from pruning, andUnprotect()
to remove the protection.Protected peers don't count towards the target quantity to prune during a connection manager cycle. That is, if we have 10 peers, and we need to prune 5, where 3 are protected but would've otherwise been selected, we will still prune 5 peers, saving the protected 3 from pruning.
This is the implementation for libp2p/go-libp2p-interface-connmgr#14.
Enables ipfs/kubo#6097.
NOTE: this will need a gomod release on the interface repo, and an upgrade here.