-
Notifications
You must be signed in to change notification settings - Fork 236
IPIP-0476: Delegated Routing DHT Closest Peers API #476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
0a3d8e3
351b8a7
9aa55a3
d4e94a8
ab45d97
7c79e02
b278b84
4bdfa84
dd86eb3
48fe4cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| --- | ||
| title: "IPIP-0476: Delegated Routing DHT Closest Peers API" | ||
| date: 2025-08-19 | ||
| ipip: proposal | ||
| editors: | ||
| - name: Alex Potsides | ||
| github: achingbrain | ||
| affiliation: | ||
| name: Shipyard | ||
| url: https://ipshipyard.com | ||
| - name: Marcin Rataj | ||
| github: lidel | ||
| affiliation: | ||
| name: Shipyard | ||
| url: https://ipshipyard.com | ||
| relatedIssues: | ||
| - https://github.com/ipfs/specs/pull/476 | ||
| - https://github.com/ipfs/specs/pull/497 | ||
| order: 476 | ||
| tags: ['ipips'] | ||
| --- | ||
|
|
||
| ## 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: | ||
| 1. Be a full DHT client with all the associated overhead | ||
| 2. Maintain connections to many peers | ||
| 3. 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/{peer-id}` | ||
|
|
||
| #### Path Parameters | ||
|
|
||
| - `peer-id`: The target peer ID to find closest peers for, represented as a CIDv1 encoded with `libp2p-key` codec | ||
|
|
||
| #### Query Parameters | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have any specific use cases in mind that would require query parameters? IIUC Go and JS DHT implementations only support returning the The query parameters could be used to filter the results and return less than 20 peers, but not to get more peers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @achingbrain @hsanjuan would it be ok to remove The only implementation (kad-dht) doesn't support these parameters:
Imo there is no point in listing them in spec and implementing filtering in userland. |
||
|
|
||
| - `closer-than` (optional): A peer ID represented as a CIDv1 encoded with `libp2p-key` codec | ||
| - Returned peer records must be closer to `peer-id` than `closer-than` | ||
| - If omitted, the routing implementation should use its own peer ID | ||
| - `count` (optional): Number of peer records to return | ||
| - Minimum 1, maximum 100, default 20 | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unlike the I understand this is a DHT-specific method and everything-DHT is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Not strictly true since the endpoint may know more information. For example https://github.com/ipfs/someguy learns more about peers on the network which helps it limit sending unhelpful peers to web browsers. |
||
| #### 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`: | ||
|
|
||
| 1. Add a new "## DHT Routing API" section after the "Peer Routing API" section | ||
| 2. Document the `/routing/v1/dht/closest/peers/{peer-id}` endpoint with its parameters and response format | ||
| 3. 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/{peer-id}` 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: | ||
|
|
||
| 1. **Browser Compatibility**: Browser nodes can discover circuit relay servers without implementing the full DHT protocol | ||
| 2. **Reduced Resource Usage**: Light clients save bandwidth and processing power by delegating peer discovery | ||
| 3. **Faster Peer Discovery**: Delegated routing servers can provide cached results more quickly than performing DHT walks | ||
| 4. **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: | ||
|
|
||
| 1. **Full DHT Client Implementation**: Rejected due to excessive resource requirements for browser and mobile environments | ||
|
|
||
| 2. **Custom libp2p Protocol**: Would require all nodes to implement a new protocol, creating adoption barriers | ||
|
|
||
| 3. **Extension of Existing Peer Routing**: The `/routing/v1/peers/` endpoint serves a different purpose (finding specific peers rather than closest peers) | ||
|
|
||
| 4. **Amino-Specific Endpoint**: Initially considered `/routing/v1/amino/` namespace but rejected in favor of the more generic `/dht/` approach | ||
|
|
||
| ## Test fixtures | ||
|
|
||
| This IPIP does not deal with content-addressed data, so specific test CIDs are not applicable. However, implementations should test: | ||
|
|
||
| 1. Valid peer ID inputs return appropriate closest peers | ||
| 2. The `closerThan` parameter correctly filters results | ||
| 3. The `count` parameter limits results as specified | ||
| 4. Invalid peer IDs return appropriate error responses | ||
|
|
||
| ### Copyright | ||
|
|
||
| Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory this isn't necessary.
It is true that many connections are necessary to perform a lookup, but a client technically doesn't need to maintain any connection when not performing a lookup actively. It should remember at least some addresses of DHT servers (e.g bootstrappers are enough).
I think we just miss light DHT client implementations.