Skip to content

Commit

Permalink
Use offlineProvider when --offline
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Michael Avila <davidmichaelavila@gmail.com>
  • Loading branch information
michaelavila committed Mar 9, 2019
1 parent d786a69 commit bfcea27
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion core/coreapi/coreapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type CoreAPI struct {
namesys namesys.NameSystem
routing routing.IpfsRouting

provider *provider.Provider
provider provider.Provider

pubSub *pubsub.PubSub

Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions provider/offline.go
Original file line number Diff line number Diff line change
@@ -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
}
17 changes: 11 additions & 6 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,42 @@ 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
// used to announce providing to the network
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,
}
}

// 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 {
Expand Down

0 comments on commit bfcea27

Please sign in to comment.