forked from leotons/estuary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
49 lines (41 loc) · 1.1 KB
/
init.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"context"
"github.com/application-research/estuary/config"
"github.com/ipfs/go-cid"
blockstore "github.com/ipfs/go-ipfs-blockstore"
"gorm.io/gorm"
)
type Initializer struct {
cfg *config.Node
db *gorm.DB
trackingBstore *TrackingBlockstore
}
func (init *Initializer) Config() *config.Node {
return init.cfg
}
func (init *Initializer) BlockstoreWrap(bs blockstore.Blockstore) (blockstore.Blockstore, error) {
init.trackingBstore = NewTrackingBlockstore(bs, init.db)
return init.trackingBstore, nil
}
func (init *Initializer) KeyProviderFunc(rpctx context.Context) (<-chan cid.Cid, error) {
log.Infof("running key provider func")
out := make(chan cid.Cid)
go func() {
defer close(out)
var contents []Content
if err := init.db.Find(&contents, "active").Error; err != nil {
log.Errorf("failed to load contents for reproviding: %s", err)
return
}
log.Infof("key provider func returning %d values", len(contents))
for _, c := range contents {
select {
case out <- c.Cid.CID:
case <-rpctx.Done():
return
}
}
}()
return out, nil
}