Skip to content

Commit

Permalink
feat: make accelerated-dht a flag
Browse files Browse the repository at this point in the history
Enabled by default to keep current behaviour. Useful for me personally
as my router sort of blocks my laptop every time I use the accelerated
dht client.
  • Loading branch information
hacdias committed Apr 5, 2024
1 parent 44341a5 commit 61799c7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ Generate an identity seed and launch a gateway:
EnvVars: []string{"RAINBOW_IPNS_MAX_CACHE_TTL"},
Usage: "Optional cap on caching duration for IPNS/DNSLink lookups. Set to 0 to respect original TTLs.",
},
&cli.BoolFlag{
Name: "accelerated-dht",
Value: true,
EnvVars: []string{"RAINBOW_ACCELERATED_DHT"},
Usage: "Activate the accelerated DHT client",
},

Check warning on line 210 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L205-L210

Added lines #L205 - L210 were not covered by tests
}

app.Commands = []*cli.Command{
Expand Down Expand Up @@ -299,6 +305,7 @@ share the same seed as long as the indexes are different.
InMemBlockCache: cctx.Int64("inmem-block-cache"),
RoutingV1: cctx.String("routing"),
DHTSharedHost: cctx.Bool("dht-shared-host"),
AcceleratedDHT: cctx.Bool("accelerated-dht"),

Check warning on line 308 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L308

Added line #L308 was not covered by tests
IpnsMaxCacheTTL: cctx.Duration("ipns-max-cache-ttl"),
DenylistSubs: getCommaSeparatedList(cctx.String("denylists")),
Peering: peeringAddrs,
Expand Down
19 changes: 12 additions & 7 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ type Config struct {
TrustlessGatewayDomains []string
RoutingV1 string
DHTSharedHost bool
AcceleratedDHT bool
IpnsMaxCacheTTL time.Duration

DenylistSubs []string
Expand Down Expand Up @@ -201,7 +202,7 @@ func Setup(ctx context.Context, cfg Config, key crypto.PrivKey, dnsCache *cached
}
}

dhtRouter, err := newBundledDHT(ctx, ds, dhtHost)
dhtRouter, err := setupDHT(ctx, ds, dhtHost, cfg.AcceleratedDHT)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -391,12 +392,7 @@ func setupDatastore(cfg Config) (datastore.Batching, error) {
}
}

type bundledDHT struct {
standard *dht.IpfsDHT
fullRT *fullrt.FullRT
}

func newBundledDHT(ctx context.Context, ds datastore.Batching, h host.Host) (*bundledDHT, error) {
func setupDHT(ctx context.Context, ds datastore.Batching, h host.Host, acceleratedDHT bool) (routing.Routing, error) {
standardClient, err := dht.New(ctx, h,
dht.Datastore(ds),
dht.BootstrapPeers(dht.GetDefaultBootstrapPeerAddrInfos()...),
Expand All @@ -406,6 +402,10 @@ func newBundledDHT(ctx context.Context, ds datastore.Batching, h host.Host) (*bu
return nil, err

Check warning on line 402 in setup.go

View check run for this annotation

Codecov / codecov/patch

setup.go#L402

Added line #L402 was not covered by tests
}

if !acceleratedDHT {
return standardClient, nil
}

fullRTClient, err := fullrt.NewFullRT(h, dht.DefaultPrefix,
fullrt.DHTOption(
dht.Validator(record.NamespacedValidator{
Expand All @@ -426,6 +426,11 @@ func newBundledDHT(ctx context.Context, ds datastore.Batching, h host.Host) (*bu
}, nil

Check warning on line 426 in setup.go

View check run for this annotation

Codecov / codecov/patch

setup.go#L423-L426

Added lines #L423 - L426 were not covered by tests
}

type bundledDHT struct {
standard *dht.IpfsDHT
fullRT *fullrt.FullRT
}

func (b *bundledDHT) getDHT() routing.Routing {
if b.fullRT.Ready() {
return b.fullRT
Expand Down

0 comments on commit 61799c7

Please sign in to comment.