From 0d0ccd5e9e892bd4574b56b44954eb5030ae648a Mon Sep 17 00:00:00 2001 From: Michael Avila Date: Mon, 10 Jun 2019 11:51:30 -0700 Subject: [PATCH] Refactor to create strategy with pin.Pinner dependency within go-ipfs --- core/core.go | 2 +- core/node/provider.go | 13 +++++++++++-- go.mod | 2 +- go.sum | 2 ++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/core/core.go b/core/core.go index 6829b3348c5..f87fd1da779 100644 --- a/core/core.go +++ b/core/core.go @@ -14,7 +14,6 @@ import ( "io" version "github.com/ipfs/go-ipfs" - "github.com/ipfs/go-ipfs-provider" "github.com/ipfs/go-ipfs/core/bootstrap" "github.com/ipfs/go-ipfs/core/node" "github.com/ipfs/go-ipfs/core/node/libp2p" @@ -29,6 +28,7 @@ import ( bserv "github.com/ipfs/go-blockservice" bstore "github.com/ipfs/go-ipfs-blockstore" exchange "github.com/ipfs/go-ipfs-exchange-interface" + "github.com/ipfs/go-ipfs-provider" ipld "github.com/ipfs/go-ipld-format" logging "github.com/ipfs/go-log" mfs "github.com/ipfs/go-mfs" diff --git a/core/node/provider.go b/core/node/provider.go index a9c714d0a58..39b6bda6b4b 100644 --- a/core/node/provider.go +++ b/core/node/provider.go @@ -5,11 +5,14 @@ import ( "fmt" "time" + "github.com/ipfs/go-ipfs/pin" + "github.com/ipfs/go-ipfs-provider" q "github.com/ipfs/go-ipfs-provider/queue" "github.com/ipfs/go-ipfs-provider/simple" "github.com/ipfs/go-ipfs/core/node/helpers" "github.com/ipfs/go-ipfs/repo" + ipld "github.com/ipfs/go-ipld-format" "github.com/libp2p/go-libp2p-core/routing" "go.uber.org/fx" ) @@ -101,9 +104,9 @@ func SimpleProviders(reprovideStrategy string, reprovideInterval string) fx.Opti case "": keyProvider = fx.Provide(simple.NewBlockstoreProvider) case "roots": - keyProvider = fx.Provide(simple.NewPinnedProvider(true)) + keyProvider = fx.Provide(pinnedProviderStrategy(true)) case "pinned": - keyProvider = fx.Provide(simple.NewPinnedProvider(false)) + keyProvider = fx.Provide(pinnedProviderStrategy(false)) default: return fx.Error(fmt.Errorf("unknown reprovider strategy '%s'", reprovideStrategy)) } @@ -115,3 +118,9 @@ func SimpleProviders(reprovideStrategy string, reprovideInterval string) fx.Opti fx.Provide(SimpleReprovider(reproviderInterval)), ) } + +func pinnedProviderStrategy(onlyRoots bool) interface{} { + return func(pinner pin.Pinner, dag ipld.DAGService) simple.KeyChanFunc { + return simple.NewPinnedProvider(onlyRoots, pinner, dag) + } +} diff --git a/go.mod b/go.mod index fff97d66470..ec734ac8cac 100644 --- a/go.mod +++ b/go.mod @@ -39,7 +39,7 @@ require ( github.com/ipfs/go-ipfs-exchange-offline v0.0.1 github.com/ipfs/go-ipfs-files v0.0.3 github.com/ipfs/go-ipfs-posinfo v0.0.1 - github.com/ipfs/go-ipfs-provider v0.0.0-20190606214637-245e9651e80d + github.com/ipfs/go-ipfs-provider v0.0.0-20190610184752-d7bb85e89013 github.com/ipfs/go-ipfs-routing v0.1.0 github.com/ipfs/go-ipfs-util v0.0.1 github.com/ipfs/go-ipld-cbor v0.0.2 diff --git a/go.sum b/go.sum index f666c48b7d7..4268050ea1a 100644 --- a/go.sum +++ b/go.sum @@ -272,6 +272,8 @@ github.com/ipfs/go-ipfs-provider v0.0.0-20190601062352-095af8f253ae h1:5ClijX79U github.com/ipfs/go-ipfs-provider v0.0.0-20190601062352-095af8f253ae/go.mod h1:Zbv9hdJ0m+MpafEK1FKtBUO2LbSONSw3/OMzzkx4SIY= github.com/ipfs/go-ipfs-provider v0.0.0-20190606214637-245e9651e80d h1:05Qz5fw6UA5Mj6E04R0Yvrh0hls+y1Y5nAdZelskiAk= github.com/ipfs/go-ipfs-provider v0.0.0-20190606214637-245e9651e80d/go.mod h1:r8PN9I9dKakIm6zcBwLtVtTSO29WvHlUrCp9umHhhp0= +github.com/ipfs/go-ipfs-provider v0.0.0-20190610184752-d7bb85e89013 h1:Jsln/7WIxgb6zxs2r4gFXVOVNMxGPbUp38e+7eCcdfc= +github.com/ipfs/go-ipfs-provider v0.0.0-20190610184752-d7bb85e89013/go.mod h1:r8PN9I9dKakIm6zcBwLtVtTSO29WvHlUrCp9umHhhp0= github.com/ipfs/go-ipfs-routing v0.0.1/go.mod h1:k76lf20iKFxQTjcJokbPM9iBXVXVZhcOwc360N4nuKs= github.com/ipfs/go-ipfs-routing v0.1.0 h1:gAJTT1cEeeLj6/DlLX6t+NxD9fQe2ymTO6qWRDI/HQQ= github.com/ipfs/go-ipfs-routing v0.1.0/go.mod h1:hYoUkJLyAUKhF58tysKpids8RNDPO42BVMgK5dNsoqY=