diff --git a/apis/swagger.yml b/apis/swagger.yml index b0fb82dfb..f9c80af97 100644 --- a/apis/swagger.yml +++ b/apis/swagger.yml @@ -702,6 +702,13 @@ definitions: tells whether it is a call from dfdaemon. dfdaemon is a long running process which works for container engines. It translates the image pulling request into raw requests into those dfget recognizes. + callSystem: + type: "string" + description: | + This attribute represents where the dfget requests come from. Dfget will pass + this field to supernode and supernode can do some checking and filtering via + black/white list mechanism to guarantee security, or some other purposes like debugging. + minLength: 1 PeerCreateRequest: type: "object" @@ -840,9 +847,9 @@ definitions: callSystem: type: "string" description: | - This field is for debugging. When caller of dfget is using it to files, he can pass callSystem - name to dfget. When this field is passing to supernode, supernode has ability to filter them via - some black/white list to guarantee security, or some other purposes. + This attribute represents where the dfget requests come from. Dfget will pass + this field to supernode and supernode can do some checking and filtering via + black/white list mechanism to guarantee security, or some other purposes like debugging. minLength: 1 filter: type: "array" @@ -958,20 +965,7 @@ definitions: from source server as user's wish. additionalProperties: type: "string" - dfdaemon: - type: "boolean" - description: | - tells whether it is a call from dfdaemon. dfdaemon is a long running - process which works for container engines. It translates the image - pulling request into raw requests into those dfget recganises. - callSystem: - type: "string" - description: | - This field is for debugging. When caller of dfget is using it to files, he can pass callSystem - name to dfget. When this field is passing to supernode, supernode has ability to filter them via - some black/white list to guarantee security, or some other purposes. - minLength: 1 - + TaskUpdateRequest: type: "object" description: "request used to update task attributes." @@ -1169,7 +1163,20 @@ definitions: supernodeIP: type: "string" description: "IP address of supernode which the peer connects to" - + dfdaemon: + type: "boolean" + description: | + tells whether it is a call from dfdaemon. dfdaemon is a long running + process which works for container engines. It translates the image + pulling request into raw requests into those dfget recganises. + callSystem: + type: "string" + description: | + This attribute represents where the dfget requests come from. Dfget will pass + this field to supernode and supernode can do some checking and filtering via + black/white list mechanism to guarantee security, or some other purposes like debugging. + minLength: 1 + ErrorResponse: type: "object" description: | diff --git a/apis/types/df_get_task.go b/apis/types/df_get_task.go index 457408dd8..ff0f300ef 100644 --- a/apis/types/df_get_task.go +++ b/apis/types/df_get_task.go @@ -27,6 +27,19 @@ type DfGetTask struct { // CID string `json:"cID,omitempty"` + // This attribute represents where the dfget requests come from. Dfget will pass + // this field to supernode and supernode can do some checking and filtering via + // black/white list mechanism to guarantee security, or some other purposes like debugging. + // + // Min Length: 1 + CallSystem string `json:"callSystem,omitempty"` + + // tells whether it is a call from dfdaemon. dfdaemon is a long running + // process which works for container engines. It translates the image + // pulling request into raw requests into those dfget recganises. + // + Dfdaemon bool `json:"dfdaemon,omitempty"` + // path is used in one peer A for uploading functionality. When peer B hopes // to get piece C from peer A, B must provide a URL for piece C. // Then when creating a task in supernode, peer A must provide this URL in request. @@ -61,6 +74,10 @@ type DfGetTask struct { func (m *DfGetTask) Validate(formats strfmt.Registry) error { var res []error + if err := m.validateCallSystem(formats); err != nil { + res = append(res, err) + } + if err := m.validateStatus(formats); err != nil { res = append(res, err) } @@ -71,6 +88,19 @@ func (m *DfGetTask) Validate(formats strfmt.Registry) error { return nil } +func (m *DfGetTask) validateCallSystem(formats strfmt.Registry) error { + + if swag.IsZero(m.CallSystem) { // not required + return nil + } + + if err := validate.MinLength("callSystem", "body", string(m.CallSystem), 1); err != nil { + return err + } + + return nil +} + var dfGetTaskTypeStatusPropEnum []interface{} func init() { diff --git a/apis/types/task_create_request.go b/apis/types/task_create_request.go index b07bc160e..c9eb85f21 100644 --- a/apis/types/task_create_request.go +++ b/apis/types/task_create_request.go @@ -24,9 +24,9 @@ type TaskCreateRequest struct { // CID string `json:"cID,omitempty"` - // This field is for debugging. When caller of dfget is using it to files, he can pass callSystem - // name to dfget. When this field is passing to supernode, supernode has ability to filter them via - // some black/white list to guarantee security, or some other purposes. + // This attribute represents where the dfget requests come from. Dfget will pass + // this field to supernode and supernode can do some checking and filtering via + // black/white list mechanism to guarantee security, or some other purposes like debugging. // // Min Length: 1 CallSystem string `json:"callSystem,omitempty"` diff --git a/apis/types/task_info.go b/apis/types/task_info.go index 719153c3e..f88a43985 100644 --- a/apis/types/task_info.go +++ b/apis/types/task_info.go @@ -22,24 +22,11 @@ type TaskInfo struct { // ID of the task. ID string `json:"ID,omitempty"` - // This field is for debugging. When caller of dfget is using it to files, he can pass callSystem - // name to dfget. When this field is passing to supernode, supernode has ability to filter them via - // some black/white list to guarantee security, or some other purposes. - // - // Min Length: 1 - CallSystem string `json:"callSystem,omitempty"` - // The status of the created task related to CDN functionality. // // Enum: [WAITING RUNNING FAILED SUCCESS SOURCE_ERROR] CdnStatus string `json:"cdnStatus,omitempty"` - // tells whether it is a call from dfdaemon. dfdaemon is a long running - // process which works for container engines. It translates the image - // pulling request into raw requests into those dfget recganises. - // - Dfdaemon bool `json:"dfdaemon,omitempty"` - // The length of the file dfget requests to download in bytes // which including the header and the trailer of each piece. // @@ -101,10 +88,6 @@ type TaskInfo struct { func (m *TaskInfo) Validate(formats strfmt.Registry) error { var res []error - if err := m.validateCallSystem(formats); err != nil { - res = append(res, err) - } - if err := m.validateCdnStatus(formats); err != nil { res = append(res, err) } @@ -115,19 +98,6 @@ func (m *TaskInfo) Validate(formats strfmt.Registry) error { return nil } -func (m *TaskInfo) validateCallSystem(formats strfmt.Registry) error { - - if swag.IsZero(m.CallSystem) { // not required - return nil - } - - if err := validate.MinLength("callSystem", "body", string(m.CallSystem), 1); err != nil { - return err - } - - return nil -} - var taskInfoTypeCdnStatusPropEnum []interface{} func init() { diff --git a/apis/types/task_register_request.go b/apis/types/task_register_request.go index 382973032..90886382f 100644 --- a/apis/types/task_register_request.go +++ b/apis/types/task_register_request.go @@ -28,6 +28,13 @@ type TaskRegisterRequest struct { // CID string `json:"cID,omitempty"` + // This attribute represents where the dfget requests come from. Dfget will pass + // this field to supernode and supernode can do some checking and filtering via + // black/white list mechanism to guarantee security, or some other purposes like debugging. + // + // Min Length: 1 + CallSystem string `json:"callSystem,omitempty"` + // tells whether it is a call from dfdaemon. dfdaemon is a long running // process which works for container engines. It translates the image // pulling request into raw requests into those dfget recognizes. @@ -100,6 +107,10 @@ func (m *TaskRegisterRequest) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateCallSystem(formats); err != nil { + res = append(res, err) + } + if err := m.validateHostName(formats); err != nil { res = append(res, err) } @@ -131,6 +142,19 @@ func (m *TaskRegisterRequest) validateIP(formats strfmt.Registry) error { return nil } +func (m *TaskRegisterRequest) validateCallSystem(formats strfmt.Registry) error { + + if swag.IsZero(m.CallSystem) { // not required + return nil + } + + if err := validate.MinLength("callSystem", "body", string(m.CallSystem), 1); err != nil { + return err + } + + return nil +} + func (m *TaskRegisterRequest) validateHostName(formats strfmt.Registry) error { if swag.IsZero(m.HostName) { // not required diff --git a/supernode/daemon/mgr/dfgettask/manager_test.go b/supernode/daemon/mgr/dfgettask/manager_test.go index 2de933e57..514d8fb05 100644 --- a/supernode/daemon/mgr/dfgettask/manager_test.go +++ b/supernode/daemon/mgr/dfgettask/manager_test.go @@ -35,10 +35,15 @@ func init() { } type DfgetTaskMgrTestSuite struct { + manager *Manager +} + +// SetUpSuite does common setup in the beginning of each test. +func (s *DfgetTaskMgrTestSuite) SetUpSuite(c *check.C) { + s.manager, _ = NewManager() } func (s *DfgetTaskMgrTestSuite) TestDfgetTaskMgr(c *check.C) { - dfgetTaskManager, _ := NewManager() clientID := "foo" taskID := "00c4e7b174af7ed61c414b36ef82810ac0c98142c03e5748c00e1d1113f3c882" @@ -51,11 +56,11 @@ func (s *DfgetTaskMgrTestSuite) TestDfgetTaskMgr(c *check.C) { PeerID: "foo-192.168.10.11-1553838710990554281", } - err := dfgetTaskManager.Add(context.Background(), dfgetTask) + err := s.manager.Add(context.Background(), dfgetTask) c.Check(err, check.IsNil) // Get - dt, err := dfgetTaskManager.Get(context.Background(), clientID, taskID) + dt, err := s.manager.Get(context.Background(), clientID, taskID) c.Check(err, check.IsNil) c.Check(dt, check.DeepEquals, &types.DfGetTask{ CID: clientID, @@ -67,10 +72,10 @@ func (s *DfgetTaskMgrTestSuite) TestDfgetTaskMgr(c *check.C) { }) // UpdateStatus - err = dfgetTaskManager.UpdateStatus(context.Background(), clientID, taskID, types.DfGetTaskStatusSUCCESS) + err = s.manager.UpdateStatus(context.Background(), clientID, taskID, types.DfGetTaskStatusSUCCESS) c.Check(err, check.IsNil) - dt, err = dfgetTaskManager.Get(context.Background(), clientID, taskID) + dt, err = s.manager.Get(context.Background(), clientID, taskID) c.Check(err, check.IsNil) c.Check(dt, check.DeepEquals, &types.DfGetTask{ CID: clientID, @@ -82,9 +87,9 @@ func (s *DfgetTaskMgrTestSuite) TestDfgetTaskMgr(c *check.C) { }) // Delete - err = dfgetTaskManager.Delete(context.Background(), clientID, taskID) + err = s.manager.Delete(context.Background(), clientID, taskID) c.Check(err, check.IsNil) - _, err = dfgetTaskManager.Get(context.Background(), clientID, taskID) + _, err = s.manager.Get(context.Background(), clientID, taskID) c.Check(errors.IsDataNotFound(err), check.Equals, true) } diff --git a/supernode/daemon/mgr/task/manager_util.go b/supernode/daemon/mgr/task/manager_util.go index 69f542c63..547ab348b 100644 --- a/supernode/daemon/mgr/task/manager_util.go +++ b/supernode/daemon/mgr/task/manager_util.go @@ -28,8 +28,6 @@ func (tm *Manager) addOrUpdateTask(ctx context.Context, req *types.TaskCreateReq var task *types.TaskInfo newTask := &types.TaskInfo{ ID: taskID, - CallSystem: req.CallSystem, - Dfdaemon: req.Dfdaemon, Headers: req.Headers, Identifier: req.Identifier, Md5: req.Md5, @@ -155,6 +153,8 @@ 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, + CallSystem: req.CallSystem, + Dfdaemon: req.Dfdaemon, Path: req.Path, PieceSize: task.PieceSize, Status: types.DfGetTaskStatusWAITING, diff --git a/supernode/daemon/mgr/task/manager_util_test.go b/supernode/daemon/mgr/task/manager_util_test.go index e6ee9c271..5df0ffc9f 100644 --- a/supernode/daemon/mgr/task/manager_util_test.go +++ b/supernode/daemon/mgr/task/manager_util_test.go @@ -81,9 +81,7 @@ func (s *TaskUtilTestSuite) TestAddOrUpdateTask(c *check.C) { }, task: &types.TaskInfo{ ID: generateTaskID("http://aa.bb.com", "", ""), - CallSystem: "foo", CdnStatus: types.TaskInfoCdnStatusWAITING, - Dfdaemon: true, HTTPFileLength: 1000, PieceSize: config.DefaultPieceSize, PieceTotal: 1, @@ -103,9 +101,7 @@ func (s *TaskUtilTestSuite) TestAddOrUpdateTask(c *check.C) { }, task: &types.TaskInfo{ ID: generateTaskID("http://aa.bb.com", "", ""), - CallSystem: "foo", CdnStatus: types.TaskInfoCdnStatusWAITING, - Dfdaemon: true, HTTPFileLength: 1000, PieceSize: config.DefaultPieceSize, PieceTotal: 1, diff --git a/supernode/server/0.3_bridge.go b/supernode/server/0.3_bridge.go index aac206d4f..919f6c009 100644 --- a/supernode/server/0.3_bridge.go +++ b/supernode/server/0.3_bridge.go @@ -77,6 +77,7 @@ func (s *Server) registry(ctx context.Context, rw http.ResponseWriter, req *http peerID := peerCreateResponse.ID taskCreateRequest := &types.TaskCreateRequest{ CID: request.CID, + CallSystem: request.CallSystem, Dfdaemon: request.Dfdaemon, Headers: cutil.ConvertHeaders(request.Headers), Identifier: request.Identifier,