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

Early integration of the DHT with smart-records #727

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 23 additions & 1 deletion dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/libp2p/go-libp2p-kbucket/peerdiversity"
record "github.com/libp2p/go-libp2p-record"
recpb "github.com/libp2p/go-libp2p-record/pb"
sr "github.com/libp2p/go-smart-record/protocol"

"github.com/gogo/protobuf/proto"
ds "github.com/ipfs/go-datastore"
Expand Down Expand Up @@ -60,7 +61,8 @@ const (
)

const (
kad1 protocol.ID = "/kad/1.0.0"
kad1 protocol.ID = "/kad/1.0.0"
srDhtId protocol.ID = "/sr/dht/0.0.1"
)

const (
Expand Down Expand Up @@ -148,6 +150,10 @@ type IpfsDHT struct {

// configuration variables for tests
testAddressUpdateProcessing bool

// smart records
srClient sr.SmartRecordClient
srServer sr.SmartRecordServer
}

// Assert that IPFS assumptions about interfaces aren't broken. These aren't a
Expand Down Expand Up @@ -208,6 +214,18 @@ func New(ctx context.Context, h host.Host, options ...Option) (*IpfsDHT, error)
return nil, fmt.Errorf("invalid dht mode %d", cfg.Mode)
}

// Start smart record service if enabled
if cfg.SmartRecords {
dht.srServer, err = sr.NewSmartRecordServer(ctx, h, []sr.ServerOption{sr.ServerProtocolPrefix(cfg.ProtocolPrefix)}...)
if err != nil {
return nil, fmt.Errorf("couldn't start smart record server: %v", err)
}
dht.srClient, err = sr.NewSmartRecordClient(ctx, h, []sr.ClientOption{sr.ClientProtocolPrefix(cfg.ProtocolPrefix)}...)
if err != nil {
return nil, fmt.Errorf("couldn't start smart record client: %v", err)
}
}

if dht.mode == modeServer {
if err := dht.moveToServerMode(); err != nil {
return nil, err
Expand Down Expand Up @@ -267,6 +285,10 @@ func makeDHT(ctx context.Context, h host.Host, cfg dhtcfg.Config) (*IpfsDHT, err
var protocols, serverProtocols []protocol.ID

v1proto := cfg.ProtocolPrefix + kad1
if cfg.SmartRecords {
// Use smart record protocols if enabled.
v1proto = cfg.ProtocolPrefix + srDhtId
}

if cfg.V1ProtocolOverride != "" {
v1proto = cfg.V1ProtocolOverride
Expand Down
9 changes: 9 additions & 0 deletions dht_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,12 @@ func forceAddressUpdateProcessing(t *testing.T) Option {
return nil
}
}

// EnableSmartRecords in the DHT. From now on the DHT
// supports getting
func EnableSmartRecords() Option {
return func(c *dhtcfg.Config) error {
c.SmartRecords = true
return nil
}
}
12 changes: 7 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,26 @@ require (
github.com/ipfs/go-log v1.0.5
github.com/jbenet/goprocess v0.1.4
github.com/libp2p/go-eventbus v0.2.1
github.com/libp2p/go-libp2p v0.13.0
github.com/libp2p/go-libp2p-core v0.8.0
github.com/libp2p/go-libp2p v0.13.1-0.20210420165741-6a5da01b0449
github.com/libp2p/go-libp2p-core v0.8.6-0.20210415043615-525a0b130172
github.com/libp2p/go-libp2p-kbucket v0.4.7
github.com/libp2p/go-libp2p-peerstore v0.2.7
github.com/libp2p/go-libp2p-record v0.1.3
github.com/libp2p/go-libp2p-routing-helpers v0.2.3
github.com/libp2p/go-libp2p-swarm v0.4.0
github.com/libp2p/go-libp2p-swarm v0.4.3
github.com/libp2p/go-libp2p-testing v0.4.0
github.com/libp2p/go-libp2p-xor v0.0.0-20200501025846-71e284145d58
github.com/libp2p/go-msgio v0.0.6
github.com/libp2p/go-netroute v0.1.6
github.com/libp2p/go-routing-language v0.0.0-20210531170722-12dc033e88ac
github.com/libp2p/go-smart-record v0.0.0-20210616131255-cd406cac5270
github.com/multiformats/go-base32 v0.0.3
github.com/multiformats/go-multiaddr v0.3.1
github.com/multiformats/go-multibase v0.0.3
github.com/multiformats/go-multihash v0.0.15
github.com/multiformats/go-multistream v0.2.0
github.com/multiformats/go-multistream v0.2.1
github.com/stretchr/testify v1.6.1
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1
go.opencensus.io v0.22.4
go.opencensus.io v0.23.0
go.uber.org/zap v1.16.0
)