mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-05 16:28:06 +08:00
basic reprovider implementation
make vendor
This commit is contained in:
parent
dc6b548094
commit
3269986e42
@ -16,6 +16,7 @@ import (
|
||||
bitswap "github.com/jbenet/go-ipfs/exchange/bitswap"
|
||||
bsnet "github.com/jbenet/go-ipfs/exchange/bitswap/network"
|
||||
offline "github.com/jbenet/go-ipfs/exchange/offline"
|
||||
rp "github.com/jbenet/go-ipfs/exchange/reprovide"
|
||||
mount "github.com/jbenet/go-ipfs/fuse/mount"
|
||||
merkledag "github.com/jbenet/go-ipfs/merkledag"
|
||||
namesys "github.com/jbenet/go-ipfs/namesys"
|
||||
@ -79,6 +80,7 @@ type IpfsNode struct {
|
||||
Exchange exchange.Interface // the block exchange + strategy (bitswap)
|
||||
Namesys namesys.NameSystem // the name system, resolves paths to hashes
|
||||
Diagnostics *diag.Diagnostics // the diagnostics service
|
||||
Reprovider *rp.Reprovider // the value reprovider system
|
||||
|
||||
ctxgroup.ContextGroup
|
||||
|
||||
@ -183,6 +185,10 @@ func Standard(cfg *config.Config, online bool) ConfigOption {
|
||||
if err := n.StartOnlineServices(); err != nil {
|
||||
return nil, err // debugerror.Wraps.
|
||||
}
|
||||
|
||||
// Start up reprovider system
|
||||
n.Reprovider = rp.NewReprovider(n.Routing, n.Blockstore)
|
||||
go n.Reprovider.Run(ctx)
|
||||
} else {
|
||||
n.Exchange = offline.Exchange(n.Blockstore)
|
||||
}
|
||||
|
||||
55
exchange/reprovide/reprovide.go
Normal file
55
exchange/reprovide/reprovide.go
Normal file
@ -0,0 +1,55 @@
|
||||
package reprovide
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
|
||||
|
||||
blocks "github.com/jbenet/go-ipfs/blocks/blockstore"
|
||||
routing "github.com/jbenet/go-ipfs/routing"
|
||||
"github.com/jbenet/go-ipfs/util/eventlog"
|
||||
)
|
||||
|
||||
var log = eventlog.Logger("reprovider")
|
||||
|
||||
type Reprovider struct {
|
||||
// The routing system to provide values through
|
||||
rsys routing.IpfsRouting
|
||||
|
||||
// The backing store for blocks to be provided
|
||||
bstore blocks.Blockstore
|
||||
}
|
||||
|
||||
func NewReprovider(rsys routing.IpfsRouting, bstore blocks.Blockstore) *Reprovider {
|
||||
return &Reprovider{
|
||||
rsys: rsys,
|
||||
bstore: bstore,
|
||||
}
|
||||
}
|
||||
|
||||
func (rp *Reprovider) Run(ctx context.Context) {
|
||||
after := time.After(0)
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-after:
|
||||
rp.reprovide(ctx)
|
||||
after = time.After(time.Hour * 12)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (rp *Reprovider) reprovide(ctx context.Context) {
|
||||
keychan, err := rp.bstore.AllKeysChan(ctx, 0, 1<<16)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to get key chan from blockstore: %s", err)
|
||||
return
|
||||
}
|
||||
for k := range keychan {
|
||||
err := rp.rsys.Provide(ctx, k)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to provide key: %s, %s", k, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user