Skip to content

Commit 7c79e02

Browse files
committed
feat: add IPIP-0476 for DHT closest peers API
documents the new /routing/v1/dht/closest/peers/{peer-id} endpoint that enables lightweight peer discovery for browser nodes and other resource-constrained clients without requiring full DHT participation
1 parent ab45d97 commit 7c79e02

File tree

1 file changed

+145
-0
lines changed

1 file changed

+145
-0
lines changed

src/ipips/ipip-0476.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
---
2+
title: "IPIP-0476: Delegated Routing DHT Closest Peers API"
3+
date: 2025-08-19
4+
ipip: proposal
5+
editors:
6+
- name: Alex Potsides
7+
github: achingbrain
8+
affiliation:
9+
name: Shipyard
10+
url: https://ipshipyard.com
11+
- name: Marcin Rataj
12+
github: lidel
13+
affiliation:
14+
name: Shipyard
15+
url: https://ipshipyard.com
16+
relatedIssues:
17+
- https://github.com/ipfs/specs/pull/476
18+
- https://github.com/ipfs/specs/pull/497
19+
order: 476
20+
tags: ['ipips']
21+
---
22+
23+
## Summary
24+
25+
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.
26+
27+
## Motivation
28+
29+
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.
30+
31+
Currently, to find peers close to a particular key in the DHT keyspace, a node must:
32+
1. Be a full DHT client with all the associated overhead
33+
2. Maintain connections to many peers
34+
3. Handle the complexity of the DHT protocol
35+
36+
This is particularly problematic for:
37+
- Browser nodes that need to find circuit relay servers
38+
- Light clients that want to populate their routing tables
39+
- Applications that need to find peers to host provider records
40+
41+
## Detailed design
42+
43+
This IPIP introduces a new "DHT Routing API" section to the Delegated Routing V1 HTTP API specification with the following endpoint:
44+
45+
### `GET /routing/v1/dht/closest/peers/{peer-id}`
46+
47+
#### Path Parameters
48+
49+
- `peer-id`: The target peer ID to find closest peers for, represented as a CIDv1 encoded with `libp2p-key` codec
50+
51+
#### Query Parameters
52+
53+
- `closerThan` (optional): A peer ID represented as a CIDv1 encoded with `libp2p-key` codec
54+
- Returned peer records must be closer to `peer-id` than `closerThan`
55+
- If omitted, the routing implementation should use its own peer ID
56+
- `count` (optional): Number of peer records to return
57+
- Minimum 1, maximum 100, default 20
58+
59+
#### Response
60+
61+
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.
62+
63+
### Specification Changes
64+
65+
The following changes are made to `src/routing/http-routing-v1.md`:
66+
67+
1. Add a new "## DHT Routing API" section after the "Peer Routing API" section
68+
2. Document the `/routing/v1/dht/closest/peers/{peer-id}` endpoint with its parameters and response format
69+
3. Update the document date to reflect the modification
70+
71+
## Design rationale
72+
73+
The design follows several key principles:
74+
75+
### Simple MVP Approach
76+
77+
The endpoint provides the minimum viable functionality needed for the primary use cases. It can be expanded later if more complex routing scenarios emerge.
78+
79+
### Future-Proofed Path Structure
80+
81+
The path `/routing/v1/dht/closest/peers/{peer-id}` is intentionally structured to allow future expansion:
82+
- The `/dht/` segment clearly indicates DHT-specific operations
83+
- The `/closest/peers/` structure allows for potential future endpoints like `/closest/keys/` for keyspace queries
84+
- This organization keeps the API logical and extensible
85+
86+
### Routing-Agnostic Implementation
87+
88+
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.
89+
90+
### Consistency with Existing API
91+
92+
The endpoint follows the established patterns of the Delegated Routing API:
93+
- Uses the same response format as other peer routing endpoints
94+
- Follows the same parameter conventions
95+
- Maintains consistency in error handling and status codes
96+
97+
### User benefit
98+
99+
This enhancement provides significant benefits to end users:
100+
101+
1. **Browser Compatibility**: Browser nodes can discover circuit relay servers without implementing the full DHT protocol
102+
2. **Reduced Resource Usage**: Light clients save bandwidth and processing power by delegating peer discovery
103+
3. **Faster Peer Discovery**: Delegated routing servers can provide cached results more quickly than performing DHT walks
104+
4. **Simplified Implementation**: Application developers can implement peer discovery with simple HTTP requests instead of complex DHT logic
105+
106+
### Compatibility
107+
108+
This change is fully backward compatible:
109+
- It adds a new endpoint without modifying existing ones
110+
- Existing clients continue to work unchanged
111+
- Servers that don't implement the endpoint return 501 (Not Implemented) as per the specification
112+
113+
### Security
114+
115+
The new endpoint introduces no additional security considerations beyond those already present in the Delegated Routing API:
116+
117+
- Standard rate limiting should be applied to prevent abuse
118+
- The endpoint reveals no more information than a DHT query would
119+
- Access controls can be implemented at the HTTP layer if needed
120+
- Response caching helps mitigate potential DoS attacks
121+
122+
### Alternatives
123+
124+
Several alternatives were considered:
125+
126+
1. **Full DHT Client Implementation**: Rejected due to excessive resource requirements for browser and mobile environments
127+
128+
2. **Custom libp2p Protocol**: Would require all nodes to implement a new protocol, creating adoption barriers
129+
130+
3. **Extension of Existing Peer Routing**: The `/routing/v1/peers/` endpoint serves a different purpose (finding specific peers rather than closest peers)
131+
132+
4. **Amino-Specific Endpoint**: Initially considered `/routing/v1/amino/` namespace but rejected in favor of the more generic `/dht/` approach
133+
134+
## Test fixtures
135+
136+
This IPIP does not deal with content-addressed data, so specific test CIDs are not applicable. However, implementations should test:
137+
138+
1. Valid peer ID inputs return appropriate closest peers
139+
2. The `closerThan` parameter correctly filters results
140+
3. The `count` parameter limits results as specified
141+
4. Invalid peer IDs return appropriate error responses
142+
143+
### Copyright
144+
145+
Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).

0 commit comments

Comments
 (0)