fix: filter stale addresses from provider and peer responses#141
Draft
fix: filter stale addresses from provider and peer responses#141
Conversation
some third-party DHT peers have a bug where they never clean up old addresses they observed for other peers. if a peer behind a consumer NAT gets a new port via UPnP, or the ISP rotates its IP, the old address stays in the DHT forever. over time a peer can end up with dozens of dead addresses in front of the one that actually works, so clients time out before they ever reach it. this mostly hurts direct retrieval from self-hosted peers on consumer networks with dynamic IPs or ports (UPnP, NAT-PMP, and similar). this adds two layers of cleanup: passive filtering runs inline on every response. when someguy has previously connected to a peer, it remembers which address worked and drops other addresses on the same IP and transport that have a different (stale) port. active probing (SOMEGUY_CACHED_ADDR_BOOK_STALE_PROBING, on by default) kicks in for first-encounter peers whose address set looks suspicious: multiple ports on the same IP, or more than three IPs in one address family. each unique address is probed with a quick libp2p handshake in the background. records that don't need probing stream through right away; probed results show up at the end. if every probe fails the peer is probably offline and all addresses are returned as-is (fail-open). also fixes a race in cached_addr_book where concurrent requests could clobber each other's peerCache updates (Peek + Add without a lock).
026416e to
d313f64
Compare
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.
Warning
Parking for now, but we may need this if we see the faulty DHT peers impacting the success/latency of https://inbrowser.link
Not a fan of extra complexity here, but we may not have other choice, as we don't control what people deploy on DHT, nor we control libp2p implementations.
some third-party DHT peers have a bug where they never clean up old addresses they observed for other peers. if a peer behind a consumer NAT gets a new port via UPnP, or the ISP rotates its IP, the old address stays in the DHT forever. over time a peer can end up with dozens of dead addresses in front of the one that actually works, so clients time out before they ever reach it. this mostly hurts direct retrieval from self-hosted peers on consumer networks with dynamic IPs or ports (UPnP, NAT-PMP, and similar).
this PR adds two layers of cleanup:
passive filtering runs inline on every response. when someguy has previously connected to a peer, it remembers which address worked and drops other addresses on the same IP and transport that have a different (stale) port.
active probing (
SOMEGUY_CACHED_ADDR_BOOK_STALE_PROBING, on by default) kicks in for first-encounter peers whose address set looks suspicious: multiple ports on the same IP, or more than three IPs in one address family. each unique address is probed with a quick libp2p handshake in the background. records that don't need probing stream through right away; probed results show up at the end. if every probe fails the peer is probably offline and all addresses are returned as-is (fail-open).also fixes a race in
cached_addr_bookwhere concurrent requests could clobber each other'speerCacheupdates (Peek + Add without a lock).