Commit 6ae6a780 authored by Richer Maximilien's avatar Richer Maximilien Committed by Loïck Bonniot

[c] Add goroutine to signature round

parent 3139fa6c
...@@ -15,8 +15,11 @@ import ( ...@@ -15,8 +15,11 @@ import (
) )
// SendAllSigns creates and sends signatures to all the signers of the contract // SendAllSigns creates and sends signatures to all the signers of the contract
// TODO Use goroutines to send in parallel
func (m *SignatureManager) SendAllSigns() error { func (m *SignatureManager) SendAllSigns() error {
allRecieved := make(chan error)
go m.RecieveAllSigns(allRecieved)
myID, err := m.FindID() myID, err := m.FindID()
if err != nil { if err != nil {
return err return err
...@@ -25,18 +28,40 @@ func (m *SignatureManager) SendAllSigns() error { ...@@ -25,18 +28,40 @@ func (m *SignatureManager) SendAllSigns() error {
// compute a set of all signers exept me // compute a set of all signers exept me
sendSet := common.GetAllButOne(m.sequence, myID) sendSet := common.GetAllButOne(m.sequence, myID)
errorChan := make(chan error)
for _, id := range sendSet { for _, id := range sendSet {
go func(id uint32) {
signature, err := m.CreateSignature(myID, id) signature, err := m.CreateSignature(myID, id)
if err != nil { if err != nil {
return err errorChan <- err
return
} }
dAPI.DLog("{" + fmt.Sprintf("%d", myID) + "} Send sign to " + fmt.Sprintf("%d", id))
_, err = m.SendSignature(signature, id) _, err = m.SendSignature(signature, id)
if err != nil {
errorChan <- err
return
}
errorChan <- nil
return
}(id)
}
for range sendSet {
err = <-errorChan
if err != nil { if err != nil {
return err return err
} }
} }
err = <-allRecieved
if err != nil {
return err
}
return nil return nil
} }
...@@ -81,11 +106,12 @@ func (m *SignatureManager) SendSignature(signature *cAPI.Signature, to uint32) ( ...@@ -81,11 +106,12 @@ func (m *SignatureManager) SendSignature(signature *cAPI.Signature, to uint32) (
return errCode, nil return errCode, nil
} }
// RecieveAllSigns is not done yet // RecieveAllSigns recieve all the signatures
func (m *SignatureManager) RecieveAllSigns() error { func (m *SignatureManager) RecieveAllSigns(out chan error) {
myID, err := m.FindID() myID, err := m.FindID()
if err != nil { if err != nil {
return err out <- err
return
} }
// compute a set of all signers exept me // compute a set of all signers exept me
...@@ -107,5 +133,6 @@ func (m *SignatureManager) RecieveAllSigns() error { ...@@ -107,5 +133,6 @@ func (m *SignatureManager) RecieveAllSigns() error {
} }
} }
return nil out <- nil
return
} }
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