Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add zikade DHT router #10154

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions config/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ func (r *RouterParser) UnmarshalJSON(b []byte) error {
p = &HTTPRouterParams{}
case RouterTypeDHT:
p = &DHTRouterParams{}
case RouterTypeDHTZikade:
p = &DHTZikadeRouterParams{}
case RouterTypeSequential:
p = &ComposableRouterParams{}
case RouterTypeParallel:
Expand All @@ -106,6 +108,7 @@ type RouterType string
const (
RouterTypeHTTP RouterType = "http" // HTTP JSON API for delegated routing systems (IPIP-337).
RouterTypeDHT RouterType = "dht" // DHT router.
RouterTypeDHTZikade RouterType = "dht/zikade" // DHT router using go-libp2p-kad-dht/v2.
RouterTypeSequential RouterType = "sequential" // Router helper to execute several routers sequentially.
RouterTypeParallel RouterType = "parallel" // Router helper to execute several routers in parallel.
)
Expand Down Expand Up @@ -158,6 +161,11 @@ type DHTRouterParams struct {
PublicIPNetwork bool
}

type DHTZikadeRouterParams struct {
Mode DHTMode
PublicIPNetwork bool
}

type ComposableRouterParams struct {
Routers []ConfigRouter
Timeout *OptionalDuration `json:",omitempty"`
Expand Down
10 changes: 10 additions & 0 deletions config/routing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ func TestRouterParameters(t *testing.T) {
PublicIPNetwork: false,
},
}},
"router-zikade": {Router{
Type: RouterTypeDHTZikade,
Parameters: DHTZikadeRouterParams{
Mode: "auto",
PublicIPNetwork: false,
},
}},
"router-parallel": {
Router{
Type: RouterTypeParallel,
Expand Down Expand Up @@ -97,6 +104,9 @@ func TestRouterParameters(t *testing.T) {
dhtp := r2.Routers["router-dht"].Parameters
require.IsType(&DHTRouterParams{}, dhtp)

dhtv2p := r2.Routers["router-zikade"].Parameters
require.IsType(&DHTZikadeRouterParams{}, dhtv2p)

sp := r2.Routers["router-sequential"].Parameters
require.IsType(&ComposableRouterParams{}, sp)

Expand Down
28 changes: 17 additions & 11 deletions core/node/libp2p/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package libp2p
import (
"context"
"fmt"
"io"
"runtime/debug"
"sort"
"time"
Expand Down Expand Up @@ -68,25 +69,30 @@ func BaseRouting(cfg *config.Config) interface{} {
var dualDHT *ddht.DHT
if dht, ok := in.Router.(*ddht.DHT); ok {
dualDHT = dht

lc.Append(fx.Hook{
OnStop: func(ctx context.Context) error {
return dualDHT.Close()
},
})
}

if cr, ok := in.Router.(routinghelpers.ComposableRouter); ok {
for _, r := range cr.Routers() {
if dht, ok := r.(*ddht.DHT); ok {
dualDHT = dht
if dualDHT == nil {
if dht, ok := r.(*ddht.DHT); ok {
dualDHT = dht
}
}
if cl, ok := r.(io.Closer); ok {
lc.Append(fx.Hook{
OnStop: func(ctx context.Context) error {
return dualDHT.Close()
return cl.Close()
},
})
break
}

}
} else {
if cl, ok := in.Router.(io.Closer); ok {
lc.Append(fx.Hook{
OnStop: func(ctx context.Context) error {
return cl.Close()
},
})
}
}

Expand Down
47 changes: 28 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
module github.com/ipfs/kubo

// TODO: remove this replacement when https://github.com/ipfs/boxo/pull/472 is merged
// This is https://github.com/iand/boxo/tree/dhtv2
replace github.com/ipfs/boxo => github.com/iand/boxo v0.0.0-20231005135157-93ab11b28594

require (
bazil.org/fuse v0.0.0-20200117225306-7b5117fecadc
contrib.go.opencensus.io/exporter/prometheus v0.4.2
Expand All @@ -19,7 +23,7 @@ require (
github.com/ipfs/go-block-format v0.1.2
github.com/ipfs/go-cid v0.4.1
github.com/ipfs/go-cidutil v0.1.0
github.com/ipfs/go-datastore v0.6.0
github.com/ipfs/go-datastore v0.6.1-0.20230901172804-1caa2449ed7c
github.com/ipfs/go-detect-race v0.0.1
github.com/ipfs/go-ds-badger v0.3.0
github.com/ipfs/go-ds-flatfs v0.5.1
Expand Down Expand Up @@ -75,9 +79,9 @@ require (
go.opencensus.io v0.24.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0
go.opentelemetry.io/contrib/propagators/autoprop v0.42.0
go.opentelemetry.io/otel v1.16.0
go.opentelemetry.io/otel/sdk v1.16.0
go.opentelemetry.io/otel/trace v1.16.0
go.opentelemetry.io/otel v1.19.0
go.opentelemetry.io/otel/sdk v1.19.0
go.opentelemetry.io/otel/trace v1.19.0
go.uber.org/dig v1.17.0
go.uber.org/fx v1.20.0
go.uber.org/multierr v1.11.0
Expand All @@ -86,7 +90,7 @@ require (
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63
golang.org/x/mod v0.12.0
golang.org/x/sync v0.3.0
golang.org/x/sys v0.11.0
golang.org/x/sys v0.12.0
google.golang.org/protobuf v1.31.0
)

Expand Down Expand Up @@ -127,7 +131,7 @@ require (
github.com/google/pprof v0.0.0-20230821062121-407c9e7a662f // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/hannahhoward/go-pubsub v0.0.0-20200423002714-8d62886cc36e // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
Expand Down Expand Up @@ -182,8 +186,10 @@ require (
github.com/multiformats/go-varint v0.0.7 // indirect
github.com/onsi/ginkgo/v2 v2.11.0 // indirect
github.com/opencontainers/runtime-spec v1.1.0 // indirect
github.com/openzipkin/zipkin-go v0.4.1 // indirect
github.com/openzipkin/zipkin-go v0.4.2 // indirect
github.com/petar/GoLLRB v0.0.0-20210522233825-ae3b015fd3e9 // indirect
github.com/plprobelab/go-libdht v0.0.0-20230928202609-8c74cc7954b3 // indirect
github.com/plprobelab/zikade v0.0.0-20231005134401-f9b6f3275245 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/polydawn/refmt v0.89.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
Expand Down Expand Up @@ -211,27 +217,30 @@ require (
go.opentelemetry.io/contrib/propagators/b3 v1.17.0 // indirect
go.opentelemetry.io/contrib/propagators/jaeger v1.17.0 // indirect
go.opentelemetry.io/contrib/propagators/ot v1.17.0 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.14.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.16.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.14.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.16.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.14.0 // indirect
go.opentelemetry.io/otel/exporters/zipkin v1.14.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.16.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.18.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.18.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.42.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.18.0 // indirect
go.opentelemetry.io/otel/exporters/zipkin v1.18.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.19.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/zap/exp v0.1.0 // indirect
go4.org v0.0.0-20230225012048-214862532bf5 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/term v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
gonum.org/v1/gonum v0.13.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
google.golang.org/grpc v1.55.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/grpc v1.58.0 // indirect
gopkg.in/square/go-jose.v2 v2.5.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading