Commit cee1e9cc authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

Merge pull request #223 from jbenet/issue-209

refactor(routing) replace u.ErrNotFound with routing.ErrNotFound
parents cb3a8bfc e0f4000f
...@@ -11,6 +11,7 @@ import ( ...@@ -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, ...@@ -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, ...@@ -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 ( ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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:
......
...@@ -6,6 +6,7 @@ import ( ...@@ -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) { ...@@ -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 ( ...@@ -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) { ...@@ -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) ...@@ -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
......
package routing package routing
import ( import (
"errors"
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"
u "github.com/jbenet/go-ipfs/util" u "github.com/jbenet/go-ipfs/util"
) )
// ErrNotFound is returned when a search fails to find anything
var ErrNotFound = errors.New("routing: not found")
// IpfsRouting is the routing module interface // IpfsRouting is the routing module interface
// It is implemented by things like DHTs, etc. // It is implemented by things like DHTs, etc.
type IpfsRouting interface { type IpfsRouting interface {
......
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