From 3139fa6c9b0df579ceb5925e3d620af25a137008 Mon Sep 17 00:00:00 2001 From: mricher Date: Mon, 4 Apr 2016 08:38:44 +0200 Subject: [PATCH] [c] Fix some signature issues - Fix missing sequence initialization - Fix missing answer in grpc handlers - Fix hashToID key issue - Do all rounds of promises --- dfssc/sign/protocol.go | 4 ++-- dfssc/sign/server.go | 14 ++++++++++++-- dfssc/sign/signatures.go | 2 +- dfssp/contract/ready.go | 1 + 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/dfssc/sign/protocol.go b/dfssc/sign/protocol.go index 1ef0763..a9c8dd6 100644 --- a/dfssc/sign/protocol.go +++ b/dfssc/sign/protocol.go @@ -36,7 +36,7 @@ func (m *SignatureManager) Sign() error { // Promess rounds // Follow the sequence until there is no next occurence of me - for nextIndex > 0 { + for m.currentIndex >= 0 { dAPI.DLog("Starting round at index [" + fmt.Sprintf("%d", m.currentIndex) + "]") log.Println("Starting round at index [" + fmt.Sprintf("%d", m.currentIndex) + "]") @@ -105,7 +105,7 @@ func (m *SignatureManager) promiseRound(pendingSet, sendSet []uint32, myID uint3 // TODO this ctx needs a timeout ! for len(pendingSet) > 0 { promise := <-incomingPromises - senderID, exist := hashToID[string(promise.SenderKeyHash)] + senderID, exist := hashToID[fmt.Sprintf("%x", promise.SenderKeyHash)] if exist { var err error pendingSet, err = common.Remove(pendingSet, senderID) diff --git a/dfssc/sign/server.go b/dfssc/sign/server.go index edee2c4..f797822 100644 --- a/dfssc/sign/server.go +++ b/dfssc/sign/server.go @@ -5,6 +5,7 @@ import ( cAPI "dfss/dfssc/api" pAPI "dfss/dfssp/api" "dfss/net" + "fmt" "golang.org/x/net/context" "google.golang.org/grpc" ) @@ -18,16 +19,25 @@ func (s *clientServer) TreatPromise(ctx context.Context, in *cAPI.Promise) (*pAP // Pass the message to Sign() if incomingPromises != nil { incomingPromises <- in + // Maybe we can add another channel here for better error management + return &pAPI.ErrorCode{Code: pAPI.ErrorCode_SUCCESS}, nil } - return nil, nil + return &pAPI.ErrorCode{Code: pAPI.ErrorCode_INVARG}, fmt.Errorf("Cannot pass incoming promise") } // TreatSignature handler // // Handle incoming TreatSignature messages func (s *clientServer) TreatSignature(ctx context.Context, in *cAPI.Signature) (*pAPI.ErrorCode, error) { - // TODO + if incomingSignatures != nil { + incomingSignatures <- in + // Maybe we can add another channel here for better error management + return &pAPI.ErrorCode{Code: pAPI.ErrorCode_SUCCESS}, nil + } + + return &pAPI.ErrorCode{Code: pAPI.ErrorCode_INVARG}, fmt.Errorf("Cannot pass incoming signature") + return nil, nil } diff --git a/dfssc/sign/signatures.go b/dfssc/sign/signatures.go index 4af0978..813e45a 100644 --- a/dfssc/sign/signatures.go +++ b/dfssc/sign/signatures.go @@ -94,7 +94,7 @@ func (m *SignatureManager) RecieveAllSigns() error { // TODO this ctx needs a timeout ! for len(pendingSet) > 0 { signature := <-incomingSignatures - senderID, exist := hashToID[string(signature.SenderKeyHash)] + senderID, exist := hashToID[fmt.Sprintf("%x", signature.SenderKeyHash)] if exist { var err error pendingSet, err = common.Remove(pendingSet, senderID) diff --git a/dfssp/contract/ready.go b/dfssp/contract/ready.go index 7211fa0..322822f 100644 --- a/dfssp/contract/ready.go +++ b/dfssp/contract/ready.go @@ -57,6 +57,7 @@ func ReadySign(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, ctx *contex ErrorCode: &api.ErrorCode{Code: api.ErrorCode_SUCCESS}, SignatureUuid: s.data, KeyHash: s.chain, + Sequence: s.sequence, } } // data == "" means the contractUUID is bad return &api.LaunchSignature{ErrorCode: &api.ErrorCode{Code: api.ErrorCode_INVARG}} -- GitLab