@cryptotaxi247 / kubo / commits / bfcea27d3

Use offlineProvider when --offline

License: MIT Signed-off-by: Michael Avila <davidmichaelavila@gmail.com>

Michael Avila committed Mar 8, 2019 at 16:31 UTC bfcea27d396c994406439bf74c77b309b7310485
4 files changed +29 -8
core/core.go
+1 -1
@@ -125,7 +125,7 @@ type IpfsNode struct {
125 Routing routing.IpfsRouting // the routing system. recommend ipfs-dht
126 Exchange exchange.Interface // the block exchange + strategy (bitswap)
127 Namesys namesys.NameSystem // the name system, resolves paths to hashes
128 - Provider *provider.Provider // the value provider system
128 + Provider provider.Provider // the value provider system
129 Reprovider *rp.Reprovider // the value reprovider system
130 IpnsRepub *ipnsrp.Republisher
131
core/coreapi/coreapi.go
+2 -1
@@ -67,7 +67,7 @@ type CoreAPI struct {
67 namesys namesys.NameSystem
68 routing routing.IpfsRouting
69
70 - provider *provider.Provider
70 + provider provider.Provider
71
72 pubSub *pubsub.PubSub
73
@@ -215,6 +215,7 @@ func (api *CoreAPI) WithOptions(opts ...options.ApiOption) (coreiface.CoreAPI, e
215
216 subApi.routing = offlineroute.NewOfflineRouter(subApi.repo.Datastore(), subApi.recordValidator)
217 subApi.namesys = namesys.NewNameSystem(subApi.routing, subApi.repo.Datastore(), cs)
218 + subApi.provider = provider.NewOfflineProvider()
219
220 subApi.peerstore = nil
221 subApi.peerHost = nil
provider/offline.go new
+15
@@ -0,0 +1,15 @@
1 +package provider
2 +
3 +import "github.com/ipfs/go-cid"
4 +
5 +type offlineProvider struct {}
6 +
7 +func NewOfflineProvider() Provider {
8 + return &offlineProvider{}
9 +}
10 +
11 +func (op *offlineProvider) Run() {}
12 +
13 +func (op *offlineProvider) Provide(cid cid.Cid) error {
14 + return nil
15 +}
provider/provider.go
+11 -6
@@ -18,9 +18,14 @@ const (
18 provideOutgoingWorkerLimit = 8
19 )
20
21 +type Provider interface {
22 + Run()
23 + Provide(cid.Cid) error
24 +}
25 +
26 // Provider announces blocks to the network, tracks which blocks are
27 // being provided, and untracks blocks when they're no longer in the blockstore.
23 -type Provider struct {
28 +type provider struct {
29 ctx context.Context
30 // the CIDs for which provide announcements should be made
31 queue *Queue
@@ -28,8 +33,8 @@ type Provider struct {
33 contentRouting routing.ContentRouting
34 }
35
31 -func NewProvider(ctx context.Context, queue *Queue, contentRouting routing.ContentRouting) *Provider {
32 - return &Provider{
36 +func NewProvider(ctx context.Context, queue *Queue, contentRouting routing.ContentRouting) Provider {
37 + return &provider{
38 ctx: ctx,
39 queue: queue,
40 contentRouting: contentRouting,
@@ -37,18 +42,18 @@ func NewProvider(ctx context.Context, queue *Queue, contentRouting routing.Conte
42 }
43
44 // Start workers to handle provide requests.
40 -func (p *Provider) Run() {
45 +func (p *provider) Run() {
46 p.queue.Run()
47 p.handleAnnouncements()
48 }
49
50 // Provide the given cid using specified strategy.
46 -func (p *Provider) Provide(root cid.Cid) error {
51 +func (p *provider) Provide(root cid.Cid) error {
52 return p.queue.Enqueue(root)
53 }
54
55 // Handle all outgoing cids by providing (announcing) them
51 -func (p *Provider) handleAnnouncements() {
56 +func (p *provider) handleAnnouncements() {
57 for workers := 0; workers < provideOutgoingWorkerLimit; workers++ {
58 go func() {
59 for {