-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathherald.go
73 lines (65 loc) · 1.36 KB
/
herald.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package herald
import (
"context"
"errors"
"io"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-log/v2"
"github.com/multiformats/go-multihash"
)
var (
logger = log.Logger("herald")
ErrCatalogIteratorDone = errors.New("no more items")
)
type (
CatalogID []byte
CatalogIterator interface {
Next() (multihash.Multihash, error)
Done() bool
}
Catalog interface {
ID() []byte
Iterator() CatalogIterator
Transport() interface {
Providers() any
}
}
Publisher interface {
Publish(context.Context, Catalog) (cid.Cid, error)
Retract(context.Context, CatalogID) (cid.Cid, error)
GetContent(context.Context, cid.Cid) (io.ReadCloser, error)
GetHead(context.Context) (cid.Cid, error)
// TODO:
// - Update address
// - AddProvider
// - RemoveProvider
// - UpdateProvider
// - Transport et. al.
}
Herald struct {
*options
publisher *httpPublisher
}
)
func New(o ...Option) (*Herald, error) {
opts, err := newOptions(o...)
if err != nil {
return nil, err
}
h := &Herald{options: opts}
dspub, err := newDsPublisher(h)
if err != nil {
return nil, err
}
h.publisher, err = newHttpPublisher(h, dspub)
if err != nil {
return nil, err
}
return h, err
}
func (h *Herald) Start(ctx context.Context) error {
return h.publisher.Start(ctx)
}
func (h *Herald) Shutdown(ctx context.Context) error {
return h.publisher.Shutdown(ctx)
}