refactor(routing) use routing.ErrNotFound
Brian Tiger Chow committed
Oct 28, 2014 at 02:17 UTC
321eb421e7f5b36918c8de482b2dfb3c16d5321d
4 files changed
+13
-9
routing/dht/dht.go
+4
-3
@@ -11,6 +11,7 @@ import (
11
inet "github.com/jbenet/go-ipfs/net"
12
msg "github.com/jbenet/go-ipfs/net/message"
13
peer "github.com/jbenet/go-ipfs/peer"
14
+ routing "github.com/jbenet/go-ipfs/routing"
15
pb "github.com/jbenet/go-ipfs/routing/dht/pb"
16
kb "github.com/jbenet/go-ipfs/routing/kbucket"
17
u "github.com/jbenet/go-ipfs/util"
@@ -288,8 +289,8 @@ func (dht *IpfsDHT) getValueOrPeers(ctx context.Context, p peer.Peer,
289
return nil, peers, nil
290
}
291
291
- log.Warning("getValueOrPeers: u.ErrNotFound")
292
- return nil, nil, u.ErrNotFound
292
+ log.Warning("getValueOrPeers: routing.ErrNotFound")
293
+ return nil, nil, routing.ErrNotFound
294
}
295
296
// 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,
327
return value, nil
328
}
329
}
329
- return nil, u.ErrNotFound
330
+ return nil, routing.ErrNotFound
331
}
332
333
// getLocal attempts to retrieve the value from the datastore
routing/dht/ext_test.go
+4
-3
@@ -12,6 +12,7 @@ import (
12
msg "github.com/jbenet/go-ipfs/net/message"
13
mux "github.com/jbenet/go-ipfs/net/mux"
14
peer "github.com/jbenet/go-ipfs/peer"
15
+ "github.com/jbenet/go-ipfs/routing"
16
pb "github.com/jbenet/go-ipfs/routing/dht/pb"
17
u "github.com/jbenet/go-ipfs/util"
18
@@ -145,7 +146,7 @@ func TestGetFailures(t *testing.T) {
146
ctx2, _ := context.WithTimeout(context.Background(), time.Second)
147
_, err = d.GetValue(ctx2, u.Key("test"))
148
if err != nil {
148
- if err != u.ErrNotFound {
149
+ if err != routing.ErrNotFound {
150
t.Fatalf("Expected ErrNotFound, got: %s", err)
151
}
152
} else {
@@ -247,7 +248,7 @@ func TestNotFound(t *testing.T) {
248
log.Debug("get value got %v", v)
249
if err != nil {
250
switch err {
250
- case u.ErrNotFound:
251
+ case routing.ErrNotFound:
252
//Success!
253
return
254
case u.ErrTimeout:
@@ -311,7 +312,7 @@ func TestLessThanKResponses(t *testing.T) {
312
_, err := d.GetValue(ctx, u.Key("hello"))
313
if err != nil {
314
switch err {
314
- case u.ErrNotFound:
315
+ case routing.ErrNotFound:
316
//Success!
317
return
318
case u.ErrTimeout:
routing/dht/query.go
+2
-1
@@ -6,6 +6,7 @@ import (
6
inet "github.com/jbenet/go-ipfs/net"
7
peer "github.com/jbenet/go-ipfs/peer"
8
queue "github.com/jbenet/go-ipfs/peer/queue"
9
+ "github.com/jbenet/go-ipfs/routing"
10
kb "github.com/jbenet/go-ipfs/routing/kbucket"
11
u "github.com/jbenet/go-ipfs/util"
12
todoctr "github.com/jbenet/go-ipfs/util/todocounter"
@@ -128,7 +129,7 @@ func (r *dhtQueryRunner) Run(peers []peer.Peer) (*dhtQueryResult, error) {
129
// so workers are working.
130
131
// wait until they're done.
131
- err := u.ErrNotFound
132
+ err := routing.ErrNotFound
133
134
select {
135
case <-r.peersRemaining.Done():
routing/dht/routing.go
+3
-2
@@ -6,6 +6,7 @@ import (
6
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
7
8
peer "github.com/jbenet/go-ipfs/peer"
9
+ "github.com/jbenet/go-ipfs/routing"
10
pb "github.com/jbenet/go-ipfs/routing/dht/pb"
11
kb "github.com/jbenet/go-ipfs/routing/kbucket"
12
u "github.com/jbenet/go-ipfs/util"
@@ -89,7 +90,7 @@ func (dht *IpfsDHT) GetValue(ctx context.Context, key u.Key) ([]byte, error) {
90
91
log.Debugf("GetValue %v %v", key, result.value)
92
if result.value == nil {
92
- return nil, u.ErrNotFound
93
+ return nil, routing.ErrNotFound
94
}
95
96
return result.value, nil
@@ -248,7 +249,7 @@ func (dht *IpfsDHT) FindPeer(ctx context.Context, id peer.ID) (peer.Peer, error)
249
250
log.Debug("FindPeer %v %v", id, result.success)
251
if result.peer == nil {
251
- return nil, u.ErrNotFound
252
+ return nil, routing.ErrNotFound
253
}
254
255
return result.peer, nil