Skip to content

Commit

Permalink
Merge pull request #549 from stratosnet/dev
Browse files Browse the repository at this point in the history
Release v0.11.7
  • Loading branch information
jinzuo-qsn authored Nov 22, 2023
2 parents 406e34f + d123e72 commit 405364b
Show file tree
Hide file tree
Showing 8 changed files with 1,182 additions and 1,157 deletions.
2,299 changes: 1,154 additions & 1,145 deletions msg/protos/sds.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions msg/protos/sds.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ message RspRegister {

message ReqMining {
PPBaseInfo address = 1;
string version = 2;
}

message RspMining {
Expand Down
5 changes: 3 additions & 2 deletions pp/event/download_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,13 @@ func ReqDownloadSlice(ctx context.Context, conn core.WriteCloser) {
}

// spam check
key := target.RspFileStorageInfo.TaskId + strconv.FormatInt(int64(target.SliceNumber), 10)
key := target.RspFileStorageInfo.TaskId + strconv.FormatInt(int64(target.SliceNumber), 10) +
target.P2PAddress + strconv.FormatInt(target.RspFileStorageInfo.TimeStamp, 10)
if _, ok := downloadSliceSpamCheckMap.Load(key); ok {
rsp := &protos.RspDownloadSlice{
Result: &protos.Result{
State: protos.ResultState_RES_FAIL,
Msg: "failed downloading file slice, re-download",
Msg: "repeated download slice request, refused",
},
}
_ = p2pserver.GetP2pServer(ctx).SendMessage(ctx, conn, rsp, header.RspDownloadSlice)
Expand Down
17 changes: 14 additions & 3 deletions pp/event/transfer_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ func ReqTransferDownload(ctx context.Context, conn core.WriteCloser) {
noticeFileSliceBackup := target.NoticeFileSliceBackup

// spam check
key := noticeFileSliceBackup.TaskId + strconv.FormatInt(int64(noticeFileSliceBackup.SliceNumber), 10)
key := noticeFileSliceBackup.TaskId + strconv.FormatInt(int64(noticeFileSliceBackup.SliceNumber), 10) +
noticeFileSliceBackup.ToP2PAddress + strconv.FormatInt(noticeFileSliceBackup.TimeStamp, 10)
if _, ok := transferSliceSpamCheckMap.Load(key); ok {
rsp := &protos.RspTransferDownload{
Result: &protos.Result{
State: protos.ResultState_RES_FAIL,
Msg: "failed transferring file slice, re-transfer",
Msg: "repeated transfer message, refused",
},
}
_ = p2pserver.GetP2pServer(ctx).SendMessage(ctx, conn, rsp, header.RspTransferDownload)
Expand Down Expand Up @@ -175,6 +176,14 @@ func RspTransferDownload(ctx context.Context, conn core.WriteCloser) {
if !requests.UnmarshalData(ctx, &target) {
return
}
if target.Result != nil && target.Result.State == protos.ResultState_RES_FAIL {
utils.ErrorLog("received failed transfer download,", target.Result.Msg)
return
}
if target.Data == nil {
utils.ErrorLog("no data contained in the message")
return
}
defer utils.ReleaseBuffer(target.Data)
totalCostTIme := DownRecvCostTimeMap.AddCostTime(target.TaskId+target.SliceHash, costTime)

Expand All @@ -187,7 +196,8 @@ func RspTransferDownload(ctx context.Context, conn core.WriteCloser) {
utils.DebugLogf("slice data saved, waiting for more data of this slice[%v]", target.SliceHash)
return
}
// All data has been received

// data is received
SendReportBackupSliceResult(ctx, target.TaskId, target.SliceHash, target.SpP2PAddress, true, false, totalCostTIme)
_ = p2pserver.GetP2pServer(ctx).SendMessage(ctx, conn, requests.RspTransferDownloadResultData(target.TaskId, target.SliceHash, target.SpP2PAddress), header.RspTransferDownloadResult)
}
Expand Down Expand Up @@ -232,6 +242,7 @@ func RspTransferDownloadResult(ctx context.Context, conn core.WriteCloser) {
func SendReportBackupSliceResult(ctx context.Context, taskId, sliceHash, spP2pAddress string, result bool, originDeleted bool, costTime int64) {
tTask, ok := task.GetTransferTask(taskId, sliceHash)
if !ok {
utils.ErrorLog("Transfer/backup task is already removed.")
return
}
opponentP2PAddress := tTask.PpInfo.P2PAddress
Expand Down
11 changes: 7 additions & 4 deletions pp/event/upload_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,14 @@ func ReqUploadFileSlice(ctx context.Context, conn core.WriteCloser) {
}

// spam check
key := rspUploadFile.TaskId + strconv.FormatInt(int64(target.SliceNumber), 10) + strconv.FormatInt(int64(target.PieceOffset.SliceOffsetStart), 10)
key := rspUploadFile.TaskId + strconv.FormatInt(int64(target.SliceNumber), 10) +
strconv.FormatInt(int64(target.PieceOffset.SliceOffsetStart), 10) + target.P2PAddress +
strconv.FormatInt(rspUploadFile.TimeStamp, 10)
if _, ok := uploadSliceSpamCheckMap.Load(key); ok {
rsp := &protos.RspUploadFileSlice{
Result: &protos.Result{
State: protos.ResultState_RES_FAIL,
Msg: "failed uploading file slice, re-upload",
Msg: "repeated upload slice request, refused",
},
}
_ = p2pserver.GetP2pServer(ctx).SendMessage(ctx, conn, rsp, header.RspUploadFileSlice)
Expand Down Expand Up @@ -262,12 +264,13 @@ func ReqBackupFileSlice(ctx context.Context, conn core.WriteCloser) {
}
defer utils.ReleaseBuffer(target.Data)
// spam check
key := target.RspBackupFile.TaskId + strconv.FormatInt(int64(target.SliceNumber), 10)
key := target.RspBackupFile.TaskId + strconv.FormatInt(int64(target.SliceNumber), 10) + target.P2PAddress +
strconv.FormatInt(target.RspBackupFile.TimeStamp, 10)
if _, ok := backupSliceSpamCheckMap.Load(key); ok {
rsp := &protos.RspBackupFileSlice{
Result: &protos.Result{
State: protos.ResultState_RES_FAIL,
Msg: "failed backing up file slice, re-backup",
Msg: "repeated backup slice request, refused",
},
}
_ = p2pserver.GetP2pServer(ctx).SendMessage(ctx, conn, rsp, header.RspBackupFileSlice)
Expand Down
2 changes: 1 addition & 1 deletion pp/requests/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func ReqRegisterDataTR(ctx context.Context, target *protos.ReqRegister) *msg.Rel
}

func ReqMiningData(ctx context.Context) *protos.ReqMining {
return &protos.ReqMining{Address: p2pserver.GetP2pServer(ctx).GetPPInfo()}
return &protos.ReqMining{Address: p2pserver.GetP2pServer(ctx).GetPPInfo(), Version: setting.Version}
}

func ReqGetPPlistData(ctx context.Context) *protos.ReqGetPPList {
Expand Down
2 changes: 1 addition & 1 deletion pp/setting/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

const (
Version = "v0.11.6"
Version = "v0.11.7"
AppVersion = 11
MinAppVersion = 11

Expand Down
2 changes: 1 addition & 1 deletion pp/task/transfer_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func GetTransferSliceData(taskId, sliceHash string) (int64, [][]byte) {
func SaveTransferData(target *protos.RspTransferDownload) (bool, error) {
tTask, ok := GetTransferTask(target.TaskId, target.SliceHash)
if !ok {
return false, errors.New("failed getting transfer task")
return false, errors.Errorf("failed getting transfer task - task_id:%v slice_hash:%v uploader_p2p_addess:%v", target.TaskId, target.SliceHash, target.P2PAddress)
}
err := file.SaveSliceData(target.Data, tTask.SliceStorageInfo.SliceHash, target.Offset)
if err != nil {
Expand Down

0 comments on commit 405364b

Please sign in to comment.