Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add active peer probing and caching (#90)
* feat: add cached peer book with higher ttls * feat: initial implementation of active peer probing * feat: use the cached router * chore: go mod tidy * feat: log probe duration * chore: log in probe loop * fix: update peer state if doesn't exist * fix: add addresses to cached address book * fix: wrap with cached router only if available * feat: make everything a little bit better * chore: small refinements * test: add test for cached addr book * chore: rename files * feat: add options to cached addr book fix test by allowing private ips * feat: add instrumentation * fix: thread safety * docs: update changelog * fix: small fixes * fix: simplify cached router * feat(metric): cached_router_peer_addr_lookups this adds metric for evaluating all addr lookups someguy_cached_router_peer_addr_lookups{cache="unused|hit|miss",origin="providers|peers"} I've also wired up FindPeers for completeness. * Apply suggestions from code review Co-authored-by: Marcin Rataj <[email protected]> * Update CHANGELOG.md Co-authored-by: Marcin Rataj <[email protected]> * chore: use service name for namespace * fix: type errors and missing imports * feat: add queue probe * Revert "feat: add queue probe" This reverts commit 75f1bf2. * chore: simplify composite literal * fix: implement custom cache fallback iterator * fix: add cancel and simplify * fix: move select to Val function * fix: concurrency bug from the ongoingLookups * chore: clean up comments * fix: add lint ignores * docs: update changelog * fix: increase bucket sizes for probe duration * chore: remove unused peer state fields save some memory * feat: enable caching for FindPeer in cached router * fix: handle peer not found case * Apply suggestions from code review Co-authored-by: Marcin Rataj <[email protected]> * fix: wait longer during cleanup function * test: remove bitswap record test * refactor: extract connectedness checks to a func * fix: set ttl for both signed and unsigned addrs * fix: prevent race condition * feat: use 2q-lru cache for peer state 2q-lru tracks both frequently and recently used entries separately * chore: remove return count we don't need the return count with the 2q-lru cache and the peerAddrLookups metric * test: improve reliability of tests mock the libp2p host and use a real event bus * fix: record failed connections * feat: add exponential backoff for probes/peer lookups * fix: return peers with no addrs that wont probe * fix: brittle test * feat: add probed peers counter * fix: adjust probe duration metric buckets * fix: prevent race conditions * feat: increase cache size and add max backoff * fix: omit providers whose peer cannot be found * chore: remove unused function * deps: upgrade go-libp2p * fix: avoid using the cache in FindPeers * fix: do not return cached results for FindPeers * refactor: small optimisation * chore: re-add comment * Apply suggestions from code review Co-authored-by: Marcin Rataj <[email protected]> * Apply suggestions from code review Co-authored-by: Marcin Rataj <[email protected]> * fix: use separate context for dispatched jobs * fix: ensure proper cleanup of cache fallback iter * Update main.go Co-authored-by: Marcin Rataj <[email protected]> * fix: formatting * fix: let consumer handle cleanup * fix: remove from address book when removed from peer state * fix: use normal lru cache instead of 2Q * fix: update the metric when removing from the peer cache * fix: increase max backoff to 48 hours When the max backoff duration is reached and a connection attempt fails we clear the cached addresses and state. Since this state is useful to prevent unncessary attempts to dispatch a find peer we should keep it for as long as a provider record is valid for. * feat: add env var for recently connected ttl * feat: add env var to control active probing * fix: bug from closing the iterator twice no need to close the channel. just the source iterator * docs: update comment * docs: improve changelog * test: fix background test * feat(metrics): track online vs offline probe ratio --------- Co-authored-by: Daniel N <[email protected]> Co-authored-by: Marcin Rataj <[email protected]>
- Loading branch information