[Peerstore] Pin/Unpin interface for peerstore
Open
@aarshkshah1992 is already working on this.
Since Apr 1, 2020.
- Dominant language
- Go
- Stars
- 6.9k
- Forks
- 1.3k
- Avg merge
- 13d 21h
- Merged PRs (30d)
- 1
Description
Motivation
- The peerstore currently allows ANY caller to change the TTL of a peer. For eg: The
Identifyservice changes the TTL of a peer to 10 minutes when a peer disconnects. - However, this can be problematic as we might later want to attempt a reconnection to the same peer after the expiry and we will have no address for that peer at that point.
- Please see the "Address Management" section on this comment for a motivating example.
Solution
- The solution is to allow callers to express an interest in keeping the addresses for a peer around longer than mandated by the TTL via a
Pininterface and then proactively undo the action via anUnpininterface. We should also account for buggy subsystems that forget toUnpin. - See https://github.com/libp2p/go-libp2p-core/pull/117 for a first stab at the implementation and the comment by @raulk on the PR to understand the subtleties involved in implementation of this issue.
Design Notes(to be refined)
- Subsystems holding onto a peer Pin() that peer, and Unpin() when they’re done.
- We refcount, and only peers with refcount = 0 are subject to expiry.
- We need to worry about badly-behaved / buggy subsystems.
- We should make pinning “best-effort”, i.e. the peerstore is not guaranteed to keep the peer pinned. Maybe subsystems can periodically ConfirmPin() to confirm that they still want a peer to stay pinned. We could prune peers that have not been confirmed in a while. Alternatively, pinning could maybe expose a context-like handle, indicating the pin is in effect. Peerstore then can close that pin to indicate it won't be honored unless the interested subsystem re-pins the item.
- On restart, we would garbage collect after a delay of, e.g. 10 min, to give the system time to warm up and restore any pins it actually wants.
Also, take a look at the Protect/Unprotect API in the ConnectionManager interface for inspiration.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.