Commit f06ff6e3 authored by vicotor's avatar vicotor

udpate protocol

parent 466e0c38
......@@ -141,7 +141,7 @@ func main() {
msg := &omanager.WorkerMessage{
Message: &omanager.WorkerMessage_SubmitTaskResult{
SubmitTaskResult: &omanager.SubmitTaskResult{
TaskId: b.PushTaskMessage.TaskId,
TaskUuid: b.PushTaskMessage.TaskUuid,
ContainerSignature: make([]byte, 65),
MinerSignature: make([]byte, 65),
TaskResult: []byte(demoResult),
......
......@@ -59,7 +59,7 @@ func (n *NodeManagerService) DispatchTask(ctx context.Context, request *omanager
}
res := new(omanager.DispatchTaskResponse)
res.TaskId = request.TaskData.TaskId
res.TaskUuid = request.TaskData.TaskUuid
res.Miner = request.Miner
return res, nil
}
......@@ -146,7 +146,7 @@ func (wm *WorkerManager) doCallback(hook string, response *odysseus.TaskResponse
if err != nil {
log.WithError(err).Error("post task result failed")
} else {
log.WithField("taskid", response.TaskId).Debug("post task result")
log.WithField("taskid", response.TaskUuid).Debug("post task result")
}
}
......@@ -248,7 +248,7 @@ func (wm *WorkerManager) manageWorker(worker *Worker) error {
task := dtask.task
taskMsg := new(omanager.ManagerMessage_PushTaskMessage)
taskMsg.PushTaskMessage = &omanager.PushTaskMessage{
TaskId: task.TaskId,
TaskUuid: task.TaskUuid,
TaskType: task.TaskType,
Workload: uint64(task.TaskWorkload),
TaskCmd: task.TaskCmd,
......@@ -271,19 +271,19 @@ func (wm *WorkerManager) manageWorker(worker *Worker) error {
}
case result := <-worker.resultCh:
// verify result and make a new signature.
data, exist := worker.recentTask.Get(result.TaskId)
data, exist := worker.recentTask.Get(result.TaskUuid)
if !exist {
log.WithField("worker", worker.uuid).Error("task not found for verify result")
continue
}
task := data.(*odysseus.TaskContent)
if result.TaskId != task.TaskId {
if result.TaskUuid != task.TaskUuid {
log.WithField("worker", worker.uuid).Error("task id not match")
continue
}
if result.IsSuccessed == false {
taskResponse := &odysseus.TaskResponse{
TaskId: task.TaskId,
TaskUuid: task.TaskUuid,
TaskResult: result.TaskResult,
TaskUid: task.TaskUid,
TaskFee: task.TaskFee,
......@@ -299,7 +299,7 @@ func (wm *WorkerManager) manageWorker(worker *Worker) error {
// container_signature = sign(hash(task_id+hash(task_param)+hash(task_result)))
paramHash := sha3.Sum256(task.TaskParam)
resultHash := sha3.Sum256(result.TaskResult)
dataHash := sha3.Sum256(utils.CombineBytes([]byte(result.TaskId), paramHash[:], resultHash[:]))
dataHash := sha3.Sum256(utils.CombineBytes([]byte(result.TaskUuid), paramHash[:], resultHash[:]))
containerPubkey, _ := utils.HexToPubkey(hex.EncodeToString(task.ContainerPubkey))
verified := ecdsa.VerifyASN1(containerPubkey, dataHash[:], result.ContainerSignature)
if !verified {
......@@ -311,7 +311,7 @@ func (wm *WorkerManager) manageWorker(worker *Worker) error {
// miner_signature = sign(hash((task_id+hash(task_param)+hash(task_result)))
paramHash := sha3.Sum256(task.TaskParam)
resultHash := sha3.Sum256(result.TaskResult)
dataHash := sha3.Sum256(utils.CombineBytes([]byte(result.TaskId), paramHash[:], resultHash[:]))
dataHash := sha3.Sum256(utils.CombineBytes([]byte(result.TaskUuid), paramHash[:], resultHash[:]))
minerPubkey, _ := utils.HexToPubkey(worker.publicKey) // todo: get miner pubkey
verified := ecdsa.VerifyASN1(minerPubkey, dataHash[:], result.MinerSignature)
if !verified {
......@@ -322,7 +322,7 @@ func (wm *WorkerManager) manageWorker(worker *Worker) error {
//manager_signature = sign(hash((task_id+hash(task_param)+hash(task_result)+container_signature+miner_signature+workload))
paramHash := sha3.Sum256(task.TaskParam)
resultHash := sha3.Sum256(result.TaskResult)
dataHash := sha3.Sum256(utils.CombineBytes([]byte(result.TaskId), paramHash[:], resultHash[:],
dataHash := sha3.Sum256(utils.CombineBytes([]byte(result.TaskUuid), paramHash[:], resultHash[:],
result.ContainerSignature, result.MinerSignature, big.NewInt(int64(task.TaskWorkload)).Bytes()))
signature, err := wm.node.Sign(dataHash[:])
......@@ -333,7 +333,7 @@ func (wm *WorkerManager) manageWorker(worker *Worker) error {
proof := new(omanager.ManagerMessage_ProofTaskResult)
proof.ProofTaskResult = &omanager.ProofTaskResult{
TaskId: result.TaskId,
TaskUuid: result.TaskUuid,
ManagerSignature: signature,
ContainerPubkey: utils.CombineBytes(task.ContainerPubkey),
}
......@@ -341,10 +341,10 @@ func (wm *WorkerManager) manageWorker(worker *Worker) error {
callback = func(err error) bool {
if err == nil {
// remove task from cache.
worker.recentTask.Remove(result.TaskId)
worker.recentTask.Remove(result.TaskUuid)
}
taskResponse := &odysseus.TaskResponse{
TaskId: task.TaskId,
TaskUuid: task.TaskUuid,
TaskResult: result.TaskResult,
TaskUid: task.TaskUid,
TaskFee: task.TaskFee,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment