fix: wrong md5 sign in cdn (#1126)

* fix: wrong md5 sign in cdn

Signed-off-by: Jim Ma <majinjing3@gmail.com>

* Extract the pieces sorting rule to the GetProgress method

Signed-off-by: sunwp <244372610@qq.com>

* cal sign notice

Signed-off-by: sunwp <244372610@qq.com>

Co-authored-by: sunwp <244372610@qq.com>
This commit is contained in:
Jim Ma 2022-03-04 22:07:00 +08:00 committed by Gaius
parent 7d778d7b95
commit bb73b45b46
No known key found for this signature in database
GPG Key ID: 8B4E5D1290FA2FFB
3 changed files with 7 additions and 5 deletions

View File

@ -220,7 +220,9 @@ func (css *Server) GetPieceTasks(ctx context.Context, req *base.PieceTaskRequest
}
}
pieceMd5Sign := seedTask.PieceMd5Sign
// TODO The calculation of sign has been completed after the source has been completed. This is just a fallback
if len(taskPieces) == int(seedTask.TotalPieceCount) && pieceMd5Sign == "" {
logger.WithTaskID(req.TaskId).Warn("The code flow should not go to this point, if the output of this log need to check why")
var pieceMd5s []string
for i := 0; i < len(taskPieces); i++ {
pieceMd5s = append(pieceMd5s, taskPieces[i].PieceMd5)

View File

@ -21,7 +21,6 @@ package progress
import (
"context"
"encoding/json"
"sort"
"sync"
"github.com/pkg/errors"
@ -86,9 +85,6 @@ func (pm *manager) WatchSeedProgress(ctx context.Context, clientAddr string, tas
logger.Debugf("subscriber %s starts watching task %s seed progress", clientAddr, taskID)
close(pieceChan)
}()
sort.Slice(pieces, func(i, j int) bool {
return pieces[i].PieceNum < pieces[j].PieceNum
})
for _, piece := range pieces {
logger.Debugf("notifies subscriber %s about %d piece info of taskID %s", clientAddr, piece.PieceNum, taskID)
pieceChan <- piece

View File

@ -19,6 +19,7 @@
package task
import (
"sort"
"sync"
"time"
@ -54,7 +55,7 @@ type Manager interface {
// UpdateProgress update the downloaded pieces belonging to the task
UpdateProgress(taskID string, piece *PieceInfo) (err error)
// GetProgress returns the downloaded pieces belonging to the task
// GetProgress returns the downloaded pieces belonging to the tasksorted by pieceNum ascending order
GetProgress(taskID string) ([]*PieceInfo, error)
// Exist check task existence with specified taskID.
@ -217,6 +218,9 @@ func (tm *manager) GetProgress(taskID string) ([]*PieceInfo, error) {
pieces = append(pieces, value.(*PieceInfo))
return true
})
sort.Slice(pieces, func(i, j int) bool {
return pieces[i].PieceNum < pieces[j].PieceNum
})
return pieces, nil
}