lotus/node/repo/retrievalstoremgr/retrievalstoremgr.go

61 lines
1.7 KiB
Go
Raw Normal View History

2021-07-07 05:41:29 +00:00
package retrievalstoremgr
import (
"github.com/filecoin-project/lotus/blockstore"
)
// RetrievalStore references a store for a retrieval deal.
type RetrievalStore interface {
2021-07-07 08:40:59 +00:00
IsIPFSRetrieval() bool
Blockstore() blockstore.BasicBlockstore
2021-07-07 05:41:29 +00:00
}
// RetrievalStoreManager manages stores for retrieval deals, abstracting
// the underlying storage mechanism.
type RetrievalStoreManager interface {
NewStore() (RetrievalStore, error)
ReleaseStore(RetrievalStore) error
}
2021-07-07 08:40:59 +00:00
// BlockstoreRetrievalStoreManager is a blockstore used for retrieval.
2021-07-07 05:41:29 +00:00
type BlockstoreRetrievalStoreManager struct {
2021-07-07 08:40:59 +00:00
bs blockstore.BasicBlockstore
isIpfsRetrieval bool
2021-07-07 05:41:29 +00:00
}
var _ RetrievalStoreManager = &BlockstoreRetrievalStoreManager{}
// NewBlockstoreRetrievalStoreManager returns a new blockstore based RetrievalStoreManager
2021-07-07 08:40:59 +00:00
func NewBlockstoreRetrievalStoreManager(bs blockstore.BasicBlockstore, isIpfsRetrieval bool) RetrievalStoreManager {
2021-07-07 05:41:29 +00:00
return &BlockstoreRetrievalStoreManager{
2021-07-07 08:40:59 +00:00
bs: bs,
isIpfsRetrieval: isIpfsRetrieval,
2021-07-07 05:41:29 +00:00
}
}
// NewStore creates a new store (just uses underlying blockstore)
func (brsm *BlockstoreRetrievalStoreManager) NewStore() (RetrievalStore, error) {
return &blockstoreRetrievalStore{
2021-07-07 08:40:59 +00:00
bs: brsm.bs,
isIpfsRetrieval: brsm.isIpfsRetrieval,
2021-07-07 05:41:29 +00:00
}, nil
}
// ReleaseStore for this implementation does nothing
func (brsm *BlockstoreRetrievalStoreManager) ReleaseStore(RetrievalStore) error {
return nil
}
type blockstoreRetrievalStore struct {
2021-07-07 08:40:59 +00:00
bs blockstore.BasicBlockstore
isIpfsRetrieval bool
2021-07-07 05:41:29 +00:00
}
2021-07-07 08:40:59 +00:00
func (brs *blockstoreRetrievalStore) Blockstore() blockstore.BasicBlockstore {
return brs.bs
}
func (brs *blockstoreRetrievalStore) IsIPFSRetrieval() bool {
return brs.isIpfsRetrieval
2021-07-07 05:41:29 +00:00
}