-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
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 Pin/Unpin peer addresses go-libp2p-core#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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels