Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default to v0 CIDs #10

Merged
merged 3 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion http/unixfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (as *apiServer) handleUnixFSUpload(jc jape.Context) {
}

func parseUnixFSOptions(jc jape.Context) (sia.UnixFSOptions, bool) {
cidVersion := 1
var cidVersion int
if err := jc.DecodeForm("version", &cidVersion); err != nil {
return sia.UnixFSOptions{}, false
}
Expand Down
29 changes: 23 additions & 6 deletions sia/sia.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"sync"

chunker "github.com/ipfs/boxo/chunker"
"github.com/ipfs/boxo/ipld/merkledag"
"github.com/ipfs/boxo/ipld/unixfs/importer/balanced"
ihelpers "github.com/ipfs/boxo/ipld/unixfs/importer/helpers"
blocks "github.com/ipfs/go-block-format"
Expand Down Expand Up @@ -237,13 +238,29 @@
func (n *Node) VerifyCID(ctx context.Context, c cid.Cid) error {
rbs := NewBlockStore(n.store, n.renterd, n.log.Named("verify"))

block, err := rbs.Get(ctx, c)
if err != nil {
return fmt.Errorf("failed to get block: %w", err)
} else if block.Cid().Hash().String() != c.Hash().String() {
return fmt.Errorf("unexpected root cid: %s", block.Cid().String())
var recursiveVerifyCid func(ctx context.Context, c cid.Cid) error
recursiveVerifyCid = func(ctx context.Context, c cid.Cid) error {
block, err := rbs.Get(ctx, c)
if err != nil {
return fmt.Errorf("failed to get block: %w", err)
} else if block.Cid().Hash().String() != c.Hash().String() {
return fmt.Errorf("unexpected multihash: %s != %s", block.Cid(), c)
}

switch node := block.(type) {

Check warning on line 250 in sia/sia.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.20)

unnecessary-stmt: switch with only one case can be replaced by an if-then (revive)

Check warning on line 250 in sia/sia.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.21)

unnecessary-stmt: switch with only one case can be replaced by an if-then (revive)
case *merkledag.ProtoNode:
links := node.Links()
for _, link := range links {
if err := recursiveVerifyCid(ctx, link.Cid); err != nil {
return err
}
}
}

return nil
}
return nil

return recursiveVerifyCid(ctx, c)
}

// New creates a new Sia IPFS store
Expand Down
3 changes: 3 additions & 0 deletions sia/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"time"

"github.com/gogo/protobuf/proto"
"github.com/ipfs/boxo/ipld/merkledag"
Expand Down Expand Up @@ -102,10 +103,12 @@ func (bs *RenterdBlockStore) Get(ctx context.Context, c cid.Cid) (blocks.Block,
log := bs.log.With(zap.Stringer("cid", c), zap.String("dataBucket", cm.Data.Bucket), zap.String("dataKey", cm.Data.Key), zap.String("metaBucket", cm.Metadata.Bucket), zap.String("metaKey", cm.Metadata.Key), zap.Uint64("blockSize", cm.Data.BlockSize), zap.Uint64("blockOffset", cm.Data.Offset), zap.Uint64("metadataSize", cm.Metadata.Length), zap.Uint64("metadataOffset", cm.Metadata.Offset))
log.Debug("downloading block")

start := time.Now()
block, err := bs.downloadBlock(ctx, cm)
if err != nil {
log.Error("failed to download block", zap.Error(err))
}
log.Debug("block downloaded", zap.Duration("elapsed", time.Since(start)))
return block, err
}

Expand Down
Loading