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

Asynchronous lookups #498

Merged
merged 19 commits into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
2 changes: 2 additions & 0 deletions dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ type IpfsDHT struct {

bucketSize int
alpha int // The concurrency parameter per path
beta int // The number of peers closest to a target that must have responded for a query path to terminate
d int // Number of Disjoint Paths to query

autoRefresh bool
Expand Down Expand Up @@ -234,6 +235,7 @@ func makeDHT(ctx context.Context, h host.Host, cfg config) (*IpfsDHT, error) {
serverProtocols: serverProtocols,
bucketSize: cfg.bucketSize,
alpha: cfg.concurrency,
beta: cfg.resiliency,
d: cfg.disjointPaths,
triggerRtRefresh: make(chan chan<- error),
triggerSelfLookup: make(chan chan<- error),
Expand Down
10 changes: 3 additions & 7 deletions dht_bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
multierror "github.com/hashicorp/go-multierror"
process "github.com/jbenet/goprocess"
processctx "github.com/jbenet/goprocess/context"
"github.com/libp2p/go-libp2p-core/routing"
kbucket "github.com/libp2p/go-libp2p-kbucket"
"github.com/multiformats/go-multiaddr"
_ "github.com/multiformats/go-multiaddr-dns"
Expand Down Expand Up @@ -58,8 +57,8 @@ func (dht *IpfsDHT) startSelfLookup() error {

// Do a self walk
queryCtx, cancel := context.WithTimeout(ctx, dht.rtRefreshQueryTimeout)
_, err := dht.FindPeer(queryCtx, dht.self)
if err == routing.ErrNotFound || err == kbucket.ErrLookupFailure {
_, err := dht.GetClosestPeers(queryCtx, string(dht.self))
if err == kbucket.ErrLookupFailure {
err = nil
} else if err != nil {
err = fmt.Errorf("failed to query self during routing table refresh: %s", err)
Expand Down Expand Up @@ -207,10 +206,7 @@ func (dht *IpfsDHT) refreshCpls(ctx context.Context) error {

// walk to the generated peer
walkFnc := func(c context.Context) error {
_, err := dht.FindPeer(c, randPeer)
if err == routing.ErrNotFound {
return nil
}
_, err := dht.GetClosestPeers(c, string(randPeer))
return err
}

Expand Down
13 changes: 13 additions & 0 deletions dht_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type config struct {
bucketSize int
disjointPaths int
concurrency int
resiliency int
maxRecordAge time.Duration
enableProviders bool
enableValues bool
Expand Down Expand Up @@ -87,6 +88,7 @@ var defaults = func(o *config) error {

o.bucketSize = defaultBucketSize
o.concurrency = 3
o.resiliency = 3
aschmahmann marked this conversation as resolved.
Show resolved Hide resolved

return nil
}
Expand Down Expand Up @@ -239,6 +241,17 @@ func Concurrency(alpha int) Option {
}
}

// Resiliency configures the number of peers closest to a target that must have responded in order for a given query
// path to complete.
//
// The default value is 3.
func Resiliency(beta int) Option {
return func(c *config) error {
c.resiliency = beta
return nil
}
}

// DisjointPaths configures the number of disjoint paths (d in the S/Kademlia paper) taken per query.
//
// The default value is BucketSize/2.
Expand Down
4 changes: 2 additions & 2 deletions dht_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1467,8 +1467,8 @@ func TestFindClosestPeers(t *testing.T) {
out = append(out, p)
}

if len(out) != querier.bucketSize {
t.Fatalf("got wrong number of peers (got %d, expected %d)", len(out), querier.bucketSize)
if len(out) < querier.beta {
t.Fatalf("got wrong number of peers (got %d, expected at least %d)", len(out), querier.beta)
Comment on lines +1470 to +1471
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is pretty strange but indicative of the changes we've been making. The test seems to setup a ring of peers and then calls GetClosestPeers. In the past we were much more thorough in our queries and effectively ignored most of the benefits that can be assumed in a Kademlia network with fairly accurate routing tables. This meant we could have a ring of 30 peers and get 20 of them no problem.

Now, we more strongly rely on the routing tables being good and so in this ring setup it seems like we're only guaranteed to return > beta peers instead of k.

Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've basically broken the contract of GetClosestPeers as I've commented elsewhere. There are a couple of things we can/should do to address these which have been mentioned in the comment.

}
}

Expand Down
110 changes: 0 additions & 110 deletions kpeerset/peerheap/heap.go

This file was deleted.

91 changes: 0 additions & 91 deletions kpeerset/peerheap/heap_test.go

This file was deleted.

Loading