github.com/sunrise-zone/sunrise-node@v0.13.1-sr2/share/ipld/blockserv.go (about) 1 package ipld 2 3 import ( 4 "github.com/ipfs/boxo/blockservice" 5 "github.com/ipfs/boxo/blockstore" 6 "github.com/ipfs/boxo/exchange" 7 "github.com/ipfs/go-datastore" 8 "github.com/ipfs/go-datastore/sync" 9 ) 10 11 // NewBlockservice constructs Blockservice for fetching NMTrees. 12 func NewBlockservice(bs blockstore.Blockstore, exchange exchange.Interface) blockservice.BlockService { 13 return blockservice.New(bs, exchange, blockservice.WithAllowlist(defaultAllowlist)) 14 } 15 16 // NewMemBlockservice constructs Blockservice for fetching NMTrees with in-memory blockstore. 17 func NewMemBlockservice() blockservice.BlockService { 18 bstore := blockstore.NewBlockstore(sync.MutexWrap(datastore.NewMapDatastore())) 19 return NewBlockservice(bstore, nil) 20 } 21 22 // defaultAllowlist keeps default list of hashes allowed in the network. 23 var defaultAllowlist allowlist 24 25 type allowlist struct{} 26 27 func (a allowlist) IsAllowed(code uint64) bool { 28 // we allow all codes except home-baked sha256NamespaceFlagged 29 return code == sha256NamespaceFlagged 30 }