Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
bugfix:modify supernode's response to dfget to resolve the json err
Browse files Browse the repository at this point in the history
Signed-off-by: yunfeiyangbuaa <[email protected]>
  • Loading branch information
yunfeiyanggzq committed Jul 18, 2019
1 parent 21d2390 commit bab1b04
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
2 changes: 2 additions & 0 deletions common/constants/dfget_super_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ const (
CodeNeedAuth = 608
CodeWaitAuth = 609
CodeSourceError = 610
CodeGetPieceReport = 611
CodeGetPeerDown = 612
)

/* the code of task result that dfget will report to supernode */
Expand Down
9 changes: 8 additions & 1 deletion dfget/core/downloader/p2p_downloader/client_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"
"time"

"github.com/dragonflyoss/Dragonfly/common/constants"
cutil "github.com/dragonflyoss/Dragonfly/common/util"
"github.com/dragonflyoss/Dragonfly/dfget/config"
"github.com/dragonflyoss/Dragonfly/dfget/core/api"
Expand Down Expand Up @@ -196,12 +197,18 @@ func startSyncWriter(queue util.Queue) util.Queue {
}

func (cw *ClientWriter) sendSuccessPiece(piece *Piece, cost time.Duration) {
cw.api.ReportPiece(piece.SuperNode, &types.ReportPieceRequest{
resp, e := cw.api.ReportPiece(piece.SuperNode, &types.ReportPieceRequest{
TaskID: piece.TaskID,
Cid: cw.cfg.RV.Cid,
DstCid: piece.DstCid,
PieceRange: piece.Range,
})
if e != nil {
logrus.Errorf("sendSuccessPiece error:%v", e)
}
if resp.Code != constants.CodeGetPieceReport {
logrus.Errorf("send success piece report to supernode failed")
}
if cost.Seconds() > 2.0 {
logrus.Infof(
"async writer and report suc from dst:%s... cost:%.3f for range:%s",
Expand Down
17 changes: 15 additions & 2 deletions dfget/core/uploader/peer_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"sync"
"time"

"github.com/dragonflyoss/Dragonfly/common/constants"
"github.com/dragonflyoss/Dragonfly/common/errors"
"github.com/dragonflyoss/Dragonfly/common/util"
"github.com/dragonflyoss/Dragonfly/dfget/config"
Expand Down Expand Up @@ -457,7 +458,13 @@ func (ps *peerServer) shutdown() {
ps.syncTaskMap.Range(func(key, value interface{}) bool {
task, ok := value.(*taskConfig)
if ok {
ps.api.ServiceDown(task.superNode, task.taskID, task.cid)
resp, e := ps.api.ServiceDown(task.superNode, task.taskID, task.cid)
if e != nil {
logrus.Errorf("send ServiceDown error:%v", e)
}
if resp != nil && resp.Code != constants.CodeGetPeerDown {
logrus.Errorf("send peer ServiceDown to supernode failed")
}
serviceFile := helper.GetServiceFile(key.(string), task.dataDir)
os.Remove(serviceFile)
logrus.Infof("shutdown, remove task id:%s file:%s",
Expand All @@ -484,7 +491,13 @@ func (ps *peerServer) deleteExpiredFile(path string, info os.FileInfo,
}
if time.Now().Sub(info.ModTime()) > expireTime {
if ok {
ps.api.ServiceDown(task.superNode, task.taskID, task.cid)
resp, e := ps.api.ServiceDown(task.superNode, task.taskID, task.cid)
if e != nil {
logrus.Errorf("send ServiceDown error:%v", e)
}
if resp != nil && resp.Code != constants.CodeGetPeerDown {
logrus.Errorf("send ServiceDown to supernode failed")
}
}
os.Remove(path)
ps.syncTaskMap.Delete(taskName)
Expand Down
10 changes: 6 additions & 4 deletions supernode/server/0.3_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ func (s *Server) reportPiece(ctx context.Context, rw http.ResponseWriter, req *h
return err
}

rw.WriteHeader(http.StatusOK)
return nil
return EncodeResponse(rw, http.StatusOK, &types.ResultInfo{
Code: constants.CodeGetPieceReport,
})
}

func (s *Server) reportServiceDown(ctx context.Context, rw http.ResponseWriter, req *http.Request) (err error) {
Expand Down Expand Up @@ -228,6 +229,7 @@ func (s *Server) reportServiceDown(ctx context.Context, rw http.ResponseWriter,
return err
}

rw.WriteHeader(http.StatusOK)
return nil
return EncodeResponse(rw, http.StatusOK, &types.ResultInfo{
Code: constants.CodeGetPeerDown,
})
}

0 comments on commit bab1b04

Please sign in to comment.