From 24650e71aba2e19807107a6f92fb488c2ffe9467 Mon Sep 17 00:00:00 2001 From: AstaFrode <32032991+AstaFrode@users.noreply.github.com> Date: Thu, 13 Apr 2023 17:40:27 +0800 Subject: [PATCH] add count (#25) --- core/chain/types.go | 1 + core/client/client.go | 3 +-- core/client/{file.go => putfile.go} | 12 ++++++------ core/rule/data.go | 7 +++---- core/rule/dir.go | 3 +-- 5 files changed, 12 insertions(+), 14 deletions(-) rename core/client/{file.go => putfile.go} (97%) diff --git a/core/chain/types.go b/core/chain/types.go index ee4b63c..7982081 100644 --- a/core/chain/types.go +++ b/core/chain/types.go @@ -204,6 +204,7 @@ type FragmentList struct { type StorageOrder struct { Stage types.U8 + Count types.U8 SegmentList []SegmentList NeededList []SegmentList User UserBrief diff --git a/core/client/client.go b/core/client/client.go index 3533f37..3d8c8df 100644 --- a/core/client/client.go +++ b/core/client/client.go @@ -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) @@ -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 } diff --git a/core/client/file.go b/core/client/putfile.go similarity index 97% rename from core/client/file.go rename to core/client/putfile.go index 0e16dea..5c52384 100644 --- a/core/client/file.go +++ b/core/client/putfile.go @@ -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++ { @@ -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) @@ -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) { diff --git a/core/rule/data.go b/core/rule/data.go index 2013392..315bbcd 100644 --- a/core/rule/data.go +++ b/core/rule/data.go @@ -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 diff --git a/core/rule/dir.go b/core/rule/dir.go index 96af625..d2e4056 100644 --- a/core/rule/dir.go +++ b/core/rule/dir.go @@ -1,7 +1,6 @@ package rule -const DirMode = 0755 +const DirMode = 0644 const FileDir = "file" const TempDir = "tmp" -const DbDir = "db"