Skip to content

Commit

Permalink
git upload filehash, when btfs add it
Browse files Browse the repository at this point in the history
  • Loading branch information
laocheng.cheng committed Nov 9, 2021
1 parent 76fb054 commit 94a75ea
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,12 @@ docs/examples/go-ipfs-as-a-library/example-folder/Qm*
/parts
/stage
/prime


cmd/btfs/btfs.bk
cmd/btfs/config.yaml
cmd/btfs/config.yaml.bk
cmd/btfs/config_darwin_amd64.yaml
cmd/btfs/fs-repo-migrations
cmd/btfs/fs-repo-migrations.bk
cmd/btfs/update-darwin-amd64
22 changes: 22 additions & 0 deletions core/commands/storage/upload/helper/upload_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,28 @@ func GetShardHashes(params *ContextParams, fileHash string) (shardHashes []strin
return
}

func GetShardHashesCopy(params *ContextParams, fileHash string, copyNum int) (shardHashes []string, fileSize int64,
shardSize int64, err error) {

fileCid, err := cidlib.Parse(fileHash)
if err != nil {
return nil, -1, -1, err
}
sz, err := getNodeSizeFromCid(params.Ctx, fileCid, params.Api)
if err != nil {
return nil, -1, -1, err
}
fileSize = int64(sz)
shardSize = fileSize

shardHashes = make([]string, 0)
for i:=0; i<copyNum + 1; i++ {
shardHashes = append(shardHashes, fileHash)
}

return
}

func GetPriceAndMinStorageLength(params *ContextParams) (price int64, storageLength int, err error) {
ns, err := helper.GetHostStorageConfig(params.Ctx, params.N)
if err != nil {
Expand Down
19 changes: 18 additions & 1 deletion core/commands/storage/upload/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
testOnlyOptionName = "host-search-local"
customizedPayoutOptionName = "customize-payout"
customizedPayoutPeriodOptionName = "customize-payout-period"
copyName = "copy"

defaultRepFactor = 3
defaultStorageLength = 30
Expand Down Expand Up @@ -98,6 +99,7 @@ Use status command to check for completion:
cmds.IntOption(storageLengthOptionName, "len", "File storage period on hosts in days.").WithDefault(defaultStorageLength),
cmds.BoolOption(customizedPayoutOptionName, "Enable file storage customized payout schedule.").WithDefault(false),
cmds.IntOption(customizedPayoutPeriodOptionName, "Period of customized payout schedule.").WithDefault(1),
cmds.IntOption(copyName, "copy num of file hash.").WithDefault(0),
},
RunTimeout: 15 * time.Minute,
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
Expand Down Expand Up @@ -128,8 +130,23 @@ Use status command to check for completion:
return nil
}, helper.WaitingForPeersBo)

var shardHashes []string
var fileSize int64
var shardSize int64

fileHash := req.Arguments[0]
shardHashes, fileSize, shardSize, err := helper.GetShardHashes(ctxParams, fileHash)
shardHashes, fileSize, shardSize, err = helper.GetShardHashes(ctxParams, fileHash)
fmt.Printf("rs get, shardHashes:%v fileSize:%v, shardSize:%v, err:%v \n",
shardHashes, fileSize, shardSize, err )

if len(shardHashes) == 0 && fileSize == -1 && shardSize == -1 &&
strings.HasPrefix(err.Error(),"invalid hash: file must be reed-solomon encoded") {
if copyNum, ok := req.Options[copyName].(int); ok {
shardHashes, fileSize, shardSize, err = helper.GetShardHashesCopy(ctxParams, fileHash, copyNum)
fmt.Printf("copy get, shardHashes:%v fileSize:%v, shardSize:%v, copy:%v err:%v \n",
shardHashes, fileSize, shardSize, copyNum, err )
}
}
if err != nil {
return err
}
Expand Down

0 comments on commit 94a75ea

Please sign in to comment.