Add a new HTTP endpoint to the Delegated Routing API that allows clients to find the closest peers to a given peer ID without being full DHT clients.
Browser nodes and other resource-constrained clients need to perform peer discovery operations without the overhead of being full DHT clients. The primary use case is for browser nodes performing random walks to find peers that they can make circuit relay reservations on.
Currently, to find peers close to a particular key in the DHT keyspace, a node must:
This is particularly problematic for:
This IPIP introduces a new "DHT Routing API" section to the Delegated Routing V1 HTTP API specification with the following endpoint:
GET /routing/v1/dht/closest/peers/{key}key is a CID or Peer ID to find the closest peers to.
libp2p-key (0x72) codec in Base36 or Base32.raw (0x55) codec.The response follows the same format as the existing peer routing endpoints, returning a JSON object with a Peers array containing peer records conforming to the Peer Schema.
The following changes are made to src/routing/http-routing-v1.md:
/routing/v1/dht/closest/peers/{key} endpoint with its parameters and response formatThe design follows several key principles:
The endpoint provides the minimum viable functionality needed for the primary use cases. It can be expanded later if more complex routing scenarios emerge.
The path /routing/v1/dht/closest/peers/{key} is intentionally structured to allow future expansion:
/dht/ segment clearly indicates DHT-specific operations/closest/peers/ structure allows for potential future endpoints like /closest/keys/ for keyspace queriesWhile the endpoint is in the DHT namespace, implementations have flexibility in how they determine "closest" peers. This allows for optimization based on the specific routing system being used.
The endpoint follows the established patterns of the Delegated Routing API:
This enhancement provides significant benefits to end users:
This change is fully backward compatible:
The new endpoint introduces no additional security considerations beyond those already present in the Delegated Routing API:
Several alternatives were considered:
Full DHT Client Implementation: Rejected due to excessive resource requirements for browser and mobile environments
Custom libp2p Protocol: Would require all nodes to implement a new protocol, creating adoption barriers
Extension of Existing Peer Routing: The /routing/v1/peers/ endpoint serves a different purpose (finding specific peers rather than closest peers)
Amino-Specific Endpoint: Initially considered /routing/v1/amino/ namespace but rejected in favor of the more generic /dht/ approach
Query Parameters for Filtering and Limiting: During design discussions, count and closer-than query parameters were considered:
count: limit the number of results returnedcloser-than: filter peers to only return those closer than a reference peerThese were omitted from the initial implementation (boxo v0.35.2, someguy v0.11.0) for simplicity. The endpoint defaults to returning up to the DHT bucket size (20 for Amino DHT). Future backwards-compatible updates MAY add these parameters if use cases emerge that require more fine-grained control.
Implementations SHOULD return peers sorted by closeness to the key. For Kademlia-based DHT implementations (such as Amino DHT), this means sorting by XOR distance with the closest peers first.
This IPIP does not deal with content-addressed data, so specific test CIDs are not applicable. However, implementations should test:
Copyright and related rights waived via CC0.
We gratefully acknowledge the following individuals for their valuable contributions, ranging from minor suggestions to major insights, which have shaped and improved this specification.