switch to StreamingSet in cidutil
License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
Steven Allen committed
Aug 21, 2018 at 19:24 UTC
7139b8366666492090cb2efb66aab730fc1f5593
3 files changed
+5
-43
core/coreapi/dht.go
+2
-2
@@ -7,10 +7,10 @@ import (
7
8
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
9
caopts "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
10
- "github.com/ipfs/go-ipfs/thirdparty/streaming-cid-set"
10
11
dag "gx/ipfs/QmNr4E8z9bGTztvHJktp7uQaMdx9p3r9Asrq6eYk7iCh4a/go-merkledag"
12
offline "gx/ipfs/QmPuLWvxK1vg6ckKUpT53Dow9VLCcQGdL5Trwxa8PTLp7r/go-ipfs-exchange-offline"
13
+ cidutil "gx/ipfs/QmPyxJ2QS7L5FhGkNYkNcXHGjDhvGHueJ4auqAstFHYxy5/go-cidutil"
14
blockservice "gx/ipfs/QmQLG22wSEStiociTSKQpZAuuaaWoF1B3iKyjPFvWiTQ77/go-blockservice"
15
peer "gx/ipfs/QmQsErDt8Qgw1XrsXf2BpEzDgGWtB1YLsTAARBup5b6B9W/go-libp2p-peer"
16
routing "gx/ipfs/QmY9JUvS8kbgao3XbPh6WAV3ChE2nxGKhcGTHiwMC4gmcU/go-libp2p-routing"
@@ -99,7 +99,7 @@ func provideKeys(ctx context.Context, r routing.IpfsRouting, cids []*cid.Cid) er
99
}
100
101
func provideKeysRec(ctx context.Context, r routing.IpfsRouting, bs blockstore.Blockstore, cids []*cid.Cid) error {
102
- provided := streamingset.NewStreamingSet()
102
+ provided := cidutil.NewStreamingSet()
103
104
errCh := make(chan error)
105
go func() {
exchange/reprovide/providers.go
+3
-3
@@ -4,9 +4,9 @@ import (
4
"context"
5
6
pin "github.com/ipfs/go-ipfs/pin"
7
- "github.com/ipfs/go-ipfs/thirdparty/streaming-cid-set"
7
8
merkledag "gx/ipfs/QmNr4E8z9bGTztvHJktp7uQaMdx9p3r9Asrq6eYk7iCh4a/go-merkledag"
9
+ cidutil "gx/ipfs/QmPyxJ2QS7L5FhGkNYkNcXHGjDhvGHueJ4auqAstFHYxy5/go-cidutil"
10
ipld "gx/ipfs/QmX5CsuHyVZeTLxgRSYkgLSDQKb9UjE8xnhQzCEJWWWFsC/go-ipld-format"
11
cid "gx/ipfs/QmZFbDTY9jfSBms2MchvYM9oYRbAF19K7Pby47yDBfpPrb/go-cid"
12
blocks "gx/ipfs/Qmeg56ecxRnVv7VWViMrDeEMoBHaNFMs4vQnyQrJ79Zz7i/go-ipfs-blockstore"
@@ -44,8 +44,8 @@ func NewPinnedProvider(pinning pin.Pinner, dag ipld.DAGService, onlyRoots bool)
44
}
45
}
46
47
-func pinSet(ctx context.Context, pinning pin.Pinner, dag ipld.DAGService, onlyRoots bool) (*streamingset.StreamingSet, error) {
48
- set := streamingset.NewStreamingSet()
47
+func pinSet(ctx context.Context, pinning pin.Pinner, dag ipld.DAGService, onlyRoots bool) (*cidutil.StreamingSet, error) {
48
+ set := cidutil.NewStreamingSet()
49
50
go func() {
51
ctx, cancel := context.WithCancel(ctx)
thirdparty/streaming-cid-set/set.go
deleted
-38
@@ -1,38 +0,0 @@
1
-package streamingset
2
-
3
-import (
4
- "context"
5
-
6
- cid "gx/ipfs/QmZFbDTY9jfSBms2MchvYM9oYRbAF19K7Pby47yDBfpPrb/go-cid"
7
-)
8
-
9
-// StreamingSet is an extension of cid.Set which allows to implement back-pressure
10
-// for the Visit function
11
-type StreamingSet struct {
12
- Set *cid.Set
13
- New chan *cid.Cid
14
-}
15
-
16
-// NewStreamingSet initializes and returns new Set.
17
-func NewStreamingSet() *StreamingSet {
18
- return &StreamingSet{
19
- Set: cid.NewSet(),
20
- New: make(chan *cid.Cid),
21
- }
22
-}
23
-
24
-// Visitor creates new visitor which adds a Cids to the set and emits them to
25
-// the set.New channel
26
-func (s *StreamingSet) Visitor(ctx context.Context) func(c *cid.Cid) bool {
27
- return func(c *cid.Cid) bool {
28
- if s.Set.Visit(c) {
29
- select {
30
- case s.New <- c:
31
- case <-ctx.Done():
32
- }
33
- return true
34
- }
35
-
36
- return false
37
- }
38
-}