diff --git a/common/constants/dfget_super_code.go b/common/constants/dfget_super_code.go index b59c3fc75..870045b4a 100644 --- a/common/constants/dfget_super_code.go +++ b/common/constants/dfget_super_code.go @@ -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 */ diff --git a/dfget/core/downloader/p2p_downloader/client_writer.go b/dfget/core/downloader/p2p_downloader/client_writer.go index 700d13da0..1a3edea3a 100644 --- a/dfget/core/downloader/p2p_downloader/client_writer.go +++ b/dfget/core/downloader/p2p_downloader/client_writer.go @@ -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" @@ -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", diff --git a/dfget/core/uploader/peer_server.go b/dfget/core/uploader/peer_server.go index 176d57e39..df26c3811 100644 --- a/dfget/core/uploader/peer_server.go +++ b/dfget/core/uploader/peer_server.go @@ -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" @@ -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", @@ -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) diff --git a/supernode/server/0.3_bridge.go b/supernode/server/0.3_bridge.go index ab524a6ae..19ad2b867 100644 --- a/supernode/server/0.3_bridge.go +++ b/supernode/server/0.3_bridge.go @@ -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) { @@ -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, + }) }