Skip to content

Commit

Permalink
Move reprovider behind ProviderSystem
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 Apr 11, 2019
1 parent 92a9d0a commit 0bf621c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 24 deletions.
14 changes: 6 additions & 8 deletions core/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,22 +276,20 @@ func setupNode(ctx context.Context, n *IpfsNode, cfg *BuildCfg) error {
}
n.Resolver = resolver.NewBasicResolver(n.DAG)

// Provider
// Provider System
queueP, err := provider.NewQueue(ctx, "provider-v1", n.Repo.Datastore())
if err != nil {
return err
}
tracker := provider.NewTracker(n.Repo.Datastore())
n.Provider = provider.NewProviderSystem(
provider.NewProvider(ctx, queueP, tracker, n.Routing),
)

// Reprovider
queueR, err := provider.NewQueue(ctx, "reprovider-v1", n.Repo.Datastore())
if err != nil {
return err
}
n.Reprovider = provider.NewReprovider(ctx, queueR, tracker, time.Minute, time.Hour*12, n.Blockstore, n.Routing)
tracker := provider.NewTracker(n.Repo.Datastore())
n.Provider = provider.NewProviderSystem(
provider.NewProvider(ctx, queueP, tracker, n.Routing),
provider.NewReprovider(ctx, queueR, tracker, time.Minute, time.Hour*12, n.Blockstore, n.Routing),
)

if cfg.Online {
if err := n.startLateOnlineServices(ctx); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion core/commands/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Trigger reprovider to announce tracked cids to the network.
return ErrNotOnline
}

err = nd.Reprovider.Trigger(req.Context)
err = nd.Provider.Reprovide(req.Context)
if err != nil {
return err
}
Expand Down
18 changes: 6 additions & 12 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,12 @@ type IpfsNode struct {
RecordValidator record.Validator

// Online
PeerHost p2phost.Host // the network host (server+client)
Bootstrapper io.Closer // the periodic bootstrapper
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
Reprovider *provider.Reprovider // the value reprovider system
PeerHost p2phost.Host // the network host (server+client)
Bootstrapper io.Closer // the periodic bootstrapper
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.ProviderSystem // the value provider system
IpnsRepub *ipnsrp.Republisher

AutoNAT *autonat.AutoNATService
Expand Down Expand Up @@ -321,13 +320,8 @@ func constructConnMgr(cfg config.ConnMgr) (ifconnmgr.ConnManager, error) {

func (n *IpfsNode) startLateOnlineServices(ctx context.Context) error {
// Provider

n.Provider.Run()

// Reprovider

n.Reprovider.Run()

return nil
}

Expand Down
29 changes: 26 additions & 3 deletions provider/system.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,42 @@
package provider

import "github.com/ipfs/go-cid"
import (
"context"
"github.com/ipfs/go-cid"
)

type ProviderSystem struct {
provider Provider
reprovider *Reprovider
}

func NewProviderSystem(p Provider) *ProviderSystem {
func NewProviderSystem(p Provider, r *Reprovider) *ProviderSystem {
return &ProviderSystem{
provider: p,
reprovider: r,
}
}

func (ps *ProviderSystem) Run() {
ps.provider.Run()
ps.reprovider.Run()
}

func (ps *ProviderSystem) Close() error {
return ps.provider.Close()
var errs []error

if err := ps.provider.Close(); err != nil {
errs = append(errs, err)
}

if err := ps.reprovider.Close(); err != nil {
errs = append(errs, err)
}

if len(errs) > 0 {
return errs[0]
}
return nil
}

func (ps *ProviderSystem) Provide(cid cid.Cid) {
Expand All @@ -27,3 +46,7 @@ func (ps *ProviderSystem) Provide(cid cid.Cid) {
func (ps *ProviderSystem) Tracking() (<-chan cid.Cid, error) {
return ps.provider.Tracking()
}

func (ps *ProviderSystem) Reprovide(ctx context.Context) error {
return ps.reprovider.Trigger(ctx)
}

0 comments on commit 0bf621c

Please sign in to comment.