Skip to content

Commit

Permalink
add count (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
AstaFrode authored Apr 13, 2023
1 parent f6ab0b2 commit 24650e7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
1 change: 1 addition & 0 deletions core/chain/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ type FragmentList struct {

type StorageOrder struct {
Stage types.U8
Count types.U8
SegmentList []SegmentList
NeededList []SegmentList
User UserBrief
Expand Down
3 changes: 1 addition & 2 deletions core/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Client interface {
CheckBucketName(bucketname string) bool
CreateBucket(owner []byte, bucketname string) (string, error)
ProcessingData(path string) ([]SegmentInfo, string, error)
PutFile(owner []byte, segmentInfo []SegmentInfo, roothash, filename, bucketname string) (string, error)
PutFile(owner []byte, segmentInfo []SegmentInfo, roothash, filename, bucketname string) (uint8, error)
GetFile(roothash, dir string) (string, error)
DeleteFile(owner []byte, roothash string) (string, chain.FileHash, error)
DeleteBucket(owner []byte, bucketName string) (string, error)
Expand Down Expand Up @@ -93,7 +93,6 @@ func NewBasicCli(rpc []string, name, phase, workspace, addr string, port int, ti
//
os.MkdirAll(filepath.Join(workspaceActual, rule.FileDir), rule.DirMode)
os.MkdirAll(filepath.Join(workspaceActual, rule.TempDir), rule.DirMode)
os.MkdirAll(filepath.Join(workspaceActual, rule.DbDir), rule.DirMode)

return cli, nil
}
12 changes: 6 additions & 6 deletions core/client/file.go → core/client/putfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ func (c *Cli) DeleteFile(owner []byte, roothash string) (string, chain.FileHash,
return c.Chain.DeleteFile(owner, roothash)
}

func (c *Cli) PutFile(owner []byte, segmentInfo []SegmentInfo, roothash, filename, bucketname string) (string, error) {
func (c *Cli) PutFile(owner []byte, segmentInfo []SegmentInfo, roothash, filename, bucketname string) (uint8, error) {
var err error
var storageOrder chain.StorageOrder

_, err = c.Chain.GetFileMetaInfo(roothash)
if err == nil {
return "", nil
return 0, nil
}

for i := 0; i < 3; i++ {
Expand All @@ -42,7 +42,7 @@ func (c *Cli) PutFile(owner []byte, segmentInfo []SegmentInfo, roothash, filenam
if err.Error() == chain.ERR_Empty {
err = c.GenerateStorageOrder(roothash, segmentInfo, owner, filename, bucketname)
if err != nil {
return "", err
return 0, err
}
}
time.Sleep(rule.BlockInterval)
Expand All @@ -51,15 +51,15 @@ func (c *Cli) PutFile(owner []byte, segmentInfo []SegmentInfo, roothash, filenam
break
}
if err != nil {
return "", err
return 0, err
}

// store fragment to storage
err = c.StorageData(roothash, segmentInfo, storageOrder.AssignedMiner)
if err != nil {
return roothash, err
return 0, err
}
return "", err
return uint8(storageOrder.Count), nil
}

func (c *Cli) ProcessingData(path string) ([]SegmentInfo, string, error) {
Expand Down
7 changes: 3 additions & 4 deletions core/rule/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package rule

// byte size
const (
SIZE_1KiB = 1024
SIZE_1MiB = 1024 * SIZE_1KiB
SIZE_1GiB = 1024 * SIZE_1MiB
SIZE_SLICE = 512 * SIZE_1MiB
SIZE_1KiB = 1024
SIZE_1MiB = 1024 * SIZE_1KiB
SIZE_1GiB = 1024 * SIZE_1MiB
)

const SegmentSize = 16 * SIZE_1MiB
Expand Down
3 changes: 1 addition & 2 deletions core/rule/dir.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package rule

const DirMode = 0755
const DirMode = 0644

const FileDir = "file"
const TempDir = "tmp"
const DbDir = "db"

0 comments on commit 24650e7

Please sign in to comment.