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 8, 2024
1 parent 2c694e2 commit 5acdfbb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 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 209 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L203-L209

Added lines #L203 - L209 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: cctx.StringSlice("denylists"),

Check warning on line 310 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L310

Added line #L310 was not covered by tests
Peering: peeringAddrs,
Expand Down
40 changes: 23 additions & 17 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ type Config struct {
TrustlessGatewayDomains []string
RoutingV1 string
DHTSharedHost bool
AcceleratedDHT bool
IpnsMaxCacheTTL time.Duration

DenylistSubs []string
Expand Down Expand Up @@ -220,6 +221,8 @@ func Setup(ctx context.Context, cfg Config, key crypto.PrivKey, dnsCache *cached
}
}

var dhtRouter routing.Routing

standardClient, err := dht.New(ctx, dhtHost,
dht.Datastore(ds),
dht.BootstrapPeers(dht.GetDefaultBootstrapPeerAddrInfos()...),
Expand All @@ -229,23 +232,26 @@ func Setup(ctx context.Context, cfg Config, key crypto.PrivKey, dnsCache *cached
return nil, err
}

fullRTClient, err := fullrt.NewFullRT(dhtHost, dht.DefaultPrefix,
fullrt.DHTOption(
dht.Validator(record.NamespacedValidator{
"pk": record.PublicKeyValidator{},
"ipns": ipns.Validator{KeyBook: h.Peerstore()},
}),
dht.Datastore(ds),
dht.BootstrapPeers(dht.GetDefaultBootstrapPeerAddrInfos()...),
dht.BucketSize(20),
))
if err != nil {
return nil, err
}

dhtRouter := &bundledDHT{
standard: standardClient,
fullRT: fullRTClient,
if cfg.AcceleratedDHT {
fullRTClient, err := fullrt.NewFullRT(dhtHost, dht.DefaultPrefix,
fullrt.DHTOption(
dht.Validator(record.NamespacedValidator{
"pk": record.PublicKeyValidator{},
"ipns": ipns.Validator{KeyBook: h.Peerstore()},
}),
dht.Datastore(ds),
dht.BootstrapPeers(dht.GetDefaultBootstrapPeerAddrInfos()...),
dht.BucketSize(20),
))
if err != nil {
return nil, err

Check warning on line 247 in setup.go

View check run for this annotation

Codecov / codecov/patch

setup.go#L236-L247

Added lines #L236 - L247 were not covered by tests
}
dhtRouter = &bundledDHT{
standard: standardClient,
fullRT: fullRTClient,

Check warning on line 251 in setup.go

View check run for this annotation

Codecov / codecov/patch

setup.go#L249-L251

Added lines #L249 - L251 were not covered by tests
}
} else {
dhtRouter = standardClient
}

// we want to also use the default HTTP routers, so wrap the FullRT client
Expand Down

0 comments on commit 5acdfbb

Please sign in to comment.