diff --git a/main.go b/main.go index 3cf5c57..58cb73e 100644 --- a/main.go +++ b/main.go @@ -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", + }, } app.Commands = []*cli.Command{ @@ -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"), IpnsMaxCacheTTL: cctx.Duration("ipns-max-cache-ttl"), DenylistSubs: cctx.StringSlice("denylists"), Peering: peeringAddrs, diff --git a/setup.go b/setup.go index 8a4a68c..54508f2 100644 --- a/setup.go +++ b/setup.go @@ -99,6 +99,7 @@ type Config struct { TrustlessGatewayDomains []string RoutingV1 string DHTSharedHost bool + AcceleratedDHT bool IpnsMaxCacheTTL time.Duration DenylistSubs []string @@ -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()...), @@ -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 + } + dhtRouter = &bundledDHT{ + standard: standardClient, + fullRT: fullRTClient, + } + } else { + dhtRouter = standardClient } // we want to also use the default HTTP routers, so wrap the FullRT client