Skip to content

Commit

Permalink
Merge pull request #1197 from TRON-US/master
Browse files Browse the repository at this point in the history
  • Loading branch information
olenheim authored Nov 25, 2021
2 parents 17053fc + 9b39d4c commit 8a7ed7e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 2 deletions.
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
10 changes: 10 additions & 0 deletions core/commands/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"path"
"sort"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -97,6 +98,14 @@ var swarmPeersCmd = &cmds.Command{
Peer: c.ID().Pretty(),
}

s := strings.Split(c.Address().String(), "/")
if len(s) >= 4 {
ip := s[2]
if len(ip) >= 4 {
ci.Ip = ip
}
}

if verbose || direction {
// set direction
ci.Direction = c.Direction()
Expand Down Expand Up @@ -170,6 +179,7 @@ type connInfo struct {
Muxer string
Direction inet.Direction
Streams []streamInfo
Ip string
}

func (ci *connInfo) Less(i, j int) bool {
Expand Down
2 changes: 1 addition & 1 deletion spin/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func (dc *dcWrap) sendData(node *core.IpfsNode, config *config.Config) {
backoff.Retry(func() error {
err := dc.doSendData(node.Context(), config, sm)
if err != nil {
log.Error("failed to send data to status server: ", err)
log.Infof("failed to send data to status server: ", err)
} else {
log.Debug("sent analytics to status server")
}
Expand Down

0 comments on commit 8a7ed7e

Please sign in to comment.