master
go 64 lines 1.59 KB
Raw
1 package verifbs
2
3 import (
4 "context"
5
6 bstore "github.com/ipfs/boxo/blockstore"
7 "github.com/ipfs/boxo/verifcid"
8 blocks "github.com/ipfs/go-block-format"
9 cid "github.com/ipfs/go-cid"
10 )
11
12 type VerifBSGC struct {
13 bstore.GCBlockstore
14 }
15
16 func (bs *VerifBSGC) Put(ctx context.Context, b blocks.Block) error {
17 if err := verifcid.ValidateCid(verifcid.DefaultAllowlist, b.Cid()); err != nil {
18 return err
19 }
20 return bs.GCBlockstore.Put(ctx, b)
21 }
22
23 func (bs *VerifBSGC) PutMany(ctx context.Context, blks []blocks.Block) error {
24 for _, b := range blks {
25 if err := verifcid.ValidateCid(verifcid.DefaultAllowlist, b.Cid()); err != nil {
26 return err
27 }
28 }
29 return bs.GCBlockstore.PutMany(ctx, blks)
30 }
31
32 func (bs *VerifBSGC) Get(ctx context.Context, c cid.Cid) (blocks.Block, error) {
33 if err := verifcid.ValidateCid(verifcid.DefaultAllowlist, c); err != nil {
34 return nil, err
35 }
36 return bs.GCBlockstore.Get(ctx, c)
37 }
38
39 type VerifBS struct {
40 bstore.Blockstore
41 }
42
43 func (bs *VerifBS) Put(ctx context.Context, b blocks.Block) error {
44 if err := verifcid.ValidateCid(verifcid.DefaultAllowlist, b.Cid()); err != nil {
45 return err
46 }
47 return bs.Blockstore.Put(ctx, b)
48 }
49
50 func (bs *VerifBS) PutMany(ctx context.Context, blks []blocks.Block) error {
51 for _, b := range blks {
52 if err := verifcid.ValidateCid(verifcid.DefaultAllowlist, b.Cid()); err != nil {
53 return err
54 }
55 }
56 return bs.Blockstore.PutMany(ctx, blks)
57 }
58
59 func (bs *VerifBS) Get(ctx context.Context, c cid.Cid) (blocks.Block, error) {
60 if err := verifcid.ValidateCid(verifcid.DefaultAllowlist, c); err != nil {
61 return nil, err
62 }
63 return bs.Blockstore.Get(ctx, c)
64 }