Skip to content

Commit

Permalink
Merge pull request #10 from SiaFoundation/nate/default-to-v0
Browse files Browse the repository at this point in the history
Default to v0 CIDs
  • Loading branch information
n8maninger authored Nov 30, 2023
2 parents 9b34c2b + 1fde904 commit 102d14a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
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 @@ import (
"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) CalculateBlocks(ctx context.Context, r io.Reader, opts UnixFSOpti
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

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.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

0 comments on commit 102d14a

Please sign in to comment.