@cryptotaxi247 / kubo / commits / 3269986e4

basic reprovider implementation

make vendor

Jeromy committed Jan 13, 2015 at 22:00 UTC 3269986e4281f24fc5a23de5b5d89aa5b23be0ac
2 files changed +61
core/core.go
+6
@@ -16,6 +16,7 @@ import (
16 bitswap "github.com/jbenet/go-ipfs/exchange/bitswap"
17 bsnet "github.com/jbenet/go-ipfs/exchange/bitswap/network"
18 offline "github.com/jbenet/go-ipfs/exchange/offline"
19 + rp "github.com/jbenet/go-ipfs/exchange/reprovide"
20 mount "github.com/jbenet/go-ipfs/fuse/mount"
21 merkledag "github.com/jbenet/go-ipfs/merkledag"
22 namesys "github.com/jbenet/go-ipfs/namesys"
@@ -79,6 +80,7 @@ type IpfsNode struct {
80 Exchange exchange.Interface // the block exchange + strategy (bitswap)
81 Namesys namesys.NameSystem // the name system, resolves paths to hashes
82 Diagnostics *diag.Diagnostics // the diagnostics service
83 + Reprovider *rp.Reprovider // the value reprovider system
84
85 ctxgroup.ContextGroup
86
@@ -183,6 +185,10 @@ func Standard(cfg *config.Config, online bool) ConfigOption {
185 if err := n.StartOnlineServices(); err != nil {
186 return nil, err // debugerror.Wraps.
187 }
188 +
189 + // Start up reprovider system
190 + n.Reprovider = rp.NewReprovider(n.Routing, n.Blockstore)
191 + go n.Reprovider.Run(ctx)
192 } else {
193 n.Exchange = offline.Exchange(n.Blockstore)
194 }
exchange/reprovide/reprovide.go new
+55
@@ -0,0 +1,55 @@
1 +package reprovide
2 +
3 +import (
4 + "time"
5 +
6 + context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
7 +
8 + blocks "github.com/jbenet/go-ipfs/blocks/blockstore"
9 + routing "github.com/jbenet/go-ipfs/routing"
10 + "github.com/jbenet/go-ipfs/util/eventlog"
11 +)
12 +
13 +var log = eventlog.Logger("reprovider")
14 +
15 +type Reprovider struct {
16 + // The routing system to provide values through
17 + rsys routing.IpfsRouting
18 +
19 + // The backing store for blocks to be provided
20 + bstore blocks.Blockstore
21 +}
22 +
23 +func NewReprovider(rsys routing.IpfsRouting, bstore blocks.Blockstore) *Reprovider {
24 + return &Reprovider{
25 + rsys: rsys,
26 + bstore: bstore,
27 + }
28 +}
29 +
30 +func (rp *Reprovider) Run(ctx context.Context) {
31 + after := time.After(0)
32 + for {
33 + select {
34 + case <-ctx.Done():
35 + return
36 + case <-after:
37 + rp.reprovide(ctx)
38 + after = time.After(time.Hour * 12)
39 + }
40 + }
41 +}
42 +
43 +func (rp *Reprovider) reprovide(ctx context.Context) {
44 + keychan, err := rp.bstore.AllKeysChan(ctx, 0, 1<<16)
45 + if err != nil {
46 + log.Errorf("Failed to get key chan from blockstore: %s", err)
47 + return
48 + }
49 + for k := range keychan {
50 + err := rp.rsys.Provide(ctx, k)
51 + if err != nil {
52 + log.Errorf("Failed to provide key: %s, %s", k, err)
53 + }
54 + }
55 +}