Gofmt
License: MIT Signed-off-by: Erik Ingenito <erik@carbonfive.com>
Erik Ingenito committed
Mar 15, 2019 at 16:36 UTC
7fcafb66152f5ac0f49e82899932432d0e445a55
4 files changed
+26
-29
provider/provider.go
+1
-1
@@ -11,7 +11,7 @@ import (
11
routing "github.com/libp2p/go-libp2p-routing"
12
)
13
14
-var log = logging.Logger("provider")
14
+var log = logging.Logger("provider")
15
16
const provideOutgoingWorkerLimit = 8
17
provider/provider_test.go
+10
-10
@@ -6,11 +6,11 @@ import (
6
"testing"
7
"time"
8
9
- blocksutil "github.com/ipfs/go-ipfs-blocksutil"
9
cid "github.com/ipfs/go-cid"
10
datastore "github.com/ipfs/go-datastore"
12
- pstore "github.com/libp2p/go-libp2p-peerstore"
11
sync "github.com/ipfs/go-datastore/sync"
12
+ blocksutil "github.com/ipfs/go-ipfs-blocksutil"
13
+ pstore "github.com/libp2p/go-libp2p-peerstore"
14
)
15
16
var blockGenerator = blocksutil.NewBlockGenerator()
@@ -58,13 +58,13 @@ func TestAnnouncement(t *testing.T) {
58
59
for cids.Len() > 0 {
60
select {
61
- case cp := <-r.provided:
62
- if !cids.Has(cp) {
63
- t.Fatal("Wrong CID provided")
64
- }
65
- cids.Remove(cp)
66
- case <-time.After(time.Second * 5):
67
- t.Fatal("Timeout waiting for cids to be provided.")
61
+ case cp := <-r.provided:
62
+ if !cids.Has(cp) {
63
+ t.Fatal("Wrong CID provided")
64
+ }
65
+ cids.Remove(cp)
66
+ case <-time.After(time.Second * 5):
67
+ t.Fatal("Timeout waiting for cids to be provided.")
68
}
69
}
70
}
@@ -77,4 +77,4 @@ func (r *mockRouting) Provide(ctx context.Context, cid cid.Cid, recursive bool)
77
// Search for peers who are able to provide a given key
78
func (r *mockRouting) FindProvidersAsync(ctx context.Context, cid cid.Cid, timeout int) <-chan pstore.PeerInfo {
79
return nil
80
-}
\ No newline at end of file
80
+}
provider/queue.go
+14
-17
@@ -19,14 +19,11 @@ import (
19
type Queue struct {
20
// used to differentiate queues in datastore
21
// e.g. provider vs reprovider
22
- name string
23
- ctx context.Context
24
-
25
- tail uint64
26
- head uint64
27
-
28
- ds datastore.Datastore // Must be threadsafe
29
-
22
+ name string
23
+ ctx context.Context
24
+ tail uint64
25
+ head uint64
26
+ ds datastore.Datastore // Must be threadsafe
27
dequeue chan cid.Cid
28
enqueue chan cid.Cid
29
}
@@ -39,13 +36,13 @@ func NewQueue(ctx context.Context, name string, ds datastore.Datastore) (*Queue,
36
return nil, err
37
}
38
q := &Queue{
42
- name: name,
43
- ctx: ctx,
44
- head: head,
45
- tail: tail,
46
- ds: namespaced,
47
- dequeue: make(chan cid.Cid),
48
- enqueue: make(chan cid.Cid),
39
+ name: name,
40
+ ctx: ctx,
41
+ head: head,
42
+ tail: tail,
43
+ ds: namespaced,
44
+ dequeue: make(chan cid.Cid),
45
+ enqueue: make(chan cid.Cid),
46
}
47
q.work()
48
return q, nil
@@ -54,8 +51,8 @@ func NewQueue(ctx context.Context, name string, ds datastore.Datastore) (*Queue,
51
// Enqueue puts a cid in the queue
52
func (q *Queue) Enqueue(cid cid.Cid) {
53
select {
57
- case q.enqueue <- cid:
58
- case <-q.ctx.Done():
54
+ case q.enqueue <- cid:
55
+ case <-q.ctx.Done():
56
}
57
}
58
provider/queue_test.go
+1
-1
@@ -22,7 +22,7 @@ func makeCids(n int) []cid.Cid {
22
func assertOrdered(cids []cid.Cid, q *Queue, t *testing.T) {
23
for _, c := range cids {
24
select {
25
- case dequeued := <- q.dequeue:
25
+ case dequeued := <-q.dequeue:
26
if c != dequeued {
27
t.Fatalf("Error in ordering of CIDs retrieved from queue. Expected: %s, got: %s", c, dequeued)
28
}