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

fix: prioritize closer peers #424

Merged
merged 3 commits into from
Dec 12, 2019
Merged
Changes from 1 commit
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
10 changes: 6 additions & 4 deletions dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import (
ds "github.com/ipfs/go-datastore"
logging "github.com/ipfs/go-log"
"github.com/jbenet/goprocess"
"github.com/jbenet/goprocess/context"
goprocessctx "github.com/jbenet/goprocess/context"
kb "github.com/libp2p/go-libp2p-kbucket"
"github.com/libp2p/go-libp2p-record"
record "github.com/libp2p/go-libp2p-record"
recpb "github.com/libp2p/go-libp2p-record/pb"
"github.com/multiformats/go-base32"
)
Expand Down Expand Up @@ -144,11 +144,13 @@ func NewDHTClient(ctx context.Context, h host.Host, dstore ds.Batching) *IpfsDHT
}

func makeDHT(ctx context.Context, h host.Host, dstore ds.Batching, protocols []protocol.ID, bucketSize int) *IpfsDHT {
rt := kb.NewRoutingTable(bucketSize, kb.ConvertPeerID(h.ID()), time.Minute, h.Peerstore())
self := kb.ConvertPeerID(h.ID())
rt := kb.NewRoutingTable(bucketSize, self, time.Minute, h.Peerstore())
cmgr := h.ConnManager()

rt.PeerAdded = func(p peer.ID) {
cmgr.TagPeer(p, "kbucket", 5)
dist := kb.CommonPrefixLen(self, kb.ConvertPeerID(p))
hacdias marked this conversation as resolved.
Show resolved Hide resolved
cmgr.TagPeer(p, "kbucket", 5+dist)
hacdias marked this conversation as resolved.
Show resolved Hide resolved
}

rt.PeerRemoved = func(p peer.ID) {
Stebalien marked this conversation as resolved.
Show resolved Hide resolved
Expand Down