From 86f8437c656b8535bf1f540cee89005522e12177 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Fri, 6 Oct 2023 19:37:50 +0200 Subject: [PATCH] Remove DHTType option - it wasn't wired-in Statichecks --- handlers.go | 4 ++-- main.go | 13 ++++------ setup.go | 68 +++++++++++++++++------------------------------------ 3 files changed, 27 insertions(+), 58 deletions(-) diff --git a/handlers.go b/handlers.go index 7bc5ca2..49ccde8 100644 --- a/handlers.go +++ b/handlers.go @@ -148,8 +148,8 @@ func setupGatewayHandler(nd *Node) (http.Handler, error) { }) // TODO: below is legacy which we want to remove, measuring this separately // allows us to decide when is the time to do it. - legacyKuboRpcHandler := withHTTPMetrics(newKuboRPCHandler(nd.kuboRPCs), "legacyKuboRpc") - topMux.Handle("/api/v0/", legacyKuboRpcHandler) + legacyKuboRPCHandler := withHTTPMetrics(newKuboRPCHandler(nd.kuboRPCs), "legacyKuboRpc") + topMux.Handle("/api/v0/", legacyKuboRPCHandler) // Construct the HTTP handler for the gateway. handler := withConnect(topMux) diff --git a/main.go b/main.go index f2a2752..b1cb37f 100644 --- a/main.go +++ b/main.go @@ -71,11 +71,6 @@ func main() { Value: false, Usage: "If using an Amino DHT client should the libp2p host be shared with the data downloading host", }, - &cli.StringFlag{ - Name: "dht-fallback-type", - Value: "combined", - Usage: "the type of Amino client to be used as a fallback (standard, accelerated, combined)", - }, } app.Name = "rainbow" @@ -83,6 +78,9 @@ func main() { app.Version = version app.Action = func(cctx *cli.Context) error { ddir := cctx.String("datadir") + cdns := newCachedDNS(dnsCacheRefreshInterval) + defer cdns.Close() + gnd, err := Setup(cctx.Context, &Config{ ConnMgrLow: cctx.Int("connmgr-low"), ConnMgrHi: cctx.Int("connmgr-hi"), @@ -93,7 +91,7 @@ func main() { RoutingV1: cctx.String("routing"), KuboRPCURLs: getEnvs(EnvKuboRPC, DefaultKuboRPC), DHTSharedHost: cctx.Bool("dht-fallback-shared-host"), - DNSCache: newCachedDNS(dnsCacheRefreshInterval), + DNSCache: cdns, }) if err != nil { return err @@ -125,9 +123,6 @@ func main() { otel.SetTracerProvider(tp) otel.SetTextMapPropagator(autoprop.NewTextMapPropagator()) - cdns := newCachedDNS(dnsCacheRefreshInterval) - defer cdns.Close() - apiMux := makeMetricsAndDebuggingHandler() apiMux.HandleFunc("/mgr/gc", GCHandler(gnd)) diff --git a/setup.go b/setup.go index daf7521..c86fcd1 100644 --- a/setup.go +++ b/setup.go @@ -62,14 +62,6 @@ type Node struct { bwc *metrics.BandwidthCounter } -type DHTType int - -const ( - Combined DHTType = iota - Standard - Accelerated -) - type Config struct { ListenAddrs []string AnnounceAddrs []string @@ -87,7 +79,6 @@ type Config struct { RoutingV1 string KuboRPCURLs []string DHTSharedHost bool - DHTType DHTType DNSCache *cachedDNS } @@ -198,49 +189,32 @@ func Setup(ctx context.Context, cfg *Config) (*Node, error) { } } - var standardClient *dht.IpfsDHT - var fullRTClient *fullrt.FullRT + standardClient, err := dht.New(ctx, dhtHost, + dht.Datastore(memDS), + dht.BootstrapPeers(dht.GetDefaultBootstrapPeerAddrInfos()...), + dht.Mode(dht.ModeClient), + ) + if err != nil { + return nil, err + } - if cfg.DHTType == Combined || cfg.DHTType == Standard { - standardClient, err = dht.New(ctx, dhtHost, + fullRTClient, err := fullrt.NewFullRT(dhtHost, dht.DefaultPrefix, + fullrt.DHTOption( + dht.Validator(record.NamespacedValidator{ + "pk": record.PublicKeyValidator{}, + "ipns": ipns.Validator{KeyBook: h.Peerstore()}, + }), dht.Datastore(memDS), dht.BootstrapPeers(dht.GetDefaultBootstrapPeerAddrInfos()...), - dht.Mode(dht.ModeClient), - ) - if err != nil { - return nil, err - } - } - - if cfg.DHTType == Combined || cfg.DHTType == Accelerated { - fullRTClient, err = fullrt.NewFullRT(dhtHost, dht.DefaultPrefix, - fullrt.DHTOption( - dht.Validator(record.NamespacedValidator{ - "pk": record.PublicKeyValidator{}, - "ipns": ipns.Validator{KeyBook: h.Peerstore()}, - }), - dht.Datastore(memDS), - dht.BootstrapPeers(dht.GetDefaultBootstrapPeerAddrInfos()...), - dht.BucketSize(20), - )) - if err != nil { - return nil, err - } + dht.BucketSize(20), + )) + if err != nil { + return nil, err } - var dhtRouter routing.Routing - switch cfg.DHTType { - case Combined: - dhtRouter = &bundledDHT{ - standard: standardClient, - fullRT: fullRTClient, - } - case Standard: - dhtRouter = standardClient - case Accelerated: - dhtRouter = fullRTClient - default: - return nil, fmt.Errorf("unsupported DHT type") + dhtRouter := &bundledDHT{ + standard: standardClient, + fullRT: fullRTClient, } // we want to also use the default HTTP routers, so wrap the FullRT client