Skip to content

Commit

Permalink
Merge pull request #223 from jbenet/issue-209
Browse files Browse the repository at this point in the history
refactor(routing) replace u.ErrNotFound with routing.ErrNotFound
  • Loading branch information
jbenet committed Oct 28, 2014
2 parents cb3a8bf + e0f4000 commit cee1e9c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
7 changes: 4 additions & 3 deletions routing/dht/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
inet "github.com/jbenet/go-ipfs/net"
msg "github.com/jbenet/go-ipfs/net/message"
peer "github.com/jbenet/go-ipfs/peer"
routing "github.com/jbenet/go-ipfs/routing"
pb "github.com/jbenet/go-ipfs/routing/dht/pb"
kb "github.com/jbenet/go-ipfs/routing/kbucket"
u "github.com/jbenet/go-ipfs/util"
Expand Down Expand Up @@ -288,8 +289,8 @@ func (dht *IpfsDHT) getValueOrPeers(ctx context.Context, p peer.Peer,
return nil, peers, nil
}

log.Warning("getValueOrPeers: u.ErrNotFound")
return nil, nil, u.ErrNotFound
log.Warning("getValueOrPeers: routing.ErrNotFound")
return nil, nil, routing.ErrNotFound
}

// getValueSingle simply performs the get value RPC with the given parameters
Expand Down Expand Up @@ -326,7 +327,7 @@ func (dht *IpfsDHT) getFromPeerList(ctx context.Context, key u.Key,
return value, nil
}
}
return nil, u.ErrNotFound
return nil, routing.ErrNotFound
}

// getLocal attempts to retrieve the value from the datastore
Expand Down
7 changes: 4 additions & 3 deletions routing/dht/ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
msg "github.com/jbenet/go-ipfs/net/message"
mux "github.com/jbenet/go-ipfs/net/mux"
peer "github.com/jbenet/go-ipfs/peer"
"github.com/jbenet/go-ipfs/routing"
pb "github.com/jbenet/go-ipfs/routing/dht/pb"
u "github.com/jbenet/go-ipfs/util"

Expand Down Expand Up @@ -145,7 +146,7 @@ func TestGetFailures(t *testing.T) {
ctx2, _ := context.WithTimeout(context.Background(), time.Second)
_, err = d.GetValue(ctx2, u.Key("test"))
if err != nil {
if err != u.ErrNotFound {
if err != routing.ErrNotFound {
t.Fatalf("Expected ErrNotFound, got: %s", err)
}
} else {
Expand Down Expand Up @@ -247,7 +248,7 @@ func TestNotFound(t *testing.T) {
log.Debug("get value got %v", v)
if err != nil {
switch err {
case u.ErrNotFound:
case routing.ErrNotFound:
//Success!
return
case u.ErrTimeout:
Expand Down Expand Up @@ -311,7 +312,7 @@ func TestLessThanKResponses(t *testing.T) {
_, err := d.GetValue(ctx, u.Key("hello"))
if err != nil {
switch err {
case u.ErrNotFound:
case routing.ErrNotFound:
//Success!
return
case u.ErrTimeout:
Expand Down
3 changes: 2 additions & 1 deletion routing/dht/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
inet "github.com/jbenet/go-ipfs/net"
peer "github.com/jbenet/go-ipfs/peer"
queue "github.com/jbenet/go-ipfs/peer/queue"
"github.com/jbenet/go-ipfs/routing"
kb "github.com/jbenet/go-ipfs/routing/kbucket"
u "github.com/jbenet/go-ipfs/util"
todoctr "github.com/jbenet/go-ipfs/util/todocounter"
Expand Down Expand Up @@ -128,7 +129,7 @@ func (r *dhtQueryRunner) Run(peers []peer.Peer) (*dhtQueryResult, error) {
// so workers are working.

// wait until they're done.
err := u.ErrNotFound
err := routing.ErrNotFound

select {
case <-r.peersRemaining.Done():
Expand Down
5 changes: 3 additions & 2 deletions routing/dht/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"

peer "github.com/jbenet/go-ipfs/peer"
"github.com/jbenet/go-ipfs/routing"
pb "github.com/jbenet/go-ipfs/routing/dht/pb"
kb "github.com/jbenet/go-ipfs/routing/kbucket"
u "github.com/jbenet/go-ipfs/util"
Expand Down Expand Up @@ -89,7 +90,7 @@ func (dht *IpfsDHT) GetValue(ctx context.Context, key u.Key) ([]byte, error) {

log.Debugf("GetValue %v %v", key, result.value)
if result.value == nil {
return nil, u.ErrNotFound
return nil, routing.ErrNotFound
}

return result.value, nil
Expand Down Expand Up @@ -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)
if result.peer == nil {
return nil, u.ErrNotFound
return nil, routing.ErrNotFound
}

return result.peer, nil
Expand Down
5 changes: 5 additions & 0 deletions routing/routing.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package routing

import (
"errors"

context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"

peer "github.com/jbenet/go-ipfs/peer"
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
// It is implemented by things like DHTs, etc.
type IpfsRouting interface {
Expand Down

0 comments on commit cee1e9c

Please sign in to comment.