Skip to content

Commit

Permalink
Merge pull request #30 from TRON-US/BTFS-1849
Browse files Browse the repository at this point in the history
Btfs 1849
  • Loading branch information
Eric Chen authored Apr 23, 2020
2 parents ec54a2f + 495901f commit b214409
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
28 changes: 18 additions & 10 deletions file/reed_solomon_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,18 @@ func (f *rsDirectory) SetSize(size int64) error {
return errors.New("not supported")
}

func (f *rsDirectory) IsReedSolomon() bool {
return true
}

type rsIterator struct {
state int
ctx context.Context
cidString string
files chan interface{}
dserv ipld.DAGService
rsDir *rsDirectory
state int
ctx context.Context
cidString string
files chan interface{}
dserv ipld.DAGService
rsDir *rsDirectory
breadthFirstTraversal bool

curName string
curFile files.Node
Expand Down Expand Up @@ -162,7 +167,8 @@ func (it *rsIterator) Next() bool {
case *uio.DirNode:
it.curFile, it.err = NewReedSolomonSubDirectory(it.ctx, it.dserv, it.cidString, nd)
case *uio.FileNode:
it.curFile, it.err = NewReedSolomonFileUnderDirectory(it.ctx, it.dserv, it.cidString, nd)
it.curFile, it.err =
NewReedSolomonFileUnderDirectory(it.ctx, it.dserv, it.cidString, nd, it.breadthFirstTraversal)
case *uio.SymlinkNode:
it.curFile, it.err = files.NewLinkFile(nd.Data, nil), nil
default:
Expand Down Expand Up @@ -219,7 +225,8 @@ func (it *rsIterator) Err() error {
return it.err
}

func (it *rsIterator) SetReedSolomon() {
func (it *rsIterator) BreadthFirstTraversal() {
it.breadthFirstTraversal = true
}

type rsFile struct {
Expand Down Expand Up @@ -321,7 +328,8 @@ func NewReedSolomonSubDirectory(ctx context.Context, dserv ipld.DAGService, cid
// NewReedSolomonFileUnderDirectory returns a files.Node for the given `nd` Node.
// This functioon is called within the context of Reed-Solomon DAG for directory.
// The given `nd` is a uio.FileNode and is used to create a reader.
func NewReedSolomonFileUnderDirectory(ctx context.Context, dserv ipld.DAGService, cid string, nd uio.Node) (files.Node, error) {
func NewReedSolomonFileUnderDirectory(
ctx context.Context, dserv ipld.DAGService, cid string, nd uio.Node, bfs bool) (files.Node, error) {
// Locking is for synchronizing write access to rsDagInstance.offset.
// But rsDagInstance.offset may not be necessary. We use this field to verify the offset in `nd`.
rsDagInstance := GetDag(ctx, cid)
Expand All @@ -340,7 +348,7 @@ func NewReedSolomonFileUnderDirectory(ctx context.Context, dserv ipld.DAGService

b := rsDagInstance.buff.Bytes()
offset := fNode.StartOffset
if rsDagInstance.offset != offset {
if !bfs && rsDagInstance.offset != offset {
return nil, errors.New("offset from the given FileNode is invalid.")
}
newOffset := offset + uint64(fNode.NodeSize())
Expand Down
6 changes: 5 additions & 1 deletion file/unixfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (it *ufsIterator) Err() error {
return it.err
}

func (it *ufsIterator) SetReedSolomon() {
func (it *ufsIterator) BreadthFirstTraversal() {
}

func (d *ufsDirectory) Close() error {
Expand Down Expand Up @@ -141,6 +141,10 @@ func (f *ufsDirectory) SetSize(size int64) error {
return errors.New("not supported")
}

func (f *ufsDirectory) IsReedSolomon() bool {
return false
}

type ufsFile struct {
uio.DagReader
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/TRON-US/go-unixfs
require (
github.com/Stebalien/go-bitfield v0.0.1
github.com/TRON-US/go-btfs-chunker v0.2.8
github.com/TRON-US/go-btfs-files v0.1.6
github.com/TRON-US/go-btfs-files v0.1.7
github.com/gogo/protobuf v1.2.1
github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c // indirect
github.com/ipfs/go-bitswap v0.1.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ github.com/TRON-US/go-btfs-chunker v0.2.8/go.mod h1:Wj0oyybAWtu5lpcAc90QQ3bhJ14J
github.com/TRON-US/go-btfs-files v0.1.1/go.mod h1:tD2vOKLcLCDNMn9rrA27n2VbNpHdKewGzEguIFY+EJ0=
github.com/TRON-US/go-btfs-files v0.1.6 h1:POR7n7UUIMNtjIDEloqqi1/pRua2Gn5asjMJZsfiSxI=
github.com/TRON-US/go-btfs-files v0.1.6/go.mod h1:I8LeoFulha712BW03zGgmDdNwa0qbAPwfMIglzw0fnE=
github.com/TRON-US/go-btfs-files v0.1.7 h1:Yce1ycvUWPtvQ+Iv3stKqQXYymxhx/XyRZT0jJzdgVI=
github.com/TRON-US/go-btfs-files v0.1.7/go.mod h1:I8LeoFulha712BW03zGgmDdNwa0qbAPwfMIglzw0fnE=
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32 h1:qkOC5Gd33k54tobS36cXdAzJbeHaduLtnLQQwNoIi78=
github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32/go.mod h1:DrZx5ec/dmnfpw9KyYoQyYo7d0KEvTkk/5M/vbZjAr8=
Expand Down

0 comments on commit b214409

Please sign in to comment.