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

Commit

Permalink
feature: return supernode ip according to the value specified by peer
Browse files Browse the repository at this point in the history
Signed-off-by: Starnop <[email protected]>
  • Loading branch information
starnop committed Jul 25, 2019
1 parent dbaaa73 commit 5ce8009
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
7 changes: 7 additions & 0 deletions apis/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,10 @@ definitions:
description: |
PeerID is used to uniquely identifies a peer which will be used to create a dfgetTask.
The value must be the value in the response after registering a peer.
supernodeIP:
type: "string"
description: "IP address of supernode which the peer connects to"


TaskCreateResponse:
type: "object"
Expand Down Expand Up @@ -1162,6 +1166,9 @@ definitions:
PeerID uniquely identifies a peer, and the cID uniquely identifies a
download task belonging to a peer. One peer can initiate multiple download tasks,
which means that one peer corresponds to multiple cIDs.
supernodeIP:
type: "string"
description: "IP address of supernode which the peer connects to"

ErrorResponse:
type: "object"
Expand Down
3 changes: 3 additions & 0 deletions apis/types/df_get_task.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions apis/types/task_create_request.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions supernode/daemon/mgr/task/manager_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,13 @@ func (tm *Manager) updateTask(taskID string, updateTaskInfo *types.TaskInfo) err

func (tm *Manager) addDfgetTask(ctx context.Context, req *types.TaskCreateRequest, task *types.TaskInfo) (*types.DfGetTask, error) {
dfgetTask := &types.DfGetTask{
CID: req.CID,
Path: req.Path,
PieceSize: task.PieceSize,
Status: types.DfGetTaskStatusWAITING,
TaskID: task.ID,
PeerID: req.PeerID,
CID: req.CID,
Path: req.Path,
PieceSize: task.PieceSize,
Status: types.DfGetTaskStatusWAITING,
TaskID: task.ID,
PeerID: req.PeerID,
SupernodeIP: req.SupernodeIP,
}

if err := tm.dfgetTaskMgr.Add(ctx, dfgetTask); err != nil {
Expand Down Expand Up @@ -301,6 +302,11 @@ func (tm *Manager) parseAvailablePeers(ctx context.Context, clientID string, tas
return false, nil, err
}

// get supernode IP according to the cid dynamically
if tm.cfg.IsSuperPID(pieceInfo.PID) {
pieceInfo.PeerIP = dfgetTask.SupernodeIP
}

pieceInfos = append(pieceInfos, pieceInfo)
}

Expand Down
19 changes: 10 additions & 9 deletions supernode/server/0.3_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,16 @@ func (s *Server) registry(ctx context.Context, rw http.ResponseWriter, req *http

peerID := peerCreateResponse.ID
taskCreateRequest := &types.TaskCreateRequest{
CID: request.CID,
Dfdaemon: request.Dfdaemon,
Headers: cutil.ConvertHeaders(request.Headers),
Identifier: request.Identifier,
Md5: request.Md5,
Path: request.Path,
PeerID: peerID,
RawURL: request.RawURL,
TaskURL: request.TaskURL,
CID: request.CID,
Dfdaemon: request.Dfdaemon,
Headers: cutil.ConvertHeaders(request.Headers),
Identifier: request.Identifier,
Md5: request.Md5,
Path: request.Path,
PeerID: peerID,
RawURL: request.RawURL,
TaskURL: request.TaskURL,
SupernodeIP: request.SuperNodeIP.String(),
}
resp, err := s.TaskMgr.Register(ctx, taskCreateRequest)
if err != nil {
Expand Down

0 comments on commit 5ce8009

Please sign in to comment.