From 321eb421e7f5b36918c8de482b2dfb3c16d5321d Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow <brian.holderchow@gmail.com> Date: Tue, 28 Oct 2014 02:17:46 -0700 Subject: [PATCH] refactor(routing) use routing.ErrNotFound --- routing/dht/dht.go | 7 ++++--- routing/dht/ext_test.go | 7 ++++--- routing/dht/query.go | 3 ++- routing/dht/routing.go | 5 +++-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/routing/dht/dht.go b/routing/dht/dht.go index 76cde7fb5..f1c422721 100644 --- a/routing/dht/dht.go +++ b/routing/dht/dht.go @@ -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" @@ -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 @@ -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 diff --git a/routing/dht/ext_test.go b/routing/dht/ext_test.go index be6f17d96..77684db28 100644 --- a/routing/dht/ext_test.go +++ b/routing/dht/ext_test.go @@ -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" @@ -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 { @@ -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: @@ -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: diff --git a/routing/dht/query.go b/routing/dht/query.go index d15e939b7..48974b8eb 100644 --- a/routing/dht/query.go +++ b/routing/dht/query.go @@ -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" @@ -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(): diff --git a/routing/dht/routing.go b/routing/dht/routing.go index 64a7edbd6..44edd99a7 100644 --- a/routing/dht/routing.go +++ b/routing/dht/routing.go @@ -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" @@ -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 @@ -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 -- GitLab