mirror of
https://github.com/fluencelabs/go-libp2p-kad-dht
synced 2025-04-24 22:32:13 +00:00
refactor(routing) use routing.ErrNotFound
This commit is contained in:
parent
be52e35ed7
commit
e3d7d2b50c
7
dht.go
7
dht.go
@ -11,6 +11,7 @@ import (
|
|||||||
inet "github.com/jbenet/go-ipfs/net"
|
inet "github.com/jbenet/go-ipfs/net"
|
||||||
msg "github.com/jbenet/go-ipfs/net/message"
|
msg "github.com/jbenet/go-ipfs/net/message"
|
||||||
peer "github.com/jbenet/go-ipfs/peer"
|
peer "github.com/jbenet/go-ipfs/peer"
|
||||||
|
routing "github.com/jbenet/go-ipfs/routing"
|
||||||
pb "github.com/jbenet/go-ipfs/routing/dht/pb"
|
pb "github.com/jbenet/go-ipfs/routing/dht/pb"
|
||||||
kb "github.com/jbenet/go-ipfs/routing/kbucket"
|
kb "github.com/jbenet/go-ipfs/routing/kbucket"
|
||||||
u "github.com/jbenet/go-ipfs/util"
|
u "github.com/jbenet/go-ipfs/util"
|
||||||
@ -288,8 +289,8 @@ func (dht *IpfsDHT) getValueOrPeers(ctx context.Context, p peer.Peer,
|
|||||||
return nil, peers, nil
|
return nil, peers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Warning("getValueOrPeers: u.ErrNotFound")
|
log.Warning("getValueOrPeers: routing.ErrNotFound")
|
||||||
return nil, nil, u.ErrNotFound
|
return nil, nil, routing.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
// getValueSingle simply performs the get value RPC with the given parameters
|
// getValueSingle simply performs the get value RPC with the given parameters
|
||||||
@ -326,7 +327,7 @@ func (dht *IpfsDHT) getFromPeerList(ctx context.Context, key u.Key,
|
|||||||
return value, nil
|
return value, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, u.ErrNotFound
|
return nil, routing.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
// getLocal attempts to retrieve the value from the datastore
|
// getLocal attempts to retrieve the value from the datastore
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
msg "github.com/jbenet/go-ipfs/net/message"
|
msg "github.com/jbenet/go-ipfs/net/message"
|
||||||
mux "github.com/jbenet/go-ipfs/net/mux"
|
mux "github.com/jbenet/go-ipfs/net/mux"
|
||||||
peer "github.com/jbenet/go-ipfs/peer"
|
peer "github.com/jbenet/go-ipfs/peer"
|
||||||
|
"github.com/jbenet/go-ipfs/routing"
|
||||||
pb "github.com/jbenet/go-ipfs/routing/dht/pb"
|
pb "github.com/jbenet/go-ipfs/routing/dht/pb"
|
||||||
u "github.com/jbenet/go-ipfs/util"
|
u "github.com/jbenet/go-ipfs/util"
|
||||||
|
|
||||||
@ -145,7 +146,7 @@ func TestGetFailures(t *testing.T) {
|
|||||||
ctx2, _ := context.WithTimeout(context.Background(), time.Second)
|
ctx2, _ := context.WithTimeout(context.Background(), time.Second)
|
||||||
_, err = d.GetValue(ctx2, u.Key("test"))
|
_, err = d.GetValue(ctx2, u.Key("test"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != u.ErrNotFound {
|
if err != routing.ErrNotFound {
|
||||||
t.Fatalf("Expected ErrNotFound, got: %s", err)
|
t.Fatalf("Expected ErrNotFound, got: %s", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -247,7 +248,7 @@ func TestNotFound(t *testing.T) {
|
|||||||
log.Debug("get value got %v", v)
|
log.Debug("get value got %v", v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch err {
|
switch err {
|
||||||
case u.ErrNotFound:
|
case routing.ErrNotFound:
|
||||||
//Success!
|
//Success!
|
||||||
return
|
return
|
||||||
case u.ErrTimeout:
|
case u.ErrTimeout:
|
||||||
@ -311,7 +312,7 @@ func TestLessThanKResponses(t *testing.T) {
|
|||||||
_, err := d.GetValue(ctx, u.Key("hello"))
|
_, err := d.GetValue(ctx, u.Key("hello"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch err {
|
switch err {
|
||||||
case u.ErrNotFound:
|
case routing.ErrNotFound:
|
||||||
//Success!
|
//Success!
|
||||||
return
|
return
|
||||||
case u.ErrTimeout:
|
case u.ErrTimeout:
|
||||||
|
3
query.go
3
query.go
@ -6,6 +6,7 @@ import (
|
|||||||
inet "github.com/jbenet/go-ipfs/net"
|
inet "github.com/jbenet/go-ipfs/net"
|
||||||
peer "github.com/jbenet/go-ipfs/peer"
|
peer "github.com/jbenet/go-ipfs/peer"
|
||||||
queue "github.com/jbenet/go-ipfs/peer/queue"
|
queue "github.com/jbenet/go-ipfs/peer/queue"
|
||||||
|
"github.com/jbenet/go-ipfs/routing"
|
||||||
kb "github.com/jbenet/go-ipfs/routing/kbucket"
|
kb "github.com/jbenet/go-ipfs/routing/kbucket"
|
||||||
u "github.com/jbenet/go-ipfs/util"
|
u "github.com/jbenet/go-ipfs/util"
|
||||||
todoctr "github.com/jbenet/go-ipfs/util/todocounter"
|
todoctr "github.com/jbenet/go-ipfs/util/todocounter"
|
||||||
@ -128,7 +129,7 @@ func (r *dhtQueryRunner) Run(peers []peer.Peer) (*dhtQueryResult, error) {
|
|||||||
// so workers are working.
|
// so workers are working.
|
||||||
|
|
||||||
// wait until they're done.
|
// wait until they're done.
|
||||||
err := u.ErrNotFound
|
err := routing.ErrNotFound
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-r.peersRemaining.Done():
|
case <-r.peersRemaining.Done():
|
||||||
|
@ -6,6 +6,7 @@ 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"
|
||||||
|
|
||||||
peer "github.com/jbenet/go-ipfs/peer"
|
peer "github.com/jbenet/go-ipfs/peer"
|
||||||
|
"github.com/jbenet/go-ipfs/routing"
|
||||||
pb "github.com/jbenet/go-ipfs/routing/dht/pb"
|
pb "github.com/jbenet/go-ipfs/routing/dht/pb"
|
||||||
kb "github.com/jbenet/go-ipfs/routing/kbucket"
|
kb "github.com/jbenet/go-ipfs/routing/kbucket"
|
||||||
u "github.com/jbenet/go-ipfs/util"
|
u "github.com/jbenet/go-ipfs/util"
|
||||||
@ -89,7 +90,7 @@ func (dht *IpfsDHT) GetValue(ctx context.Context, key u.Key) ([]byte, error) {
|
|||||||
|
|
||||||
log.Debugf("GetValue %v %v", key, result.value)
|
log.Debugf("GetValue %v %v", key, result.value)
|
||||||
if result.value == nil {
|
if result.value == nil {
|
||||||
return nil, u.ErrNotFound
|
return nil, routing.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.value, nil
|
return result.value, nil
|
||||||
@ -248,7 +249,7 @@ func (dht *IpfsDHT) FindPeer(ctx context.Context, id peer.ID) (peer.Peer, error)
|
|||||||
|
|
||||||
log.Debug("FindPeer %v %v", id, result.success)
|
log.Debug("FindPeer %v %v", id, result.success)
|
||||||
if result.peer == nil {
|
if result.peer == nil {
|
||||||
return nil, u.ErrNotFound
|
return nil, routing.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.peer, nil
|
return result.peer, nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user