diff --git a/apis/swagger.yml b/apis/swagger.yml index 70ecea0f9..b0fb82dfb 100644 --- a/apis/swagger.yml +++ b/apis/swagger.yml @@ -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" @@ -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" diff --git a/apis/types/df_get_task.go b/apis/types/df_get_task.go index 2348c1234..457408dd8 100644 --- a/apis/types/df_get_task.go +++ b/apis/types/df_get_task.go @@ -50,6 +50,9 @@ type DfGetTask struct { // Enum: [WAITING RUNNING FAILED SUCCESS] Status string `json:"status,omitempty"` + // IP address of supernode which the peer connects to + SupernodeIP string `json:"supernodeIP,omitempty"` + // task Id TaskID string `json:"taskId,omitempty"` } diff --git a/apis/types/task_create_request.go b/apis/types/task_create_request.go index a829efe8f..b07bc160e 100644 --- a/apis/types/task_create_request.go +++ b/apis/types/task_create_request.go @@ -83,6 +83,9 @@ type TaskCreateRequest struct { // RawURL string `json:"rawURL,omitempty"` + // IP address of supernode which the peer connects to + SupernodeIP string `json:"supernodeIP,omitempty"` + // taskURL is generated from rawURL. rawURL may contains some queries or parameter, dfget will filter some queries via // --filter parameter of dfget. The usage of it is that different rawURL may generate the same taskID. // diff --git a/supernode/daemon/mgr/task/manager_util.go b/supernode/daemon/mgr/task/manager_util.go index 3c327350a..69f542c63 100644 --- a/supernode/daemon/mgr/task/manager_util.go +++ b/supernode/daemon/mgr/task/manager_util.go @@ -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 { @@ -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) } diff --git a/supernode/server/0.3_bridge.go b/supernode/server/0.3_bridge.go index ab524a6ae..aac206d4f 100644 --- a/supernode/server/0.3_bridge.go +++ b/supernode/server/0.3_bridge.go @@ -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 {