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

reduce dht bandwidth consumption #986

Merged
merged 1 commit into from
Apr 1, 2015
Merged
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
2 changes: 1 addition & 1 deletion routing/dht/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,5 +226,5 @@ func (dht *IpfsDHT) handleAddProvider(ctx context.Context, p peer.ID, pmes *pb.M
dht.providers.AddProvider(ctx, key, p)
}

return pmes, nil // send back same msg as confirmation.
return nil, nil
Copy link
Member

Choose a reason for hiding this comment

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

hmm so then we really have no way of confirming. could we maybe comment this out and make note of this? from a protocol standpoint it will be useful to confirm these things-- but perhaps the protocol can change.

By the way, muxing all dht traffic over one stream will really, really help.

Copy link
Member Author

Choose a reason for hiding this comment

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

This change makes it more closely follow kademlia, and makes more sense with us wanting to change over to a UDP protocol for the DHT (not saying thats happening soon, just those concepts).

Copy link
Member

Choose a reason for hiding this comment

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

agreed on that. but some dht protocols (particularly if we start doing cryptographic proofs on things) may call for other constructions too. in any case, not very important. either way

}
9 changes: 7 additions & 2 deletions routing/dht/records.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ func (dht *IpfsDHT) getPublicKeyOnline(ctx context.Context, p peer.ID) (ci.PubKe
ctxT, cancelFunc := ctxutil.WithDeadlineFraction(ctx, 0.3)
defer cancelFunc()
if pk, err := dht.getPublicKeyFromNode(ctx, p); err == nil {
err := dht.peerstore.AddPubKey(p, pk)
if err != nil {
return pk, err
}
return pk, nil
}

// last ditch effort: let's try the dht.
log.Debugf("pk for %s not in peerstore, and peer failed. trying dht.", p)
pkkey := KeyForPublicKey(p)

// ok, try the node itself. if they're overwhelmed or slow we can move on.
// ok, now try the dht. Anyone who has previously fetched the key should have it
val, err := dht.GetValue(ctxT, pkkey)
if err != nil {
log.Warning("Failed to find requested public key.")
Expand All @@ -50,7 +54,8 @@ func (dht *IpfsDHT) getPublicKeyOnline(ctx context.Context, p peer.ID) (ci.PubKe
log.Debugf("Failed to unmarshal public key: %s", err)
return nil, err
}
return pk, nil

return pk, dht.peerstore.AddPubKey(p, pk)
}

func (dht *IpfsDHT) getPublicKeyFromNode(ctx context.Context, p peer.ID) (ci.PubKey, error) {
Expand Down
8 changes: 4 additions & 4 deletions routing/dht/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (dht *IpfsDHT) GetValue(ctx context.Context, key u.Key) ([]byte, error) {
}

// get closest peers in the routing table
rtp := dht.routingTable.ListPeers()
rtp := dht.routingTable.NearestPeers(kb.ConvertKey(key), AlphaValue)
log.Debugf("peers in rt: %s", len(rtp), rtp)
if len(rtp) == 0 {
log.Warning("No peers from routing table!")
Expand Down Expand Up @@ -256,7 +256,7 @@ func (dht *IpfsDHT) findProvidersAsyncRoutine(ctx context.Context, key u.Key, co
return &dhtQueryResult{closerPeers: clpeers}, nil
})

peers := dht.routingTable.ListPeers()
peers := dht.routingTable.NearestPeers(kb.ConvertKey(key), AlphaValue)
_, err := query.Run(ctx, peers)
if err != nil {
log.Debugf("Query error: %s", err)
Expand All @@ -276,7 +276,7 @@ func (dht *IpfsDHT) FindPeer(ctx context.Context, id peer.ID) (peer.PeerInfo, er
return pi, nil
}

peers := dht.routingTable.ListPeers()
peers := dht.routingTable.NearestPeers(kb.ConvertPeerID(id), AlphaValue)
if len(peers) == 0 {
return peer.PeerInfo{}, errors.Wrap(kb.ErrLookupFailure)
}
Expand Down Expand Up @@ -342,7 +342,7 @@ func (dht *IpfsDHT) FindPeersConnectedToPeer(ctx context.Context, id peer.ID) (<
peerchan := make(chan peer.PeerInfo, asyncQueryBuffer)
peersSeen := peer.Set{}

peers := dht.routingTable.ListPeers()
peers := dht.routingTable.NearestPeers(kb.ConvertPeerID(id), AlphaValue)
if len(peers) == 0 {
return nil, errors.Wrap(kb.ErrLookupFailure)
}
Expand Down