Skip to content

Commit

Permalink
cmd, config, ipfs: add provider config
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed May 13, 2024
1 parent 230f7dd commit 9ef29c7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
5 changes: 5 additions & 0 deletions cmd/fsd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"path/filepath"
"strings"
"syscall"
"time"

levelds "github.com/ipfs/go-ds-leveldb"
"github.com/libp2p/go-libp2p/core/crypto"
Expand Down Expand Up @@ -50,6 +51,10 @@ var (
Gateway: config.HTTPGateway{
ListenAddress: ":8080",
},
Provider: config.IPFSProvider{
BatchSize: 5000,
Interval: 18 * time.Hour,
},
},
API: config.API{
Address: ":8081",
Expand Down
19 changes: 14 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package config

import (
"time"

"github.com/ipfs/go-cid"
"github.com/libp2p/go-libp2p/core/peer"
)
Expand Down Expand Up @@ -49,11 +51,18 @@ type (

// IPFS contains the configuration for the IPFS node
IPFS struct {
PrivateKey string `yaml:"privateKey"`
ListenAddresses []string `yaml:"listenAddresses"`
AnnounceAddresses []string `yaml:"announceAddresses"`
Peers []IPFSPeer `yaml:"peers"`
Gateway HTTPGateway `yaml:"gateway"`
PrivateKey string `yaml:"privateKey"`
ListenAddresses []string `yaml:"listenAddresses"`
AnnounceAddresses []string `yaml:"announceAddresses"`
Peers []IPFSPeer `yaml:"peers"`
Gateway HTTPGateway `yaml:"gateway"`
Provider IPFSProvider `yaml:"provider"`
}

// IPFSProvider contains the configuration for the IPFS provider
IPFSProvider struct {
BatchSize int `yaml:"batchSize"`
Interval time.Duration `yaml:"interval"`
}

// API contains the listen address of the API server
Expand Down
2 changes: 1 addition & 1 deletion ipfs/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func NewNode(ctx context.Context, privateKey crypto.PrivKey, cfg config.IPFS, rs
}

rp := NewReprovider(frt, rs, log.Named("reprovider"))
go rp.Run(ctx, 16*time.Hour)
go rp.Run(ctx, cfg.Provider.Interval, cfg.Provider.BatchSize)

return &Node{
log: log,
Expand Down
4 changes: 2 additions & 2 deletions ipfs/provide.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (r *Reprovider) Trigger() {

// Run starts the reprovider loop, which periodically announces CIDs that
// have not been announced in the last interval.
func (r *Reprovider) Run(ctx context.Context, interval time.Duration) {
func (r *Reprovider) Run(ctx context.Context, interval time.Duration, batchSize int) {
var once sync.Once
once.Do(func() {
var reprovideSleep time.Duration
Expand Down Expand Up @@ -80,7 +80,7 @@ func (r *Reprovider) Run(ctx context.Context, interval time.Duration) {
for {
start := time.Now()

cids, err := r.store.ProvideCIDs(5000)
cids, err := r.store.ProvideCIDs(batchSize)
if err != nil {
reprovideSleep = time.Minute
r.log.Error("failed to fetch CIDs to provide", zap.Error(err))
Expand Down

0 comments on commit 9ef29c7

Please sign in to comment.