mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-10 14:34:24 +08:00
a few more cleanup changes to handlers
This commit is contained in:
@ -3,7 +3,6 @@ package dht
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
|
|
||||||
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
|
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"
|
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
|
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 we have the value, send it back
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.Debugf("%s handleGetValue success!", dht.self)
|
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
|
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
|
// Find closest peer on given cluster to desired key and reply with that info
|
||||||
closer := dht.betterPeersToQuery(pmes, p, CloserPeerCount)
|
closer := dht.betterPeersToQuery(pmes, p, CloserPeerCount)
|
||||||
closerinfos := peer.PeerInfos(dht.peerstore, closer)
|
|
||||||
if closer != nil {
|
if closer != nil {
|
||||||
|
closerinfos := peer.PeerInfos(dht.peerstore, closer)
|
||||||
for _, pi := range closerinfos {
|
for _, pi := range closerinfos {
|
||||||
log.Debugf("handleGetValue returning closer peer: '%s'", pi.ID)
|
log.Debugf("handleGetValue returning closer peer: '%s'", pi.ID)
|
||||||
if len(pi.Addrs) < 1 {
|
if len(pi.Addrs) < 1 {
|
||||||
@ -209,11 +197,6 @@ func (dht *IpfsDHT) handleGetProviders(ctx context.Context, p peer.ID, pmes *pb.
|
|||||||
return resp, nil
|
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) {
|
func (dht *IpfsDHT) handleAddProvider(ctx context.Context, p peer.ID, pmes *pb.Message) (*pb.Message, error) {
|
||||||
defer log.EventBegin(ctx, "handleAddProvider", p).Done()
|
defer log.EventBegin(ctx, "handleAddProvider", p).Done()
|
||||||
key := u.Key(pmes.GetKey())
|
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"
|
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 {
|
type ProviderManager struct {
|
||||||
providers map[u.Key][]*providerInfo
|
providers map[u.Key][]*providerInfo
|
||||||
local map[u.Key]struct{}
|
local map[u.Key]struct{}
|
||||||
|
Reference in New Issue
Block a user