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