Skip to content

feat(config): single-purpose deleagted routing endpoints #10806

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions config/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@ type Routing struct {

IgnoreProviders []string `json:",omitempty"`

DelegatedRouters []string `json:",omitempty"`
// Simplified configuration used when Routing.Type=auto (or autoclient)
DelegatedRouters []string `json:",omitempty"`
DelegatedProviderRouters []string `json:",omitempty"`
DelegatedPeerRouters []string `json:",omitempty"`
DelegatedIPNSRouters []string `json:",omitempty"`

// Advanced configuration used when Routing.Type=custom
Routers Routers `json:",omitempty"`

Methods Methods `json:",omitempty"`
}

Expand Down
85 changes: 80 additions & 5 deletions core/node/libp2p/routingopt.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,19 @@ func constructDefaultHTTPRouters(cfg *config.Config) ([]*routinghelpers.Parallel
httpRouterEndpoints = cfg.Routing.DelegatedRouters
}

// Append HTTP routers for additional speed
// Settings for delegated http routers
ignoreError := true // assuming DHT is always present as a fallback: https://github.com/ipfs/kubo/pull/9475#discussion_r1042507387
routerTimeout := 15 * time.Second // 5x server value from https://github.com/ipfs/kubo/pull/9475#discussion_r1042428529
doNotWaitForSearchValue := true
executeAfter := 0 * time.Second

// Append General-purpose HTTP routers for additional speed
for _, endpoint := range httpRouterEndpoints {
httpRouter, err := irouting.ConstructHTTPRouter(endpoint, cfg.Identity.PeerID, httpAddrsFromConfig(cfg.Addresses), cfg.Identity.PrivKey, httpRetrievalEnabled)
if err != nil {
return nil, err
}

// Mapping router to /routing/v1/* endpoints
// https://specs.ipfs.tech/routing/http-routing-v1/
r := &irouting.Composer{
Expand All @@ -61,6 +68,7 @@ func constructDefaultHTTPRouters(cfg *config.Config) ([]*routinghelpers.Parallel
FindProvidersRouter: httpRouter, // /routing/v1/providers
}

// TODO: we do this here for legacy reasons
if endpoint == config.CidContactRoutingURL {
// Special-case: cid.contact only supports /routing/v1/providers/cid
// we disable other endpoints to avoid sending requests that always fail
Expand All @@ -72,12 +80,79 @@ func constructDefaultHTTPRouters(cfg *config.Config) ([]*routinghelpers.Parallel

routers = append(routers, &routinghelpers.ParallelRouter{
Router: r,
IgnoreError: true, // https://github.com/ipfs/kubo/pull/9475#discussion_r1042507387
Timeout: 15 * time.Second, // 5x server value from https://github.com/ipfs/kubo/pull/9475#discussion_r1042428529
DoNotWaitForSearchValue: true,
ExecuteAfter: 0,
IgnoreError: ignoreError,
Timeout: routerTimeout,
DoNotWaitForSearchValue: doNotWaitForSearchValue,
ExecuteAfter: executeAfter,
})
}

// Append Provider-only HTTP routers
for _, endpoint := range cfg.Routing.DelegatedProviderRouters {
httpRouter, err := irouting.ConstructHTTPRouter(endpoint, cfg.Identity.PeerID, httpAddrsFromConfig(cfg.Addresses), cfg.Identity.PrivKey, httpRetrievalEnabled)
if err != nil {
return nil, err
}
r := &irouting.Composer{
GetValueRouter: noopRouter,
PutValueRouter: noopRouter,
ProvideRouter: noopRouter,
FindPeersRouter: noopRouter,
FindProvidersRouter: httpRouter, // GET /routing/v1/providers
}
routers = append(routers, &routinghelpers.ParallelRouter{
Router: r,
IgnoreError: ignoreError,
Timeout: routerTimeout,
DoNotWaitForSearchValue: doNotWaitForSearchValue,
ExecuteAfter: executeAfter,
})
}

// Append Peer-only HTTP routers
for _, endpoint := range cfg.Routing.DelegatedPeerRouters {
httpRouter, err := irouting.ConstructHTTPRouter(endpoint, cfg.Identity.PeerID, httpAddrsFromConfig(cfg.Addresses), cfg.Identity.PrivKey, httpRetrievalEnabled)
if err != nil {
return nil, err
}
r := &irouting.Composer{
GetValueRouter: noopRouter,
PutValueRouter: noopRouter,
ProvideRouter: noopRouter,
FindPeersRouter: httpRouter, // GET /routing/v1/peers
FindProvidersRouter: noopRouter,
}
routers = append(routers, &routinghelpers.ParallelRouter{
Router: r,
IgnoreError: ignoreError,
Timeout: routerTimeout,
DoNotWaitForSearchValue: doNotWaitForSearchValue,
ExecuteAfter: executeAfter,
})
}

// Append IPNS-only HTTP routers
for _, endpoint := range cfg.Routing.DelegatedIPNSRouters {
httpRouter, err := irouting.ConstructHTTPRouter(endpoint, cfg.Identity.PeerID, httpAddrsFromConfig(cfg.Addresses), cfg.Identity.PrivKey, httpRetrievalEnabled)
if err != nil {
return nil, err
}
r := &irouting.Composer{
GetValueRouter: httpRouter, // GET /routing/v1/ipns
PutValueRouter: httpRouter, // PUT /routing/v1/ipns
ProvideRouter: noopRouter,
FindPeersRouter: noopRouter,
FindProvidersRouter: noopRouter,
}
routers = append(routers, &routinghelpers.ParallelRouter{
Router: r,
IgnoreError: ignoreError,
Timeout: routerTimeout,
DoNotWaitForSearchValue: doNotWaitForSearchValue,
ExecuteAfter: executeAfter,
})
}

return routers, nil
}

Expand Down
37 changes: 35 additions & 2 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ config file at runtime.
- [`Routing.LoopbackAddressesOnLanDHT`](#routingloopbackaddressesonlandht)
- [`Routing.IgnoreProviders`](#routingignoreproviders)
- [`Routing.DelegatedRouters`](#routingdelegatedrouters)
- [`Routing.DelegatedProviderRouters`](#routingdelegatedproviderrouters)
- [`Routing.DelegatedPeerRouters`](#routingdelegatedpeerrouters)
- [`Routing.DelegatedIPNSRouters`](#routingdelegatedipnsrouters)
- [`Routing.Routers`](#routingrouters)
- [`Routing.Routers: Type`](#routingrouters-type)
- [`Routing.Routers: Parameters`](#routingrouters-parameters)
Expand Down Expand Up @@ -1868,7 +1871,7 @@ Type: `array[string]`

### `Routing.DelegatedRouters`

This is an array of URL hostnames that support the [Delegated Routing V1 HTTP API](https://specs.ipfs.tech/routing/http-routing-v1/) which are used alongside the DHT when [`Routing.Type`](#routingtype) is set to `auto` or `autoclient`.
This is an array of URL hostnames that support all endpoints from the [Delegated Routing V1 HTTP API](https://specs.ipfs.tech/routing/http-routing-v1/) which are used alongside the DHT when [`Routing.Type`](#routingtype) is set to `auto` or `autoclient`.

> [!TIP]
> Delegated routing allows IPFS implementations to offload tasks like content routing, peer routing, and naming to a separate process or server while also benefiting from HTTP caching.
Expand All @@ -1879,11 +1882,38 @@ Default: `["https://cid.contact"]` (empty or `nil` will also use this default; t

Type: `array[string]`

### `Routing.DelegatedProviderRouters`

Same as `Routing.DelegatedRouters` but limited to `GET /routing/v1/providers`.

Default: `[]`

Type: `array[string]`

### `Routing.DelegatedPeerRouters`

Same as `Routing.DelegatedRouters` but limited to `GET /routing/v1/peers`.

Default: `[]`

Type: `array[string]`

### `Routing.DelegatedIPNSRouters`

Same as `Routing.DelegatedRouters` but limited to `GET|PUT /routing/v1/ipns`.

Default: `[]`

Type: `array[string]`

### `Routing.Routers`

**EXPERIMENTAL: `Routing.Routers` configuration may change in future release**

Map of additional Routers.
Map of additional Routers used when `Routing.Type=custom`.

> [!TIP]
> Most users should use `Routing.Type=auto` or `autoclient` and set simplified config in `Routing.DelegatedRouters` instead.

Allows for extending the default routing (Amino DHT) with alternative Router
implementations.
Expand Down Expand Up @@ -1947,6 +1977,9 @@ Type: `object[string->string]`

`Methods:map` will define which routers will be executed per method. The key will be the name of the method: `"provide"`, `"find-providers"`, `"find-peers"`, `"put-ipns"`, `"get-ipns"`. All methods must be added to the list.

> [!TIP]
> Most users should use `Routing.Type=auto` or `autoclient` and set simplified config in `Routing.DelegatedRouters` instead.

The value will contain:
- `RouterName:string`: Name of the router. It should be one of the previously added to `Routing.Routers` list.

Expand Down
Loading