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 19, 2019
1 parent ae9e9a3 commit dfc9b7e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 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
14 changes: 13 additions & 1 deletion dfget/core/api/supernode_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ import (
"fmt"
"time"

"github.com/dragonflyoss/Dragonfly/common/constants"
"github.com/dragonflyoss/Dragonfly/common/util"
"github.com/dragonflyoss/Dragonfly/dfget/types"

"github.com/sirupsen/logrus"
)

/* the url paths of supernode APIs*/
Expand Down Expand Up @@ -100,9 +103,13 @@ func (api *supernodeAPI) ReportPiece(node string, req *types.ReportPieceRequest)

url := fmt.Sprintf("%s://%s%s?%s",
api.Scheme, node, peerReportPiecePath, util.ParseQuery(req))

resp = new(types.BaseResponse)
e = api.get(url, resp)
if e != nil {
logrus.Infof("failed to report piece{taskid:%s,range:%s},err: %v", req.TaskID, req.PieceRange, e)
} else if resp != nil && resp.Code != constants.CodeGetPieceReport {
logrus.Infof("failed to report piece{taskid:%s,range:%s} to supernode: api response code is %d not equal to %d", req.TaskID, req.PieceRange, e, resp.Code, constants.CodeGetPieceReport)
}
return
}

Expand All @@ -115,6 +122,11 @@ func (api *supernodeAPI) ServiceDown(node string, taskID string, cid string) (

resp = new(types.BaseResponse)
e = api.get(url, resp)
if e != nil {
logrus.Infof("failed to send service{taskid:%s} down,err: %v", taskID, e)
} else if resp != nil && resp.Code != constants.CodeGetPeerDown {
logrus.Infof("failed to send service{taskid:%s} down to supernode: api response code is %d not equal to %d", taskID, resp.Code, constants.CodeGetPeerDown)
}
return
}

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 dfc9b7e

Please sign in to comment.