2019-08-26 10:04:57 +00:00
|
|
|
package sectorblocks
|
2019-08-26 08:02:26 +00:00
|
|
|
|
|
|
|
import (
|
2019-08-26 10:04:57 +00:00
|
|
|
"context"
|
2019-11-22 16:20:56 +00:00
|
|
|
|
|
|
|
blocks "github.com/ipfs/go-block-format"
|
2019-08-26 08:02:26 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
2019-08-27 18:45:21 +00:00
|
|
|
blockstore "github.com/ipfs/go-ipfs-blockstore"
|
2019-08-26 08:02:26 +00:00
|
|
|
)
|
|
|
|
|
2019-08-27 18:45:21 +00:00
|
|
|
type SectorBlockStore struct {
|
2019-08-27 23:03:22 +00:00
|
|
|
intermediate blockstore.Blockstore
|
2019-08-27 18:45:21 +00:00
|
|
|
sectorBlocks *SectorBlocks
|
2019-08-26 09:08:39 +00:00
|
|
|
|
2019-08-27 18:45:21 +00:00
|
|
|
approveUnseal func() error
|
2019-08-26 08:02:26 +00:00
|
|
|
}
|
|
|
|
|
2019-08-27 18:45:21 +00:00
|
|
|
func (s *SectorBlockStore) DeleteBlock(cid.Cid) error {
|
|
|
|
panic("not supported")
|
2019-08-26 09:08:39 +00:00
|
|
|
}
|
2019-08-27 18:45:21 +00:00
|
|
|
func (s *SectorBlockStore) GetSize(cid.Cid) (int, error) {
|
|
|
|
panic("not supported")
|
2019-08-26 08:02:26 +00:00
|
|
|
}
|
|
|
|
|
2019-08-27 18:45:21 +00:00
|
|
|
func (s *SectorBlockStore) Put(blocks.Block) error {
|
|
|
|
panic("not supported")
|
2019-08-26 08:02:26 +00:00
|
|
|
}
|
|
|
|
|
2019-08-27 18:45:21 +00:00
|
|
|
func (s *SectorBlockStore) PutMany([]blocks.Block) error {
|
|
|
|
panic("not supported")
|
2019-08-26 08:02:26 +00:00
|
|
|
}
|
|
|
|
|
2019-08-27 18:45:21 +00:00
|
|
|
func (s *SectorBlockStore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) {
|
|
|
|
panic("not supported")
|
|
|
|
}
|
2019-08-26 08:02:26 +00:00
|
|
|
|
2019-08-27 18:45:21 +00:00
|
|
|
func (s *SectorBlockStore) HashOnRead(enabled bool) {
|
|
|
|
panic("not supported")
|
2019-08-26 08:02:26 +00:00
|
|
|
}
|
|
|
|
|
2019-08-27 18:45:21 +00:00
|
|
|
func (s *SectorBlockStore) Has(c cid.Cid) (bool, error) {
|
2019-08-27 23:03:22 +00:00
|
|
|
has, err := s.intermediate.Has(c)
|
2019-08-26 08:02:26 +00:00
|
|
|
if err != nil {
|
2019-08-27 18:45:21 +00:00
|
|
|
return false, err
|
2019-08-26 08:02:26 +00:00
|
|
|
}
|
2019-08-27 18:45:21 +00:00
|
|
|
if has {
|
|
|
|
return true, nil
|
2019-08-27 23:03:22 +00:00
|
|
|
}
|
2019-08-26 08:02:26 +00:00
|
|
|
|
2019-08-27 18:45:21 +00:00
|
|
|
return s.sectorBlocks.Has(c)
|
2019-08-26 08:02:26 +00:00
|
|
|
}
|
2019-08-26 10:04:57 +00:00
|
|
|
|
2019-08-27 18:45:21 +00:00
|
|
|
func (s *SectorBlockStore) Get(c cid.Cid) (blocks.Block, error) {
|
2019-08-27 23:03:22 +00:00
|
|
|
val, err := s.intermediate.Get(c)
|
2019-08-27 18:45:21 +00:00
|
|
|
if err == nil {
|
|
|
|
return val, nil
|
2019-08-26 10:04:57 +00:00
|
|
|
}
|
2019-08-27 18:45:21 +00:00
|
|
|
if err != blockstore.ErrNotFound {
|
|
|
|
return nil, err
|
2019-08-27 23:03:22 +00:00
|
|
|
}
|
2019-08-26 10:04:57 +00:00
|
|
|
|
2019-08-27 18:45:21 +00:00
|
|
|
refs, err := s.sectorBlocks.GetRefs(c)
|
2019-08-26 10:04:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-08-27 18:45:21 +00:00
|
|
|
if len(refs) == 0 {
|
|
|
|
return nil, blockstore.ErrNotFound
|
2019-08-26 10:04:57 +00:00
|
|
|
}
|
|
|
|
|
2019-08-27 18:45:21 +00:00
|
|
|
data, err := s.sectorBlocks.unsealed.getRef(context.TODO(), refs, s.approveUnseal)
|
2019-08-26 13:45:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-08-27 18:45:21 +00:00
|
|
|
return blocks.NewBlockWithCid(data, c)
|
2019-08-26 13:45:36 +00:00
|
|
|
}
|
2019-08-27 18:45:21 +00:00
|
|
|
|
|
|
|
var _ blockstore.Blockstore = &SectorBlockStore{}
|