Delegated Routing DHT Closest Peers API
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: 1. Be a full DHT client with all the asso
No reviewsSpecification
Summary
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.
Motivation
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:
- Be a full DHT client with all the associated overhead
- Maintain connections to many peers
- Handle the complexity of the DHT protocol
This is particularly problematic for:
- Browser nodes that need to find circuit relay servers
- Light clients that want to populate their routing tables
- Applications that need to find peers to host provider records
Detailed design
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}
Path Parameters
keyis a CID or Peer ID to find the closest peers to.- CID SHOULD be a CIDv1 in any encoding.
- Peer ID can be represented as a Multihash in Base58btc, or a CIDv1 with
libp2p-key(0x72) codec in Base36 or Base32. - Arbitrary multihash lookups can be performed by wrapping the multihash in a CIDv1 with
raw(0x55) codec.
Response
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.
Specification Changes
The following changes are made to src/routing/http-routing-v1.md:
- Add a new "## DHT Routing API" section after the "Peer Routing API" section
- Document the
/routing/v1/dht/closest/peers/{key}endpoint with its parameters and response format - Update the document date to reflect the modification
Design rationale
The design follows several key principles:
Simple MVP Approach
The endpoint provides the minimum viable functionality needed for the primary use cases. It can be expanded later if more complex routing scenarios emerge.
Future-Proofed Path Structure
The path /routing/v1/dht/closest/peers/{key} is intentionally structured to allow future expansion:
- The
/dht/segment clearly indicates DHT-specific operations - The
/closest/peers/structure allows for potential future endpoints like/closest/keys/for keyspace queries - This organization keeps the API logical and extensible
Routing-Agnostic Implementation
While 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.
Consistency with Existing API
The endpoint follows the established patterns of the Delegated Routing API:
- Uses the same response format as other peer routing endpoints
- Follows the same parameter conventions
- Maintains consistency in error handling and status codes
User benefit
This enhancement provides significant benefits to end users:
- Browser Compatibility: Browser nodes can discover circuit relay servers without implementing the full DHT protocol
- Reduced Resource Usage: Light clients save bandwidth and processing power by delegating peer discovery
- Faster Peer Discovery: Delegated routing servers can provide cached results more quickly than performing DHT walks
- Simplified Implementation: Application developers can implement peer discovery with simple HTTP requests instead of complex DHT logic
Compatibility
This change is fully backward compatible:
- It adds a new endpoint without modifying existing ones
- Existing clients continue to work unchanged
- Servers that don't implement the endpoint return 501 (Not Implemented) as per the specification
Security
The new endpoint introduces no additional security considerations beyond those already present in the Delegated Routing API:
- Standard rate limiting should be applied to prevent abuse
- The endpoint reveals no more information than a DHT query would
- Access controls can be implemented at the HTTP layer if needed
- Response caching helps mitigate potential DoS attacks
Alternatives
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,
countandcloser-thanquery parameters were considered:count: limit the number of results returnedcloser-than: filter peers to only return those closer than a reference peer
These 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.
Peer Ordering
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.
Test fixtures
This IPIP does not deal with content-addressed data, so specific test CIDs are not applicable. However, implementations should test:
- Valid CID and Peer ID inputs return appropriate closest peers
- Results are limited to the DHT bucket size
- Peers are sorted by closeness (XOR distance for Kademlia DHTs)
- Invalid keys return appropriate error responses
- Both streaming (NDJSON) and non-streaming (JSON) response formats work correctly
Copyright
Copyright and related rights waived via CC0.
Discussion (0 threads)
Loading discussions...