diff --git a/core/core.go b/core/core.go index 28cf6047a62..db75e3df018 100644 --- a/core/core.go +++ b/core/core.go @@ -125,7 +125,7 @@ type IpfsNode struct { Routing routing.IpfsRouting // the routing system. recommend ipfs-dht Exchange exchange.Interface // the block exchange + strategy (bitswap) Namesys namesys.NameSystem // the name system, resolves paths to hashes - Provider *provider.Provider // the value provider system + Provider provider.Provider // the value provider system Reprovider *rp.Reprovider // the value reprovider system IpnsRepub *ipnsrp.Republisher diff --git a/core/coreapi/coreapi.go b/core/coreapi/coreapi.go index a10af96e933..5045c88eb25 100644 --- a/core/coreapi/coreapi.go +++ b/core/coreapi/coreapi.go @@ -67,7 +67,7 @@ type CoreAPI struct { namesys namesys.NameSystem routing routing.IpfsRouting - provider *provider.Provider + provider provider.Provider pubSub *pubsub.PubSub @@ -215,6 +215,7 @@ func (api *CoreAPI) WithOptions(opts ...options.ApiOption) (coreiface.CoreAPI, e subApi.routing = offlineroute.NewOfflineRouter(subApi.repo.Datastore(), subApi.recordValidator) subApi.namesys = namesys.NewNameSystem(subApi.routing, subApi.repo.Datastore(), cs) + subApi.provider = provider.NewOfflineProvider() subApi.peerstore = nil subApi.peerHost = nil diff --git a/provider/offline.go b/provider/offline.go new file mode 100644 index 00000000000..f7b9603b92a --- /dev/null +++ b/provider/offline.go @@ -0,0 +1,15 @@ +package provider + +import "github.com/ipfs/go-cid" + +type offlineProvider struct {} + +func NewOfflineProvider() Provider { + return &offlineProvider{} +} + +func (op *offlineProvider) Run() {} + +func (op *offlineProvider) Provide(cid cid.Cid) error { + return nil +} diff --git a/provider/provider.go b/provider/provider.go index e43058b396b..e4ee6d9ffbb 100644 --- a/provider/provider.go +++ b/provider/provider.go @@ -18,9 +18,14 @@ const ( provideOutgoingWorkerLimit = 8 ) +type Provider interface { + Run() + Provide(cid.Cid) error +} + // Provider announces blocks to the network, tracks which blocks are // being provided, and untracks blocks when they're no longer in the blockstore. -type Provider struct { +type provider struct { ctx context.Context // the CIDs for which provide announcements should be made queue *Queue @@ -28,8 +33,8 @@ type Provider struct { contentRouting routing.ContentRouting } -func NewProvider(ctx context.Context, queue *Queue, contentRouting routing.ContentRouting) *Provider { - return &Provider{ +func NewProvider(ctx context.Context, queue *Queue, contentRouting routing.ContentRouting) Provider { + return &provider{ ctx: ctx, queue: queue, contentRouting: contentRouting, @@ -37,18 +42,18 @@ func NewProvider(ctx context.Context, queue *Queue, contentRouting routing.Conte } // Start workers to handle provide requests. -func (p *Provider) Run() { +func (p *provider) Run() { p.queue.Run() p.handleAnnouncements() } // Provide the given cid using specified strategy. -func (p *Provider) Provide(root cid.Cid) error { +func (p *provider) Provide(root cid.Cid) error { return p.queue.Enqueue(root) } // Handle all outgoing cids by providing (announcing) them -func (p *Provider) handleAnnouncements() { +func (p *provider) handleAnnouncements() { for workers := 0; workers < provideOutgoingWorkerLimit; workers++ { go func() { for {