Skip to content

Commit

Permalink
Remove DHTType option - it wasn't wired-in
Browse files Browse the repository at this point in the history
Statichecks
  • Loading branch information
hsanjuan committed Oct 6, 2023
1 parent 0c41709 commit 86f8437
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 58 deletions.
4 changes: 2 additions & 2 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ func setupGatewayHandler(nd *Node) (http.Handler, error) {
})

Check warning on line 148 in handlers.go

View check run for this annotation

Codecov / codecov/patch

handlers.go#L132-L148

Added lines #L132 - L148 were not covered by tests
// 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)
Expand Down
13 changes: 4 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,16 @@ func main() {
Value: false,
Usage: "If using an Amino DHT client should the libp2p host be shared with the data downloading host",

Check warning on line 72 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L66-L72

Added lines #L66 - L72 were not covered by tests
},
&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"
app.Usage = "a standalone ipfs gateway"
app.Version = version
app.Action = func(cctx *cli.Context) error {
ddir := cctx.String("datadir")
cdns := newCachedDNS(dnsCacheRefreshInterval)
defer cdns.Close()

Check warning on line 83 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L81-L83

Added lines #L81 - L83 were not covered by tests
gnd, err := Setup(cctx.Context, &Config{
ConnMgrLow: cctx.Int("connmgr-low"),
ConnMgrHi: cctx.Int("connmgr-hi"),
Expand All @@ -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,

Check warning on line 94 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L92-L94

Added lines #L92 - L94 were not covered by tests
})
if err != nil {
return err
Expand Down Expand Up @@ -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))

Expand Down
68 changes: 21 additions & 47 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -87,7 +79,6 @@ type Config struct {
RoutingV1 string
KuboRPCURLs []string
DHTSharedHost bool
DHTType DHTType
DNSCache *cachedDNS
}

Expand Down Expand Up @@ -198,49 +189,32 @@ func Setup(ctx context.Context, cfg *Config) (*Node, error) {
}

Check warning on line 189 in setup.go

View check run for this annotation

Codecov / codecov/patch

setup.go#L177-L189

Added lines #L177 - L189 were not covered by tests
}

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
}

Check warning on line 199 in setup.go

View check run for this annotation

Codecov / codecov/patch

setup.go#L192-L199

Added lines #L192 - L199 were not covered by tests

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
}

Check warning on line 213 in setup.go

View check run for this annotation

Codecov / codecov/patch

setup.go#L201-L213

Added lines #L201 - L213 were not covered by tests

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
Expand Down

0 comments on commit 86f8437

Please sign in to comment.