Commit ae6f41fc authored by Caro Axel's avatar Caro Axel Committed by Loïck Bonniot

[c][t] Add resolve procedure calls

parent e520505e
Pipeline #2093 passed with stage
...@@ -74,14 +74,17 @@ func (m *SignatureManager) SendEvidence(promise *cAPI.Promise, signature *cAPI.S ...@@ -74,14 +74,17 @@ func (m *SignatureManager) SendEvidence(promise *cAPI.Promise, signature *cAPI.S
if err == nil && result != nil && result.Code == pAPI.ErrorCode_SUCCESS { if err == nil && result != nil && result.Code == pAPI.ErrorCode_SUCCESS {
m.archives.mutex.Lock() m.archives.mutex.Lock()
if promise != nil { if promise != nil {
dAPI.DLog("sent promise to " + mail) dAPI.DLog("successfully sent promise to " + mail)
} else { } else {
dAPI.DLog("sent signature to " + mail) dAPI.DLog("successfully sent signature to " + mail)
m.archives.sentSignatures = append(m.archives.sentSignatures, signature) m.archives.sentSignatures = append(m.archives.sentSignatures, signature)
} }
m.archives.mutex.Unlock() m.archives.mutex.Unlock()
} else { } else {
dAPI.DLog("unable to send evidence to " + mail) dAPI.DLog("was unable to send evidence to " + mail)
if err != nil {
return
}
err = errors.New("received wrong error code") err = errors.New("received wrong error code")
} }
......
...@@ -72,8 +72,10 @@ func (m *SignatureManager) Sign() error { ...@@ -72,8 +72,10 @@ func (m *SignatureManager) Sign() error {
} }
// Exchange messages // Exchange messages
err = m.promiseRound(pendingSet, sendSet) var stop bool
if err != nil { stop, err = m.promiseRound(pendingSet, sendSet)
if err != nil || stop {
dAPI.DLog("stopping protocol execution")
return err return err
} }
...@@ -115,7 +117,9 @@ func (m *SignatureManager) makeSignersHashToIDMap() { ...@@ -115,7 +117,9 @@ func (m *SignatureManager) makeSignersHashToIDMap() {
} }
// promiseRound describes a promise round: reception and sending // promiseRound describes a promise round: reception and sending
func (m *SignatureManager) promiseRound(pendingSet, sendSet []common.SequenceCoordinate) error { // returns true if the client has to stop the protocol, false otherwise.
// returns an error if any occured.
func (m *SignatureManager) promiseRound(pendingSet, sendSet []common.SequenceCoordinate) (bool, error) {
// Reception of the due promises // Reception of the due promises
var promises []*cAPI.Promise var promises []*cAPI.Promise
for len(pendingSet) > 0 { for len(pendingSet) > 0 {
...@@ -131,11 +135,11 @@ func (m *SignatureManager) promiseRound(pendingSet, sendSet []common.SequenceCoo ...@@ -131,11 +135,11 @@ func (m *SignatureManager) promiseRound(pendingSet, sendSet []common.SequenceCoo
} }
promises = append(promises, promise) promises = append(promises, promise)
} else { } else {
return m.resolve() return true, m.resolve()
} }
case <-time.After(net.DefaultTimeout): case <-time.After(net.DefaultTimeout):
return m.resolve() return true, m.resolve()
} }
} }
...@@ -143,24 +147,29 @@ func (m *SignatureManager) promiseRound(pendingSet, sendSet []common.SequenceCoo ...@@ -143,24 +147,29 @@ func (m *SignatureManager) promiseRound(pendingSet, sendSet []common.SequenceCoo
m.updateReceivedPromises(promises) m.updateReceivedPromises(promises)
m.lastValidIndex = m.currentIndex m.lastValidIndex = m.currentIndex
c := make(chan *cAPI.Promise, chanBufferSize) c := make(chan error, chanBufferSize)
// Sending of due promises // Sending of due promises
for _, coord := range sendSet { for _, coord := range sendSet {
go func(coord common.SequenceCoordinate, m *SignatureManager) { go func(coord common.SequenceCoordinate, m *SignatureManager) {
promise, err := m.CreatePromise(m.myID, coord.Signer, uint32(m.currentIndex)) promise, err := m.CreatePromise(m.myID, coord.Signer, uint32(m.currentIndex))
if err == nil { if err == nil {
_ = m.SendEvidence(promise, nil, coord.Signer) err = m.SendEvidence(promise, nil, coord.Signer)
} }
c <- promise c <- err
}(coord, m) }(coord, m)
} }
// Verifying we sent all the due promises // Verifying we sent all the due promises
for range sendSet { for range sendSet {
<-c v := <-c
if v != nil {
// We couldn't send a due promise
dAPI.DLog("Couldn't send promise: " + v.Error())
return true, m.resolve()
}
} }
return nil return false, nil
} }
// closeConnections tries to close all established connection with other peers and platform. // closeConnections tries to close all established connection with other peers and platform.
...@@ -222,7 +231,7 @@ func (m *SignatureManager) callForResolve() (*tAPI.TTPResponse, error) { ...@@ -222,7 +231,7 @@ func (m *SignatureManager) callForResolve() (*tAPI.TTPResponse, error) {
toSend := append(m.archives.receivedPromises, selfPromise) toSend := append(m.archives.receivedPromises, selfPromise)
request := &tAPI.AlertRequest{Promises: toSend} request := &tAPI.AlertRequest{Promises: toSend, Index: uint32(m.lastValidIndex)}
ctx, cancel := context.WithTimeout(context.Background(), net.DefaultTimeout) ctx, cancel := context.WithTimeout(context.Background(), net.DefaultTimeout)
defer cancel() defer cancel()
...@@ -241,9 +250,10 @@ func (m *SignatureManager) resolve() error { ...@@ -241,9 +250,10 @@ func (m *SignatureManager) resolve() error {
return errors.New("No connection to TTP, aborting!") return errors.New("No connection to TTP, aborting!")
} }
dAPI.DLog("contacting TTP") dAPI.DLog("contacting TTP with resolve index " + fmt.Sprint(m.lastValidIndex))
response, err := m.callForResolve() response, err := m.callForResolve()
if err != nil { if err != nil {
dAPI.DLog("Resolve call generated an error: " + err.Error())
return err return err
} }
if response.Abort { if response.Abort {
......
...@@ -3,6 +3,7 @@ package sign ...@@ -3,6 +3,7 @@ package sign
import ( import (
"dfss" "dfss"
cAPI "dfss/dfssc/api" cAPI "dfss/dfssc/api"
dAPI "dfss/dfssd/api"
pAPI "dfss/dfssp/api" pAPI "dfss/dfssp/api"
"dfss/dfsst/entities" "dfss/dfsst/entities"
"dfss/net" "dfss/net"
...@@ -31,8 +32,10 @@ func (s *clientServer) TreatPromise(ctx context.Context, in *cAPI.Promise) (*pAP ...@@ -31,8 +32,10 @@ func (s *clientServer) TreatPromise(ctx context.Context, in *cAPI.Promise) (*pAP
// we do not check that we expected that promise // we do not check that we expected that promise
valid, _, _, _ := entities.IsRequestValid(ctx, []*cAPI.Promise{in}) valid, _, _, _ := entities.IsRequestValid(ctx, []*cAPI.Promise{in})
if !valid { if !valid {
dAPI.DLog("TreatPromise route did not treat promise from " + net.GetCN(&ctx) + " because it is invalid")
return &pAPI.ErrorCode{Code: pAPI.ErrorCode_SUCCESS}, nil return &pAPI.ErrorCode{Code: pAPI.ErrorCode_SUCCESS}, nil
} }
dAPI.DLog("TreatPromise route treated promise from " + net.GetCN(&ctx) + " because it is valid")
return getServerErrorCode(s.incomingPromises, in), nil return getServerErrorCode(s.incomingPromises, in), nil
} }
......
...@@ -25,14 +25,19 @@ func NewArchivesManager(db *mgdb.MongoManager) *ArchivesManager { ...@@ -25,14 +25,19 @@ func NewArchivesManager(db *mgdb.MongoManager) *ArchivesManager {
// InitializeArchives : if an entry in the database for this signature exists, retrieves it, otherwise creates it. // InitializeArchives : if an entry in the database for this signature exists, retrieves it, otherwise creates it.
// //
// This function should only be called after function IsRequestValid. // This function should only be called after function IsRequestValid.
func (manager *ArchivesManager) InitializeArchives(promise *cAPI.Promise, signatureUUID bson.ObjectId, signers *[]Signer) { func (manager *ArchivesManager) InitializeArchives(promise *cAPI.Promise, signatureUUID bson.ObjectId, signers *[]Signer) error {
present, archives := manager.ContainsSignature(signatureUUID) present, archives := manager.ContainsSignature(signatureUUID)
if !present { if !present {
archives = NewSignatureArchives(signatureUUID, promise.Context.Sequence, *signers, promise.Context.ContractDocumentHash, promise.Context.Seal) archives = NewSignatureArchives(signatureUUID, promise.Context.Sequence, *signers, promise.Context.ContractDocumentHash, promise.Context.Seal)
ok, err := manager.DB.Get("signatures").Insert(*archives)
if !ok {
return err
}
} }
manager.Archives = archives manager.Archives = archives
return nil
} }
// ContainsSignature : checks if the specified signatureUUID matches a SignatureArchives in the database. // ContainsSignature : checks if the specified signatureUUID matches a SignatureArchives in the database.
...@@ -70,10 +75,10 @@ func (manager *ArchivesManager) WasContractSigned() (bool, []byte) { ...@@ -70,10 +75,10 @@ func (manager *ArchivesManager) WasContractSigned() (bool, []byte) {
return false, []byte{} return false, []byte{}
} }
// HasSignerPromised : determines if the specified signer has promised to sign to at least one other signer. // HasSignerPromised : determines if the specified signer has promised to sign at least one time.
func (manager *ArchivesManager) HasSignerPromised(signer uint32) bool { func (manager *ArchivesManager) HasSignerPromised(signer uint32) bool {
for _, p := range manager.Archives.ReceivedPromises { for _, p := range manager.Archives.ReceivedPromises {
if (p.SenderKeyIndex == signer) && (p.RecipientKeyIndex != signer) { if p.SenderKeyIndex == signer {
return true return true
} }
} }
......
...@@ -88,27 +88,17 @@ func TestInitializeArchives(t *testing.T) { ...@@ -88,27 +88,17 @@ func TestInitializeArchives(t *testing.T) {
Seal: seal, Seal: seal,
}, },
} }
archives := NewSignatureArchives(signatureUUIDBson, sequence, signersEntities, contractDocumentHash, seal)
manager := &ArchivesManager{ manager := &ArchivesManager{
DB: dbManager, DB: dbManager,
Archives: archives,
} }
arch := NewSignatureArchives(signatureUUIDBson, sequence, signersEntities, contractDocumentHash, seal) arch := NewSignatureArchives(signatureUUIDBson, sequence, signersEntities, contractDocumentHash, seal)
manager.InitializeArchives(promise, signatureUUIDBson, &signersEntities) err = manager.InitializeArchives(promise, signatureUUIDBson, &signersEntities)
assert.Nil(t, err)
arch.Signers = manager.Archives.Signers arch.Signers = manager.Archives.Signers
assert.Equal(t, manager.Archives, arch) assert.Equal(t, manager.Archives, arch)
ok, err := collection.Insert(manager.Archives) ok, err := collection.DeleteByID(*manager.Archives)
assert.Equal(t, ok, true)
assert.Equal(t, err, nil)
manager.Archives = &SignatureArchives{}
manager.InitializeArchives(promise, signatureUUIDBson, &signersEntities)
assert.Equal(t, err, nil)
assert.Equal(t, manager.Archives, arch)
ok, err = collection.DeleteByID(*manager.Archives)
assert.Equal(t, err, nil) assert.Equal(t, err, nil)
assert.Equal(t, ok, true) assert.Equal(t, ok, true)
} }
...@@ -209,7 +199,7 @@ func TestHasSignerPromised(t *testing.T) { ...@@ -209,7 +199,7 @@ func TestHasSignerPromised(t *testing.T) {
assert.Equal(t, len(archives.ReceivedPromises), 2) assert.Equal(t, len(archives.ReceivedPromises), 2)
ok = manager.HasSignerPromised(1) ok = manager.HasSignerPromised(1)
assert.Equal(t, ok, false) assert.Equal(t, ok, true)
promise2 := &Promise{ promise2 := &Promise{
RecipientKeyIndex: 0, RecipientKeyIndex: 0,
......
...@@ -3,9 +3,11 @@ package resolve ...@@ -3,9 +3,11 @@ package resolve
import ( import (
"errors" "errors"
"fmt"
cAPI "dfss/dfssc/api" cAPI "dfss/dfssc/api"
"dfss/dfssc/common" "dfss/dfssc/common"
dAPI "dfss/dfssd/api"
"dfss/dfsst/entities" "dfss/dfsst/entities"
) )
...@@ -15,19 +17,23 @@ import ( ...@@ -15,19 +17,23 @@ import (
func ArePromisesComplete(promiseEntities []*entities.Promise, promise *cAPI.Promise, step uint32) bool { func ArePromisesComplete(promiseEntities []*entities.Promise, promise *cAPI.Promise, step uint32) bool {
expected, err := generateExpectedPromises(promise, step) expected, err := generateExpectedPromises(promise, step)
if err != nil { if err != nil {
dAPI.DLog("error occured during the generation of expected promises")
return false return false
} }
if len(promiseEntities) != len(expected) { if len(promiseEntities) != len(expected) {
dAPI.DLog("promise sets are not equal, nb received: " + fmt.Sprint(len(promiseEntities)) + " ; expected: " + fmt.Sprint(len(expected)))
return false return false
} }
for _, p := range expected { for i, p := range expected {
if !containsPromise(promiseEntities, p) { if !containsPromise(promiseEntities, p) {
dAPI.DLog("promise sets are not equal, promise at index: " + fmt.Sprint(i))
return false return false
} }
} }
dAPI.DLog("promise sets are equal")
return true return true
} }
...@@ -39,42 +45,59 @@ func generateExpectedPromises(promise *cAPI.Promise, step uint32) ([]*entities.P ...@@ -39,42 +45,59 @@ func generateExpectedPromises(promise *cAPI.Promise, step uint32) ([]*entities.P
recipientH := promise.Context.RecipientKeyHash recipientH := promise.Context.RecipientKeyHash
recipientID, err := entities.GetIndexOfSigner(promise, recipientH) recipientID, err := entities.GetIndexOfSigner(promise, recipientH)
if err != nil { if err != nil {
dAPI.DLog(err.Error())
return nil, err return nil, err
} }
if seq[int(step)] != recipientID { // if step is 0, then it means that the resolve call occured during the first round.
// therefore, there is no way we can generate the signed contract.
// so we don't check the 0 case, because it has no consequence on the folloing of the resolve algorithm: an abort token will be sent
// checking the 0 case would cause an error in the consistency between of the resolve index and the promise recipient sequence index.
if (step != 0) && (seq[int(step)] != recipientID) {
dAPI.DLog("sequence index at step " + fmt.Sprint(int(step)) + " is " + fmt.Sprint(seq[int(step)]) + ", recipientID is " + fmt.Sprint(recipientID))
return nil, errors.New("Signer at step is not recipient") return nil, errors.New("Signer at step is not recipient")
} }
currentIndex, err := common.FindNextIndex(seq, recipientID, -1) currentIndex, err := common.FindNextIndex(seq, recipientID, -1)
if err != nil { if err != nil {
dAPI.DLog(err.Error())
return nil, err return nil, err
} }
dAPI.DLog("resolve index is: " + fmt.Sprint(step))
dAPI.DLog("first index is: " + fmt.Sprint(currentIndex))
for currentIndex <= int(step) { for currentIndex <= int(step) {
dAPI.DLog("started generation round with currentIndex " + fmt.Sprint(currentIndex))
roundPromises, err := generationRound(seq, recipientID, currentIndex) roundPromises, err := generationRound(seq, recipientID, currentIndex)
if err != nil { if err != nil {
dAPI.DLog("error occured during the generation round, currentIndex: " + fmt.Sprint(currentIndex))
return nil, err return nil, err
} }
dAPI.DLog(fmt.Sprint(len(roundPromises)) + " promises were generated for this round")
for _, p := range roundPromises { for _, p := range roundPromises {
res = addPromiseToExpected(res, p) res = addPromiseToExpected(res, p)
} }
currentIndex, _ = common.FindNextIndex(seq, recipientID, currentIndex) dAPI.DLog("total number of expected promises this far: " + fmt.Sprint(len(res)))
currentIndex, err = common.FindNextIndex(seq, recipientID, currentIndex)
if err != nil {
dAPI.DLog(err.Error())
}
// if it was the last occurence, then we finish // if it was the last occurence, then we finish
if currentIndex == -1 { if currentIndex == -1 {
break break
} }
} }
dAPI.DLog("promise from rounds have been generated")
selfPromise := &entities.Promise{ selfPromise := &entities.Promise{
RecipientKeyIndex: recipientID, RecipientKeyIndex: recipientID,
SenderKeyIndex: recipientID, SenderKeyIndex: recipientID,
SequenceIndex: step, SequenceIndex: step,
} }
dAPI.DLog("adding self promise")
return append(res, selfPromise), nil return append(res, selfPromise), nil
} }
......
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"os" "os"
"sync"
cAPI "dfss/dfssc/api" cAPI "dfss/dfssc/api"
"dfss/dfssc/security" "dfss/dfssc/security"
...@@ -22,18 +23,25 @@ import ( ...@@ -22,18 +23,25 @@ import (
// InternalError : constant string used to return a generic error message through gRPC in case of an internal error. // InternalError : constant string used to return a generic error message through gRPC in case of an internal error.
const InternalError string = "Internal server error" const InternalError string = "Internal server error"
var mutex sync.Mutex
type ttpServer struct { type ttpServer struct {
DB *mgdb.MongoManager DB *mgdb.MongoManager
} }
// Alert route for the TTP. // Alert route for the TTP.
func (server *ttpServer) Alert(ctx context.Context, in *tAPI.AlertRequest) (*tAPI.TTPResponse, error) { func (server *ttpServer) Alert(ctx context.Context, in *tAPI.AlertRequest) (*tAPI.TTPResponse, error) {
mutex.Lock()
defer mutex.Unlock()
valid, signatureUUID, signers, senderIndex := entities.IsRequestValid(ctx, in.Promises) valid, signatureUUID, signers, senderIndex := entities.IsRequestValid(ctx, in.Promises)
if !valid { if !valid {
dAPI.DLog("invalid request from " + net.GetCN(&ctx)) dAPI.DLog("invalid request from " + net.GetCN(&ctx))
return nil, errors.New(InternalError) return nil, errors.New(InternalError)
} }
valid = int(in.Index) >= len(in.Promises[0].Context.Sequence)
dAPI.DLog("resolve index is: " + fmt.Sprint(in.Index))
valid = int(in.Index) < len(in.Promises[0].Context.Sequence)
if !valid { if !valid {
dAPI.DLog("invalid sequence index from " + net.GetCN(&ctx)) dAPI.DLog("invalid sequence index from " + net.GetCN(&ctx))
return nil, errors.New(InternalError) return nil, errors.New(InternalError)
...@@ -42,8 +50,14 @@ func (server *ttpServer) Alert(ctx context.Context, in *tAPI.AlertRequest) (*tAP ...@@ -42,8 +50,14 @@ func (server *ttpServer) Alert(ctx context.Context, in *tAPI.AlertRequest) (*tAP
// with the same signatureUUID (thus signed information) for all promises, and sent by a valid signer // with the same signatureUUID (thus signed information) for all promises, and sent by a valid signer
// wrt to the signed signers' hashes // wrt to the signed signers' hashes
dAPI.DLog("Resolve request from " + net.GetCN(&ctx) + " is valid")
manager := entities.NewArchivesManager(server.DB) manager := entities.NewArchivesManager(server.DB)
manager.InitializeArchives(in.Promises[0], signatureUUID, &signers) err := manager.InitializeArchives(in.Promises[0], signatureUUID, &signers)
if err != nil {
dAPI.DLog("error occured during the initialization of the signature archives")
return nil, err
}
// Now archives contains the new or already present SignatureArchives // Now archives contains the new or already present SignatureArchives
// We check if we have already sent an abort token to the sender of the request // We check if we have already sent an abort token to the sender of the request
...@@ -56,6 +70,7 @@ func (server *ttpServer) Alert(ctx context.Context, in *tAPI.AlertRequest) (*tAP ...@@ -56,6 +70,7 @@ func (server *ttpServer) Alert(ctx context.Context, in *tAPI.AlertRequest) (*tAP
// We check that the sender of the request sent valid and complete information // We check that the sender of the request sent valid and complete information
stop, message, tmpPromises, err := server.handleInvalidPromises(manager, in.Promises, senderIndex, in.Index) stop, message, tmpPromises, err := server.handleInvalidPromises(manager, in.Promises, senderIndex, in.Index)
if stop { if stop {
dAPI.DLog("invalid promise caused stop")
return message, err return message, err
} }
// Now we are sure that the sender of the AlertRequest is not dishonest // Now we are sure that the sender of the AlertRequest is not dishonest
...@@ -63,6 +78,7 @@ func (server *ttpServer) Alert(ctx context.Context, in *tAPI.AlertRequest) (*tAP ...@@ -63,6 +78,7 @@ func (server *ttpServer) Alert(ctx context.Context, in *tAPI.AlertRequest) (*tAP
// We try to use the already generated contract if it exists // We try to use the already generated contract if it exists
generated, contract := manager.WasContractSigned() generated, contract := manager.WasContractSigned()
if generated { if generated {
dAPI.DLog("sending the signed contract")
return &tAPI.TTPResponse{ return &tAPI.TTPResponse{
Abort: false, Abort: false,
Contract: contract, Contract: contract,
...@@ -75,8 +91,9 @@ func (server *ttpServer) Alert(ctx context.Context, in *tAPI.AlertRequest) (*tAP ...@@ -75,8 +91,9 @@ func (server *ttpServer) Alert(ctx context.Context, in *tAPI.AlertRequest) (*tAP
// Try to generate the contract now // Try to generate the contract now
message, err = server.handleContractGenerationTry(manager) message, err = server.handleContractGenerationTry(manager)
// We manually update the database // We manually update the database
ok, _ := server.DB.Get("signatures").UpdateByID(manager.Archives) ok, err := server.DB.Get("signatures").UpdateByID(*(manager.Archives))
if !ok { if !ok {
dAPI.DLog("error during 'UpdateByID' l.81" + fmt.Sprint(err.Error()))
return nil, errors.New(InternalError) return nil, errors.New(InternalError)
} }
...@@ -90,10 +107,12 @@ func (server *ttpServer) Alert(ctx context.Context, in *tAPI.AlertRequest) (*tAP ...@@ -90,10 +107,12 @@ func (server *ttpServer) Alert(ctx context.Context, in *tAPI.AlertRequest) (*tAP
// If an error occurs during this process, it is returned. // If an error occurs during this process, it is returned.
func (server *ttpServer) handleAbortedSender(manager *entities.ArchivesManager, senderIndex uint32) (bool, *tAPI.TTPResponse, error) { func (server *ttpServer) handleAbortedSender(manager *entities.ArchivesManager, senderIndex uint32) (bool, *tAPI.TTPResponse, error) {
if manager.HasReceivedAbortToken(senderIndex) { if manager.HasReceivedAbortToken(senderIndex) {
dAPI.DLog("Sender has already contacted the ttp. He is dishonnest.")
manager.AddToDishonest(senderIndex) manager.AddToDishonest(senderIndex)
ok, _ := manager.DB.Get("signatures").UpdateByID(manager.Archives) ok, err := manager.DB.Get("signatures").UpdateByID(*(manager.Archives))
if !ok { if !ok {
dAPI.DLog("error during 'UpdateByID' l.99" + fmt.Sprint(err.Error()))
return true, nil, errors.New(InternalError) return true, nil, errors.New(InternalError)
} }
...@@ -102,7 +121,7 @@ func (server *ttpServer) handleAbortedSender(manager *entities.ArchivesManager, ...@@ -102,7 +121,7 @@ func (server *ttpServer) handleAbortedSender(manager *entities.ArchivesManager,
Contract: nil, Contract: nil,
}, nil }, nil
} }
dAPI.DLog("sender has never contacted the ttp before")
return false, nil, nil return false, nil, nil
} }
...@@ -119,16 +138,30 @@ func (server *ttpServer) handleAbortedSender(manager *entities.ArchivesManager, ...@@ -119,16 +138,30 @@ func (server *ttpServer) handleAbortedSender(manager *entities.ArchivesManager,
// If an error occurs during this process, it is returned. // If an error occurs during this process, it is returned.
func (server *ttpServer) handleInvalidPromises(manager *entities.ArchivesManager, promises []*cAPI.Promise, senderIndex, stepIndex uint32) (bool, *tAPI.TTPResponse, []*entities.Promise, error) { func (server *ttpServer) handleInvalidPromises(manager *entities.ArchivesManager, promises []*cAPI.Promise, senderIndex, stepIndex uint32) (bool, *tAPI.TTPResponse, []*entities.Promise, error) {
valid, tmpPromises := entities.ArePromisesValid(promises) valid, tmpPromises := entities.ArePromisesValid(promises)
if valid {
dAPI.DLog("received promises are valid")
}
complete := resolve.ArePromisesComplete(tmpPromises, promises[0], stepIndex) complete := resolve.ArePromisesComplete(tmpPromises, promises[0], stepIndex)
if complete {
dAPI.DLog("received promises are complete")
}
if !valid || !complete { if !valid || !complete {
if !valid {
dAPI.DLog("received promises are not valid")
}
if !complete {
dAPI.DLog("received promises are not complete")
}
manager.AddToAbort(senderIndex) manager.AddToAbort(senderIndex)
manager.AddToDishonest(senderIndex) manager.AddToDishonest(senderIndex)
ok, _ := manager.DB.Get("signatures").UpdateByID(manager.Archives) ok, err := manager.DB.Get("signatures").UpdateByID(*(manager.Archives))
if !ok { if !ok {
dAPI.DLog("error during 'UpdateByID' l.132" + fmt.Sprint(err.Error()))
return true, nil, nil, errors.New(InternalError) return true, nil, nil, errors.New(InternalError)
} }
dAPI.DLog("sending an abort token")
return true, &tAPI.TTPResponse{ return true, &tAPI.TTPResponse{
Abort: true, Abort: true,
Contract: nil, Contract: nil,
...@@ -164,6 +197,7 @@ func (server *ttpServer) updateArchiveWithEvidence(manager *entities.ArchivesMan ...@@ -164,6 +197,7 @@ func (server *ttpServer) updateArchiveWithEvidence(manager *entities.ArchivesMan
func (server *ttpServer) handleContractGenerationTry(manager *entities.ArchivesManager) (*tAPI.TTPResponse, error) { func (server *ttpServer) handleContractGenerationTry(manager *entities.ArchivesManager) (*tAPI.TTPResponse, error) {
generated, contract := resolve.Solve(manager) generated, contract := resolve.Solve(manager)
if !generated { if !generated {
dAPI.DLog("contract couldn't be generated. Sending an abort token.")
return &tAPI.TTPResponse{ return &tAPI.TTPResponse{
Abort: true, Abort: true,
Contract: nil, Contract: nil,
...@@ -172,7 +206,7 @@ func (server *ttpServer) handleContractGenerationTry(manager *entities.ArchivesM ...@@ -172,7 +206,7 @@ func (server *ttpServer) handleContractGenerationTry(manager *entities.ArchivesM
// We add the generated contract to the signatureArchives // We add the generated contract to the signatureArchives
manager.Archives.SignedContract = contract manager.Archives.SignedContract = contract
dAPI.DLog("contract was generated. Sending the signed contract.")
return &tAPI.TTPResponse{ return &tAPI.TTPResponse{
Abort: false, Abort: false,
Contract: contract, Contract: contract,
......
...@@ -82,7 +82,6 @@ func TestRegisterAuth(t *testing.T) { ...@@ -82,7 +82,6 @@ func TestRegisterAuth(t *testing.T) {
} }
func registerAndAuth(client *exec.Cmd, mail, password, keySize string, authMail, authToken bool) error { func registerAndAuth(client *exec.Cmd, mail, password, keySize string, authMail, authToken bool) error {
setLastArg(client, "register", false) setLastArg(client, "register", false)
client.Stdin = strings.NewReader( client.Stdin = strings.NewReader(
mail + "\n" + mail + "\n" +
......
package tests package tests
import ( import (
"bufio"
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
...@@ -140,16 +141,28 @@ func checkProofFile(t *testing.T, nb int) { ...@@ -140,16 +141,28 @@ func checkProofFile(t *testing.T, nb int) {
assert.Equal(t, nb, matches, "Invalid number of proof file(s)") assert.Equal(t, nb, matches, "Invalid number of proof file(s)")
} }
// TestSignContractFailure tests the signature with a faulty client. // TestSignContractFailure tests the signature with a faulty client, when contract can't be generated.
// In this test, everything should not work fine, because client1 shutdowns way too early. // In this test, everything should not work fine, because client3 shutdowns way too early.
func TestSignContractFailure(t *testing.T) { func TestSignContractFailure(t *testing.T) {
signatureHelper(t, "1", 0)
}
// TestSignContractSuccess tests the signature with a faulty client, when contract can be generated.
// In this test, everything should not work fine, because client3 shutdowns way too early.
func TestSignContractSuccess(t *testing.T) {
signatureHelper(t, "2", 2)
}
// signatureHelper : launches a parametrized signature, with the number of rounds a client will accomplish before shutting down,
// and the number of proof files expected to be generated.
func signatureHelper(t *testing.T, round string, nbFiles int) {
// Setup // Setup
stop, clients, contractPath, contractFilePath := setupSignature(t) stop, clients, contractPath, contractFilePath := setupSignature(t)
defer stop() defer stop()
// Configure client3 to be faulty // Configure client3 to be faulty
setLastArg(clients[2], "--stopbefore", true)