Skip to content

Commit

Permalink
Revert "Merge pull request ipfs/go-ipfs-provider#30 from ipfs/feat/us…
Browse files Browse the repository at this point in the history
…e_ipld_prime"

This reverts commit bbafe76, reversing
changes made to b8fd93c8e02bf176c5649b5684e535f51ae8686c.


This commit was moved from ipfs/go-ipfs-provider@46797b1
  • Loading branch information
Stebalien committed Mar 22, 2021
1 parent bbafe76 commit 0f4e8f0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
25 changes: 9 additions & 16 deletions provider/simple/reprovide.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"github.com/cenkalti/backoff"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-cidutil"
"github.com/ipfs/go-fetcher"
blocks "github.com/ipfs/go-ipfs-blockstore"
ipld "github.com/ipfs/go-ipld-format"
logging "github.com/ipfs/go-log"
"github.com/ipfs/go-merkledag"
"github.com/ipfs/go-verifcid"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
"github.com/libp2p/go-libp2p-core/routing"
)

Expand Down Expand Up @@ -184,9 +184,9 @@ type Pinner interface {
}

// NewPinnedProvider returns provider supplying pinned keys
func NewPinnedProvider(onlyRoots bool, pinning Pinner, fetchConfig fetcher.FetcherConfig) KeyChanFunc {
func NewPinnedProvider(onlyRoots bool, pinning Pinner, dag ipld.DAGService) KeyChanFunc {
return func(ctx context.Context) (<-chan cid.Cid, error) {
set, err := pinSet(ctx, pinning, fetchConfig, onlyRoots)
set, err := pinSet(ctx, pinning, dag, onlyRoots)
if err != nil {
return nil, err
}
Expand All @@ -208,7 +208,7 @@ func NewPinnedProvider(onlyRoots bool, pinning Pinner, fetchConfig fetcher.Fetch
}
}

func pinSet(ctx context.Context, pinning Pinner, fetchConfig fetcher.FetcherConfig, onlyRoots bool) (*cidutil.StreamingSet, error) {
func pinSet(ctx context.Context, pinning Pinner, dag ipld.DAGService, onlyRoots bool) (*cidutil.StreamingSet, error) {
set := cidutil.NewStreamingSet()

go func() {
Expand All @@ -230,18 +230,11 @@ func pinSet(ctx context.Context, pinning Pinner, fetchConfig fetcher.FetcherConf
logR.Errorf("reprovide indirect pins: %s", err)
return
}

session := fetchConfig.NewSession(ctx)
for _, key := range rkeys {
set.Visitor(ctx)(key)
if !onlyRoots {
err := fetcher.BlockAll(ctx, session, cidlink.Link{key}, func(res fetcher.FetchResult) error {
clink, ok := res.LastBlockLink.(cidlink.Link)
if ok {
set.Visitor(ctx)(clink.Cid)
}
return nil
})
if onlyRoots {
set.Visitor(ctx)(key)
} else {
err := merkledag.Walk(ctx, merkledag.GetLinksWithDAG(dag), key, set.Visitor(ctx))
if err != nil {
logR.Errorf("reprovide indirect pins: %s", err)
return
Expand Down
7 changes: 3 additions & 4 deletions provider/simple/reprovide_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import (
"github.com/ipfs/go-cid"
ds "github.com/ipfs/go-datastore"
dssync "github.com/ipfs/go-datastore/sync"
"github.com/ipfs/go-fetcher"
"github.com/ipfs/go-ipfs-blockstore"
offline "github.com/ipfs/go-ipfs-exchange-offline"
mock "github.com/ipfs/go-ipfs-routing/mock"
cbor "github.com/ipfs/go-ipld-cbor"
_ "github.com/ipld/go-ipld-prime/codec/dagcbor"
merkledag "github.com/ipfs/go-merkledag"
peer "github.com/libp2p/go-libp2p-core/peer"
testutil "github.com/libp2p/go-libp2p-testing/net"
mh "github.com/multiformats/go-multihash"
Expand Down Expand Up @@ -196,7 +195,7 @@ func TestReprovidePinned(t *testing.T) {

nodes, bstore := setupDag(t)

fetchConfig := fetcher.NewFetcherConfig(bsrv.New(bstore, offline.Exchange(bstore)))
dag := merkledag.NewDAGService(bsrv.New(bstore, offline.Exchange(bstore)))

for i := 0; i < 2; i++ {
clA, clB, idA, _ := setupRouting(t)
Expand All @@ -216,7 +215,7 @@ func TestReprovidePinned(t *testing.T) {
keyProvider := NewPinnedProvider(onlyRoots, &mockPinner{
recursive: []cid.Cid{nodes[1]},
direct: []cid.Cid{nodes[3]},
}, fetchConfig)
}, dag)

reprov := NewReprovider(ctx, time.Hour, clA, keyProvider)
err := reprov.Reprovide()
Expand Down

0 comments on commit 0f4e8f0

Please sign in to comment.