Skip to content

Commit

Permalink
feat(http-routers): filter-protocols from IPIP-484 (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel authored Oct 16, 2024
1 parent 59af74b commit c20ca3a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ The following emojis are used to highlight certain changes:
## [Unreleased]

### Added
- Ability to specify the maximum blocksize that bitswap will replace WantHave with WantBlock responses, and to disable replacement when set to zero. [#165](https://github.com/ipfs/rainbow/pull/165)
- Support use and configuration of pebble as [datastore](https://github.com/ipfs/rainbow/blob/main/docs/blockstores.md). Pebble provides a high-performance alternative to badger. Options are available to configure key tuning parameters (`pebble-*` in `rainbow --help`).

- Support implicit default list for `filter-protocols` from [IPIP-484](https://github.com/ipfs/specs/pull/484) and customizing them via `--http-routers-filter-protocols`.

### Changed

Expand All @@ -25,6 +25,13 @@ The following emojis are used to highlight certain changes:

### Security

## [v1.7.0]

### Added

- Ability to specify the maximum blocksize that bitswap will replace WantHave with WantBlock responses, and to disable replacement when set to zero. [#165](https://github.com/ipfs/rainbow/pull/165)
- Support use and configuration of pebble as [datastore](https://github.com/ipfs/rainbow/blob/main/docs/blockstores.md). Pebble provides a high-performance alternative to badger. Options are available to configure key tuning parameters (`pebble-*` in `rainbow --help`).

## [v1.6.0]

### Added
Expand Down
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ Generate an identity seed and launch a gateway:
EnvVars: []string{"RAINBOW_HTTP_ROUTERS"},
Usage: "HTTP servers with /routing/v1 endpoints to use for delegated routing (comma-separated)",
},
&cli.StringSliceFlag{
Name: "http-routers-filter-protocols",
Value: cli.NewStringSlice(httpRoutersFilterProtocols...),
EnvVars: []string{"RAINBOW_HTTP_ROUTERS_FILTER_PROTOCOLS"},
Usage: "IPIP-484 filter-protocols to apply to delegated routing requests (comma-separated)",
},
&cli.StringFlag{
Name: "dht-routing",
Value: "accelerated",
Expand Down Expand Up @@ -502,6 +508,7 @@ share the same seed as long as the indexes are different.
MaxFD: cctx.Int("libp2p-max-fd"),
InMemBlockCache: cctx.Int64("inmem-block-cache"),
RoutingV1Endpoints: cctx.StringSlice("http-routers"),
RoutingV1FilterProtocols: cctx.StringSlice("http-routers-filter-protocols"),
DHTRouting: dhtRouting,
DHTSharedHost: cctx.Bool("dht-shared-host"),
Bitswap: bitswap,
Expand Down
19 changes: 11 additions & 8 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func init() {

const cidContactEndpoint = "https://cid.contact"

var httpRoutersFilterProtocols = []string{"unknown", "transport-bitswap"} // IPIP-484

type DHTRouting string

const (
Expand Down Expand Up @@ -100,14 +102,15 @@ type Config struct {
MaxMemory uint64
MaxFD int

GatewayDomains []string
SubdomainGatewayDomains []string
TrustlessGatewayDomains []string
RoutingV1Endpoints []string
DHTRouting DHTRouting
DHTSharedHost bool
IpnsMaxCacheTTL time.Duration
Bitswap bool
GatewayDomains []string
SubdomainGatewayDomains []string
TrustlessGatewayDomains []string
RoutingV1Endpoints []string
RoutingV1FilterProtocols []string
DHTRouting DHTRouting
DHTSharedHost bool
IpnsMaxCacheTTL time.Duration
Bitswap bool

// BitswapWantHaveReplaceSize tells the bitswap server to replace WantHave
// with WantBlock responses when the block size less then or equal to this
Expand Down
13 changes: 7 additions & 6 deletions setup_routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ func setupDelegatedRouting(cfg Config, dnsCache *cachedDNS) ([]routing.Routing,
)

for _, endpoint := range cfg.RoutingV1Endpoints {
rv1Opts := []routingv1client.Option{routingv1client.WithHTTPClient(httpClient)}
if endpoint != cidContactEndpoint {
rv1Opts = append(rv1Opts, routingv1client.WithStreamResultsRequired())
}
delegatedRouter, err := delegatedHTTPContentRouter(endpoint, rv1Opts...)
delegatedRouter, err := delegatedHTTPContentRouter(endpoint,
routingv1client.WithHTTPClient(httpClient),
routingv1client.WithProtocolFilter(cfg.RoutingV1FilterProtocols), // IPIP-484
routingv1client.WithStreamResultsRequired(), // https://specs.ipfs.tech/routing/http-routing-v1/#streaming
routingv1client.WithDisabledLocalFiltering(false), // force local filtering in case remote server does not support IPIP-484
)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -276,7 +277,7 @@ func delegatedHTTPContentRouter(endpoint string, rv1Opts ...routingv1client.Opti
cli, err := routingv1client.New(
endpoint,
append([]routingv1client.Option{
routingv1client.WithUserAgent(buildVersion()),
routingv1client.WithUserAgent("rainbow/" + buildVersion()),
}, rv1Opts...)...,
)
if err != nil {
Expand Down

0 comments on commit c20ca3a

Please sign in to comment.