Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ The following emojis are used to highlight certain changes:
- `bitswap`: Updated to use `verifcid.DefaultMaxDigestSize` for `MaximumHashLength` constant
- The default `MaximumAllowedCid` limit for incoming CIDs can be adjusted using `bitswap.MaxCidSize` or `server.MaxCidSize` options
- 🛠 `bitswap/client`: The `RebroadcastDelay` option now takes a `time.Duration` value. This is a potentially BREAKING CHANGE. The time-varying functionality of `delay.Delay` was never used, so it was replaced with a fixed duration value. This also removes the `github.com/ipfs/go-ipfs-delay` dependency.
- `filestore`: Support providing filestore-blocks. A new `provider.MultihashProvider` parameter has been added to `filestore.New()`. When used, the blocks handled by the Filestore's `FileManager` will be provided on write (Put and PutMany).

### Removed

Expand Down
9 changes: 5 additions & 4 deletions blockstore/blockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,12 @@ func (bs *blockstore) PutMany(ctx context.Context, blocks []blocks.Block) error
return err
}

var hashes []multihash.Multihash
for _, block := range blocks {
hashes = append(hashes, block.Cid().Hash())
}
if bs.provider != nil {
var hashes []multihash.Multihash
for _, block := range blocks {
hashes = append(hashes, block.Cid().Hash())
}
logger.Debugf("blockstore: provide %d hashes", len(hashes))
if err := bs.provider.StartProviding(false, hashes...); err != nil {
logger.Warnf("blockstore: error while providing blocks: %s", err)
}
Expand Down
39 changes: 33 additions & 6 deletions filestore/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import (

blockstore "github.com/ipfs/boxo/blockstore"
posinfo "github.com/ipfs/boxo/filestore/posinfo"
"github.com/ipfs/boxo/provider"
blocks "github.com/ipfs/go-block-format"
cid "github.com/ipfs/go-cid"
dsq "github.com/ipfs/go-datastore/query"
ipld "github.com/ipfs/go-ipld-format"
logging "github.com/ipfs/go-log/v2"
"github.com/multiformats/go-multihash"
)

var logger = logging.Logger("filestore")
Expand All @@ -31,8 +33,9 @@ var (
// to store regular blocks and a special Blockstore called
// FileManager to store blocks which data exists in an external file.
type Filestore struct {
fm *FileManager
bs blockstore.Blockstore
fm *FileManager
bs blockstore.Blockstore
provider provider.MultihashProvider
}

// FileManager returns the FileManager in Filestore.
Expand All @@ -45,9 +48,12 @@ func (f *Filestore) MainBlockstore() blockstore.Blockstore {
return f.bs
}

// NewFilestore creates one using the given Blockstore and FileManager.
func NewFilestore(bs blockstore.Blockstore, fm *FileManager) *Filestore {
return &Filestore{fm, bs}
// NewFilestore creates one using the given Blockstore and FileManager. An
// optional MultihashProvider can be used to provide blocks written to the
// FileManager (blocks written to the normal blockstore will be provided by it
// if it has been initialized with the blockstore.Provider option).
func NewFilestore(bs blockstore.Blockstore, fm *FileManager, prov provider.MultihashProvider) *Filestore {
return &Filestore{fm, bs, prov}
}

// AllKeysChan returns a channel from which to read the keys stored in
Expand Down Expand Up @@ -193,7 +199,17 @@ func (f *Filestore) Put(ctx context.Context, b blocks.Block) error {

switch b := b.(type) {
case *posinfo.FilestoreNode:
return f.fm.Put(ctx, b)
err = f.fm.Put(ctx, b)
if err != nil {
return err
}
if f.provider != nil {
logger.Debugf("filestore: provide %s", b.Cid())
if err := f.provider.StartProviding(false, b.Cid().Hash()); err != nil {
logger.Warnf("filestore: error while providing %s: %s", b.Cid(), err)
}
}
return nil
default:
return f.bs.Put(ctx, b)
}
Expand Down Expand Up @@ -235,6 +251,17 @@ func (f *Filestore) PutMany(ctx context.Context, bs []blocks.Block) error {
if err != nil {
return err
}

if f.provider != nil {
var hashes []multihash.Multihash
for _, n := range fstores {
hashes = append(hashes, n.Node.Cid().Hash())
}
logger.Debugf("filestore: provide %d hashes", len(hashes))
if err := f.provider.StartProviding(false, hashes...); err != nil {
logger.Warnf("filestore: error while providing blocks: %s", err)
}
}
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion filestore/filestore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func newTestFilestore(t *testing.T, option ...Option) (string, *Filestore) {
fm.AllowFiles = true

bs := blockstore.NewBlockstore(mds)
fstore := NewFilestore(bs, fm)
fstore := NewFilestore(bs, fm, nil)
return testdir, fstore
}

Expand Down
Loading