Repository navigation
feat(service-disco): add discoverer - #2306
Conversation
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
| let searchTable = disco.rtManager.getTable(serviceId).valueOr: | ||
| return err("service table not found for service id: " & $serviceId) | ||
|
|
||
| var found = newSeqOfCap[Advertisement](disco.discoConfig.fLookup) |
There was a problem hiding this comment.
disco.discoConfig.fLookup
why is this not
disco.config.fLookup
There was a problem hiding this comment.
ServiceDiscovery is of type KadDHT which already has a config field
There was a problem hiding this comment.
still, should be doable. KadDHT will have type param C that represents config. then ServiceDiscovery extends KadDHT with config type DiscoveryConfig that extends KadConfig.
but talking out from top of my head 1) not sure how this will work in nim 2) not sure how these would stack if there is really senergy or not
853da6f to
9e47fe8
Compare
9e47fe8 to
d1e3824
Compare
There was a problem hiding this comment.
Pull request overview
This PR completes the Service Discovery protocol round-trip by adding a client-side Discoverer (lookup) and implementing server-side handling for REGISTER and GET_ADS messages, plus associated maintenance loops and tests.
Changes:
- Added
discoverer.nimimplementinglookup+ GET_ADS querying/peer seeding. - Implemented
handleRegisterandhandleGetAdsin the registrar and wired both into the ServiceDiscovery message dispatch. - Added/updated tests and test utilities for discoverer behavior and registrar validation.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
libp2p/protocols/service_discovery/discoverer.nim |
New discoverer component implementing GET_ADS dialing/decoding and lookup. |
libp2p/protocols/service_discovery/registrar.nim |
Implements REGISTER and GET_ADS handlers (rate limiting, tickets, cached ad responses). |
libp2p/protocols/service_discovery/types.nim |
Adds background loop fields to ServiceDiscovery and introduces ad-seq encoding helper. |
libp2p/protocols/service_discovery.nim |
Wires registrar/discoverer into imports/exports, message dispatch, and start/stop maintenance loops. |
libp2p/protocols/kademlia/types.nim |
Adds toPeerIds helper used by discoverer peer selection. |
tests/libp2p/service_discovery/test_discoverer.nim |
New tests for discoverer lookup/table initialization behavior. |
tests/libp2p/service_discovery/utils.nim |
Adds helper to populate per-service search tables for tests. |
tests/libp2p/service_discovery/test_registrar.nim |
Updates registrar validation tests for new validateRegisterMessage signature/service check. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
db902bb to
5d0148b
Compare
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Merge commits are not allowed on this repository
Summary
This PR introduces the Discoverer component and completes the service discovery protocol by implementing the previously stubbed
REGISTERandGET_ADShandlers.lookupenables a node to query the network for providers of a given service ID by iterating its per-service routing table and issuingGET_ADSrequests.handleRegister,handleGetAds) complete the round-trip:Changes
libp2p/protocols/service_discovery/discoverer.nim (new)
sendGetAdsGET_ADSmessagelookupkLookuppeers per bucket viasendGetAdsfLookupvalid advertisementslibp2p/protocols/service_discovery/registrar.nim
handleRegisterConfirmed→ callsacceptAdvertisementWait→ returns a signedTicketRejected→ fallback on signing failurehandleGetAdsfReturnadvertisementslibp2p/protocols/service_discovery.nim
registraranddiscovererimportsdiscoverer(exposeslookup)"Unimplemented"stubs:MessageType.register→await disco.handleRegister(conn, msg)MessageType.getAds→await disco.handleGetAds(conn, msg)tests/libp2p/service_discovery/test_discoverer.nim (new)
Covers:
ok([])tests/libp2p/service_discovery/utils.nim
routing_table_managerpopulateRoutingTablepopulateAdvTablepopulateSearchTableAffected Areas
Peer Management / Discovery
Implements client-side provider lookup over per-service Kademlia routing tables.
Protocol Logic
REGISTERandGET_ADSare now fully handled server-side (previously dropped).Gossipsub
Transports
Build / Tooling
Other
(No direct changes in these areas.)
Compatibility & Downstream Validation
register(16) andgetAds(17) already existed; only dispatch was missingNo validation required for standard KadDHT consumers (Nimbus, Waku, Codex).
ServiceDiscovery users should verify that
stop()correctly drains in-flight advertising tasks.Impact on Library Users
New API
lookup*(disco: ServiceDiscovery, serviceId: ServiceId): Future[Result[seq[Advertisement], string]]Behavior changes
REGISTERis now processed (returnsConfirmed,Wait, orRejected)GET_ADSis now processed (returns cached advertisements)Risk Assessment
Retry ticket
tInitnot bounded to wall timeA manipulated past
tInitcould produce a large negative adjustment.Mitigated by retry-window validation in
processRetryTicket.Risk: Low
Deterministic advertisement ordering
handleGetAdsreturns ads in insertion order (no randomization).May bias results under load.
Risk: Low (can be improved later)
Ticket signing fallback to
RejectedIf signing fails, advertiser backs off for full expiry instead of retrying sooner.
Safe but may introduce delays.
Risk: Low
Test uses
kLookupinstead offLookupResult cap assertion may be weaker than intended if values differ.
Risk: Low
References
feat/service-disco/advertiserfeat/service-disco/registrar