diff --git a/core/builder.go b/core/builder.go index 0916f0771d7..650afa31281 100644 --- a/core/builder.go +++ b/core/builder.go @@ -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 { diff --git a/core/commands/provider.go b/core/commands/provider.go index 52519e93b47..360030ea360 100644 --- a/core/commands/provider.go +++ b/core/commands/provider.go @@ -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 } diff --git a/core/core.go b/core/core.go index aa0a373b169..7c342269b1d 100644 --- a/core/core.go +++ b/core/core.go @@ -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 @@ -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 } diff --git a/provider/system.go b/provider/system.go index df2260e2d99..f3207b337c8 100644 --- a/provider/system.go +++ b/provider/system.go @@ -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) { @@ -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) +}