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:
parent
7d778d7b95
commit
bb73b45b46
|
|
@ -220,7 +220,9 @@ func (css *Server) GetPieceTasks(ctx context.Context, req *base.PieceTaskRequest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pieceMd5Sign := seedTask.PieceMd5Sign
|
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 == "" {
|
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
|
var pieceMd5s []string
|
||||||
for i := 0; i < len(taskPieces); i++ {
|
for i := 0; i < len(taskPieces); i++ {
|
||||||
pieceMd5s = append(pieceMd5s, taskPieces[i].PieceMd5)
|
pieceMd5s = append(pieceMd5s, taskPieces[i].PieceMd5)
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ package progress
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"sort"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"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)
|
logger.Debugf("subscriber %s starts watching task %s seed progress", clientAddr, taskID)
|
||||||
close(pieceChan)
|
close(pieceChan)
|
||||||
}()
|
}()
|
||||||
sort.Slice(pieces, func(i, j int) bool {
|
|
||||||
return pieces[i].PieceNum < pieces[j].PieceNum
|
|
||||||
})
|
|
||||||
for _, piece := range pieces {
|
for _, piece := range pieces {
|
||||||
logger.Debugf("notifies subscriber %s about %d piece info of taskID %s", clientAddr, piece.PieceNum, taskID)
|
logger.Debugf("notifies subscriber %s about %d piece info of taskID %s", clientAddr, piece.PieceNum, taskID)
|
||||||
pieceChan <- piece
|
pieceChan <- piece
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
package task
|
package task
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -54,7 +55,7 @@ type Manager interface {
|
||||||
// UpdateProgress update the downloaded pieces belonging to the task
|
// UpdateProgress update the downloaded pieces belonging to the task
|
||||||
UpdateProgress(taskID string, piece *PieceInfo) (err error)
|
UpdateProgress(taskID string, piece *PieceInfo) (err error)
|
||||||
|
|
||||||
// GetProgress returns the downloaded pieces belonging to the task
|
// GetProgress returns the downloaded pieces belonging to the task,sorted by pieceNum ascending order
|
||||||
GetProgress(taskID string) ([]*PieceInfo, error)
|
GetProgress(taskID string) ([]*PieceInfo, error)
|
||||||
|
|
||||||
// Exist check task existence with specified taskID.
|
// Exist check task existence with specified taskID.
|
||||||
|
|
@ -217,6 +218,9 @@ func (tm *manager) GetProgress(taskID string) ([]*PieceInfo, error) {
|
||||||
pieces = append(pieces, value.(*PieceInfo))
|
pieces = append(pieces, value.(*PieceInfo))
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
sort.Slice(pieces, func(i, j int) bool {
|
||||||
|
return pieces[i].PieceNum < pieces[j].PieceNum
|
||||||
|
})
|
||||||
return pieces, nil
|
return pieces, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue