Commit 8fb94daa authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

Merge pull request #779 from jbenet/fix/dht

this might solve all our problems
parents dee43a39 066ebda6
......@@ -3,7 +3,6 @@ package dht
import (
"errors"
"fmt"
"time"
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
......@@ -63,9 +62,6 @@ func (dht *IpfsDHT) handleGetValue(ctx context.Context, p peer.ID, pmes *pb.Mess
return nil, err
}
// Note: changed the behavior here to return _as much_ info as possible
// (potentially all of {value, closer peers, provider})
// if we have the value, send it back
if err == nil {
log.Debugf("%s handleGetValue success!", dht.self)
......@@ -85,18 +81,10 @@ func (dht *IpfsDHT) handleGetValue(ctx context.Context, p peer.ID, pmes *pb.Mess
resp.Record = rec
}
// if we know any providers for the requested value, return those.
provs := dht.providers.GetProviders(ctx, u.Key(pmes.GetKey()))
provinfos := peer.PeerInfos(dht.peerstore, provs)
if len(provs) > 0 {
log.Debugf("handleGetValue returning %d provider[s]", len(provs))
resp.ProviderPeers = pb.PeerInfosToPBPeers(dht.host.Network(), provinfos)
}
// Find closest peer on given cluster to desired key and reply with that info
closer := dht.betterPeersToQuery(pmes, p, CloserPeerCount)
closerinfos := peer.PeerInfos(dht.peerstore, closer)
if closer != nil {
closerinfos := peer.PeerInfos(dht.peerstore, closer)
for _, pi := range closerinfos {
log.Debugf("handleGetValue returning closer peer: '%s'", pi.ID)
if len(pi.Addrs) < 1 {
......@@ -201,7 +189,7 @@ func (dht *IpfsDHT) handleGetProviders(ctx context.Context, p peer.ID, pmes *pb.
// Also send closer peers.
closer := dht.betterPeersToQuery(pmes, p, CloserPeerCount)
if closer != nil {
infos := peer.PeerInfos(dht.peerstore, providers)
infos := peer.PeerInfos(dht.peerstore, closer)
resp.CloserPeers = pb.PeerInfosToPBPeers(dht.host.Network(), infos)
log.Debugf("%s have %d closer peers: %s", reqDesc, len(closer), infos)
}
......@@ -209,11 +197,6 @@ func (dht *IpfsDHT) handleGetProviders(ctx context.Context, p peer.ID, pmes *pb.
return resp, nil
}
type providerInfo struct {
Creation time.Time
Value peer.ID
}
func (dht *IpfsDHT) handleAddProvider(ctx context.Context, p peer.ID, pmes *pb.Message) (*pb.Message, error) {
defer log.EventBegin(ctx, "handleAddProvider", p).Done()
key := u.Key(pmes.GetKey())
......
......@@ -10,6 +10,11 @@ import (
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
)
type providerInfo struct {
Creation time.Time
Value peer.ID
}
type ProviderManager struct {
providers map[u.Key][]*providerInfo
local map[u.Key]struct{}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment