Repository navigation
feat(pstore): cap unconnected addrs per peer - #3486
Merged
Merged
Conversation
Third-party peers (e.g. via DHT gossip) can flood the peerstore with stale or misconfigured addresses for a single peer id. Real-world delegated-routing responses top out around 26 addrs per well-connected node, but a misbehaving peer can push hundreds before the global peerstore cap kicks in, crowding out good addrs during dial selection. Bound the stored unconnected addrs per peer to 64 by default and evict the unconnected entry with the nearest expiry when the cap is reached. This naturally sheds short-TTL gossip (TempAddrTTL) before longer-lived identify-backed entries (RecentlyConnectedAddrTTL) without tracking provenance. Addrs held by a live connection are never counted toward the cap and never evicted. - `WithMaxAddressesPerPeer(n)` lets callers tune the cap. - Enforcement lives in `addAddrsUnlocked` and `SetAddrs`, the two write paths that can grow the per-peer set. - Shared-suite `SetNegativeTTLClears` adds 100 addrs, above the new default; the inmem test factory raises the cap to 10000 so the shared suite keeps exercising general behavior rather than the cap path.
Mirror the per-peer address cap from pstoremem in the datastore-backed addr book so both backends bound peerstore pollution from sources like DHT gossip. Adds Options.MaxAddrsPerPeer (default 64); when full, the unconnected entry with the nearest expiry is evicted before the new entry is inserted. Addresses held by a live connection (TTL >= ConnectedAddrTTL) are not counted and never evicted. A non-positive cap now disables the check in both backends, so WithMaxAddressesPerPeer(0) and Options.MaxAddrsPerPeer = 0 opt out cleanly. Shared suite fixtures use that switch instead of an arbitrary high number.
lidel
marked this pull request as ready for review
April 15, 2026 00:29
lidel
commented
Apr 15, 2026
MarcoPolo
approved these changes
Apr 17, 2026
Co-authored-by: Marco Munizaga <git@marcopolo.io>
Collaborator
|
@lidel, could you please take a look at the conflicts? |
apply Strunk's rules to the new doc comments and inline notes: prefer active voice and positive form, drop needless words. - pstoremem/addr_book.go: revise WithMaxAddressesPerPeer, defaultMaxAddrsPerPeer, and evictNearestExpiryUnconnectedForPeerUnlocked - pstoreds/addr_book.go: revise ttlIsConnected and the per-peer cap inline comment
Contributor
Author
|
@MarcoPolo done :) |
- pstoremem: TestMaxAddrsPerPeerEnforcedOnSetAddrs asserts the cap fires on SetAddrs, evicting the nearest-expiry unconnected addr. - pstoreds: same coverage via TestDsMaxAddrsPerPeerEnforcedOnSetAddrs. - pstoreds: TestDsMaxAddrsPerPeerDisabled regression-checks that MaxAddrsPerPeer = 0 lets a peer retain 200 addrs (above the default 64).
7 tasks
gammazero
added a commit
to ipni/go-libipni
that referenced
this pull request
Jul 29, 2026
The update to `go-libp2p` 0.49.0 update contains security fixes and enhancements for DoS/hardening: - fix for CVE-2026-57497: GHSA-g35j-m5xg-vh3q - [3501](libp2p/go-libp2p#3501) bounds protocols accepted per peer in identify (a peer could plant 1800+ protocol entries in your peerstore via chunked identify) - [3486](libp2p/go-libp2p#3486) caps unconnected addrs per peer (stops DHT gossip flooding the peerstore with stale addrs; relevant to us) - [3500](libp2p/go-libp2p#3500) caps webrtc remote addrs per ufrag - [3487](libp2p/go-libp2p#3487) evicts stale certified addrs when a newer signed peer record drops them (an address a peer once advertised no longer lingers after removal)
gammazero
added a commit
to ipni/go-libipni
that referenced
this pull request
Jul 30, 2026
The update to `go-libp2p` 0.49.0 update contains security fixes and enhancements for DoS/hardening: - fix for CVE-2026-57497: GHSA-g35j-m5xg-vh3q - [3501](libp2p/go-libp2p#3501) bounds protocols accepted per peer in identify (a peer could plant 1800+ protocol entries in your peerstore via chunked identify) - [3486](libp2p/go-libp2p#3486) caps unconnected addrs per peer (stops DHT gossip flooding the peerstore with stale addrs; relevant to us) - [3500](libp2p/go-libp2p#3500) caps webrtc remote addrs per ufrag - [3487](libp2p/go-libp2p#3487) evicts stale certified addrs when a newer signed peer record drops them (an address a peer once advertised no longer lingers after removal)
This was referenced Jul 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
This is another fix that aims to reduce stale addr accumulation (defensive, on Consumer side).
Note
Filed as part of Kubo maintenance:
Problem
Third-party peers (e.g. via DHT gossip) can flood the peerstore with stale or misconfigured addresses for a single peer id. Real-world delegated-routing responses top out around 26 addrs per well-connected node, but a misbehaving peer can push hundreds before the global peerstore cap kicks in, crowding out good addrs during dial selection.
This PR
Bound the stored unconnected addrs per peer to 64 by default and evict the unconnected entry with the nearest expiry when the cap is reached. This naturally sheds short-TTL gossip (TempAddrTTL) before longer-lived identify-backed entries (RecentlyConnectedAddrTTL) without tracking provenance. Addrs held by a live connection are never counted toward the cap and never evicted.
WithMaxAddressesPerPeer(n)lets callers tune the cap.addAddrsUnlockedandSetAddrs, the two write paths that can grow the per-peer set.SetNegativeTTLClearsadds 100 addrs, above the new default; the inmem test factory raises the cap to 10000 so the shared suite keeps exercising general behavior rather than the cap path.Open Questions