From ec63e485b7f07b202ec98a1528d78135a2c5c5a1 Mon Sep 17 00:00:00 2001 From: Joao Sa Sousa Date: Tue, 10 Mar 2020 11:23:59 +0100 Subject: [PATCH 01/22] Added select timeouts for unlynx protocols --- go.mod | 2 ++ protocols/collective_aggregation_protocol.go | 18 +++++++++++---- protocols/deterministic_tagging_protocol.go | 23 +++++++++++++++++-- protocols/key_switching_protocol.go | 14 +++++++++++- protocols/shuffling+ddt_protocol.go | 24 ++++++++++++++++++-- protocols/shuffling_protocol.go | 23 +++++++++++++++++-- 6 files changed, 93 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index eae1b42..71025b3 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,7 @@ module github.com/ldsec/unlynx +go 1.14 + require ( github.com/BurntSushi/toml v0.3.1 github.com/Knetic/govaluate v3.0.0+incompatible diff --git a/protocols/collective_aggregation_protocol.go b/protocols/collective_aggregation_protocol.go index 5c4077d..f529f34 100644 --- a/protocols/collective_aggregation_protocol.go +++ b/protocols/collective_aggregation_protocol.go @@ -10,6 +10,7 @@ package protocolsunlynx import ( "errors" "sync" + "time" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/lib/aggregation" @@ -106,6 +107,8 @@ type CollectiveAggregationProtocol struct { Proofs bool ProofFunc proofCollectiveAggregationFunction // proof function for when we want to do something different with the proofs (e.g. insert in the blockchain) MapPIs map[string]onet.ProtocolInstance // protocol instances to be able to call protocols inside protocols (e.g. proof_collection_protocol) + + Timeout time.Duration } // NewCollectiveAggregationProtocol initializes the protocol instance. @@ -129,6 +132,9 @@ func NewCollectiveAggregationProtocol(n *onet.TreeNodeInstance) (onet.ProtocolIn return nil, errors.New("couldn't register data reference channel: " + err.Error()) } + // default timeout + pap.Timeout = 10 * time.Minute + return pap, nil } @@ -195,11 +201,15 @@ func (p *CollectiveAggregationProtocol) Dispatch() error { // Announce forwarding down the tree. func (p *CollectiveAggregationProtocol) aggregationAnnouncementPhase() error { - dataReferenceMessage := <-p.DataReferenceChannel - if !p.IsLeaf() { - if err := p.SendToChildren(&dataReferenceMessage.DataReferenceMessage); err != nil { - return errors.New("Error sending :" + err.Error()) + select { + case dataReferenceMessage := <-p.DataReferenceChannel : + if !p.IsLeaf() { + if err := p.SendToChildren(&dataReferenceMessage.DataReferenceMessage); err != nil { + return errors.New("Error sending :" + err.Error()) + } } + case <-time.After(p.Timeout): + return errors.New(p.ServerIdentity().String() + "didn't get the on time.") } return nil } diff --git a/protocols/deterministic_tagging_protocol.go b/protocols/deterministic_tagging_protocol.go index f6f8dcd..4427b56 100644 --- a/protocols/deterministic_tagging_protocol.go +++ b/protocols/deterministic_tagging_protocol.go @@ -91,6 +91,8 @@ type DeterministicTaggingProtocol struct { Proofs bool ExecTime time.Duration + + Timeout time.Duration } // NewDeterministicTaggingProtocol constructs tagging switching protocol instances. @@ -117,6 +119,9 @@ func NewDeterministicTaggingProtocol(n *onet.TreeNodeInstance) (onet.ProtocolIns } } + // default timeout + dsp.Timeout = 10 * time.Minute + return dsp, nil } @@ -156,7 +161,14 @@ func (p *DeterministicTaggingProtocol) Dispatch() error { defer p.Done() //************ ----- first round, add value derivated from ephemeral secret to message ---- ******************** - deterministicTaggingTargetBytesBef := <-p.PreviousNodeInPathChannel + var deterministicTaggingTargetBytesBef deterministicTaggingBytesStruct + select { + case deterministicTaggingTargetBytesBef = <-p.PreviousNodeInPathChannel: + break + case <-time.After(p.Timeout): + return errors.New(p.ServerIdentity().String() + "didn't get the (first round) on time.") + } + deterministicTaggingTargetBef := DeterministicTaggingMessage{Data: make([]libunlynx.CipherText, 0)} err := deterministicTaggingTargetBef.FromBytes(deterministicTaggingTargetBytesBef.Data) if err != nil { @@ -203,7 +215,14 @@ func (p *DeterministicTaggingProtocol) Dispatch() error { } //************ ----- second round, deterministic tag creation ---- ******************** - deterministicTaggingTargetBytes := <-p.PreviousNodeInPathChannel + var deterministicTaggingTargetBytes deterministicTaggingBytesStruct + select { + case deterministicTaggingTargetBytes = <-p.PreviousNodeInPathChannel: + break + case <-time.After(p.Timeout): + return errors.New(p.ServerIdentity().String() + "didn't get the (second round) on time.") + } + deterministicTaggingTarget := DeterministicTaggingMessage{Data: make([]libunlynx.CipherText, 0)} err = deterministicTaggingTarget.FromBytes(deterministicTaggingTargetBytes.Data) if err != nil { diff --git a/protocols/key_switching_protocol.go b/protocols/key_switching_protocol.go index 5f9971a..be2d898 100644 --- a/protocols/key_switching_protocol.go +++ b/protocols/key_switching_protocol.go @@ -114,6 +114,8 @@ type KeySwitchingProtocol struct { // Test (only use in order to test the protocol) ExecTime time.Duration + + Timeout time.Duration } // NewKeySwitchingProtocol initializes the protocol instance. @@ -137,6 +139,9 @@ func NewKeySwitchingProtocol(n *onet.TreeNodeInstance) (onet.ProtocolInstance, e return nil, errors.New("couldn't register length channel: " + err.Error()) } + // default timeout + pap.Timeout = 10 * time.Minute + return pap, nil } @@ -230,7 +235,14 @@ func (p *KeySwitchingProtocol) Dispatch() error { // Announce forwarding down the tree. func (p *KeySwitchingProtocol) announcementKSPhase() (kyber.Point, []kyber.Point, error) { - dataReferenceMessage := <-p.DownChannel + var dataReferenceMessage DownBytesStruct + select { + case dataReferenceMessage = <-p.DownChannel: + break + case <-time.After(p.Timeout): + return nil, nil, errors.New(p.ServerIdentity().String() + "didn't get the on time.") + } + if !p.IsLeaf() { if err := p.SendToChildren(&dataReferenceMessage.DownMessageBytes); err != nil { return nil, nil, errors.New("Node " + p.ServerIdentity().String() + " failed to broadcast DownMessageBytes: " + err.Error()) diff --git a/protocols/shuffling+ddt_protocol.go b/protocols/shuffling+ddt_protocol.go index 989f908..730fe0a 100644 --- a/protocols/shuffling+ddt_protocol.go +++ b/protocols/shuffling+ddt_protocol.go @@ -3,6 +3,7 @@ package protocolsunlynx import ( "errors" "sync" + "time" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/lib/deterministic_tag" @@ -81,6 +82,8 @@ type ShufflingPlusDDTProtocol struct { // Proofs Proofs bool + + Timeout time.Duration } // NewShufflingPlusDDTProtocol constructs neff shuffle + ddt protocol instance. @@ -106,6 +109,10 @@ func NewShufflingPlusDDTProtocol(n *onet.TreeNodeInstance) (onet.ProtocolInstanc break } } + + // default timeout + pi.Timeout = 10 * time.Minute + return pi, nil } @@ -152,8 +159,21 @@ func (p *ShufflingPlusDDTProtocol) Start() error { func (p *ShufflingPlusDDTProtocol) Dispatch() error { defer p.Done() - shufflingPlusDDTBytesMessageLength := <-p.LengthNodeChannel - tmp := <-p.PreviousNodeInPathChannel + var shufflingPlusDDTBytesMessageLength shufflingPlusDDTBytesLengthStruct + select { + case shufflingPlusDDTBytesMessageLength = <-p.LengthNodeChannel: + break + case <-time.After(p.Timeout): + return errors.New(p.ServerIdentity().String() + "didn't get the on time.") + } + + var tmp shufflingPlusDDTBytesStruct + select { + case tmp = <-p.PreviousNodeInPathChannel: + break + case <-time.After(p.Timeout): + return errors.New(p.ServerIdentity().String() + "didn't get the on time.") + } readData := libunlynx.StartTimer(p.Name() + "_ShufflingPlusDDT(ReadData)") sm := ShufflingPlusDDTMessage{} diff --git a/protocols/shuffling_protocol.go b/protocols/shuffling_protocol.go index 8d82fff..4cc45a2 100644 --- a/protocols/shuffling_protocol.go +++ b/protocols/shuffling_protocol.go @@ -91,6 +91,8 @@ type ShufflingProtocol struct { CollectiveKey kyber.Point ExecTimeStart time.Duration ExecTime time.Duration + + Timeout time.Duration } // NewShufflingProtocol constructs neff shuffle protocol instances. @@ -116,6 +118,10 @@ func NewShufflingProtocol(n *onet.TreeNodeInstance) (onet.ProtocolInstance, erro break } } + + // default timeout + dsp.Timeout = 10 * time.Minute + return dsp, nil } @@ -186,9 +192,22 @@ func (p *ShufflingProtocol) Start() error { func (p *ShufflingProtocol) Dispatch() error { defer p.Done() - shufflingBytesMessageLength := <-p.LengthNodeChannel + var shufflingBytesMessageLength shufflingBytesLengthStruct + select { + case shufflingBytesMessageLength = <-p.LengthNodeChannel: + break + case <-time.After(p.Timeout): + return errors.New(p.ServerIdentity().String() + "didn't get the on time.") + } + + var tmp shufflingBytesStruct + select { + case tmp = <-p.PreviousNodeInPathChannel: + break + case <-time.After(p.Timeout): + return errors.New(p.ServerIdentity().String() + "didn't get the on time.") + } - tmp := <-p.PreviousNodeInPathChannel sm := ShufflingMessage{} if err := sm.FromBytes(tmp.Data, shufflingBytesMessageLength.CVLengths); err != nil { return err From b0d3547675edb0150700eccbe6874b0d01ad0047 Mon Sep 17 00:00:00 2001 From: Joao Sa Sousa Date: Tue, 10 Mar 2020 13:15:50 +0100 Subject: [PATCH 02/22] Added select timeouts for unlynx protocols/utils --- protocols/utils/addrm_server_protocol.go | 17 +++++++++++++++-- protocols/utils/local_aggregation_protocol.go | 18 ++++++++++++++++-- .../utils/local_clear_aggregation_protocol.go | 18 ++++++++++++++++-- .../utils/proofs_verification_protocol.go | 18 ++++++++++++++++-- 4 files changed, 63 insertions(+), 8 deletions(-) diff --git a/protocols/utils/addrm_server_protocol.go b/protocols/utils/addrm_server_protocol.go index 9cdd695..6da6222 100644 --- a/protocols/utils/addrm_server_protocol.go +++ b/protocols/utils/addrm_server_protocol.go @@ -6,6 +6,7 @@ package protocolsunlynxutils import ( "errors" "sync" + "time" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/lib/add_rm" @@ -38,6 +39,8 @@ type AddRmServerProtocol struct { KeyToRm kyber.Scalar Proofs bool Add bool + + Timeout time.Duration } // NewAddRmProtocol is constructor of add/rm protocol instances. @@ -47,6 +50,9 @@ func NewAddRmProtocol(n *onet.TreeNodeInstance) (onet.ProtocolInstance, error) { FeedbackChannel: make(chan []libunlynx.CipherText), } + // default timeout + pvp.Timeout = 10 * time.Minute + return pvp, nil } @@ -92,8 +98,15 @@ func (p *AddRmServerProtocol) Start() error { func (p *AddRmServerProtocol) Dispatch() error { defer p.Done() - aux := <-finalResultAddrm - p.FeedbackChannel <- aux + var finalResultMessage []libunlynx.CipherText + select { + case finalResultMessage = <-finalResultAddrm: + break + case <-time.After(p.Timeout): + return errors.New(p.ServerIdentity().String() + "didn't get the on time.") + } + + p.FeedbackChannel <- finalResultMessage return nil } diff --git a/protocols/utils/local_aggregation_protocol.go b/protocols/utils/local_aggregation_protocol.go index 226af6a..1b83c93 100644 --- a/protocols/utils/local_aggregation_protocol.go +++ b/protocols/utils/local_aggregation_protocol.go @@ -3,10 +3,12 @@ package protocolsunlynxutils import ( + "errors" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/lib/aggregation" "go.dedis.ch/onet/v3" "go.dedis.ch/onet/v3/log" + "time" ) // LocalAggregationProtocolName is the registered name for the local aggregation protocol. @@ -33,6 +35,8 @@ type LocalAggregationProtocol struct { // Protocol state data TargetOfAggregation []libunlynx.FilteredResponseDet Proofs bool + + Timeout time.Duration } // NewLocalAggregationProtocol is constructor of Local Aggregation protocol instances. @@ -42,6 +46,9 @@ func NewLocalAggregationProtocol(n *onet.TreeNodeInstance) (onet.ProtocolInstanc FeedbackChannel: make(chan map[libunlynx.GroupingKey]libunlynx.FilteredResponse), } + // default timeout + pvp.Timeout = 10 * time.Minute + return pvp, nil } @@ -83,7 +90,14 @@ func (p *LocalAggregationProtocol) Start() error { func (p *LocalAggregationProtocol) Dispatch() error { defer p.Done() - aux := <-finalResultAggr - p.FeedbackChannel <- aux + var finalResultMessage map[libunlynx.GroupingKey]libunlynx.FilteredResponse + select { + case finalResultMessage = <-finalResultAggr: + break + case <-time.After(p.Timeout): + return errors.New(p.ServerIdentity().String() + "didn't get the on time.") + } + + p.FeedbackChannel <- finalResultMessage return nil } diff --git a/protocols/utils/local_clear_aggregation_protocol.go b/protocols/utils/local_clear_aggregation_protocol.go index 5924f0c..d1fd05b 100644 --- a/protocols/utils/local_clear_aggregation_protocol.go +++ b/protocols/utils/local_clear_aggregation_protocol.go @@ -3,10 +3,12 @@ package protocolsunlynxutils import ( + "errors" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/lib/store" "go.dedis.ch/onet/v3" "go.dedis.ch/onet/v3/log" + "time" ) // LocalClearAggregationProtocolName is the registered name for the local cleartext aggregation protocol. @@ -29,6 +31,8 @@ type LocalClearAggregationProtocol struct { // Protocol state data TargetOfAggregation []libunlynx.DpClearResponse + + Timeout time.Duration } // NewLocalClearAggregationProtocol is constructor of Proofs Verification protocol instances. @@ -38,6 +42,9 @@ func NewLocalClearAggregationProtocol(n *onet.TreeNodeInstance) (onet.ProtocolIn FeedbackChannel: make(chan []libunlynx.DpClearResponse), } + // default timeout + pvp.Timeout = 10 * time.Minute + return pvp, nil } @@ -57,7 +64,14 @@ func (p *LocalClearAggregationProtocol) Start() error { func (p *LocalClearAggregationProtocol) Dispatch() error { defer p.Done() - aux := <-finalResultClearAggr - p.FeedbackChannel <- aux + var finalResultMessage []libunlynx.DpClearResponse + select { + case finalResultMessage = <-finalResultClearAggr: + break + case <-time.After(p.Timeout): + return errors.New(p.ServerIdentity().String() + "didn't get the on time.") + } + + p.FeedbackChannel <- finalResultMessage return nil } diff --git a/protocols/utils/proofs_verification_protocol.go b/protocols/utils/proofs_verification_protocol.go index 61cbaee..d32a39c 100644 --- a/protocols/utils/proofs_verification_protocol.go +++ b/protocols/utils/proofs_verification_protocol.go @@ -5,6 +5,7 @@ package protocolsunlynxutils import ( + "errors" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/lib/aggregation" "github.com/ldsec/unlynx/lib/deterministic_tag" @@ -12,6 +13,7 @@ import ( "github.com/ldsec/unlynx/lib/shuffle" "go.dedis.ch/onet/v3" "go.dedis.ch/onet/v3/log" + "time" ) // ProofsVerificationProtocolName is the registered name for the proof verification protocol. @@ -45,6 +47,8 @@ type ProofsVerificationProtocol struct { // Protocol state data TargetOfVerification ProofsToVerify + + Timeout time.Duration } // NewProofsVerificationProtocol is constructor of Proofs Verification protocol instances. @@ -54,6 +58,9 @@ func NewProofsVerificationProtocol(n *onet.TreeNodeInstance) (onet.ProtocolInsta FeedbackChannel: make(chan []bool), } + // default timeout + pvp.Timeout = 10 * time.Minute + return pvp, nil } @@ -107,7 +114,14 @@ func (p *ProofsVerificationProtocol) Start() error { func (p *ProofsVerificationProtocol) Dispatch() error { defer p.Done() - aux := <-finalResult - p.FeedbackChannel <- aux + var finalResultMessage []bool + select { + case finalResultMessage = <-finalResult: + break + case <-time.After(p.Timeout): + return errors.New(p.ServerIdentity().String() + "didn't get the on time.") + } + + p.FeedbackChannel <- finalResultMessage return nil } From 66925ca1a61b09781d99654668d6dfc29da631f3 Mon Sep 17 00:00:00 2001 From: Joao Sa Sousa Date: Tue, 10 Mar 2020 13:57:15 +0100 Subject: [PATCH 03/22] Added select timeouts for unlynx services and simulations --- Makefile | 2 +- protocols/collective_aggregation_protocol.go | 2 +- protocols/utils/local_aggregation_protocol.go | 2 +- services/service.go | 54 +++++++++++++++++-- simul/addrm_server_simul.go | 15 ++++-- simul/local_aggregation_simul.go | 15 ++++-- simul/local_clear_aggregation_simul.go | 26 +++++---- simul/proofs_verification_simul.go | 40 ++++++++------ 8 files changed, 114 insertions(+), 42 deletions(-) diff --git a/Makefile b/Makefile index 31e9c90..567d585 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ test_lint: } test_local: - go test -v -race -short -p=1 ./... + go test -v -short -p=1 ./... test_codecov: ./coveralls.sh diff --git a/protocols/collective_aggregation_protocol.go b/protocols/collective_aggregation_protocol.go index f529f34..cf4cfd7 100644 --- a/protocols/collective_aggregation_protocol.go +++ b/protocols/collective_aggregation_protocol.go @@ -202,7 +202,7 @@ func (p *CollectiveAggregationProtocol) Dispatch() error { // Announce forwarding down the tree. func (p *CollectiveAggregationProtocol) aggregationAnnouncementPhase() error { select { - case dataReferenceMessage := <-p.DataReferenceChannel : + case dataReferenceMessage := <-p.DataReferenceChannel: if !p.IsLeaf() { if err := p.SendToChildren(&dataReferenceMessage.DataReferenceMessage); err != nil { return errors.New("Error sending :" + err.Error()) diff --git a/protocols/utils/local_aggregation_protocol.go b/protocols/utils/local_aggregation_protocol.go index 1b83c93..a5d963e 100644 --- a/protocols/utils/local_aggregation_protocol.go +++ b/protocols/utils/local_aggregation_protocol.go @@ -36,7 +36,7 @@ type LocalAggregationProtocol struct { TargetOfAggregation []libunlynx.FilteredResponseDet Proofs bool - Timeout time.Duration + Timeout time.Duration } // NewLocalAggregationProtocol is constructor of Local Aggregation protocol instances. diff --git a/services/service.go b/services/service.go index f342d1f..b60cd85 100644 --- a/services/service.go +++ b/services/service.go @@ -3,6 +3,7 @@ package servicesunlynx import ( "errors" "strconv" + "time" "github.com/Knetic/govaluate" "github.com/fanliao/go-concurrentMap" @@ -88,8 +89,14 @@ func init() { network.RegisterMessage(&SurveyResponseQuery{}) network.RegisterMessage(&ServiceState{}) network.RegisterMessage(&ServiceResult{}) + + // Default timeout just for all tests to work + TimeoutService = 20 * time.Minute } +// TimeoutService is the communication idle timeout +var TimeoutService time.Duration + // QueryBroadcastFinished is used to ensure that all servers have received the query/survey type QueryBroadcastFinished struct { SurveyID SurveyID @@ -127,6 +134,8 @@ type ServiceResult struct { type Service struct { *onet.ServiceProcessor + Timeout time.Duration + Survey *concurrent.ConcurrentMap } @@ -149,6 +158,7 @@ func (s *Service) putSurvey(sid SurveyID, surv Survey) error { // NewService constructor which registers the needed messages. func NewService(c *onet.Context) (onet.Service, error) { newUnLynxInstance := &Service{ + Timeout: TimeoutService, ServiceProcessor: onet.NewServiceProcessor(c), Survey: concurrent.NewConcurrentMap(), } @@ -728,7 +738,14 @@ func (s *Service) ShufflingPhase(targetSurvey SurveyID) error { if err != nil { return err } - tmpShufflingResult := <-pi.(*protocolsunlynx.ShufflingProtocol).FeedbackChannel + + var tmpShufflingResult []libunlynx.CipherVector + select { + case tmpShufflingResult = <-pi.(*protocolsunlynx.ShufflingProtocol).FeedbackChannel: + break + case <-time.After(s.Timeout): + return errors.New(s.ServerIdentity().String() + "didn't get the on time.") + } survey, err = s.getSurvey(targetSurvey) if err != nil { @@ -758,7 +775,13 @@ func (s *Service) TaggingPhase(targetSurvey SurveyID) error { return err } - tmpDeterministicTaggingResult := <-pi.(*protocolsunlynx.DeterministicTaggingProtocol).FeedbackChannel + var tmpDeterministicTaggingResult []libunlynx.DeterministCipherText + select { + case tmpDeterministicTaggingResult = <-pi.(*protocolsunlynx.DeterministicTaggingProtocol).FeedbackChannel: + break + case <-time.After(s.Timeout): + return errors.New(s.ServerIdentity().String() + "didn't get the on time.") + } survey, err = s.getSurvey(targetSurvey) if err != nil { @@ -791,7 +814,14 @@ func (s *Service) AggregationPhase(targetSurvey SurveyID) error { if err != nil { return err } - cothorityAggregatedData := <-pi.(*protocolsunlynx.CollectiveAggregationProtocol).FeedbackChannel + + var cothorityAggregatedData protocolsunlynx.CothorityAggregatedData + select { + case cothorityAggregatedData = <-pi.(*protocolsunlynx.CollectiveAggregationProtocol).FeedbackChannel: + break + case <-time.After(s.Timeout): + return errors.New(s.ServerIdentity().String() + "didn't get the on time.") + } survey, err := s.getSurvey(targetSurvey) if err != nil { @@ -815,7 +845,14 @@ func (s *Service) DROPhase(targetSurvey SurveyID) error { return err } - tmpShufflingResult := <-pi.(*protocolsunlynx.ShufflingProtocol).FeedbackChannel + var tmpShufflingResult []libunlynx.CipherVector + select { + case tmpShufflingResult = <-pi.(*protocolsunlynx.ShufflingProtocol).FeedbackChannel: + break + case <-time.After(s.Timeout): + return errors.New(s.ServerIdentity().String() + "didn't get the on time.") + } + shufflingResult := protocolsunlynx.MatrixCipherTextToProcessResponse(tmpShufflingResult, survey.Lengths) survey.Noise = shufflingResult[0].AggregatingAttributes[0] @@ -835,7 +872,14 @@ func (s *Service) KeySwitchingPhase(targetSurvey SurveyID) error { return err } - tmpKeySwitchedAggregatedResponses := <-pi.(*protocolsunlynx.KeySwitchingProtocol).FeedbackChannel + var tmpKeySwitchedAggregatedResponses libunlynx.CipherVector + select { + case tmpKeySwitchedAggregatedResponses = <-pi.(*protocolsunlynx.KeySwitchingProtocol).FeedbackChannel: + break + case <-time.After(s.Timeout): + return errors.New(s.ServerIdentity().String() + "didn't get the on time.") + } + keySwitchedAggregatedResponses := protocolsunlynx.CipherVectorToFilteredResponse(tmpKeySwitchedAggregatedResponses, survey.Lengths) survey.PushQuerierKeyEncryptedResponses(keySwitchedAggregatedResponses) diff --git a/simul/addrm_server_simul.go b/simul/addrm_server_simul.go index 970ebff..d70d174 100644 --- a/simul/addrm_server_simul.go +++ b/simul/addrm_server_simul.go @@ -1,12 +1,14 @@ package main import ( + "errors" "github.com/BurntSushi/toml" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/protocols/utils" "go.dedis.ch/kyber/v3/util/random" "go.dedis.ch/onet/v3" "go.dedis.ch/onet/v3/log" + "time" ) func init() { @@ -51,6 +53,8 @@ func (sim *AddRmSimulation) Setup(dir string, hosts []string) (*onet.SimulationC // Run starts the simulation. func (sim *AddRmSimulation) Run(config *onet.SimulationConfig) error { + timeout := 10 * time.Minute + for round := 0; round < sim.Rounds; round++ { log.Lvl1("Starting round", round) @@ -83,11 +87,14 @@ func (sim *AddRmSimulation) Run(config *onet.SimulationConfig) error { if err := root.Start(); err != nil { return err } - results := <-root.ProtocolInstance().(*protocolsunlynxutils.AddRmServerProtocol).FeedbackChannel - log.Lvl1("Number of aggregated lines: ", len(results)) - - libunlynx.EndTimer(round) + select { + case results := <-root.ProtocolInstance().(*protocolsunlynxutils.AddRmServerProtocol).FeedbackChannel: + log.Lvl1("Number of aggregated lines: ", len(results)) + libunlynx.EndTimer(round) + case <-time.After(timeout): + return errors.New("simulation didn't finish in time") + } } return nil diff --git a/simul/local_aggregation_simul.go b/simul/local_aggregation_simul.go index 2e87629..767e16d 100644 --- a/simul/local_aggregation_simul.go +++ b/simul/local_aggregation_simul.go @@ -1,6 +1,7 @@ package main import ( + "errors" "github.com/BurntSushi/toml" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/protocols" @@ -8,6 +9,7 @@ import ( "go.dedis.ch/kyber/v3/util/random" "go.dedis.ch/onet/v3" "go.dedis.ch/onet/v3/log" + "time" ) func init() { @@ -54,6 +56,8 @@ func (sim *LocalAggregationSimulation) Setup(dir string, hosts []string) (*onet. // Run starts the simulation. func (sim *LocalAggregationSimulation) Run(config *onet.SimulationConfig) error { + timeout := 10 * time.Minute + for round := 0; round < sim.Rounds; round++ { log.Lvl1("Starting round", round) rooti, err := config.Overlay.CreateProtocol("LocalAggregation", config.Tree, onet.NilServiceID) @@ -113,11 +117,14 @@ func (sim *LocalAggregationSimulation) Run(config *onet.SimulationConfig) error if err := root.Start(); err != nil { return err } - results := <-root.ProtocolInstance().(*protocolsunlynxutils.LocalAggregationProtocol).FeedbackChannel - log.Lvl1("Number of aggregated lines: ", len(results)) - - libunlynx.EndTimer(round) + select { + case results := <-root.ProtocolInstance().(*protocolsunlynxutils.LocalAggregationProtocol).FeedbackChannel: + log.Lvl1("Number of aggregated lines: ", len(results)) + libunlynx.EndTimer(round) + case <-time.After(timeout): + return errors.New("simulation didn't finish in time") + } } return nil diff --git a/simul/local_clear_aggregation_simul.go b/simul/local_clear_aggregation_simul.go index 4029436..cce609d 100644 --- a/simul/local_clear_aggregation_simul.go +++ b/simul/local_clear_aggregation_simul.go @@ -1,12 +1,14 @@ package main import ( + "errors" "github.com/BurntSushi/toml" "github.com/ldsec/unlynx/data" "github.com/ldsec/unlynx/protocols/utils" "go.dedis.ch/onet/v3" "go.dedis.ch/onet/v3/log" "go.dedis.ch/onet/v3/simul/monitor" + "time" ) func init() { @@ -54,6 +56,8 @@ func (sim *LocalClearAggregationSimulation) Setup(dir string, hosts []string) (* // Run starts the simulation. func (sim *LocalClearAggregationSimulation) Run(config *onet.SimulationConfig) error { + timeout := 10 * time.Minute + for round := 0; round < sim.Rounds; round++ { log.Lvl1("Starting round", round) rooti, err := config.Overlay.CreateProtocol("LocalClearAggregation", config.Tree, onet.NilServiceID) @@ -83,16 +87,20 @@ func (sim *LocalClearAggregationSimulation) Run(config *onet.SimulationConfig) e if err := root.Start(); err != nil { return err } - results := <-root.ProtocolInstance().(*protocolsunlynxutils.LocalClearAggregationProtocol).FeedbackChannel - log.Lvl1("Number of aggregated lines (groups): ", len(results)) - - // Test Simulation - if dataunlynx.CompareClearResponses(dataunlynx.ComputeExpectedResult(testData, 1, false), results) { - log.Lvl1("Result is right! :)") - } else { - log.Lvl1("Result is wrong! :(") + + select { + case results := <-root.ProtocolInstance().(*protocolsunlynxutils.LocalClearAggregationProtocol).FeedbackChannel: + log.Lvl1("Number of aggregated lines (groups): ", len(results)) + // Test Simulation + if dataunlynx.CompareClearResponses(dataunlynx.ComputeExpectedResult(testData, 1, false), results) { + log.Lvl1("Result is right! :)") + } else { + log.Lvl1("Result is wrong! :(") + } + round.Record() + case <-time.After(timeout): + return errors.New("simulation didn't finish in time") } - round.Record() } return nil diff --git a/simul/proofs_verification_simul.go b/simul/proofs_verification_simul.go index feefbb1..d698ea7 100644 --- a/simul/proofs_verification_simul.go +++ b/simul/proofs_verification_simul.go @@ -14,6 +14,7 @@ import ( "go.dedis.ch/kyber/v3/util/random" "go.dedis.ch/onet/v3" "go.dedis.ch/onet/v3/log" + "time" ) func init() { @@ -55,6 +56,7 @@ func (sim *ProofsVerificationSimulation) Setup(dir string, hosts []string) (*one // Run starts the simulation. func (sim *ProofsVerificationSimulation) Run(config *onet.SimulationConfig) error { + timeout := 10 * time.Minute for round := 0; round < sim.Rounds; round++ { log.Lvl1("Starting round", round) @@ -231,23 +233,27 @@ func (sim *ProofsVerificationSimulation) Run(config *onet.SimulationConfig) erro if err := root.Start(); err != nil { return err } - results := <-root.ProtocolInstance().(*protocolsunlynxutils.ProofsVerificationProtocol).FeedbackChannel - libunlynx.EndTimer(round) - - log.Lvl1(len(results), " proofs verified") - - if results[0] == false { - return errors.New("key switching proofs failed") - } else if results[1] == false { - return errors.New("deterministic tagging (creation) proofs failed") - } else if results[2] == false { - return errors.New("deterministic tagging (addition) proofs failed") - } else if results[3] == false { - return errors.New("local aggregation proofs failed") - } else if results[4] == false { - return errors.New("shuffling proofs failed") - } else if results[5] == false { - return errors.New("collective aggregation proofs failed") + select { + case results := <-root.ProtocolInstance().(*protocolsunlynxutils.ProofsVerificationProtocol).FeedbackChannel: + libunlynx.EndTimer(round) + + log.Lvl1(len(results), " proofs verified") + + if results[0] == false { + return errors.New("key switching proofs failed") + } else if results[1] == false { + return errors.New("deterministic tagging (creation) proofs failed") + } else if results[2] == false { + return errors.New("deterministic tagging (addition) proofs failed") + } else if results[3] == false { + return errors.New("local aggregation proofs failed") + } else if results[4] == false { + return errors.New("shuffling proofs failed") + } else if results[5] == false { + return errors.New("collective aggregation proofs failed") + } + case <-time.After(timeout): + return errors.New("simulation didn't finish in time") } } return nil From 17479ba26937dcb24926dc18730b926982d72e01 Mon Sep 17 00:00:00 2001 From: Joao Sa Sousa Date: Tue, 10 Mar 2020 14:23:44 +0100 Subject: [PATCH 04/22] Updated libraries except Onet --- go.mod | 12 +++++++++--- go.sum | 30 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 71025b3..6f48759 100644 --- a/go.mod +++ b/go.mod @@ -5,13 +5,19 @@ go 1.14 require ( github.com/BurntSushi/toml v0.3.1 github.com/Knetic/govaluate v3.0.0+incompatible + github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect github.com/fanliao/go-concurrentMap v0.0.0-20141114143905-7d2d7a5ea67b + github.com/gorilla/websocket v1.4.1 // indirect + github.com/montanaflynn/stats v0.6.3 // indirect github.com/r0fls/gostats v0.0.0-20180711082619-e793b1fda35c github.com/satori/go.uuid v1.2.0 - github.com/stretchr/testify v1.3.0 - github.com/urfave/cli v1.22.1 - go.dedis.ch/kyber/v3 v3.0.5 + github.com/stretchr/testify v1.4.0 + github.com/urfave/cli v1.22.3 + go.dedis.ch/kyber/v3 v3.0.12 go.dedis.ch/onet/v3 v3.0.24 + golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 // indirect + golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 // indirect + golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect ) //replace go.dedis.ch/onet/v3 => ../../../go.dedis.ch/onet diff --git a/go.sum b/go.sum index fe57fc0..6c5103f 100644 --- a/go.sum +++ b/go.sum @@ -5,6 +5,8 @@ github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8L github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM= +github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -18,11 +20,15 @@ github.com/golangplus/fmt v0.0.0-20150411045040-2a5d6d7d2995/go.mod h1:lJgMEyOkY github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e/go.mod h1:0AA//k/eakGydO4jKRoRL2j92ZKSzTgj9tclaCrvXHk= github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= +github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/montanaflynn/stats v0.5.0 h1:2EkzeTSqBB4V4bJwWrt5gIIrZmpJBcoIRGS2kWLgzmk= github.com/montanaflynn/stats v0.5.0/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= +github.com/montanaflynn/stats v0.6.3 h1:F8446DrvIF5V5smZfZ8K9nrmmix0AFgevPdLruGOmzk= +github.com/montanaflynn/stats v0.6.3/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -39,8 +45,13 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v0.0.0-20190311161405-34c6fa2dc709/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/urfave/cli v1.22.1 h1:+mkCCcOFKPnCmVYVcURKps1Xe+3zP90gSYGNfRkjoIY= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +github.com/urfave/cli v1.22.3 h1:FpNT6zq26xNpHZy08emi755QwzLPs6Pukqjlc7RfOMU= +github.com/urfave/cli v1.22.3/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= go.dedis.ch/fixbuf v1.0.3 h1:hGcV9Cd/znUxlusJ64eAlExS+5cJDIyTyEG+otu5wQs= go.dedis.ch/fixbuf v1.0.3/go.mod h1:yzJMt34Wa5xD37V5RTdmp38cz3QhMagdGoem9anUalw= go.dedis.ch/kyber/v3 v3.0.0-pre2/go.mod h1:OzvaEnPvKlyrWyp3kGXlFdp7ap1VC6RkZDTaPikqhsQ= @@ -51,11 +62,16 @@ go.dedis.ch/kyber/v3 v3.0.2/go.mod h1:OzvaEnPvKlyrWyp3kGXlFdp7ap1VC6RkZDTaPikqhs go.dedis.ch/kyber/v3 v3.0.4/go.mod h1:OzvaEnPvKlyrWyp3kGXlFdp7ap1VC6RkZDTaPikqhsQ= go.dedis.ch/kyber/v3 v3.0.5 h1:BpjX6vY1R3b7TnJ0mUnCFRVXEJThSAj1zQzmNh4v+70= go.dedis.ch/kyber/v3 v3.0.5/go.mod h1:V1z0JihG9+dUEUCKLI9j9tjnlIflBw3wx8UOg0g3Pnk= +go.dedis.ch/kyber/v3 v3.0.9/go.mod h1:rhNjUUg6ahf8HEg5HUvVBYoWY4boAafX8tYxX+PS+qg= +go.dedis.ch/kyber/v3 v3.0.12 h1:15d61EyBcBoFIS97kS2c/Vz4o3FR8ALnZ2ck9J/ebYM= +go.dedis.ch/kyber/v3 v3.0.12/go.mod h1:kXy7p3STAurkADD+/aZcsznZGKVHEqbtmdIzvPfrs1U= go.dedis.ch/onet/v3 v3.0.0 h1:haBqkwkNNu/jHz7+PoZJS+xbtA5JheQvt0SSIjGyk5I= go.dedis.ch/onet/v3 v3.0.0/go.mod h1:xqmP2+NvxeNzgmNj/4hf56EZm3KT0Qksz98miZw5G3A= go.dedis.ch/onet/v3 v3.0.4 h1:sIHdiuhg5LMVVDAKQbSiBZsQnJGP2EDxImcp12OnWKo= go.dedis.ch/onet/v3 v3.0.24 h1:DjPcMDgQgQdxi6Z6vHt3BSuKtZioDUHpIUEC9wQ9NmI= go.dedis.ch/onet/v3 v3.0.24/go.mod h1:JhOZn9nJgpvxQWiY7Uebjj1AdXTW0ksQyq8RocRhwPk= +go.dedis.ch/onet/v3 v3.1.1 h1:DN0t3Qj611kUrdmNn5quhWDdite1bxhoqoPna8IAWS0= +go.dedis.ch/onet/v3 v3.1.1/go.mod h1:dDV7bRKbT3LJ7enHBcys2O0jXEY2jTUB4dq8HtekGbA= go.dedis.ch/protobuf v1.0.5/go.mod h1:eIV4wicvi6JK0q/QnfIEGeSFNG0ZeB24kzut5+HaRLo= go.dedis.ch/protobuf v1.0.6 h1:E61p2XjYbYrTf3WeXE8M8Ui5WA3hX/NgbHHi5D0FLxI= go.dedis.ch/protobuf v1.0.6/go.mod h1:YHYXW6dQ9p2iJ3f+2fxKnOpjGx0MvL4cwpg1RVNXaV8= @@ -63,6 +79,8 @@ go.dedis.ch/protobuf v1.0.7 h1:wRUEiq3u0/vBhLjcw9CmAVrol+BnDyq2M0XLukdphyI= go.dedis.ch/protobuf v1.0.7/go.mod h1:pv5ysfkDX/EawiPqcW3ikOxsL5t+BqnV6xHSmE79KI4= go.dedis.ch/protobuf v1.0.8 h1:lmyHigYqVxoTN1V0adoGPvqSdjycAMK0XmTFjP893mA= go.dedis.ch/protobuf v1.0.8/go.mod h1:pv5ysfkDX/EawiPqcW3ikOxsL5t+BqnV6xHSmE79KI4= +go.dedis.ch/protobuf v1.0.11 h1:FTYVIEzY/bfl37lu3pR4lIj+F9Vp1jE8oh91VmxKgLo= +go.dedis.ch/protobuf v1.0.11/go.mod h1:97QR256dnkimeNdfmURz0wAMNVbd1VmLXhG1CrTYrJ4= go.etcd.io/bbolt v1.3.0 h1:oY10fI923Q5pVCVt1GBTZMn8LHo5M+RCInFpeMnV4QI= go.etcd.io/bbolt v1.3.0/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk= @@ -71,7 +89,10 @@ golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b h1:Elez2XeF2p9uyVj0yEUDqQ golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 h1:xMPOj6Pz6UipU1wXLkrtqpHbR0AVFnyPEQq/wRWz9lM= +golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f h1:hX65Cu3JDlGH3uEdK7I99Ii+9kjD6mvnnpfLdEAH0x4= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= @@ -79,17 +100,25 @@ golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20191021144547-ec77196f6094/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/sys v0.0.0-20190124100055-b90733256f2e h1:3GIlrlVLfkoipSReOMNAgApI0ajnalyLa/EZHHca/XI= golang.org/x/sys v0.0.0-20190124100055-b90733256f2e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So= +golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190311215038-5c2858a9cfe5 h1:ZcPpqKMdoZeNQ/4GHlyY4COf8n8SmpPv6mcqF1+VPSM= golang.org/x/tools v0.0.0-20190311215038-5c2858a9cfe5/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/satori/go.uuid.v1 v1.2.0 h1:AH9uksa7bGe9rluapecRKBCpZvxaBEyu0RepitcD0Hw= @@ -99,6 +128,7 @@ gopkg.in/tylerb/graceful.v1 v1.2.15/go.mod h1:yBhekWvR20ACXVObSSdD3u6S9DeSylanL2 gopkg.in/urfave/cli.v1 v1.20.0 h1:NdAVW6RYxDif9DhDHaAortIu956m2c0v+09AZBPTbE0= gopkg.in/urfave/cli.v1 v1.20.0/go.mod h1:vuBzUtMdQeixQj8LVd+/98pzhxNGQoyuPBlsXHOQNO0= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= rsc.io/goversion v1.2.0 h1:SPn+NLTiAG7w30IRK/DKp1BjvpWabYgxlLp/+kx5J8w= rsc.io/goversion v1.2.0/go.mod h1:Eih9y/uIBS3ulggl7KNJ09xGSLcuNaLgmvvqa07sgfo= From 2c8b8bdb08cd672c6b81372d6f5705773b3eb42a Mon Sep 17 00:00:00 2001 From: Joao Sa Sousa Date: Wed, 11 Mar 2020 10:25:25 +0100 Subject: [PATCH 05/22] Removed break and re-adding race flag --- Makefile | 2 +- go.mod | 2 +- go.sum | 2 ++ lib/constants.go | 5 ++--- protocols/collective_aggregation_test.go | 1 - protocols/deterministic_tagging_protocol.go | 2 -- protocols/key_switching_protocol.go | 1 - protocols/shuffling+ddt_protocol.go | 2 -- protocols/shuffling_protocol.go | 2 -- protocols/utils/addrm_server_protocol.go | 1 - protocols/utils/local_aggregation_protocol.go | 1 - protocols/utils/local_clear_aggregation_protocol.go | 1 - protocols/utils/proofs_verification_protocol.go | 1 - services/service.go | 5 ----- simul/simul_test.go | 3 +-- 15 files changed, 7 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 567d585..fa19dbb 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ test_lint: } test_local: - go test -v -short -p=1 ./... + go test -v -short -race -p=1 ./... test_codecov: ./coveralls.sh diff --git a/go.mod b/go.mod index 6f48759..1288c1b 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/stretchr/testify v1.4.0 github.com/urfave/cli v1.22.3 go.dedis.ch/kyber/v3 v3.0.12 - go.dedis.ch/onet/v3 v3.0.24 + go.dedis.ch/onet/v3 v3.1.0 golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 // indirect golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 // indirect golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect diff --git a/go.sum b/go.sum index 6c5103f..4879da9 100644 --- a/go.sum +++ b/go.sum @@ -70,6 +70,8 @@ go.dedis.ch/onet/v3 v3.0.0/go.mod h1:xqmP2+NvxeNzgmNj/4hf56EZm3KT0Qksz98miZw5G3A go.dedis.ch/onet/v3 v3.0.4 h1:sIHdiuhg5LMVVDAKQbSiBZsQnJGP2EDxImcp12OnWKo= go.dedis.ch/onet/v3 v3.0.24 h1:DjPcMDgQgQdxi6Z6vHt3BSuKtZioDUHpIUEC9wQ9NmI= go.dedis.ch/onet/v3 v3.0.24/go.mod h1:JhOZn9nJgpvxQWiY7Uebjj1AdXTW0ksQyq8RocRhwPk= +go.dedis.ch/onet/v3 v3.1.0 h1:KwofJGuw9T+051ejuWWxA6K1N6blNvhuwz5neasWg8Y= +go.dedis.ch/onet/v3 v3.1.0/go.mod h1:dDV7bRKbT3LJ7enHBcys2O0jXEY2jTUB4dq8HtekGbA= go.dedis.ch/onet/v3 v3.1.1 h1:DN0t3Qj611kUrdmNn5quhWDdite1bxhoqoPna8IAWS0= go.dedis.ch/onet/v3 v3.1.1/go.mod h1:dDV7bRKbT3LJ7enHBcys2O0jXEY2jTUB4dq8HtekGbA= go.dedis.ch/protobuf v1.0.5/go.mod h1:eIV4wicvi6JK0q/QnfIEGeSFNG0ZeB24kzut5+HaRLo= diff --git a/lib/constants.go b/lib/constants.go index a7719c3..e0ef1a8 100644 --- a/lib/constants.go +++ b/lib/constants.go @@ -20,11 +20,10 @@ const DIFFPRI = false // StartTimer starts measurement of time func StartTimer(name string) *monitor.TimeMeasure { - var timer *monitor.TimeMeasure if TIME { - timer = monitor.NewTimeMeasure(name) + return monitor.NewTimeMeasure(name) } - return timer + return nil } // EndTimer finishes measurement of time diff --git a/protocols/collective_aggregation_test.go b/protocols/collective_aggregation_test.go index f383620..d634faa 100644 --- a/protocols/collective_aggregation_test.go +++ b/protocols/collective_aggregation_test.go @@ -62,7 +62,6 @@ func TestCollectiveAggregationGroup(t *testing.T) { resultData := make(map[libunlynx.GroupingKey][]int64) for k, v := range encryptedResult.GroupedData { resultData[k] = libunlynx.DecryptIntVector(clientPrivate, &v.AggregatingAttributes) - log.Lvl1(k, resultData[k]) } for k, v1 := range expectedGroups { diff --git a/protocols/deterministic_tagging_protocol.go b/protocols/deterministic_tagging_protocol.go index 4427b56..11cac51 100644 --- a/protocols/deterministic_tagging_protocol.go +++ b/protocols/deterministic_tagging_protocol.go @@ -164,7 +164,6 @@ func (p *DeterministicTaggingProtocol) Dispatch() error { var deterministicTaggingTargetBytesBef deterministicTaggingBytesStruct select { case deterministicTaggingTargetBytesBef = <-p.PreviousNodeInPathChannel: - break case <-time.After(p.Timeout): return errors.New(p.ServerIdentity().String() + "didn't get the (first round) on time.") } @@ -218,7 +217,6 @@ func (p *DeterministicTaggingProtocol) Dispatch() error { var deterministicTaggingTargetBytes deterministicTaggingBytesStruct select { case deterministicTaggingTargetBytes = <-p.PreviousNodeInPathChannel: - break case <-time.After(p.Timeout): return errors.New(p.ServerIdentity().String() + "didn't get the (second round) on time.") } diff --git a/protocols/key_switching_protocol.go b/protocols/key_switching_protocol.go index be2d898..76ac82f 100644 --- a/protocols/key_switching_protocol.go +++ b/protocols/key_switching_protocol.go @@ -238,7 +238,6 @@ func (p *KeySwitchingProtocol) announcementKSPhase() (kyber.Point, []kyber.Point var dataReferenceMessage DownBytesStruct select { case dataReferenceMessage = <-p.DownChannel: - break case <-time.After(p.Timeout): return nil, nil, errors.New(p.ServerIdentity().String() + "didn't get the on time.") } diff --git a/protocols/shuffling+ddt_protocol.go b/protocols/shuffling+ddt_protocol.go index 730fe0a..0b3abe9 100644 --- a/protocols/shuffling+ddt_protocol.go +++ b/protocols/shuffling+ddt_protocol.go @@ -162,7 +162,6 @@ func (p *ShufflingPlusDDTProtocol) Dispatch() error { var shufflingPlusDDTBytesMessageLength shufflingPlusDDTBytesLengthStruct select { case shufflingPlusDDTBytesMessageLength = <-p.LengthNodeChannel: - break case <-time.After(p.Timeout): return errors.New(p.ServerIdentity().String() + "didn't get the on time.") } @@ -170,7 +169,6 @@ func (p *ShufflingPlusDDTProtocol) Dispatch() error { var tmp shufflingPlusDDTBytesStruct select { case tmp = <-p.PreviousNodeInPathChannel: - break case <-time.After(p.Timeout): return errors.New(p.ServerIdentity().String() + "didn't get the on time.") } diff --git a/protocols/shuffling_protocol.go b/protocols/shuffling_protocol.go index 4cc45a2..7973c7c 100644 --- a/protocols/shuffling_protocol.go +++ b/protocols/shuffling_protocol.go @@ -195,7 +195,6 @@ func (p *ShufflingProtocol) Dispatch() error { var shufflingBytesMessageLength shufflingBytesLengthStruct select { case shufflingBytesMessageLength = <-p.LengthNodeChannel: - break case <-time.After(p.Timeout): return errors.New(p.ServerIdentity().String() + "didn't get the on time.") } @@ -203,7 +202,6 @@ func (p *ShufflingProtocol) Dispatch() error { var tmp shufflingBytesStruct select { case tmp = <-p.PreviousNodeInPathChannel: - break case <-time.After(p.Timeout): return errors.New(p.ServerIdentity().String() + "didn't get the on time.") } diff --git a/protocols/utils/addrm_server_protocol.go b/protocols/utils/addrm_server_protocol.go index 6da6222..90349b3 100644 --- a/protocols/utils/addrm_server_protocol.go +++ b/protocols/utils/addrm_server_protocol.go @@ -101,7 +101,6 @@ func (p *AddRmServerProtocol) Dispatch() error { var finalResultMessage []libunlynx.CipherText select { case finalResultMessage = <-finalResultAddrm: - break case <-time.After(p.Timeout): return errors.New(p.ServerIdentity().String() + "didn't get the on time.") } diff --git a/protocols/utils/local_aggregation_protocol.go b/protocols/utils/local_aggregation_protocol.go index a5d963e..c548bae 100644 --- a/protocols/utils/local_aggregation_protocol.go +++ b/protocols/utils/local_aggregation_protocol.go @@ -93,7 +93,6 @@ func (p *LocalAggregationProtocol) Dispatch() error { var finalResultMessage map[libunlynx.GroupingKey]libunlynx.FilteredResponse select { case finalResultMessage = <-finalResultAggr: - break case <-time.After(p.Timeout): return errors.New(p.ServerIdentity().String() + "didn't get the on time.") } diff --git a/protocols/utils/local_clear_aggregation_protocol.go b/protocols/utils/local_clear_aggregation_protocol.go index d1fd05b..66f1fb7 100644 --- a/protocols/utils/local_clear_aggregation_protocol.go +++ b/protocols/utils/local_clear_aggregation_protocol.go @@ -67,7 +67,6 @@ func (p *LocalClearAggregationProtocol) Dispatch() error { var finalResultMessage []libunlynx.DpClearResponse select { case finalResultMessage = <-finalResultClearAggr: - break case <-time.After(p.Timeout): return errors.New(p.ServerIdentity().String() + "didn't get the on time.") } diff --git a/protocols/utils/proofs_verification_protocol.go b/protocols/utils/proofs_verification_protocol.go index d32a39c..e4185d1 100644 --- a/protocols/utils/proofs_verification_protocol.go +++ b/protocols/utils/proofs_verification_protocol.go @@ -117,7 +117,6 @@ func (p *ProofsVerificationProtocol) Dispatch() error { var finalResultMessage []bool select { case finalResultMessage = <-finalResult: - break case <-time.After(p.Timeout): return errors.New(p.ServerIdentity().String() + "didn't get the on time.") } diff --git a/services/service.go b/services/service.go index b60cd85..b824635 100644 --- a/services/service.go +++ b/services/service.go @@ -742,7 +742,6 @@ func (s *Service) ShufflingPhase(targetSurvey SurveyID) error { var tmpShufflingResult []libunlynx.CipherVector select { case tmpShufflingResult = <-pi.(*protocolsunlynx.ShufflingProtocol).FeedbackChannel: - break case <-time.After(s.Timeout): return errors.New(s.ServerIdentity().String() + "didn't get the on time.") } @@ -778,7 +777,6 @@ func (s *Service) TaggingPhase(targetSurvey SurveyID) error { var tmpDeterministicTaggingResult []libunlynx.DeterministCipherText select { case tmpDeterministicTaggingResult = <-pi.(*protocolsunlynx.DeterministicTaggingProtocol).FeedbackChannel: - break case <-time.After(s.Timeout): return errors.New(s.ServerIdentity().String() + "didn't get the on time.") } @@ -818,7 +816,6 @@ func (s *Service) AggregationPhase(targetSurvey SurveyID) error { var cothorityAggregatedData protocolsunlynx.CothorityAggregatedData select { case cothorityAggregatedData = <-pi.(*protocolsunlynx.CollectiveAggregationProtocol).FeedbackChannel: - break case <-time.After(s.Timeout): return errors.New(s.ServerIdentity().String() + "didn't get the on time.") } @@ -848,7 +845,6 @@ func (s *Service) DROPhase(targetSurvey SurveyID) error { var tmpShufflingResult []libunlynx.CipherVector select { case tmpShufflingResult = <-pi.(*protocolsunlynx.ShufflingProtocol).FeedbackChannel: - break case <-time.After(s.Timeout): return errors.New(s.ServerIdentity().String() + "didn't get the on time.") } @@ -875,7 +871,6 @@ func (s *Service) KeySwitchingPhase(targetSurvey SurveyID) error { var tmpKeySwitchedAggregatedResponses libunlynx.CipherVector select { case tmpKeySwitchedAggregatedResponses = <-pi.(*protocolsunlynx.KeySwitchingProtocol).FeedbackChannel: - break case <-time.After(s.Timeout): return errors.New(s.ServerIdentity().String() + "didn't get the on time.") } diff --git a/simul/simul_test.go b/simul/simul_test.go index 7591ef0..f963a29 100644 --- a/simul/simul_test.go +++ b/simul/simul_test.go @@ -12,6 +12,5 @@ func TestMain(m *testing.M) { } func TestSimulation(t *testing.T) { - simul.Start("runfiles/addrm_server.toml", "runfiles/collective_aggregation.toml", "runfiles/deterministic_tagging.toml", "runfiles/key_switching.toml", - "runfiles/local_aggregation.toml", "runfiles/local_clear_aggregation.toml", "runfiles/proofs_verification.toml", "runfiles/shuffling.toml", "runfiles/shuffling+ddt.toml", "runfiles/unlynx_default.toml") + simul.Start("runfiles/addrm_server.toml") } From 32819216dd9db948a71b7142eb72161c4c087c17 Mon Sep 17 00:00:00 2001 From: Joao Sa Sousa Date: Wed, 11 Mar 2020 10:32:33 +0100 Subject: [PATCH 06/22] Re-added simulation tests --- simul/simul_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/simul/simul_test.go b/simul/simul_test.go index f963a29..7591ef0 100644 --- a/simul/simul_test.go +++ b/simul/simul_test.go @@ -12,5 +12,6 @@ func TestMain(m *testing.M) { } func TestSimulation(t *testing.T) { - simul.Start("runfiles/addrm_server.toml") + simul.Start("runfiles/addrm_server.toml", "runfiles/collective_aggregation.toml", "runfiles/deterministic_tagging.toml", "runfiles/key_switching.toml", + "runfiles/local_aggregation.toml", "runfiles/local_clear_aggregation.toml", "runfiles/proofs_verification.toml", "runfiles/shuffling.toml", "runfiles/shuffling+ddt.toml", "runfiles/unlynx_default.toml") } From 3dcc5b411f1b338d2dfd0aa236503e0f3a0991c1 Mon Sep 17 00:00:00 2001 From: Joao Sa Sousa Date: Wed, 11 Mar 2020 11:35:43 +0100 Subject: [PATCH 07/22] Changed timeouts to use os.Getenv --- lib/constants.go | 6 ++- protocols/collective_aggregation_protocol.go | 13 +++--- protocols/deterministic_tagging_protocol.go | 18 ++++---- protocols/key_switching_protocol.go | 13 +++--- protocols/shuffling+ddt_protocol.go | 18 ++++---- protocols/shuffling_protocol.go | 15 +++--- protocols/utils/addrm_server_protocol.go | 13 +++--- protocols/utils/local_aggregation_protocol.go | 14 +++--- .../utils/local_clear_aggregation_protocol.go | 14 +++--- .../utils/proofs_verification_protocol.go | 13 +++--- services/service.go | 46 +++++++++++++------ 11 files changed, 104 insertions(+), 79 deletions(-) diff --git a/lib/constants.go b/lib/constants.go index e0ef1a8..aa5edf8 100644 --- a/lib/constants.go +++ b/lib/constants.go @@ -2,6 +2,7 @@ package libunlynx import ( "sync" + "time" "go.dedis.ch/onet/v3/simul/monitor" ) @@ -10,7 +11,7 @@ import ( //______________________________________________________________________________________________________________________ // TIME is true if we use protocols with time measurements of computations. -const TIME = false +var TIME = false // VPARALLELIZE allows to choose the level of parallelization in the vector computations const VPARALLELIZE = 100 @@ -18,6 +19,9 @@ const VPARALLELIZE = 100 // DIFFPRI enables the DRO protocol (Distributed Results Obfuscation) const DIFFPRI = false +// TIMEOUT ddefines the default channel timeout +var TIMEOUT = 10 * time.Minute + // StartTimer starts measurement of time func StartTimer(name string) *monitor.TimeMeasure { if TIME { diff --git a/protocols/collective_aggregation_protocol.go b/protocols/collective_aggregation_protocol.go index cf4cfd7..0524511 100644 --- a/protocols/collective_aggregation_protocol.go +++ b/protocols/collective_aggregation_protocol.go @@ -9,6 +9,7 @@ package protocolsunlynx import ( "errors" + "os" "sync" "time" @@ -107,8 +108,6 @@ type CollectiveAggregationProtocol struct { Proofs bool ProofFunc proofCollectiveAggregationFunction // proof function for when we want to do something different with the proofs (e.g. insert in the blockchain) MapPIs map[string]onet.ProtocolInstance // protocol instances to be able to call protocols inside protocols (e.g. proof_collection_protocol) - - Timeout time.Duration } // NewCollectiveAggregationProtocol initializes the protocol instance. @@ -132,9 +131,6 @@ func NewCollectiveAggregationProtocol(n *onet.TreeNodeInstance) (onet.ProtocolIn return nil, errors.New("couldn't register data reference channel: " + err.Error()) } - // default timeout - pap.Timeout = 10 * time.Minute - return pap, nil } @@ -201,6 +197,11 @@ func (p *CollectiveAggregationProtocol) Dispatch() error { // Announce forwarding down the tree. func (p *CollectiveAggregationProtocol) aggregationAnnouncementPhase() error { + timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) + if err != nil { + timeout = libunlynx.TIMEOUT + } + select { case dataReferenceMessage := <-p.DataReferenceChannel: if !p.IsLeaf() { @@ -208,7 +209,7 @@ func (p *CollectiveAggregationProtocol) aggregationAnnouncementPhase() error { return errors.New("Error sending :" + err.Error()) } } - case <-time.After(p.Timeout): + case <-time.After(timeout): return errors.New(p.ServerIdentity().String() + "didn't get the on time.") } return nil diff --git a/protocols/deterministic_tagging_protocol.go b/protocols/deterministic_tagging_protocol.go index 11cac51..854d40f 100644 --- a/protocols/deterministic_tagging_protocol.go +++ b/protocols/deterministic_tagging_protocol.go @@ -8,6 +8,7 @@ package protocolsunlynx import ( "errors" + "os" "sync" "time" @@ -91,8 +92,6 @@ type DeterministicTaggingProtocol struct { Proofs bool ExecTime time.Duration - - Timeout time.Duration } // NewDeterministicTaggingProtocol constructs tagging switching protocol instances. @@ -118,10 +117,6 @@ func NewDeterministicTaggingProtocol(n *onet.TreeNodeInstance) (onet.ProtocolIns break } } - - // default timeout - dsp.Timeout = 10 * time.Minute - return dsp, nil } @@ -160,16 +155,21 @@ func (p *DeterministicTaggingProtocol) Start() error { func (p *DeterministicTaggingProtocol) Dispatch() error { defer p.Done() + timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) + if err != nil { + timeout = libunlynx.TIMEOUT + } + //************ ----- first round, add value derivated from ephemeral secret to message ---- ******************** var deterministicTaggingTargetBytesBef deterministicTaggingBytesStruct select { case deterministicTaggingTargetBytesBef = <-p.PreviousNodeInPathChannel: - case <-time.After(p.Timeout): + case <-time.After(timeout): return errors.New(p.ServerIdentity().String() + "didn't get the (first round) on time.") } deterministicTaggingTargetBef := DeterministicTaggingMessage{Data: make([]libunlynx.CipherText, 0)} - err := deterministicTaggingTargetBef.FromBytes(deterministicTaggingTargetBytesBef.Data) + err = deterministicTaggingTargetBef.FromBytes(deterministicTaggingTargetBytesBef.Data) if err != nil { return err } @@ -217,7 +217,7 @@ func (p *DeterministicTaggingProtocol) Dispatch() error { var deterministicTaggingTargetBytes deterministicTaggingBytesStruct select { case deterministicTaggingTargetBytes = <-p.PreviousNodeInPathChannel: - case <-time.After(p.Timeout): + case <-time.After(timeout): return errors.New(p.ServerIdentity().String() + "didn't get the (second round) on time.") } diff --git a/protocols/key_switching_protocol.go b/protocols/key_switching_protocol.go index 76ac82f..5755053 100644 --- a/protocols/key_switching_protocol.go +++ b/protocols/key_switching_protocol.go @@ -8,6 +8,7 @@ package protocolsunlynx import ( "errors" + "os" "time" "github.com/ldsec/unlynx/lib" @@ -114,8 +115,6 @@ type KeySwitchingProtocol struct { // Test (only use in order to test the protocol) ExecTime time.Duration - - Timeout time.Duration } // NewKeySwitchingProtocol initializes the protocol instance. @@ -139,9 +138,6 @@ func NewKeySwitchingProtocol(n *onet.TreeNodeInstance) (onet.ProtocolInstance, e return nil, errors.New("couldn't register length channel: " + err.Error()) } - // default timeout - pap.Timeout = 10 * time.Minute - return pap, nil } @@ -235,10 +231,15 @@ func (p *KeySwitchingProtocol) Dispatch() error { // Announce forwarding down the tree. func (p *KeySwitchingProtocol) announcementKSPhase() (kyber.Point, []kyber.Point, error) { + timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) + if err != nil { + timeout = libunlynx.TIMEOUT + } + var dataReferenceMessage DownBytesStruct select { case dataReferenceMessage = <-p.DownChannel: - case <-time.After(p.Timeout): + case <-time.After(timeout): return nil, nil, errors.New(p.ServerIdentity().String() + "didn't get the on time.") } diff --git a/protocols/shuffling+ddt_protocol.go b/protocols/shuffling+ddt_protocol.go index 0b3abe9..1344788 100644 --- a/protocols/shuffling+ddt_protocol.go +++ b/protocols/shuffling+ddt_protocol.go @@ -2,6 +2,7 @@ package protocolsunlynx import ( "errors" + "os" "sync" "time" @@ -82,8 +83,6 @@ type ShufflingPlusDDTProtocol struct { // Proofs Proofs bool - - Timeout time.Duration } // NewShufflingPlusDDTProtocol constructs neff shuffle + ddt protocol instance. @@ -109,10 +108,6 @@ func NewShufflingPlusDDTProtocol(n *onet.TreeNodeInstance) (onet.ProtocolInstanc break } } - - // default timeout - pi.Timeout = 10 * time.Minute - return pi, nil } @@ -159,23 +154,28 @@ func (p *ShufflingPlusDDTProtocol) Start() error { func (p *ShufflingPlusDDTProtocol) Dispatch() error { defer p.Done() + timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) + if err != nil { + timeout = libunlynx.TIMEOUT + } + var shufflingPlusDDTBytesMessageLength shufflingPlusDDTBytesLengthStruct select { case shufflingPlusDDTBytesMessageLength = <-p.LengthNodeChannel: - case <-time.After(p.Timeout): + case <-time.After(timeout): return errors.New(p.ServerIdentity().String() + "didn't get the on time.") } var tmp shufflingPlusDDTBytesStruct select { case tmp = <-p.PreviousNodeInPathChannel: - case <-time.After(p.Timeout): + case <-time.After(timeout): return errors.New(p.ServerIdentity().String() + "didn't get the on time.") } readData := libunlynx.StartTimer(p.Name() + "_ShufflingPlusDDT(ReadData)") sm := ShufflingPlusDDTMessage{} - err := sm.FromBytes(tmp.Data, tmp.ShuffKey, shufflingPlusDDTBytesMessageLength.CVLengths) + err = sm.FromBytes(tmp.Data, tmp.ShuffKey, shufflingPlusDDTBytesMessageLength.CVLengths) if err != nil { return err } diff --git a/protocols/shuffling_protocol.go b/protocols/shuffling_protocol.go index 7973c7c..cf548f7 100644 --- a/protocols/shuffling_protocol.go +++ b/protocols/shuffling_protocol.go @@ -5,6 +5,7 @@ package protocolsunlynx import ( "errors" + "os" "time" "github.com/ldsec/unlynx/lib" @@ -91,8 +92,6 @@ type ShufflingProtocol struct { CollectiveKey kyber.Point ExecTimeStart time.Duration ExecTime time.Duration - - Timeout time.Duration } // NewShufflingProtocol constructs neff shuffle protocol instances. @@ -119,9 +118,6 @@ func NewShufflingProtocol(n *onet.TreeNodeInstance) (onet.ProtocolInstance, erro } } - // default timeout - dsp.Timeout = 10 * time.Minute - return dsp, nil } @@ -192,17 +188,22 @@ func (p *ShufflingProtocol) Start() error { func (p *ShufflingProtocol) Dispatch() error { defer p.Done() + timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) + if err != nil { + timeout = libunlynx.TIMEOUT + } + var shufflingBytesMessageLength shufflingBytesLengthStruct select { case shufflingBytesMessageLength = <-p.LengthNodeChannel: - case <-time.After(p.Timeout): + case <-time.After(timeout): return errors.New(p.ServerIdentity().String() + "didn't get the on time.") } var tmp shufflingBytesStruct select { case tmp = <-p.PreviousNodeInPathChannel: - case <-time.After(p.Timeout): + case <-time.After(timeout): return errors.New(p.ServerIdentity().String() + "didn't get the on time.") } diff --git a/protocols/utils/addrm_server_protocol.go b/protocols/utils/addrm_server_protocol.go index 90349b3..a83c63a 100644 --- a/protocols/utils/addrm_server_protocol.go +++ b/protocols/utils/addrm_server_protocol.go @@ -5,6 +5,7 @@ package protocolsunlynxutils import ( "errors" + "os" "sync" "time" @@ -39,8 +40,6 @@ type AddRmServerProtocol struct { KeyToRm kyber.Scalar Proofs bool Add bool - - Timeout time.Duration } // NewAddRmProtocol is constructor of add/rm protocol instances. @@ -50,9 +49,6 @@ func NewAddRmProtocol(n *onet.TreeNodeInstance) (onet.ProtocolInstance, error) { FeedbackChannel: make(chan []libunlynx.CipherText), } - // default timeout - pvp.Timeout = 10 * time.Minute - return pvp, nil } @@ -98,10 +94,15 @@ func (p *AddRmServerProtocol) Start() error { func (p *AddRmServerProtocol) Dispatch() error { defer p.Done() + timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) + if err != nil { + timeout = libunlynx.TIMEOUT + } + var finalResultMessage []libunlynx.CipherText select { case finalResultMessage = <-finalResultAddrm: - case <-time.After(p.Timeout): + case <-time.After(timeout): return errors.New(p.ServerIdentity().String() + "didn't get the on time.") } diff --git a/protocols/utils/local_aggregation_protocol.go b/protocols/utils/local_aggregation_protocol.go index c548bae..7de617a 100644 --- a/protocols/utils/local_aggregation_protocol.go +++ b/protocols/utils/local_aggregation_protocol.go @@ -8,6 +8,7 @@ import ( "github.com/ldsec/unlynx/lib/aggregation" "go.dedis.ch/onet/v3" "go.dedis.ch/onet/v3/log" + "os" "time" ) @@ -35,8 +36,6 @@ type LocalAggregationProtocol struct { // Protocol state data TargetOfAggregation []libunlynx.FilteredResponseDet Proofs bool - - Timeout time.Duration } // NewLocalAggregationProtocol is constructor of Local Aggregation protocol instances. @@ -45,10 +44,6 @@ func NewLocalAggregationProtocol(n *onet.TreeNodeInstance) (onet.ProtocolInstanc TreeNodeInstance: n, FeedbackChannel: make(chan map[libunlynx.GroupingKey]libunlynx.FilteredResponse), } - - // default timeout - pvp.Timeout = 10 * time.Minute - return pvp, nil } @@ -90,10 +85,15 @@ func (p *LocalAggregationProtocol) Start() error { func (p *LocalAggregationProtocol) Dispatch() error { defer p.Done() + timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) + if err != nil { + timeout = libunlynx.TIMEOUT + } + var finalResultMessage map[libunlynx.GroupingKey]libunlynx.FilteredResponse select { case finalResultMessage = <-finalResultAggr: - case <-time.After(p.Timeout): + case <-time.After(timeout): return errors.New(p.ServerIdentity().String() + "didn't get the on time.") } diff --git a/protocols/utils/local_clear_aggregation_protocol.go b/protocols/utils/local_clear_aggregation_protocol.go index 66f1fb7..207b6e6 100644 --- a/protocols/utils/local_clear_aggregation_protocol.go +++ b/protocols/utils/local_clear_aggregation_protocol.go @@ -8,6 +8,7 @@ import ( "github.com/ldsec/unlynx/lib/store" "go.dedis.ch/onet/v3" "go.dedis.ch/onet/v3/log" + "os" "time" ) @@ -31,8 +32,6 @@ type LocalClearAggregationProtocol struct { // Protocol state data TargetOfAggregation []libunlynx.DpClearResponse - - Timeout time.Duration } // NewLocalClearAggregationProtocol is constructor of Proofs Verification protocol instances. @@ -41,10 +40,6 @@ func NewLocalClearAggregationProtocol(n *onet.TreeNodeInstance) (onet.ProtocolIn TreeNodeInstance: n, FeedbackChannel: make(chan []libunlynx.DpClearResponse), } - - // default timeout - pvp.Timeout = 10 * time.Minute - return pvp, nil } @@ -64,10 +59,15 @@ func (p *LocalClearAggregationProtocol) Start() error { func (p *LocalClearAggregationProtocol) Dispatch() error { defer p.Done() + timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) + if err != nil { + timeout = libunlynx.TIMEOUT + } + var finalResultMessage []libunlynx.DpClearResponse select { case finalResultMessage = <-finalResultClearAggr: - case <-time.After(p.Timeout): + case <-time.After(timeout): return errors.New(p.ServerIdentity().String() + "didn't get the on time.") } diff --git a/protocols/utils/proofs_verification_protocol.go b/protocols/utils/proofs_verification_protocol.go index e4185d1..b416fc2 100644 --- a/protocols/utils/proofs_verification_protocol.go +++ b/protocols/utils/proofs_verification_protocol.go @@ -13,6 +13,7 @@ import ( "github.com/ldsec/unlynx/lib/shuffle" "go.dedis.ch/onet/v3" "go.dedis.ch/onet/v3/log" + "os" "time" ) @@ -47,8 +48,6 @@ type ProofsVerificationProtocol struct { // Protocol state data TargetOfVerification ProofsToVerify - - Timeout time.Duration } // NewProofsVerificationProtocol is constructor of Proofs Verification protocol instances. @@ -58,9 +57,6 @@ func NewProofsVerificationProtocol(n *onet.TreeNodeInstance) (onet.ProtocolInsta FeedbackChannel: make(chan []bool), } - // default timeout - pvp.Timeout = 10 * time.Minute - return pvp, nil } @@ -114,10 +110,15 @@ func (p *ProofsVerificationProtocol) Start() error { func (p *ProofsVerificationProtocol) Dispatch() error { defer p.Done() + timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) + if err != nil { + timeout = libunlynx.TIMEOUT + } + var finalResultMessage []bool select { case finalResultMessage = <-finalResult: - case <-time.After(p.Timeout): + case <-time.After(timeout): return errors.New(p.ServerIdentity().String() + "didn't get the on time.") } diff --git a/services/service.go b/services/service.go index b824635..fb1025d 100644 --- a/services/service.go +++ b/services/service.go @@ -2,6 +2,7 @@ package servicesunlynx import ( "errors" + "os" "strconv" "time" @@ -89,14 +90,8 @@ func init() { network.RegisterMessage(&SurveyResponseQuery{}) network.RegisterMessage(&ServiceState{}) network.RegisterMessage(&ServiceResult{}) - - // Default timeout just for all tests to work - TimeoutService = 20 * time.Minute } -// TimeoutService is the communication idle timeout -var TimeoutService time.Duration - // QueryBroadcastFinished is used to ensure that all servers have received the query/survey type QueryBroadcastFinished struct { SurveyID SurveyID @@ -133,9 +128,6 @@ type ServiceResult struct { // Service defines a service in unlynx with a survey. type Service struct { *onet.ServiceProcessor - - Timeout time.Duration - Survey *concurrent.ConcurrentMap } @@ -158,7 +150,6 @@ func (s *Service) putSurvey(sid SurveyID, surv Survey) error { // NewService constructor which registers the needed messages. func NewService(c *onet.Context) (onet.Service, error) { newUnLynxInstance := &Service{ - Timeout: TimeoutService, ServiceProcessor: onet.NewServiceProcessor(c), Survey: concurrent.NewConcurrentMap(), } @@ -724,6 +715,11 @@ func (s *Service) StartService(targetSurvey SurveyID, root bool) error { // ShufflingPhase performs the shuffling of the ClientResponses func (s *Service) ShufflingPhase(targetSurvey SurveyID) error { + timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) + if err != nil { + timeout = libunlynx.TIMEOUT + } + survey, err := s.getSurvey(targetSurvey) if err != nil { return err @@ -742,7 +738,7 @@ func (s *Service) ShufflingPhase(targetSurvey SurveyID) error { var tmpShufflingResult []libunlynx.CipherVector select { case tmpShufflingResult = <-pi.(*protocolsunlynx.ShufflingProtocol).FeedbackChannel: - case <-time.After(s.Timeout): + case <-time.After(timeout): return errors.New(s.ServerIdentity().String() + "didn't get the on time.") } @@ -759,6 +755,11 @@ func (s *Service) ShufflingPhase(targetSurvey SurveyID) error { // TaggingPhase performs the private grouping on the currently collected data. func (s *Service) TaggingPhase(targetSurvey SurveyID) error { + timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) + if err != nil { + timeout = libunlynx.TIMEOUT + } + survey, err := s.getSurvey(targetSurvey) if err != nil { return err @@ -777,7 +778,7 @@ func (s *Service) TaggingPhase(targetSurvey SurveyID) error { var tmpDeterministicTaggingResult []libunlynx.DeterministCipherText select { case tmpDeterministicTaggingResult = <-pi.(*protocolsunlynx.DeterministicTaggingProtocol).FeedbackChannel: - case <-time.After(s.Timeout): + case <-time.After(timeout): return errors.New(s.ServerIdentity().String() + "didn't get the on time.") } @@ -808,6 +809,11 @@ func (s *Service) TaggingPhase(targetSurvey SurveyID) error { // AggregationPhase performs the per-group aggregation on the currently grouped data. func (s *Service) AggregationPhase(targetSurvey SurveyID) error { + timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) + if err != nil { + timeout = libunlynx.TIMEOUT + } + pi, err := s.StartProtocol(protocolsunlynx.CollectiveAggregationProtocolName, targetSurvey) if err != nil { return err @@ -816,7 +822,7 @@ func (s *Service) AggregationPhase(targetSurvey SurveyID) error { var cothorityAggregatedData protocolsunlynx.CothorityAggregatedData select { case cothorityAggregatedData = <-pi.(*protocolsunlynx.CollectiveAggregationProtocol).FeedbackChannel: - case <-time.After(s.Timeout): + case <-time.After(timeout): return errors.New(s.ServerIdentity().String() + "didn't get the on time.") } @@ -832,6 +838,11 @@ func (s *Service) AggregationPhase(targetSurvey SurveyID) error { // DROPhase shuffles the list of noise values. func (s *Service) DROPhase(targetSurvey SurveyID) error { + timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) + if err != nil { + timeout = libunlynx.TIMEOUT + } + pi, err := s.StartProtocol(protocolsunlynx.DROProtocolName, targetSurvey) if err != nil { return err @@ -845,7 +856,7 @@ func (s *Service) DROPhase(targetSurvey SurveyID) error { var tmpShufflingResult []libunlynx.CipherVector select { case tmpShufflingResult = <-pi.(*protocolsunlynx.ShufflingProtocol).FeedbackChannel: - case <-time.After(s.Timeout): + case <-time.After(timeout): return errors.New(s.ServerIdentity().String() + "didn't get the on time.") } @@ -858,6 +869,11 @@ func (s *Service) DROPhase(targetSurvey SurveyID) error { // KeySwitchingPhase performs the switch to the querier's key on the currently aggregated data. func (s *Service) KeySwitchingPhase(targetSurvey SurveyID) error { + timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) + if err != nil { + timeout = libunlynx.TIMEOUT + } + pi, err := s.StartProtocol(protocolsunlynx.KeySwitchingProtocolName, targetSurvey) if err != nil { return err @@ -871,7 +887,7 @@ func (s *Service) KeySwitchingPhase(targetSurvey SurveyID) error { var tmpKeySwitchedAggregatedResponses libunlynx.CipherVector select { case tmpKeySwitchedAggregatedResponses = <-pi.(*protocolsunlynx.KeySwitchingProtocol).FeedbackChannel: - case <-time.After(s.Timeout): + case <-time.After(timeout): return errors.New(s.ServerIdentity().String() + "didn't get the on time.") } From abbe27769c1ffc5db7bdd955be5218ec7e7a32ed Mon Sep 17 00:00:00 2001 From: Joao Sa Sousa Date: Wed, 11 Mar 2020 14:09:38 +0100 Subject: [PATCH 08/22] Added init() for timeout --- lib/constants.go | 8 +++++ protocols/collective_aggregation_protocol.go | 8 +---- protocols/deterministic_tagging_protocol.go | 12 ++----- protocols/key_switching_protocol.go | 8 +---- protocols/shuffling+ddt_protocol.go | 9 ++--- protocols/shuffling_protocol.go | 10 ++---- protocols/utils/addrm_server_protocol.go | 8 +---- protocols/utils/local_aggregation_protocol.go | 8 +---- .../utils/local_clear_aggregation_protocol.go | 8 +---- .../utils/proofs_verification_protocol.go | 8 +---- services/service.go | 36 +++---------------- simul/addrm_server_simul.go | 4 +-- simul/local_aggregation_simul.go | 4 +-- simul/local_clear_aggregation_simul.go | 5 ++- simul/proofs_verification_simul.go | 4 +-- 15 files changed, 31 insertions(+), 109 deletions(-) diff --git a/lib/constants.go b/lib/constants.go index aa5edf8..b317c23 100644 --- a/lib/constants.go +++ b/lib/constants.go @@ -1,12 +1,20 @@ package libunlynx import ( + "os" "sync" "time" "go.dedis.ch/onet/v3/simul/monitor" ) +func init() { + tmp, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) + if err != nil { + TIMEOUT = tmp + } +} + // Global Variables //______________________________________________________________________________________________________________________ diff --git a/protocols/collective_aggregation_protocol.go b/protocols/collective_aggregation_protocol.go index 0524511..f8a79ba 100644 --- a/protocols/collective_aggregation_protocol.go +++ b/protocols/collective_aggregation_protocol.go @@ -9,7 +9,6 @@ package protocolsunlynx import ( "errors" - "os" "sync" "time" @@ -197,11 +196,6 @@ func (p *CollectiveAggregationProtocol) Dispatch() error { // Announce forwarding down the tree. func (p *CollectiveAggregationProtocol) aggregationAnnouncementPhase() error { - timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) - if err != nil { - timeout = libunlynx.TIMEOUT - } - select { case dataReferenceMessage := <-p.DataReferenceChannel: if !p.IsLeaf() { @@ -209,7 +203,7 @@ func (p *CollectiveAggregationProtocol) aggregationAnnouncementPhase() error { return errors.New("Error sending :" + err.Error()) } } - case <-time.After(timeout): + case <-time.After(libunlynx.TIMEOUT): return errors.New(p.ServerIdentity().String() + "didn't get the on time.") } return nil diff --git a/protocols/deterministic_tagging_protocol.go b/protocols/deterministic_tagging_protocol.go index 854d40f..143d088 100644 --- a/protocols/deterministic_tagging_protocol.go +++ b/protocols/deterministic_tagging_protocol.go @@ -8,7 +8,6 @@ package protocolsunlynx import ( "errors" - "os" "sync" "time" @@ -155,21 +154,16 @@ func (p *DeterministicTaggingProtocol) Start() error { func (p *DeterministicTaggingProtocol) Dispatch() error { defer p.Done() - timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) - if err != nil { - timeout = libunlynx.TIMEOUT - } - //************ ----- first round, add value derivated from ephemeral secret to message ---- ******************** var deterministicTaggingTargetBytesBef deterministicTaggingBytesStruct select { case deterministicTaggingTargetBytesBef = <-p.PreviousNodeInPathChannel: - case <-time.After(timeout): + case <-time.After(libunlynx.TIMEOUT): return errors.New(p.ServerIdentity().String() + "didn't get the (first round) on time.") } deterministicTaggingTargetBef := DeterministicTaggingMessage{Data: make([]libunlynx.CipherText, 0)} - err = deterministicTaggingTargetBef.FromBytes(deterministicTaggingTargetBytesBef.Data) + err := deterministicTaggingTargetBef.FromBytes(deterministicTaggingTargetBytesBef.Data) if err != nil { return err } @@ -217,7 +211,7 @@ func (p *DeterministicTaggingProtocol) Dispatch() error { var deterministicTaggingTargetBytes deterministicTaggingBytesStruct select { case deterministicTaggingTargetBytes = <-p.PreviousNodeInPathChannel: - case <-time.After(timeout): + case <-time.After(libunlynx.TIMEOUT): return errors.New(p.ServerIdentity().String() + "didn't get the (second round) on time.") } diff --git a/protocols/key_switching_protocol.go b/protocols/key_switching_protocol.go index 5755053..0b92137 100644 --- a/protocols/key_switching_protocol.go +++ b/protocols/key_switching_protocol.go @@ -8,7 +8,6 @@ package protocolsunlynx import ( "errors" - "os" "time" "github.com/ldsec/unlynx/lib" @@ -231,15 +230,10 @@ func (p *KeySwitchingProtocol) Dispatch() error { // Announce forwarding down the tree. func (p *KeySwitchingProtocol) announcementKSPhase() (kyber.Point, []kyber.Point, error) { - timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) - if err != nil { - timeout = libunlynx.TIMEOUT - } - var dataReferenceMessage DownBytesStruct select { case dataReferenceMessage = <-p.DownChannel: - case <-time.After(timeout): + case <-time.After(libunlynx.TIMEOUT): return nil, nil, errors.New(p.ServerIdentity().String() + "didn't get the on time.") } diff --git a/protocols/shuffling+ddt_protocol.go b/protocols/shuffling+ddt_protocol.go index 1344788..827f364 100644 --- a/protocols/shuffling+ddt_protocol.go +++ b/protocols/shuffling+ddt_protocol.go @@ -154,22 +154,17 @@ func (p *ShufflingPlusDDTProtocol) Start() error { func (p *ShufflingPlusDDTProtocol) Dispatch() error { defer p.Done() - timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) - if err != nil { - timeout = libunlynx.TIMEOUT - } - var shufflingPlusDDTBytesMessageLength shufflingPlusDDTBytesLengthStruct select { case shufflingPlusDDTBytesMessageLength = <-p.LengthNodeChannel: - case <-time.After(timeout): + case <-time.After(libunlynx.TIMEOUT): return errors.New(p.ServerIdentity().String() + "didn't get the on time.") } var tmp shufflingPlusDDTBytesStruct select { case tmp = <-p.PreviousNodeInPathChannel: - case <-time.After(timeout): + case <-time.After(libunlynx.TIMEOUT): return errors.New(p.ServerIdentity().String() + "didn't get the on time.") } diff --git a/protocols/shuffling_protocol.go b/protocols/shuffling_protocol.go index cf548f7..7432589 100644 --- a/protocols/shuffling_protocol.go +++ b/protocols/shuffling_protocol.go @@ -5,7 +5,6 @@ package protocolsunlynx import ( "errors" - "os" "time" "github.com/ldsec/unlynx/lib" @@ -188,22 +187,17 @@ func (p *ShufflingProtocol) Start() error { func (p *ShufflingProtocol) Dispatch() error { defer p.Done() - timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) - if err != nil { - timeout = libunlynx.TIMEOUT - } - var shufflingBytesMessageLength shufflingBytesLengthStruct select { case shufflingBytesMessageLength = <-p.LengthNodeChannel: - case <-time.After(timeout): + case <-time.After(libunlynx.TIMEOUT): return errors.New(p.ServerIdentity().String() + "didn't get the on time.") } var tmp shufflingBytesStruct select { case tmp = <-p.PreviousNodeInPathChannel: - case <-time.After(timeout): + case <-time.After(libunlynx.TIMEOUT): return errors.New(p.ServerIdentity().String() + "didn't get the on time.") } diff --git a/protocols/utils/addrm_server_protocol.go b/protocols/utils/addrm_server_protocol.go index a83c63a..d3cdbac 100644 --- a/protocols/utils/addrm_server_protocol.go +++ b/protocols/utils/addrm_server_protocol.go @@ -5,7 +5,6 @@ package protocolsunlynxutils import ( "errors" - "os" "sync" "time" @@ -94,15 +93,10 @@ func (p *AddRmServerProtocol) Start() error { func (p *AddRmServerProtocol) Dispatch() error { defer p.Done() - timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) - if err != nil { - timeout = libunlynx.TIMEOUT - } - var finalResultMessage []libunlynx.CipherText select { case finalResultMessage = <-finalResultAddrm: - case <-time.After(timeout): + case <-time.After(libunlynx.TIMEOUT): return errors.New(p.ServerIdentity().String() + "didn't get the on time.") } diff --git a/protocols/utils/local_aggregation_protocol.go b/protocols/utils/local_aggregation_protocol.go index 7de617a..dc86a1c 100644 --- a/protocols/utils/local_aggregation_protocol.go +++ b/protocols/utils/local_aggregation_protocol.go @@ -8,7 +8,6 @@ import ( "github.com/ldsec/unlynx/lib/aggregation" "go.dedis.ch/onet/v3" "go.dedis.ch/onet/v3/log" - "os" "time" ) @@ -85,15 +84,10 @@ func (p *LocalAggregationProtocol) Start() error { func (p *LocalAggregationProtocol) Dispatch() error { defer p.Done() - timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) - if err != nil { - timeout = libunlynx.TIMEOUT - } - var finalResultMessage map[libunlynx.GroupingKey]libunlynx.FilteredResponse select { case finalResultMessage = <-finalResultAggr: - case <-time.After(timeout): + case <-time.After(libunlynx.TIMEOUT): return errors.New(p.ServerIdentity().String() + "didn't get the on time.") } diff --git a/protocols/utils/local_clear_aggregation_protocol.go b/protocols/utils/local_clear_aggregation_protocol.go index 207b6e6..173b89c 100644 --- a/protocols/utils/local_clear_aggregation_protocol.go +++ b/protocols/utils/local_clear_aggregation_protocol.go @@ -8,7 +8,6 @@ import ( "github.com/ldsec/unlynx/lib/store" "go.dedis.ch/onet/v3" "go.dedis.ch/onet/v3/log" - "os" "time" ) @@ -59,15 +58,10 @@ func (p *LocalClearAggregationProtocol) Start() error { func (p *LocalClearAggregationProtocol) Dispatch() error { defer p.Done() - timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) - if err != nil { - timeout = libunlynx.TIMEOUT - } - var finalResultMessage []libunlynx.DpClearResponse select { case finalResultMessage = <-finalResultClearAggr: - case <-time.After(timeout): + case <-time.After(libunlynx.TIMEOUT): return errors.New(p.ServerIdentity().String() + "didn't get the on time.") } diff --git a/protocols/utils/proofs_verification_protocol.go b/protocols/utils/proofs_verification_protocol.go index b416fc2..f0c7de5 100644 --- a/protocols/utils/proofs_verification_protocol.go +++ b/protocols/utils/proofs_verification_protocol.go @@ -13,7 +13,6 @@ import ( "github.com/ldsec/unlynx/lib/shuffle" "go.dedis.ch/onet/v3" "go.dedis.ch/onet/v3/log" - "os" "time" ) @@ -110,15 +109,10 @@ func (p *ProofsVerificationProtocol) Start() error { func (p *ProofsVerificationProtocol) Dispatch() error { defer p.Done() - timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) - if err != nil { - timeout = libunlynx.TIMEOUT - } - var finalResultMessage []bool select { case finalResultMessage = <-finalResult: - case <-time.After(timeout): + case <-time.After(libunlynx.TIMEOUT): return errors.New(p.ServerIdentity().String() + "didn't get the on time.") } diff --git a/services/service.go b/services/service.go index fb1025d..c0b709c 100644 --- a/services/service.go +++ b/services/service.go @@ -2,7 +2,6 @@ package servicesunlynx import ( "errors" - "os" "strconv" "time" @@ -715,11 +714,6 @@ func (s *Service) StartService(targetSurvey SurveyID, root bool) error { // ShufflingPhase performs the shuffling of the ClientResponses func (s *Service) ShufflingPhase(targetSurvey SurveyID) error { - timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) - if err != nil { - timeout = libunlynx.TIMEOUT - } - survey, err := s.getSurvey(targetSurvey) if err != nil { return err @@ -738,7 +732,7 @@ func (s *Service) ShufflingPhase(targetSurvey SurveyID) error { var tmpShufflingResult []libunlynx.CipherVector select { case tmpShufflingResult = <-pi.(*protocolsunlynx.ShufflingProtocol).FeedbackChannel: - case <-time.After(timeout): + case <-time.After(libunlynx.TIMEOUT): return errors.New(s.ServerIdentity().String() + "didn't get the on time.") } @@ -755,11 +749,6 @@ func (s *Service) ShufflingPhase(targetSurvey SurveyID) error { // TaggingPhase performs the private grouping on the currently collected data. func (s *Service) TaggingPhase(targetSurvey SurveyID) error { - timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) - if err != nil { - timeout = libunlynx.TIMEOUT - } - survey, err := s.getSurvey(targetSurvey) if err != nil { return err @@ -778,7 +767,7 @@ func (s *Service) TaggingPhase(targetSurvey SurveyID) error { var tmpDeterministicTaggingResult []libunlynx.DeterministCipherText select { case tmpDeterministicTaggingResult = <-pi.(*protocolsunlynx.DeterministicTaggingProtocol).FeedbackChannel: - case <-time.After(timeout): + case <-time.After(libunlynx.TIMEOUT): return errors.New(s.ServerIdentity().String() + "didn't get the on time.") } @@ -809,11 +798,6 @@ func (s *Service) TaggingPhase(targetSurvey SurveyID) error { // AggregationPhase performs the per-group aggregation on the currently grouped data. func (s *Service) AggregationPhase(targetSurvey SurveyID) error { - timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) - if err != nil { - timeout = libunlynx.TIMEOUT - } - pi, err := s.StartProtocol(protocolsunlynx.CollectiveAggregationProtocolName, targetSurvey) if err != nil { return err @@ -822,7 +806,7 @@ func (s *Service) AggregationPhase(targetSurvey SurveyID) error { var cothorityAggregatedData protocolsunlynx.CothorityAggregatedData select { case cothorityAggregatedData = <-pi.(*protocolsunlynx.CollectiveAggregationProtocol).FeedbackChannel: - case <-time.After(timeout): + case <-time.After(libunlynx.TIMEOUT): return errors.New(s.ServerIdentity().String() + "didn't get the on time.") } @@ -838,11 +822,6 @@ func (s *Service) AggregationPhase(targetSurvey SurveyID) error { // DROPhase shuffles the list of noise values. func (s *Service) DROPhase(targetSurvey SurveyID) error { - timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) - if err != nil { - timeout = libunlynx.TIMEOUT - } - pi, err := s.StartProtocol(protocolsunlynx.DROProtocolName, targetSurvey) if err != nil { return err @@ -856,7 +835,7 @@ func (s *Service) DROPhase(targetSurvey SurveyID) error { var tmpShufflingResult []libunlynx.CipherVector select { case tmpShufflingResult = <-pi.(*protocolsunlynx.ShufflingProtocol).FeedbackChannel: - case <-time.After(timeout): + case <-time.After(libunlynx.TIMEOUT): return errors.New(s.ServerIdentity().String() + "didn't get the on time.") } @@ -869,11 +848,6 @@ func (s *Service) DROPhase(targetSurvey SurveyID) error { // KeySwitchingPhase performs the switch to the querier's key on the currently aggregated data. func (s *Service) KeySwitchingPhase(targetSurvey SurveyID) error { - timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) - if err != nil { - timeout = libunlynx.TIMEOUT - } - pi, err := s.StartProtocol(protocolsunlynx.KeySwitchingProtocolName, targetSurvey) if err != nil { return err @@ -887,7 +861,7 @@ func (s *Service) KeySwitchingPhase(targetSurvey SurveyID) error { var tmpKeySwitchedAggregatedResponses libunlynx.CipherVector select { case tmpKeySwitchedAggregatedResponses = <-pi.(*protocolsunlynx.KeySwitchingProtocol).FeedbackChannel: - case <-time.After(timeout): + case <-time.After(libunlynx.TIMEOUT): return errors.New(s.ServerIdentity().String() + "didn't get the on time.") } diff --git a/simul/addrm_server_simul.go b/simul/addrm_server_simul.go index d70d174..78e96fa 100644 --- a/simul/addrm_server_simul.go +++ b/simul/addrm_server_simul.go @@ -53,8 +53,6 @@ func (sim *AddRmSimulation) Setup(dir string, hosts []string) (*onet.SimulationC // Run starts the simulation. func (sim *AddRmSimulation) Run(config *onet.SimulationConfig) error { - timeout := 10 * time.Minute - for round := 0; round < sim.Rounds; round++ { log.Lvl1("Starting round", round) @@ -92,7 +90,7 @@ func (sim *AddRmSimulation) Run(config *onet.SimulationConfig) error { case results := <-root.ProtocolInstance().(*protocolsunlynxutils.AddRmServerProtocol).FeedbackChannel: log.Lvl1("Number of aggregated lines: ", len(results)) libunlynx.EndTimer(round) - case <-time.After(timeout): + case <-time.After(libunlynx.TIMEOUT): return errors.New("simulation didn't finish in time") } } diff --git a/simul/local_aggregation_simul.go b/simul/local_aggregation_simul.go index 767e16d..ce2af5c 100644 --- a/simul/local_aggregation_simul.go +++ b/simul/local_aggregation_simul.go @@ -56,8 +56,6 @@ func (sim *LocalAggregationSimulation) Setup(dir string, hosts []string) (*onet. // Run starts the simulation. func (sim *LocalAggregationSimulation) Run(config *onet.SimulationConfig) error { - timeout := 10 * time.Minute - for round := 0; round < sim.Rounds; round++ { log.Lvl1("Starting round", round) rooti, err := config.Overlay.CreateProtocol("LocalAggregation", config.Tree, onet.NilServiceID) @@ -122,7 +120,7 @@ func (sim *LocalAggregationSimulation) Run(config *onet.SimulationConfig) error case results := <-root.ProtocolInstance().(*protocolsunlynxutils.LocalAggregationProtocol).FeedbackChannel: log.Lvl1("Number of aggregated lines: ", len(results)) libunlynx.EndTimer(round) - case <-time.After(timeout): + case <-time.After(libunlynx.TIMEOUT): return errors.New("simulation didn't finish in time") } } diff --git a/simul/local_clear_aggregation_simul.go b/simul/local_clear_aggregation_simul.go index cce609d..9c685e6 100644 --- a/simul/local_clear_aggregation_simul.go +++ b/simul/local_clear_aggregation_simul.go @@ -4,6 +4,7 @@ import ( "errors" "github.com/BurntSushi/toml" "github.com/ldsec/unlynx/data" + libunlynx "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/protocols/utils" "go.dedis.ch/onet/v3" "go.dedis.ch/onet/v3/log" @@ -56,8 +57,6 @@ func (sim *LocalClearAggregationSimulation) Setup(dir string, hosts []string) (* // Run starts the simulation. func (sim *LocalClearAggregationSimulation) Run(config *onet.SimulationConfig) error { - timeout := 10 * time.Minute - for round := 0; round < sim.Rounds; round++ { log.Lvl1("Starting round", round) rooti, err := config.Overlay.CreateProtocol("LocalClearAggregation", config.Tree, onet.NilServiceID) @@ -98,7 +97,7 @@ func (sim *LocalClearAggregationSimulation) Run(config *onet.SimulationConfig) e log.Lvl1("Result is wrong! :(") } round.Record() - case <-time.After(timeout): + case <-time.After(libunlynx.TIMEOUT): return errors.New("simulation didn't finish in time") } } diff --git a/simul/proofs_verification_simul.go b/simul/proofs_verification_simul.go index d698ea7..f9baab9 100644 --- a/simul/proofs_verification_simul.go +++ b/simul/proofs_verification_simul.go @@ -56,8 +56,6 @@ func (sim *ProofsVerificationSimulation) Setup(dir string, hosts []string) (*one // Run starts the simulation. func (sim *ProofsVerificationSimulation) Run(config *onet.SimulationConfig) error { - timeout := 10 * time.Minute - for round := 0; round < sim.Rounds; round++ { log.Lvl1("Starting round", round) rooti, err := config.Overlay.CreateProtocol("ProofsVerification", config.Tree, onet.NilServiceID) @@ -252,7 +250,7 @@ func (sim *ProofsVerificationSimulation) Run(config *onet.SimulationConfig) erro } else if results[5] == false { return errors.New("collective aggregation proofs failed") } - case <-time.After(timeout): + case <-time.After(libunlynx.TIMEOUT): return errors.New("simulation didn't finish in time") } } From 3a7f3392f39de29f5813e8bc755d2580344ee2cf Mon Sep 17 00:00:00 2001 From: Joao Sa Sousa Date: Wed, 11 Mar 2020 14:33:00 +0100 Subject: [PATCH 09/22] Fixed init() in constants.go mistake in condition --- go.mod | 4 ++-- lib/constants.go | 2 +- protocols/collective_aggregation_protocol.go | 2 +- protocols/deterministic_tagging_protocol.go | 4 ++-- protocols/key_switching_protocol.go | 2 +- protocols/shuffling+ddt_protocol.go | 7 +++---- protocols/shuffling_protocol.go | 4 ++-- protocols/utils/addrm_server_protocol.go | 2 +- protocols/utils/local_aggregation_protocol.go | 2 +- .../utils/local_clear_aggregation_protocol.go | 2 +- .../utils/proofs_verification_protocol.go | 2 +- services/service.go | 18 ++++++++---------- 12 files changed, 24 insertions(+), 27 deletions(-) diff --git a/go.mod b/go.mod index 1288c1b..619136d 100644 --- a/go.mod +++ b/go.mod @@ -14,10 +14,10 @@ require ( github.com/stretchr/testify v1.4.0 github.com/urfave/cli v1.22.3 go.dedis.ch/kyber/v3 v3.0.12 - go.dedis.ch/onet/v3 v3.1.0 + go.dedis.ch/onet/v3 v3.1.1 golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 // indirect golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 // indirect - golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect + golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 ) //replace go.dedis.ch/onet/v3 => ../../../go.dedis.ch/onet diff --git a/lib/constants.go b/lib/constants.go index b317c23..0f0b23b 100644 --- a/lib/constants.go +++ b/lib/constants.go @@ -10,7 +10,7 @@ import ( func init() { tmp, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) - if err != nil { + if err == nil { TIMEOUT = tmp } } diff --git a/protocols/collective_aggregation_protocol.go b/protocols/collective_aggregation_protocol.go index f8a79ba..c53fd7d 100644 --- a/protocols/collective_aggregation_protocol.go +++ b/protocols/collective_aggregation_protocol.go @@ -204,7 +204,7 @@ func (p *CollectiveAggregationProtocol) aggregationAnnouncementPhase() error { } } case <-time.After(libunlynx.TIMEOUT): - return errors.New(p.ServerIdentity().String() + "didn't get the on time.") + return errors.New(p.ServerIdentity().String() + " didn't get the on time.") } return nil } diff --git a/protocols/deterministic_tagging_protocol.go b/protocols/deterministic_tagging_protocol.go index 143d088..b70d78b 100644 --- a/protocols/deterministic_tagging_protocol.go +++ b/protocols/deterministic_tagging_protocol.go @@ -159,7 +159,7 @@ func (p *DeterministicTaggingProtocol) Dispatch() error { select { case deterministicTaggingTargetBytesBef = <-p.PreviousNodeInPathChannel: case <-time.After(libunlynx.TIMEOUT): - return errors.New(p.ServerIdentity().String() + "didn't get the (first round) on time.") + return errors.New(p.ServerIdentity().String() + " didn't get the (first round) on time.") } deterministicTaggingTargetBef := DeterministicTaggingMessage{Data: make([]libunlynx.CipherText, 0)} @@ -212,7 +212,7 @@ func (p *DeterministicTaggingProtocol) Dispatch() error { select { case deterministicTaggingTargetBytes = <-p.PreviousNodeInPathChannel: case <-time.After(libunlynx.TIMEOUT): - return errors.New(p.ServerIdentity().String() + "didn't get the (second round) on time.") + return errors.New(p.ServerIdentity().String() + " didn't get the (second round) on time.") } deterministicTaggingTarget := DeterministicTaggingMessage{Data: make([]libunlynx.CipherText, 0)} diff --git a/protocols/key_switching_protocol.go b/protocols/key_switching_protocol.go index 0b92137..7230808 100644 --- a/protocols/key_switching_protocol.go +++ b/protocols/key_switching_protocol.go @@ -234,7 +234,7 @@ func (p *KeySwitchingProtocol) announcementKSPhase() (kyber.Point, []kyber.Point select { case dataReferenceMessage = <-p.DownChannel: case <-time.After(libunlynx.TIMEOUT): - return nil, nil, errors.New(p.ServerIdentity().String() + "didn't get the on time.") + return nil, nil, errors.New(p.ServerIdentity().String() + " didn't get the on time.") } if !p.IsLeaf() { diff --git a/protocols/shuffling+ddt_protocol.go b/protocols/shuffling+ddt_protocol.go index 827f364..8966dea 100644 --- a/protocols/shuffling+ddt_protocol.go +++ b/protocols/shuffling+ddt_protocol.go @@ -2,7 +2,6 @@ package protocolsunlynx import ( "errors" - "os" "sync" "time" @@ -158,19 +157,19 @@ func (p *ShufflingPlusDDTProtocol) Dispatch() error { select { case shufflingPlusDDTBytesMessageLength = <-p.LengthNodeChannel: case <-time.After(libunlynx.TIMEOUT): - return errors.New(p.ServerIdentity().String() + "didn't get the on time.") + return errors.New(p.ServerIdentity().String() + " didn't get the on time.") } var tmp shufflingPlusDDTBytesStruct select { case tmp = <-p.PreviousNodeInPathChannel: case <-time.After(libunlynx.TIMEOUT): - return errors.New(p.ServerIdentity().String() + "didn't get the on time.") + return errors.New(p.ServerIdentity().String() + " didn't get the on time.") } readData := libunlynx.StartTimer(p.Name() + "_ShufflingPlusDDT(ReadData)") sm := ShufflingPlusDDTMessage{} - err = sm.FromBytes(tmp.Data, tmp.ShuffKey, shufflingPlusDDTBytesMessageLength.CVLengths) + err := sm.FromBytes(tmp.Data, tmp.ShuffKey, shufflingPlusDDTBytesMessageLength.CVLengths) if err != nil { return err } diff --git a/protocols/shuffling_protocol.go b/protocols/shuffling_protocol.go index 7432589..245def7 100644 --- a/protocols/shuffling_protocol.go +++ b/protocols/shuffling_protocol.go @@ -191,14 +191,14 @@ func (p *ShufflingProtocol) Dispatch() error { select { case shufflingBytesMessageLength = <-p.LengthNodeChannel: case <-time.After(libunlynx.TIMEOUT): - return errors.New(p.ServerIdentity().String() + "didn't get the on time.") + return errors.New(p.ServerIdentity().String() + " didn't get the on time.") } var tmp shufflingBytesStruct select { case tmp = <-p.PreviousNodeInPathChannel: case <-time.After(libunlynx.TIMEOUT): - return errors.New(p.ServerIdentity().String() + "didn't get the on time.") + return errors.New(p.ServerIdentity().String() + " didn't get the on time.") } sm := ShufflingMessage{} diff --git a/protocols/utils/addrm_server_protocol.go b/protocols/utils/addrm_server_protocol.go index d3cdbac..da62a8b 100644 --- a/protocols/utils/addrm_server_protocol.go +++ b/protocols/utils/addrm_server_protocol.go @@ -97,7 +97,7 @@ func (p *AddRmServerProtocol) Dispatch() error { select { case finalResultMessage = <-finalResultAddrm: case <-time.After(libunlynx.TIMEOUT): - return errors.New(p.ServerIdentity().String() + "didn't get the on time.") + return errors.New(p.ServerIdentity().String() + " didn't get the on time.") } p.FeedbackChannel <- finalResultMessage diff --git a/protocols/utils/local_aggregation_protocol.go b/protocols/utils/local_aggregation_protocol.go index dc86a1c..c48870d 100644 --- a/protocols/utils/local_aggregation_protocol.go +++ b/protocols/utils/local_aggregation_protocol.go @@ -88,7 +88,7 @@ func (p *LocalAggregationProtocol) Dispatch() error { select { case finalResultMessage = <-finalResultAggr: case <-time.After(libunlynx.TIMEOUT): - return errors.New(p.ServerIdentity().String() + "didn't get the on time.") + return errors.New(p.ServerIdentity().String() + " didn't get the on time.") } p.FeedbackChannel <- finalResultMessage diff --git a/protocols/utils/local_clear_aggregation_protocol.go b/protocols/utils/local_clear_aggregation_protocol.go index 173b89c..bf5eeb9 100644 --- a/protocols/utils/local_clear_aggregation_protocol.go +++ b/protocols/utils/local_clear_aggregation_protocol.go @@ -62,7 +62,7 @@ func (p *LocalClearAggregationProtocol) Dispatch() error { select { case finalResultMessage = <-finalResultClearAggr: case <-time.After(libunlynx.TIMEOUT): - return errors.New(p.ServerIdentity().String() + "didn't get the on time.") + return errors.New(p.ServerIdentity().String() + " didn't get the on time.") } p.FeedbackChannel <- finalResultMessage diff --git a/protocols/utils/proofs_verification_protocol.go b/protocols/utils/proofs_verification_protocol.go index f0c7de5..64a642e 100644 --- a/protocols/utils/proofs_verification_protocol.go +++ b/protocols/utils/proofs_verification_protocol.go @@ -113,7 +113,7 @@ func (p *ProofsVerificationProtocol) Dispatch() error { select { case finalResultMessage = <-finalResult: case <-time.After(libunlynx.TIMEOUT): - return errors.New(p.ServerIdentity().String() + "didn't get the on time.") + return errors.New(p.ServerIdentity().String() + " didn't get the on time.") } p.FeedbackChannel <- finalResultMessage diff --git a/services/service.go b/services/service.go index c0b709c..a652c59 100644 --- a/services/service.go +++ b/services/service.go @@ -2,6 +2,7 @@ package servicesunlynx import ( "errors" + "golang.org/x/xerrors" "strconv" "time" @@ -416,13 +417,11 @@ func (s *Service) HandleQueryBroadcastFinished(recq *QueryBroadcastFinished) (ne // NewProtocol creates a protocol instance executed by all nodes func (s *Service) NewProtocol(tn *onet.TreeNodeInstance, conf *onet.GenericConfig) (onet.ProtocolInstance, error) { - err := tn.SetConfig(conf) - if err != nil { - return nil, err + if err := tn.SetConfig(conf); err != nil { + return nil, xerrors.Errorf("couldn't set config: %+v", err) } var pi onet.ProtocolInstance - target := SurveyID(string(conf.Data)) survey, err := s.getSurvey(SurveyID(conf.Data)) if err != nil { @@ -580,7 +579,6 @@ func (s *Service) NewProtocol(tn *onet.TreeNodeInstance, conf *onet.GenericConfi default: return nil, errors.New("Service attempts to start an unknown protocol: " + tn.ProtocolName() + ".") } - return pi, nil } @@ -733,7 +731,7 @@ func (s *Service) ShufflingPhase(targetSurvey SurveyID) error { select { case tmpShufflingResult = <-pi.(*protocolsunlynx.ShufflingProtocol).FeedbackChannel: case <-time.After(libunlynx.TIMEOUT): - return errors.New(s.ServerIdentity().String() + "didn't get the on time.") + return errors.New(s.ServerIdentity().String() + " didn't get the on time.") } survey, err = s.getSurvey(targetSurvey) @@ -768,7 +766,7 @@ func (s *Service) TaggingPhase(targetSurvey SurveyID) error { select { case tmpDeterministicTaggingResult = <-pi.(*protocolsunlynx.DeterministicTaggingProtocol).FeedbackChannel: case <-time.After(libunlynx.TIMEOUT): - return errors.New(s.ServerIdentity().String() + "didn't get the on time.") + return errors.New(s.ServerIdentity().String() + " didn't get the on time.") } survey, err = s.getSurvey(targetSurvey) @@ -807,7 +805,7 @@ func (s *Service) AggregationPhase(targetSurvey SurveyID) error { select { case cothorityAggregatedData = <-pi.(*protocolsunlynx.CollectiveAggregationProtocol).FeedbackChannel: case <-time.After(libunlynx.TIMEOUT): - return errors.New(s.ServerIdentity().String() + "didn't get the on time.") + return errors.New(s.ServerIdentity().String() + " didn't get the on time.") } survey, err := s.getSurvey(targetSurvey) @@ -836,7 +834,7 @@ func (s *Service) DROPhase(targetSurvey SurveyID) error { select { case tmpShufflingResult = <-pi.(*protocolsunlynx.ShufflingProtocol).FeedbackChannel: case <-time.After(libunlynx.TIMEOUT): - return errors.New(s.ServerIdentity().String() + "didn't get the on time.") + return errors.New(s.ServerIdentity().String() + " didn't get the on time.") } shufflingResult := protocolsunlynx.MatrixCipherTextToProcessResponse(tmpShufflingResult, survey.Lengths) @@ -862,7 +860,7 @@ func (s *Service) KeySwitchingPhase(targetSurvey SurveyID) error { select { case tmpKeySwitchedAggregatedResponses = <-pi.(*protocolsunlynx.KeySwitchingProtocol).FeedbackChannel: case <-time.After(libunlynx.TIMEOUT): - return errors.New(s.ServerIdentity().String() + "didn't get the on time.") + return errors.New(s.ServerIdentity().String() + " didn't get the on time.") } keySwitchedAggregatedResponses := protocolsunlynx.CipherVectorToFilteredResponse(tmpKeySwitchedAggregatedResponses, survey.Lengths) From 5564657693ffa3d6b4d09a61df152e61f76041b1 Mon Sep 17 00:00:00 2001 From: Joao Sa Sousa Date: Wed, 11 Mar 2020 14:35:15 +0100 Subject: [PATCH 10/22] Added warning while parsing timeout --- lib/constants.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/constants.go b/lib/constants.go index 0f0b23b..6e65ade 100644 --- a/lib/constants.go +++ b/lib/constants.go @@ -1,6 +1,7 @@ package libunlynx import ( + "go.dedis.ch/onet/v3/log" "os" "sync" "time" @@ -12,6 +13,8 @@ func init() { tmp, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) if err == nil { TIMEOUT = tmp + } else { + log.Warn("Couldn't parse MEDCO_TIMEOUT") } } From 3031cdab898e0c513b41b1e4e43ceae542c80d81 Mon Sep 17 00:00:00 2001 From: Joao Sa Sousa Date: Wed, 11 Mar 2020 14:52:54 +0100 Subject: [PATCH 11/22] Removed error condition around tn.SetConfig --- lib/constants.go | 2 +- services/service.go | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/constants.go b/lib/constants.go index 6e65ade..7f3ba19 100644 --- a/lib/constants.go +++ b/lib/constants.go @@ -14,7 +14,7 @@ func init() { if err == nil { TIMEOUT = tmp } else { - log.Warn("Couldn't parse MEDCO_TIMEOUT") + log.Warn("Couldn't parse MEDCO_TIMEOUT, using default value: ", TIMEOUT.String()) } } diff --git a/services/service.go b/services/service.go index a652c59..6c03a81 100644 --- a/services/service.go +++ b/services/service.go @@ -2,7 +2,6 @@ package servicesunlynx import ( "errors" - "golang.org/x/xerrors" "strconv" "time" @@ -417,9 +416,7 @@ func (s *Service) HandleQueryBroadcastFinished(recq *QueryBroadcastFinished) (ne // NewProtocol creates a protocol instance executed by all nodes func (s *Service) NewProtocol(tn *onet.TreeNodeInstance, conf *onet.GenericConfig) (onet.ProtocolInstance, error) { - if err := tn.SetConfig(conf); err != nil { - return nil, xerrors.Errorf("couldn't set config: %+v", err) - } + tn.SetConfig(conf) var pi onet.ProtocolInstance target := SurveyID(string(conf.Data)) From 31c25d5ee254d95b232e04f45f5042c4fd910590 Mon Sep 17 00:00:00 2001 From: Joao Sa Sousa Date: Wed, 11 Mar 2020 17:00:52 +0100 Subject: [PATCH 12/22] Removed unecessary if condition when sending empty structs --- protocols/collective_aggregation_protocol.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/protocols/collective_aggregation_protocol.go b/protocols/collective_aggregation_protocol.go index c53fd7d..9a3f21c 100644 --- a/protocols/collective_aggregation_protocol.go +++ b/protocols/collective_aggregation_protocol.go @@ -136,9 +136,7 @@ func NewCollectiveAggregationProtocol(n *onet.TreeNodeInstance) (onet.ProtocolIn // Start is called at the root to begin the execution of the protocol. func (p *CollectiveAggregationProtocol) Start() error { log.Lvl1(p.ServerIdentity(), " started a Colective Aggregation Protocol") - if err := p.SendToChildren(&DataReferenceMessage{}); err != nil { - return errors.New("Error sending :" + err.Error()) - } + p.SendToChildren(&DataReferenceMessage{}) return nil } @@ -199,9 +197,7 @@ func (p *CollectiveAggregationProtocol) aggregationAnnouncementPhase() error { select { case dataReferenceMessage := <-p.DataReferenceChannel: if !p.IsLeaf() { - if err := p.SendToChildren(&dataReferenceMessage.DataReferenceMessage); err != nil { - return errors.New("Error sending :" + err.Error()) - } + p.SendToChildren(&dataReferenceMessage.DataReferenceMessage) } case <-time.After(libunlynx.TIMEOUT): return errors.New(p.ServerIdentity().String() + " didn't get the on time.") From 8861342c8d2260e2bc3874201077d9a702246602 Mon Sep 17 00:00:00 2001 From: Joao Sa Sousa Date: Wed, 11 Mar 2020 17:35:03 +0100 Subject: [PATCH 13/22] Switched from errors.new to fmt.Errorf --- app/client.go | 16 ++++---- app/unlynx.go | 8 ++-- data/handle_data.go | 5 +-- lib/add_rm/add_rm_proofs.go | 4 +- lib/crypto.go | 29 +++++++------- .../deterministic_tag_proofs.go | 6 +-- lib/key_switch/key_switch_proofs.go | 4 +- lib/shuffle/shuffle_proofs.go | 8 ++-- lib/tools/tools.go | 7 ++-- protocols/collective_aggregation_protocol.go | 18 ++++----- protocols/deterministic_tagging_protocol.go | 14 +++---- protocols/key_switching_protocol.go | 22 +++++----- protocols/shuffling+ddt_protocol.go | 12 +++--- protocols/shuffling_protocol.go | 12 +++--- protocols/tools_protocol.go | 6 +-- protocols/utils/addrm_server_protocol.go | 6 +-- protocols/utils/local_aggregation_protocol.go | 4 +- .../utils/local_clear_aggregation_protocol.go | 4 +- .../utils/proofs_verification_protocol.go | 4 +- services/service.go | 40 +++++++++---------- simul/addrm_server_simul.go | 4 +- simul/collective_aggregation_simul.go | 4 +- simul/deterministic_tagging_simul.go | 4 +- simul/local_aggregation_simul.go | 4 +- simul/local_clear_aggregation_simul.go | 4 +- simul/proofs_verification_simul.go | 16 ++++---- simul/shuffling+ddt_simul.go | 4 +- simul/shuffling_simul.go | 4 +- simul/unlynx_simul.go | 8 ++-- 29 files changed, 139 insertions(+), 142 deletions(-) diff --git a/app/client.go b/app/client.go index 686e916..3fe022a 100644 --- a/app/client.go +++ b/app/client.go @@ -1,7 +1,7 @@ package appunlynx import ( - "errors" + "fmt" "os" "regexp" "strconv" @@ -32,7 +32,7 @@ func startQuery(el *onet.Roster, proofs bool, sum []string, count bool, whereQue grp, aggr, err := client.SendSurveyResultsQuery(*surveyID) if err != nil { - return errors.New("service could not output the results: " + err.Error()) + return fmt.Errorf("service could not output the results: %v", err) } // Print Output @@ -77,7 +77,7 @@ func openGroupToml(tomlFileName string) (*onet.Roster, error) { } if len(el.Roster.List) <= 0 { - return nil, errors.New("empty or invalid unlynx group file:" + tomlFileName) + return nil, fmt.Errorf("empty or invalid unlynx group file: %v", tomlFileName) } return el.Roster, nil @@ -91,7 +91,7 @@ func checkRegex(input, expression string) bool { func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, groupBy string) ([]string, bool, []libunlynx.WhereQueryAttribute, string, []string, error) { if sum == "" || (where != "" && predicate == "") || (where == "" && predicate != "") { - return nil, false, nil, "", nil, errors.New("wrong query! please check the sum, where and the predicate parameters") + return nil, false, nil, "", nil, fmt.Errorf("wrong query! please check the sum, where and the predicate parameters") } sumRegex := "{s[0-9]+(,\\s*s[0-9]+)*}" @@ -99,7 +99,7 @@ func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, group groupByRegex := "{g[0-9]+(,\\s*g[0-9]+)*}" if !checkRegex(sum, sumRegex) { - return nil, false, nil, "", nil, errors.New("error parsing the sum parameter(s)") + return nil, false, nil, "", nil, fmt.Errorf("error parsing the sum parameter(s)") } sum = strings.Replace(sum, " ", "", -1) sum = strings.Replace(sum, "{", "", -1) @@ -115,12 +115,12 @@ func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, group } if !check { - return nil, false, nil, "", nil, errors.New("no 'count' attribute in the sum variables") + return nil, false, nil, "", nil, fmt.Errorf("no 'count' attribute in the sum variables") } } if !checkRegex(where, whereRegex) { - return nil, false, nil, "", nil, errors.New("error parsing the where parameter(s)") + return nil, false, nil, "", nil, fmt.Errorf("error parsing the where parameter(s)") } where = strings.Replace(where, " ", "", -1) where = strings.Replace(where, "{", "", -1) @@ -145,7 +145,7 @@ func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, group } if !checkRegex(groupBy, groupByRegex) { - return nil, false, nil, "", nil, errors.New("error parsing the groupBy parameter(s)") + return nil, false, nil, "", nil, fmt.Errorf("error parsing the groupBy parameter(s)") } groupBy = strings.Replace(groupBy, " ", "", -1) groupBy = strings.Replace(groupBy, "{", "", -1) diff --git a/app/unlynx.go b/app/unlynx.go index 913e24d..3faf968 100644 --- a/app/unlynx.go +++ b/app/unlynx.go @@ -1,7 +1,7 @@ package appunlynx import ( - "errors" + "fmt" "os" "github.com/ldsec/unlynx/lib" @@ -123,7 +123,7 @@ func main() { Usage: "Start unlynx server", Action: func(c *cli.Context) error { if err := runServer(c); err != nil { - return errors.New("error during runServer(): " + err.Error()) + return fmt.Errorf("error during runServer(): %v", err) } return nil }, @@ -135,10 +135,10 @@ func main() { Usage: "Setup server configuration (interactive)", Action: func(c *cli.Context) error { if c.String(optionConfig) != "" { - return errors.New("[-] Configuration file option cannot be used for the 'setup' command") + return fmt.Errorf("[-] configuration file option cannot be used for the 'setup' command") } if c.GlobalIsSet("debug") { - return errors.New("[-] Debug option cannot be used for the 'setup' command") + return fmt.Errorf("[-] debug option cannot be used for the 'setup' command") } app.InteractiveConfig(libunlynx.SuiTe, BinaryName) return nil diff --git a/data/handle_data.go b/data/handle_data.go index ee7d852..913b07f 100644 --- a/data/handle_data.go +++ b/data/handle_data.go @@ -2,7 +2,6 @@ package dataunlynx import ( "bufio" - "errors" "fmt" "math" "math/rand" @@ -78,7 +77,7 @@ func GenerateData(numDPs, numEntries, numEntriesFiltered, numGroupsClear, numGro numWhereClear, numWhereEnc, numAggrClear, numAggrEnc int64, numType []int64, randomGroups bool) (map[string][]libunlynx.DpClearResponse, error) { if int64(len(numType)) != (numGroupsClear + numGroupsEnc) { - return nil, errors.New("specify the correct number of group types for each grouping attribute") + return nil, fmt.Errorf("specify the correct number of group types for each grouping attribute") } testData := make(map[string][]libunlynx.DpClearResponse) @@ -94,7 +93,7 @@ func GenerateData(numDPs, numEntries, numEntriesFiltered, numGroupsClear, numGro group := make([]int64, 0) AllPossibleGroups(numType[:], group, 0, &groups) } else { - return nil, errors.New("the number of groups is different from the number of entries") + return nil, fmt.Errorf("the number of groups is different from the number of entries") } } diff --git a/lib/add_rm/add_rm_proofs.go b/lib/add_rm/add_rm_proofs.go index 1b0c4c5..817cafd 100644 --- a/lib/add_rm/add_rm_proofs.go +++ b/lib/add_rm/add_rm_proofs.go @@ -1,7 +1,7 @@ package libunlynxaddrm import ( - "errors" + "fmt" "math" "sync" @@ -65,7 +65,7 @@ func AddRmProofCreation(cBef, cAft libunlynx.CipherText, K kyber.Point, k kyber. proofTmp, err := proof.HashProve(libunlynx.SuiTe, "proofTest", prover) if err != nil { - return PublishedAddRmProof{}, errors.New("---------Prover:" + err.Error()) + return PublishedAddRmProof{}, fmt.Errorf("---------prover: %v", err) } return PublishedAddRmProof{Proof: proofTmp, CtBef: cBef, CtAft: cAft, RB: rB}, nil diff --git a/lib/crypto.go b/lib/crypto.go index 69306aa..9b85049 100644 --- a/lib/crypto.go +++ b/lib/crypto.go @@ -3,7 +3,6 @@ package libunlynx import ( "encoding" "encoding/base64" - "errors" "fmt" "math/big" "strings" @@ -635,7 +634,7 @@ func (c *CipherText) Serialize() (string, error) { func (c *CipherText) Deserialize(b64Encoded string) error { decoded, err := base64.URLEncoding.DecodeString(b64Encoded) if err != nil { - return errors.New("Invalid CipherText (decoding failed): " + err.Error()) + return fmt.Errorf("invalid ciphertext (decoding failed): %v", err) } err = (*c).FromBytes(decoded) if err != nil { @@ -648,7 +647,7 @@ func (c *CipherText) Deserialize(b64Encoded string) error { func SerializeElement(el encoding.BinaryMarshaler) (string, error) { bytes, err := el.MarshalBinary() if err != nil { - return "", errors.New("Error marshalling element: " + err.Error()) + return "", fmt.Errorf("error marshalling element: %v", err) } return base64.URLEncoding.EncodeToString(bytes), nil } @@ -665,15 +664,15 @@ func SerializeScalar(scalar encoding.BinaryMarshaler) (string, error) { // DeserializePoint deserializes a point using base64 encoding func DeserializePoint(encodedPoint string) (kyber.Point, error) { - decoded, errD := base64.URLEncoding.DecodeString(encodedPoint) - if errD != nil { - return nil, errors.New("Error decoding point: " + errD.Error()) + decoded, err := base64.URLEncoding.DecodeString(encodedPoint) + if err != nil { + return nil, fmt.Errorf("error decoding point: %v", err) } point := SuiTe.Point() - errM := point.UnmarshalBinary(decoded) - if errM != nil { - return nil, errors.New("Error unmarshalling point: " + errM.Error()) + err = point.UnmarshalBinary(decoded) + if err != nil { + return nil, fmt.Errorf("error unmarshalling point: %v", err) } return point, nil @@ -681,15 +680,15 @@ func DeserializePoint(encodedPoint string) (kyber.Point, error) { // DeserializeScalar deserializes a scalar using base64 encoding func DeserializeScalar(encodedScalar string) (kyber.Scalar, error) { - decoded, errD := base64.URLEncoding.DecodeString(encodedScalar) - if errD != nil { - return nil, errors.New("Error decoding scalar: " + errD.Error()) + decoded, err := base64.URLEncoding.DecodeString(encodedScalar) + if err != nil { + return nil, fmt.Errorf("error decoding scalar: %v", err) } scalar := SuiTe.Scalar() - errM := scalar.UnmarshalBinary(decoded) - if errM != nil { - return nil, errors.New("Error unmarshalling scalar: " + errM.Error()) + err = scalar.UnmarshalBinary(decoded) + if err != nil { + return nil, fmt.Errorf("error unmarshalling scalar: %v", err) } return scalar, nil diff --git a/lib/deterministic_tag/deterministic_tag_proofs.go b/lib/deterministic_tag/deterministic_tag_proofs.go index 81822a2..09bea34 100644 --- a/lib/deterministic_tag/deterministic_tag_proofs.go +++ b/lib/deterministic_tag/deterministic_tag_proofs.go @@ -1,7 +1,7 @@ package libunlynxdetertag import ( - "errors" + "fmt" "math" "reflect" "sync" @@ -82,7 +82,7 @@ func DeterministicTagCrProofCreation(ctBef, ctAft libunlynx.CipherText, K kyber. prover := predicate.Prover(libunlynx.SuiTe, sval, pval, nil) // computes: commitment, challenge, response Proof, err := proof.HashProve(libunlynx.SuiTe, "proofTest", prover) if err != nil { - return PublishedDDTCreationProof{}, errors.New("---------Prover: " + err.Error()) + return PublishedDDTCreationProof{}, fmt.Errorf("---------prover: %v", err) } return PublishedDDTCreationProof{Proof: Proof, Ciminus11Si: ciminus11Si, CTbef: ctBef, CTaft: ctAft}, nil @@ -191,7 +191,7 @@ func DeterministicTagAdditionProofCreation(c1 kyber.Point, s kyber.Scalar, c2 ky prover := predicate.Prover(libunlynx.SuiTe, sval, pval, nil) // computes: commitment, challenge, response Proof, err := proof.HashProve(libunlynx.SuiTe, "proofTest", prover) if err != nil { - return PublishedDDTAdditionProof{}, errors.New("---------Prover: " + err.Error()) + return PublishedDDTAdditionProof{}, fmt.Errorf("---------prover: %v", err) } return PublishedDDTAdditionProof{Proof: Proof, C1: c1, C2: c2, R: r}, nil diff --git a/lib/key_switch/key_switch_proofs.go b/lib/key_switch/key_switch_proofs.go index 3f03845..ff5ae54 100644 --- a/lib/key_switch/key_switch_proofs.go +++ b/lib/key_switch/key_switch_proofs.go @@ -1,7 +1,7 @@ package libunlynxkeyswitch import ( - "errors" + "fmt" "math" "sync" @@ -68,7 +68,7 @@ func KeySwitchProofCreation(K, Q kyber.Point, k kyber.Scalar, viB, ks2, rBNeg ky prover := predicate.Prover(libunlynx.SuiTe, sval, pval, nil) // computes: commitment, challenge, response proofKS, err := proof.HashProve(libunlynx.SuiTe, "proofTest", prover) if err != nil { - return PublishedKSProof{}, errors.New("---------Prover: " + err.Error()) + return PublishedKSProof{}, fmt.Errorf("---------prover: %v", err) } return PublishedKSProof{Proof: proofKS, K: K, ViB: viB, Ks2: ks2, RbNeg: rBNeg, Q: Q}, nil diff --git a/lib/shuffle/shuffle_proofs.go b/lib/shuffle/shuffle_proofs.go index 956d0af..78be8fa 100644 --- a/lib/shuffle/shuffle_proofs.go +++ b/lib/shuffle/shuffle_proofs.go @@ -1,7 +1,7 @@ package libunlynxshuffle import ( - "errors" + "fmt" "math" "sync" @@ -84,7 +84,7 @@ func ShuffleProofCreation(originalList, shuffledList []libunlynx.CipherVector, g // do k-shuffle of ElGamal on the (Xhat,Yhat) and check it k = len(Xhat) if k != len(Yhat) { - return PublishedShufflingProof{}, errors.New("X,Y vectors have inconsistent lengths") + return PublishedShufflingProof{}, fmt.Errorf("X,Y vectors have inconsistent lengths") } ps := shuffleKyber.PairShuffle{} ps.Init(libunlynx.SuiTe, k) @@ -95,7 +95,7 @@ func ShuffleProofCreation(originalList, shuffledList []libunlynx.CipherVector, g prf, err := proof.HashProve(libunlynx.SuiTe, "PairShuffle", prover) if err != nil { - return PublishedShufflingProof{}, errors.New("Shuffle proof failed: " + err.Error()) + return PublishedShufflingProof{}, fmt.Errorf("shuffle proof failed: %v", err) } return PublishedShufflingProof{originalList, shuffledList, g, h, prf}, nil } @@ -293,7 +293,7 @@ func compressCipherVector(ciphervector libunlynx.CipherVector, e []kyber.Scalar) // check that e and cipher vectors have the same size if len(e) != k { - return libunlynx.CipherText{}, errors.New("e is not the right size") + return libunlynx.CipherText{}, fmt.Errorf("e is not the right size") } ciphertext := *libunlynx.NewCipherText() diff --git a/lib/tools/tools.go b/lib/tools/tools.go index fed6829..0aa8f29 100644 --- a/lib/tools/tools.go +++ b/lib/tools/tools.go @@ -3,7 +3,6 @@ package libunlynxtools import ( "encoding/binary" "encoding/gob" - "errors" "fmt" "os" "strconv" @@ -27,7 +26,7 @@ func SendISMOthers(s *onet.ServiceProcessor, el *onet.Roster, msg interface{}) e } var err error if len(errStrs) > 0 { - err = errors.New(strings.Join(errStrs, "\n")) + err = fmt.Errorf(strings.Join(errStrs, "\n")) } return err } @@ -119,7 +118,7 @@ func WriteToGobFile(path string, object interface{}) error { return err } } else { - return errors.New("Could not write Gob file:" + err.Error()) + return fmt.Errorf("could not write Gob file: %v", err) } return nil @@ -137,7 +136,7 @@ func ReadFromGobFile(path string, object interface{}) error { return err } } else { - return errors.New("Could not read Gob file:" + err.Error()) + return fmt.Errorf("could not read Gob file: %v", err) } return nil diff --git a/protocols/collective_aggregation_protocol.go b/protocols/collective_aggregation_protocol.go index 9a3f21c..3694262 100644 --- a/protocols/collective_aggregation_protocol.go +++ b/protocols/collective_aggregation_protocol.go @@ -8,7 +8,7 @@ package protocolsunlynx import ( - "errors" + "fmt" "sync" "time" @@ -118,16 +118,16 @@ func NewCollectiveAggregationProtocol(n *onet.TreeNodeInstance) (onet.ProtocolIn err := pap.RegisterChannel(&pap.DataReferenceChannel) if err != nil { - return nil, errors.New("couldn't register data reference channel: " + err.Error()) + return nil, fmt.Errorf("couldn't register data reference channel: %v", err) } err = pap.RegisterChannel(&pap.ChildDataChannel) if err != nil { - return nil, errors.New("couldn't register child-data channel: " + err.Error()) + return nil, fmt.Errorf("couldn't register child-data channel: %v", err) } if err := pap.RegisterChannel(&pap.LengthNodeChannel); err != nil { - return nil, errors.New("couldn't register data reference channel: " + err.Error()) + return nil, fmt.Errorf("couldn't register data reference channel: %v", err) } return pap, nil @@ -200,7 +200,7 @@ func (p *CollectiveAggregationProtocol) aggregationAnnouncementPhase() error { p.SendToChildren(&dataReferenceMessage.DataReferenceMessage) } case <-time.After(libunlynx.TIMEOUT): - return errors.New(p.ServerIdentity().String() + " didn't get the on time.") + return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } return nil } @@ -281,10 +281,10 @@ func (p *CollectiveAggregationProtocol) ascendingAggregationPhase(cvMap map[libu } if err := p.SendToParent(&CADBLengthMessage{gacbLength, aabLength, dtbLength}); err != nil { - return nil, errors.New("Error sending :" + err.Error()) + return nil, fmt.Errorf("error sending : %v", err) } if err := p.SendToParent(&message); err != nil { - return nil, errors.New("Error sending :" + err.Error()) + return nil, fmt.Errorf("error sending : %v", err) } } @@ -295,10 +295,10 @@ func (p *CollectiveAggregationProtocol) ascendingAggregationPhase(cvMap map[libu func (p *CollectiveAggregationProtocol) checkData() error { // If no data is passed to the collection protocol if p.GroupedData == nil && p.SimpleData == nil { - return errors.New("no data reference is provided") + return fmt.Errorf("no data reference is provided") // If both data entry points are used } else if p.GroupedData != nil && p.SimpleData != nil { - return errors.New("two data references are given in the struct") + return fmt.Errorf("two data references are given in the struct") // If we are using the GroupedData keep everything as is } else if p.GroupedData != nil { return nil diff --git a/protocols/deterministic_tagging_protocol.go b/protocols/deterministic_tagging_protocol.go index b70d78b..047ed20 100644 --- a/protocols/deterministic_tagging_protocol.go +++ b/protocols/deterministic_tagging_protocol.go @@ -7,7 +7,7 @@ package protocolsunlynx import ( - "errors" + "fmt" "sync" "time" @@ -101,10 +101,10 @@ func NewDeterministicTaggingProtocol(n *onet.TreeNodeInstance) (onet.ProtocolIns } if err := dsp.RegisterChannel(&dsp.PreviousNodeInPathChannel); err != nil { - return nil, errors.New("couldn't register data reference channel: " + err.Error()) + return nil, fmt.Errorf("couldn't register data reference channel: %v", err) } if err := dsp.RegisterChannel(&dsp.LengthNodeChannel); err != nil { - return nil, errors.New("couldn't register data reference channel: " + err.Error()) + return nil, fmt.Errorf("couldn't register data reference channel: %v", err) } var i int @@ -125,10 +125,10 @@ func (p *DeterministicTaggingProtocol) Start() error { roundTotalStart := libunlynx.StartTimer(p.Name() + "_DetTagging(START)") if p.TargetOfSwitch == nil { - return errors.New("no data on which to do a deterministic tagging") + return fmt.Errorf("no data on which to do a deterministic tagging") } if p.SurveySecretKey == nil { - return errors.New("no survey secret key given") + return fmt.Errorf("no survey secret key given") } p.ExecTime = 0 @@ -159,7 +159,7 @@ func (p *DeterministicTaggingProtocol) Dispatch() error { select { case deterministicTaggingTargetBytesBef = <-p.PreviousNodeInPathChannel: case <-time.After(libunlynx.TIMEOUT): - return errors.New(p.ServerIdentity().String() + " didn't get the (first round) on time.") + return fmt.Errorf(p.ServerIdentity().String() + " didn't get the (first round) on time") } deterministicTaggingTargetBef := DeterministicTaggingMessage{Data: make([]libunlynx.CipherText, 0)} @@ -212,7 +212,7 @@ func (p *DeterministicTaggingProtocol) Dispatch() error { select { case deterministicTaggingTargetBytes = <-p.PreviousNodeInPathChannel: case <-time.After(libunlynx.TIMEOUT): - return errors.New(p.ServerIdentity().String() + " didn't get the (second round) on time.") + return fmt.Errorf(p.ServerIdentity().String() + " didn't get the (second round) on time") } deterministicTaggingTarget := DeterministicTaggingMessage{Data: make([]libunlynx.CipherText, 0)} diff --git a/protocols/key_switching_protocol.go b/protocols/key_switching_protocol.go index 7230808..102841b 100644 --- a/protocols/key_switching_protocol.go +++ b/protocols/key_switching_protocol.go @@ -7,7 +7,7 @@ package protocolsunlynx import ( - "errors" + "fmt" "time" "github.com/ldsec/unlynx/lib" @@ -125,16 +125,16 @@ func NewKeySwitchingProtocol(n *onet.TreeNodeInstance) (onet.ProtocolInstance, e err := pap.RegisterChannel(&pap.DownChannel) if err != nil { - return nil, errors.New("couldn't register down channel: " + err.Error()) + return nil, fmt.Errorf("couldn't register down channel: %v", err) } err = pap.RegisterChannel(&pap.ChildDataChannel) if err != nil { - return nil, errors.New("couldn't register child-data channel: " + err.Error()) + return nil, fmt.Errorf("couldn't register child-data channel: %v", err) } if err := pap.RegisterChannel(&pap.LengthChannel); err != nil { - return nil, errors.New("couldn't register length channel: " + err.Error()) + return nil, fmt.Errorf("couldn't register length channel: %v", err) } return pap, nil @@ -146,11 +146,11 @@ func (p *KeySwitchingProtocol) Start() error { keySwitchingStart := libunlynx.StartTimer(p.Name() + "_KeySwitching(START)") if p.TargetOfSwitch == nil { - return errors.New("no ciphertext given as key switching target") + return fmt.Errorf("no ciphertext given as key switching target") } if p.TargetPublicKey == nil { - return errors.New("no new public key to be switched on provided") + return fmt.Errorf("no new public key to be switched on provided") } log.Lvl2("[KEY SWITCHING PROTOCOL] Server", p.ServerIdentity(), " started a Key Switching Protocol") @@ -178,7 +178,7 @@ func (p *KeySwitchingProtocol) Start() error { } if err := p.SendToChildren(&DownMessageBytes{Data: data}); err != nil { - return errors.New("Root " + p.ServerIdentity().String() + " failed to broadcast DownMessageBytes: " + err.Error()) + return fmt.Errorf("Root "+p.ServerIdentity().String()+" failed to broadcast DownMessageBytes: %v", err) } libunlynx.EndTimer(keySwitchingStart) @@ -234,12 +234,12 @@ func (p *KeySwitchingProtocol) announcementKSPhase() (kyber.Point, []kyber.Point select { case dataReferenceMessage = <-p.DownChannel: case <-time.After(libunlynx.TIMEOUT): - return nil, nil, errors.New(p.ServerIdentity().String() + " didn't get the on time.") + return nil, nil, fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } if !p.IsLeaf() { if err := p.SendToChildren(&dataReferenceMessage.DownMessageBytes); err != nil { - return nil, nil, errors.New("Node " + p.ServerIdentity().String() + " failed to broadcast DownMessageBytes: " + err.Error()) + return nil, nil, fmt.Errorf("Node "+p.ServerIdentity().String()+" failed to broadcast DownMessageBytes: %v", err) } } message, err := libunlynx.FromBytesToAbstractPoints(dataReferenceMessage.Data) @@ -282,7 +282,7 @@ func (p *KeySwitchingProtocol) ascendingKSPhase() (*libunlynx.CipherVector, erro if !p.IsRoot() { if err := p.SendToParent(&LengthMessage{Length: libunlynxtools.UnsafeCastIntsToBytes([]int{len(*p.NodeContribution)})}); err != nil { - return nil, errors.New("Node " + p.ServerIdentity().String() + " failed to broadcast LengthMessage ( " + err.Error() + " )") + return nil, fmt.Errorf("Node "+p.ServerIdentity().String()+" failed to broadcast LengthMessage: %v", err) } message, _, err := (*p.NodeContribution).ToBytes() if err != nil { @@ -290,7 +290,7 @@ func (p *KeySwitchingProtocol) ascendingKSPhase() (*libunlynx.CipherVector, erro } if err := p.SendToParent(&UpBytesMessage{Data: message}); err != nil { - return nil, errors.New("Node " + p.ServerIdentity().String() + " failed to broadcast UpBytesMessage: " + err.Error()) + return nil, fmt.Errorf("Node "+p.ServerIdentity().String()+" failed to broadcast UpBytesMessage: %v", err) } } diff --git a/protocols/shuffling+ddt_protocol.go b/protocols/shuffling+ddt_protocol.go index 8966dea..20759fd 100644 --- a/protocols/shuffling+ddt_protocol.go +++ b/protocols/shuffling+ddt_protocol.go @@ -1,7 +1,7 @@ package protocolsunlynx import ( - "errors" + "fmt" "sync" "time" @@ -92,11 +92,11 @@ func NewShufflingPlusDDTProtocol(n *onet.TreeNodeInstance) (onet.ProtocolInstanc } if err := pi.RegisterChannel(&pi.PreviousNodeInPathChannel); err != nil { - return nil, errors.New("couldn't register data reference channel: " + err.Error()) + return nil, fmt.Errorf("couldn't register data reference channel: %v", err) } if err := pi.RegisterChannel(&pi.LengthNodeChannel); err != nil { - return nil, errors.New("couldn't register data reference channel: " + err.Error()) + return nil, fmt.Errorf("couldn't register data reference channel: %v", err) } // choose next node in circuit @@ -114,7 +114,7 @@ func NewShufflingPlusDDTProtocol(n *onet.TreeNodeInstance) (onet.ProtocolInstanc func (p *ShufflingPlusDDTProtocol) Start() error { if p.TargetData == nil { - return errors.New("no data is given") + return fmt.Errorf("no data is given") } nbrSqCVs := len(*p.TargetData) log.Lvl1("["+p.Name()+"]", " started a Shuffling+DDT Protocol (", nbrSqCVs, " responses)") @@ -157,14 +157,14 @@ func (p *ShufflingPlusDDTProtocol) Dispatch() error { select { case shufflingPlusDDTBytesMessageLength = <-p.LengthNodeChannel: case <-time.After(libunlynx.TIMEOUT): - return errors.New(p.ServerIdentity().String() + " didn't get the on time.") + return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } var tmp shufflingPlusDDTBytesStruct select { case tmp = <-p.PreviousNodeInPathChannel: case <-time.After(libunlynx.TIMEOUT): - return errors.New(p.ServerIdentity().String() + " didn't get the on time.") + return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } readData := libunlynx.StartTimer(p.Name() + "_ShufflingPlusDDT(ReadData)") diff --git a/protocols/shuffling_protocol.go b/protocols/shuffling_protocol.go index 245def7..3bc90d2 100644 --- a/protocols/shuffling_protocol.go +++ b/protocols/shuffling_protocol.go @@ -4,7 +4,7 @@ package protocolsunlynx import ( - "errors" + "fmt" "time" "github.com/ldsec/unlynx/lib" @@ -101,11 +101,11 @@ func NewShufflingProtocol(n *onet.TreeNodeInstance) (onet.ProtocolInstance, erro } if err := dsp.RegisterChannel(&dsp.PreviousNodeInPathChannel); err != nil { - return nil, errors.New("couldn't register data reference channel: " + err.Error()) + return nil, fmt.Errorf("couldn't register data reference channel: %v", err) } if err := dsp.RegisterChannel(&dsp.LengthNodeChannel); err != nil { - return nil, errors.New("couldn't register data reference channel: " + err.Error()) + return nil, fmt.Errorf("couldn't register data reference channel: %v", err) } // choose next node in circuit @@ -126,7 +126,7 @@ func (p *ShufflingProtocol) Start() error { shufflingStart := libunlynx.StartTimer(p.Name() + "_Shuffling(START)") if p.ShuffleTarget == nil { - return errors.New("no map given as shuffling target") + return fmt.Errorf("no map given as shuffling target") } p.ExecTimeStart = 0 @@ -191,14 +191,14 @@ func (p *ShufflingProtocol) Dispatch() error { select { case shufflingBytesMessageLength = <-p.LengthNodeChannel: case <-time.After(libunlynx.TIMEOUT): - return errors.New(p.ServerIdentity().String() + " didn't get the on time.") + return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } var tmp shufflingBytesStruct select { case tmp = <-p.PreviousNodeInPathChannel: case <-time.After(libunlynx.TIMEOUT): - return errors.New(p.ServerIdentity().String() + " didn't get the on time.") + return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } sm := ShufflingMessage{} diff --git a/protocols/tools_protocol.go b/protocols/tools_protocol.go index 7474180..b882ecb 100644 --- a/protocols/tools_protocol.go +++ b/protocols/tools_protocol.go @@ -3,7 +3,7 @@ package protocolsunlynx import ( - "errors" + "fmt" "github.com/ldsec/unlynx/lib" ) @@ -13,7 +13,7 @@ import ( // RetrieveSimpleDataFromMap extract the data from a map into an array func RetrieveSimpleDataFromMap(groupedData map[libunlynx.GroupingKey]libunlynx.FilteredResponse) ([]libunlynx.CipherText, error) { if len(groupedData) != 1 { - return nil, errors.New("the map given in arguments is empty or have more than one key") + return nil, fmt.Errorf("the map given in arguments is empty or have more than one key") } filteredResp, present := groupedData[EMPTYKEY] @@ -25,7 +25,7 @@ func RetrieveSimpleDataFromMap(groupedData map[libunlynx.GroupingKey]libunlynx.F return result, nil } - return nil, errors.New("the map element doesn't have key with value EMPTYKEY") + return nil, fmt.Errorf("the map element doesn't have key with value EMPTYKEY") } // _____________________ DETERMINISTIC_TAGGING PROTOCOL _____________________ diff --git a/protocols/utils/addrm_server_protocol.go b/protocols/utils/addrm_server_protocol.go index da62a8b..ec192c7 100644 --- a/protocols/utils/addrm_server_protocol.go +++ b/protocols/utils/addrm_server_protocol.go @@ -4,7 +4,7 @@ package protocolsunlynxutils import ( - "errors" + "fmt" "sync" "time" @@ -79,7 +79,7 @@ func (p *AddRmServerProtocol) Start() error { roundProof = libunlynx.StartTimer(p.Name() + "_AddRmServer(PROOFSVerif)") if p.Proofs && len(proofs.List) == 0 { - return errors.New("something went wrong during the creation of the add/rm proofs") + return fmt.Errorf("something went wrong during the creation of the add/rm proofs") } libunlynxaddrm.AddRmListProofVerification(proofs, 1.0) @@ -97,7 +97,7 @@ func (p *AddRmServerProtocol) Dispatch() error { select { case finalResultMessage = <-finalResultAddrm: case <-time.After(libunlynx.TIMEOUT): - return errors.New(p.ServerIdentity().String() + " didn't get the on time.") + return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } p.FeedbackChannel <- finalResultMessage diff --git a/protocols/utils/local_aggregation_protocol.go b/protocols/utils/local_aggregation_protocol.go index c48870d..665cb3b 100644 --- a/protocols/utils/local_aggregation_protocol.go +++ b/protocols/utils/local_aggregation_protocol.go @@ -3,7 +3,7 @@ package protocolsunlynxutils import ( - "errors" + "fmt" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/lib/aggregation" "go.dedis.ch/onet/v3" @@ -88,7 +88,7 @@ func (p *LocalAggregationProtocol) Dispatch() error { select { case finalResultMessage = <-finalResultAggr: case <-time.After(libunlynx.TIMEOUT): - return errors.New(p.ServerIdentity().String() + " didn't get the on time.") + return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } p.FeedbackChannel <- finalResultMessage diff --git a/protocols/utils/local_clear_aggregation_protocol.go b/protocols/utils/local_clear_aggregation_protocol.go index bf5eeb9..9e73549 100644 --- a/protocols/utils/local_clear_aggregation_protocol.go +++ b/protocols/utils/local_clear_aggregation_protocol.go @@ -3,7 +3,7 @@ package protocolsunlynxutils import ( - "errors" + "fmt" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/lib/store" "go.dedis.ch/onet/v3" @@ -62,7 +62,7 @@ func (p *LocalClearAggregationProtocol) Dispatch() error { select { case finalResultMessage = <-finalResultClearAggr: case <-time.After(libunlynx.TIMEOUT): - return errors.New(p.ServerIdentity().String() + " didn't get the on time.") + return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } p.FeedbackChannel <- finalResultMessage diff --git a/protocols/utils/proofs_verification_protocol.go b/protocols/utils/proofs_verification_protocol.go index 64a642e..7cbf169 100644 --- a/protocols/utils/proofs_verification_protocol.go +++ b/protocols/utils/proofs_verification_protocol.go @@ -5,7 +5,7 @@ package protocolsunlynxutils import ( - "errors" + "fmt" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/lib/aggregation" "github.com/ldsec/unlynx/lib/deterministic_tag" @@ -113,7 +113,7 @@ func (p *ProofsVerificationProtocol) Dispatch() error { select { case finalResultMessage = <-finalResult: case <-time.After(libunlynx.TIMEOUT): - return errors.New(p.ServerIdentity().String() + " didn't get the on time.") + return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } p.FeedbackChannel <- finalResultMessage diff --git a/services/service.go b/services/service.go index 6c03a81..f703fe3 100644 --- a/services/service.go +++ b/services/service.go @@ -1,7 +1,7 @@ package servicesunlynx import ( - "errors" + "fmt" "strconv" "time" @@ -133,10 +133,10 @@ type Service struct { func (s *Service) getSurvey(sid SurveyID) (Survey, error) { surv, err := s.Survey.Get(string(sid)) if err != nil { - return Survey{}, errors.New("Error" + err.Error() + "while getting surveyID" + string(sid)) + return Survey{}, fmt.Errorf("error while getting surveyID "+string(sid)+": %v", err) } if surv == nil { - return Survey{}, errors.New("Empty map entry while getting surveyID" + string(sid)) + return Survey{}, fmt.Errorf("empty map entry while getting surveyID " + string(sid)) } return surv.(Survey), nil } @@ -154,19 +154,19 @@ func NewService(c *onet.Context) (onet.Service, error) { } var cerr error if cerr = newUnLynxInstance.RegisterHandler(newUnLynxInstance.HandleSurveyCreationQuery); cerr != nil { - return nil, errors.New("Wrong Handler." + cerr.Error()) + return nil, fmt.Errorf("wrong Handler: %v", cerr) } if cerr = newUnLynxInstance.RegisterHandler(newUnLynxInstance.HandleSurveyResponseQuery); cerr != nil { - return nil, errors.New("Wrong Handler." + cerr.Error()) + return nil, fmt.Errorf("wrong Handler: %v", cerr) } if cerr = newUnLynxInstance.RegisterHandler(newUnLynxInstance.HandleSurveyResultsQuery); cerr != nil { - return nil, errors.New("Wrong Handler." + cerr.Error()) + return nil, fmt.Errorf("wrong Handler: %v", cerr) } if cerr = newUnLynxInstance.RegisterHandler(newUnLynxInstance.HandleDDTfinished); cerr != nil { - return nil, errors.New("Wrong Handler." + cerr.Error()) + return nil, fmt.Errorf("wrong Handler: %v", cerr) } if cerr = newUnLynxInstance.RegisterHandler(newUnLynxInstance.HandleQueryBroadcastFinished); cerr != nil { - return nil, errors.New("Wrong Handler." + cerr.Error()) + return nil, fmt.Errorf("wrong Handler: %v", cerr) } c.RegisterProcessor(newUnLynxInstance, msgTypes.msgSurveyCreationQuery) @@ -574,7 +574,7 @@ func (s *Service) NewProtocol(tn *onet.TreeNodeInstance, conf *onet.GenericConfi } } default: - return nil, errors.New("Service attempts to start an unknown protocol: " + tn.ProtocolName() + ".") + return nil, fmt.Errorf("service attempts to start an unknown protocol: " + tn.ProtocolName()) } return pi, nil } @@ -594,7 +594,7 @@ func (s *Service) StartProtocol(name string, targetSurvey SurveyID) (onet.Protoc pi, err := s.NewProtocol(tn, &conf) if err != nil { - return nil, errors.New("Error running " + name + " :" + err.Error()) + return nil, fmt.Errorf("error running "+name+" : %v", err) } err = s.RegisterProtocolInstance(pi) @@ -647,7 +647,7 @@ func (s *Service) StartService(targetSurvey SurveyID, root bool) error { err = s.ShufflingPhase(survey.Query.SurveyID) if err != nil { - return errors.New("Error in the Shuffling Phase: " + err.Error()) + return fmt.Errorf("error in the Shuffling Phase: %v", err) } libunlynx.EndTimer(start) @@ -656,7 +656,7 @@ func (s *Service) StartService(targetSurvey SurveyID, root bool) error { err = s.TaggingPhase(target.Query.SurveyID) if err != nil { - return errors.New("Error in the Tagging Phase: " + err.Error()) + return fmt.Errorf("error in the Tagging Phase: %v", err) } // broadcasts the query to unlock waiting channel @@ -674,7 +674,7 @@ func (s *Service) StartService(targetSurvey SurveyID, root bool) error { err = s.AggregationPhase(target.Query.SurveyID) if err != nil { - return errors.New("Error in the Aggregation Phase: " + err.Error()) + return fmt.Errorf("error in the Aggregation Phase: %v", err) } libunlynx.EndTimer(start) @@ -686,7 +686,7 @@ func (s *Service) StartService(targetSurvey SurveyID, root bool) error { err := s.DROPhase(target.Query.SurveyID) if err != nil { - return errors.New("Error in the DRO Phase: " + err.Error()) + return fmt.Errorf("error in the DRO Phase: %v", err) } libunlynx.EndTimer(start) @@ -698,7 +698,7 @@ func (s *Service) StartService(targetSurvey SurveyID, root bool) error { err := s.KeySwitchingPhase(target.Query.SurveyID) if err != nil { - return errors.New("Error in the Key Switching Phase: " + err.Error()) + return fmt.Errorf("error in the Key Switching Phase: %v", err) } libunlynx.EndTimer(start) @@ -728,7 +728,7 @@ func (s *Service) ShufflingPhase(targetSurvey SurveyID) error { select { case tmpShufflingResult = <-pi.(*protocolsunlynx.ShufflingProtocol).FeedbackChannel: case <-time.After(libunlynx.TIMEOUT): - return errors.New(s.ServerIdentity().String() + " didn't get the on time.") + return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") } survey, err = s.getSurvey(targetSurvey) @@ -763,7 +763,7 @@ func (s *Service) TaggingPhase(targetSurvey SurveyID) error { select { case tmpDeterministicTaggingResult = <-pi.(*protocolsunlynx.DeterministicTaggingProtocol).FeedbackChannel: case <-time.After(libunlynx.TIMEOUT): - return errors.New(s.ServerIdentity().String() + " didn't get the on time.") + return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") } survey, err = s.getSurvey(targetSurvey) @@ -802,7 +802,7 @@ func (s *Service) AggregationPhase(targetSurvey SurveyID) error { select { case cothorityAggregatedData = <-pi.(*protocolsunlynx.CollectiveAggregationProtocol).FeedbackChannel: case <-time.After(libunlynx.TIMEOUT): - return errors.New(s.ServerIdentity().String() + " didn't get the on time.") + return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") } survey, err := s.getSurvey(targetSurvey) @@ -831,7 +831,7 @@ func (s *Service) DROPhase(targetSurvey SurveyID) error { select { case tmpShufflingResult = <-pi.(*protocolsunlynx.ShufflingProtocol).FeedbackChannel: case <-time.After(libunlynx.TIMEOUT): - return errors.New(s.ServerIdentity().String() + " didn't get the on time.") + return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") } shufflingResult := protocolsunlynx.MatrixCipherTextToProcessResponse(tmpShufflingResult, survey.Lengths) @@ -857,7 +857,7 @@ func (s *Service) KeySwitchingPhase(targetSurvey SurveyID) error { select { case tmpKeySwitchedAggregatedResponses = <-pi.(*protocolsunlynx.KeySwitchingProtocol).FeedbackChannel: case <-time.After(libunlynx.TIMEOUT): - return errors.New(s.ServerIdentity().String() + " didn't get the on time.") + return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") } keySwitchedAggregatedResponses := protocolsunlynx.CipherVectorToFilteredResponse(tmpKeySwitchedAggregatedResponses, survey.Lengths) diff --git a/simul/addrm_server_simul.go b/simul/addrm_server_simul.go index 78e96fa..512a7ac 100644 --- a/simul/addrm_server_simul.go +++ b/simul/addrm_server_simul.go @@ -1,7 +1,7 @@ package main import ( - "errors" + "fmt" "github.com/BurntSushi/toml" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/protocols/utils" @@ -91,7 +91,7 @@ func (sim *AddRmSimulation) Run(config *onet.SimulationConfig) error { log.Lvl1("Number of aggregated lines: ", len(results)) libunlynx.EndTimer(round) case <-time.After(libunlynx.TIMEOUT): - return errors.New("simulation didn't finish in time") + return fmt.Errorf("simulation didn't finish in time") } } diff --git a/simul/collective_aggregation_simul.go b/simul/collective_aggregation_simul.go index 5a0fe40..aa65aff 100644 --- a/simul/collective_aggregation_simul.go +++ b/simul/collective_aggregation_simul.go @@ -1,7 +1,7 @@ package main import ( - "errors" + "fmt" "github.com/BurntSushi/toml" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/lib/aggregation" @@ -86,7 +86,7 @@ func (sim *CollectiveAggregationSimulation) Node(config *onet.SimulationConfig) func(tni *onet.TreeNodeInstance) (onet.ProtocolInstance, error) { return NewAggregationProtocolSimul(tni, sim) }); err != nil { - return errors.New("Error while registering :" + err.Error()) + return fmt.Errorf("error while registering : %v", err) } return sim.SimulationBFTree.Node(config) diff --git a/simul/deterministic_tagging_simul.go b/simul/deterministic_tagging_simul.go index 4af5050..9b8ac02 100644 --- a/simul/deterministic_tagging_simul.go +++ b/simul/deterministic_tagging_simul.go @@ -1,7 +1,7 @@ package main import ( - "errors" + "fmt" "github.com/BurntSushi/toml" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/protocols" @@ -60,7 +60,7 @@ func (sim *DeterministicTaggingSimulation) Node(config *onet.SimulationConfig) e func(tni *onet.TreeNodeInstance) (onet.ProtocolInstance, error) { return NewDeterministicTaggingSimul(tni, sim) }); err != nil { - return errors.New("Error while registering :" + err.Error()) + return fmt.Errorf("error while registering : %v", err) } return sim.SimulationBFTree.Node(config) diff --git a/simul/local_aggregation_simul.go b/simul/local_aggregation_simul.go index ce2af5c..3ec5ce4 100644 --- a/simul/local_aggregation_simul.go +++ b/simul/local_aggregation_simul.go @@ -1,7 +1,7 @@ package main import ( - "errors" + "fmt" "github.com/BurntSushi/toml" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/protocols" @@ -121,7 +121,7 @@ func (sim *LocalAggregationSimulation) Run(config *onet.SimulationConfig) error log.Lvl1("Number of aggregated lines: ", len(results)) libunlynx.EndTimer(round) case <-time.After(libunlynx.TIMEOUT): - return errors.New("simulation didn't finish in time") + return fmt.Errorf("simulation didn't finish in time") } } diff --git a/simul/local_clear_aggregation_simul.go b/simul/local_clear_aggregation_simul.go index 9c685e6..6fd7ef4 100644 --- a/simul/local_clear_aggregation_simul.go +++ b/simul/local_clear_aggregation_simul.go @@ -1,7 +1,7 @@ package main import ( - "errors" + "fmt" "github.com/BurntSushi/toml" "github.com/ldsec/unlynx/data" libunlynx "github.com/ldsec/unlynx/lib" @@ -98,7 +98,7 @@ func (sim *LocalClearAggregationSimulation) Run(config *onet.SimulationConfig) e } round.Record() case <-time.After(libunlynx.TIMEOUT): - return errors.New("simulation didn't finish in time") + return fmt.Errorf("simulation didn't finish in time") } } diff --git a/simul/proofs_verification_simul.go b/simul/proofs_verification_simul.go index f9baab9..6d3f758 100644 --- a/simul/proofs_verification_simul.go +++ b/simul/proofs_verification_simul.go @@ -1,7 +1,7 @@ package main import ( - "errors" + "fmt" "github.com/BurntSushi/toml" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/lib/aggregation" @@ -238,20 +238,20 @@ func (sim *ProofsVerificationSimulation) Run(config *onet.SimulationConfig) erro log.Lvl1(len(results), " proofs verified") if results[0] == false { - return errors.New("key switching proofs failed") + return fmt.Errorf("key switching proofs failed") } else if results[1] == false { - return errors.New("deterministic tagging (creation) proofs failed") + return fmt.Errorf("deterministic tagging (creation) proofs failed") } else if results[2] == false { - return errors.New("deterministic tagging (addition) proofs failed") + return fmt.Errorf("deterministic tagging (addition) proofs failed") } else if results[3] == false { - return errors.New("local aggregation proofs failed") + return fmt.Errorf("local aggregation proofs failed") } else if results[4] == false { - return errors.New("shuffling proofs failed") + return fmt.Errorf("shuffling proofs failed") } else if results[5] == false { - return errors.New("collective aggregation proofs failed") + return fmt.Errorf("collective aggregation proofs failed") } case <-time.After(libunlynx.TIMEOUT): - return errors.New("simulation didn't finish in time") + return fmt.Errorf("simulation didn't finish in time") } } return nil diff --git a/simul/shuffling+ddt_simul.go b/simul/shuffling+ddt_simul.go index 9927471..2552fdc 100644 --- a/simul/shuffling+ddt_simul.go +++ b/simul/shuffling+ddt_simul.go @@ -1,7 +1,7 @@ package main import ( - "errors" + "fmt" "github.com/BurntSushi/toml" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/lib/shuffle" @@ -54,7 +54,7 @@ func (sim *ShufflingPlusDDTSimulation) Node(config *onet.SimulationConfig) error func(tni *onet.TreeNodeInstance) (onet.ProtocolInstance, error) { return NewShufflingPlusDDTSimul(tni, sim) }); err != nil { - return errors.New("Error while registering :" + err.Error()) + return fmt.Errorf("error while registering : %v", err) } return sim.SimulationBFTree.Node(config) diff --git a/simul/shuffling_simul.go b/simul/shuffling_simul.go index d1f60c5..b0be658 100644 --- a/simul/shuffling_simul.go +++ b/simul/shuffling_simul.go @@ -1,7 +1,7 @@ package main import ( - "errors" + "fmt" "github.com/BurntSushi/toml" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/lib/shuffle" @@ -56,7 +56,7 @@ func (sim *ShufflingSimulation) Node(config *onet.SimulationConfig) error { func(tni *onet.TreeNodeInstance) (onet.ProtocolInstance, error) { return NewShufflingSimul(tni, sim) }); err != nil { - return errors.New("Error while registering :" + err.Error()) + return fmt.Errorf("error while registering : %v", err) } return sim.SimulationBFTree.Node(config) diff --git a/simul/unlynx_simul.go b/simul/unlynx_simul.go index dcbdfc3..12053b0 100644 --- a/simul/unlynx_simul.go +++ b/simul/unlynx_simul.go @@ -1,7 +1,7 @@ package main import ( - "errors" + "fmt" "github.com/ldsec/unlynx/data" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/lib/tools" @@ -74,7 +74,7 @@ func (sim *SimulationUnLynx) Run(config *onet.SimulationConfig) error { // Does not make sense to have more servers than clients!! if nbrHosts > sim.NbrDPs { - return errors.New("hosts: " + strconv.FormatInt(int64(nbrHosts), 10) + " must be the same or lower as num_clients " + strconv.FormatInt(int64(sim.NbrDPs), 10)) + return fmt.Errorf("hosts: " + strconv.FormatInt(int64(nbrHosts), 10) + " must be the same or lower as num_clients " + strconv.FormatInt(int64(sim.NbrDPs), 10)) } el := (*config.Tree).Roster @@ -155,7 +155,7 @@ func (sim *SimulationUnLynx) Run(config *onet.SimulationConfig) error { client = servicesunlynx.NewUnLynxClient(server, strconv.Itoa(i+1)) if tmpErr := client.SendSurveyResponseQuery(*surveyID, dataCollection, el.Aggregate, sim.DataRepetitions, count); tmpErr != nil { mutex.Lock() - err = errors.New("Error while sending DP (" + client.String() + ") responses:" + err.Error()) + err = fmt.Errorf("Error while sending DP ("+client.String()+") responses: %v", err) log.Error(err) mutex.Unlock() } @@ -174,7 +174,7 @@ func (sim *SimulationUnLynx) Run(config *onet.SimulationConfig) error { grp, aggr, err := client.SendSurveyResultsQuery(*surveyID) if err != nil { - return errors.New("Service could not output the results: " + err.Error()) + return fmt.Errorf("service could not output the results: %v", err) } libunlynx.EndTimer(start) From f3812c3478926de5e08292640060e5dbee3d9a7d Mon Sep 17 00:00:00 2001 From: Joao Sa Sousa Date: Wed, 11 Mar 2020 17:41:37 +0100 Subject: [PATCH 14/22] Remove the isLeaf condition for the SendToChildren call --- protocols/collective_aggregation_protocol.go | 8 +++++--- protocols/key_switching_protocol.go | 6 ++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/protocols/collective_aggregation_protocol.go b/protocols/collective_aggregation_protocol.go index 3694262..43b4f00 100644 --- a/protocols/collective_aggregation_protocol.go +++ b/protocols/collective_aggregation_protocol.go @@ -136,7 +136,9 @@ func NewCollectiveAggregationProtocol(n *onet.TreeNodeInstance) (onet.ProtocolIn // Start is called at the root to begin the execution of the protocol. func (p *CollectiveAggregationProtocol) Start() error { log.Lvl1(p.ServerIdentity(), " started a Colective Aggregation Protocol") - p.SendToChildren(&DataReferenceMessage{}) + if err := p.SendToChildren(&DataReferenceMessage{}); err != nil { + return fmt.Errorf("error sending : %v", err) + } return nil } @@ -196,8 +198,8 @@ func (p *CollectiveAggregationProtocol) Dispatch() error { func (p *CollectiveAggregationProtocol) aggregationAnnouncementPhase() error { select { case dataReferenceMessage := <-p.DataReferenceChannel: - if !p.IsLeaf() { - p.SendToChildren(&dataReferenceMessage.DataReferenceMessage) + if err := p.SendToChildren(&dataReferenceMessage.DataReferenceMessage); err != nil { + return fmt.Errorf("error sending : %v", err) } case <-time.After(libunlynx.TIMEOUT): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") diff --git a/protocols/key_switching_protocol.go b/protocols/key_switching_protocol.go index 102841b..a774605 100644 --- a/protocols/key_switching_protocol.go +++ b/protocols/key_switching_protocol.go @@ -237,10 +237,8 @@ func (p *KeySwitchingProtocol) announcementKSPhase() (kyber.Point, []kyber.Point return nil, nil, fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } - if !p.IsLeaf() { - if err := p.SendToChildren(&dataReferenceMessage.DownMessageBytes); err != nil { - return nil, nil, fmt.Errorf("Node "+p.ServerIdentity().String()+" failed to broadcast DownMessageBytes: %v", err) - } + if err := p.SendToChildren(&dataReferenceMessage.DownMessageBytes); err != nil { + return nil, nil, fmt.Errorf("Node "+p.ServerIdentity().String()+" failed to broadcast DownMessageBytes: %v", err) } message, err := libunlynx.FromBytesToAbstractPoints(dataReferenceMessage.Data) if err != nil { From 5bc1e5db3bf44ad7c4d3e11c0b4c60e476aa67f7 Mon Sep 17 00:00:00 2001 From: Joao Sa Sousa Date: Thu, 12 Mar 2020 13:32:13 +0100 Subject: [PATCH 15/22] Changed TIMEOUT constant to DEFAULT_TIMEOUT --- lib/constants.go | 8 ++++---- protocols/collective_aggregation_protocol.go | 2 +- protocols/deterministic_tagging_protocol.go | 4 ++-- protocols/key_switching_protocol.go | 2 +- protocols/shuffling+ddt_protocol.go | 4 ++-- protocols/shuffling_protocol.go | 4 ++-- protocols/utils/addrm_server_protocol.go | 2 +- protocols/utils/local_aggregation_protocol.go | 2 +- protocols/utils/local_clear_aggregation_protocol.go | 2 +- protocols/utils/proofs_verification_protocol.go | 2 +- services/service.go | 10 +++++----- simul/addrm_server_simul.go | 2 +- simul/local_aggregation_simul.go | 2 +- simul/local_clear_aggregation_simul.go | 2 +- simul/proofs_verification_simul.go | 2 +- 15 files changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/constants.go b/lib/constants.go index 7f3ba19..7ea4898 100644 --- a/lib/constants.go +++ b/lib/constants.go @@ -12,9 +12,9 @@ import ( func init() { tmp, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) if err == nil { - TIMEOUT = tmp + DEFAULT_TIMEOUT = tmp } else { - log.Warn("Couldn't parse MEDCO_TIMEOUT, using default value: ", TIMEOUT.String()) + log.Warn("Couldn't parse MEDCO_TIMEOUT, using default value: ", DEFAULT_TIMEOUT.String()) } } @@ -30,8 +30,8 @@ const VPARALLELIZE = 100 // DIFFPRI enables the DRO protocol (Distributed Results Obfuscation) const DIFFPRI = false -// TIMEOUT ddefines the default channel timeout -var TIMEOUT = 10 * time.Minute +// DEFAULT_TIMEOUT ddefines the default channel timeout +var DEFAULT_TIMEOUT = 10 * time.Minute // StartTimer starts measurement of time func StartTimer(name string) *monitor.TimeMeasure { diff --git a/protocols/collective_aggregation_protocol.go b/protocols/collective_aggregation_protocol.go index 43b4f00..314854f 100644 --- a/protocols/collective_aggregation_protocol.go +++ b/protocols/collective_aggregation_protocol.go @@ -201,7 +201,7 @@ func (p *CollectiveAggregationProtocol) aggregationAnnouncementPhase() error { if err := p.SendToChildren(&dataReferenceMessage.DataReferenceMessage); err != nil { return fmt.Errorf("error sending : %v", err) } - case <-time.After(libunlynx.TIMEOUT): + case <-time.After(libunlynx.DEFAULT_TIMEOUT): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } return nil diff --git a/protocols/deterministic_tagging_protocol.go b/protocols/deterministic_tagging_protocol.go index 047ed20..fc11238 100644 --- a/protocols/deterministic_tagging_protocol.go +++ b/protocols/deterministic_tagging_protocol.go @@ -158,7 +158,7 @@ func (p *DeterministicTaggingProtocol) Dispatch() error { var deterministicTaggingTargetBytesBef deterministicTaggingBytesStruct select { case deterministicTaggingTargetBytesBef = <-p.PreviousNodeInPathChannel: - case <-time.After(libunlynx.TIMEOUT): + case <-time.After(libunlynx.DEFAULT_TIMEOUT): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the (first round) on time") } @@ -211,7 +211,7 @@ func (p *DeterministicTaggingProtocol) Dispatch() error { var deterministicTaggingTargetBytes deterministicTaggingBytesStruct select { case deterministicTaggingTargetBytes = <-p.PreviousNodeInPathChannel: - case <-time.After(libunlynx.TIMEOUT): + case <-time.After(libunlynx.DEFAULT_TIMEOUT): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the (second round) on time") } diff --git a/protocols/key_switching_protocol.go b/protocols/key_switching_protocol.go index a774605..fb01692 100644 --- a/protocols/key_switching_protocol.go +++ b/protocols/key_switching_protocol.go @@ -233,7 +233,7 @@ func (p *KeySwitchingProtocol) announcementKSPhase() (kyber.Point, []kyber.Point var dataReferenceMessage DownBytesStruct select { case dataReferenceMessage = <-p.DownChannel: - case <-time.After(libunlynx.TIMEOUT): + case <-time.After(libunlynx.DEFAULT_TIMEOUT): return nil, nil, fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } diff --git a/protocols/shuffling+ddt_protocol.go b/protocols/shuffling+ddt_protocol.go index 20759fd..cd3e146 100644 --- a/protocols/shuffling+ddt_protocol.go +++ b/protocols/shuffling+ddt_protocol.go @@ -156,14 +156,14 @@ func (p *ShufflingPlusDDTProtocol) Dispatch() error { var shufflingPlusDDTBytesMessageLength shufflingPlusDDTBytesLengthStruct select { case shufflingPlusDDTBytesMessageLength = <-p.LengthNodeChannel: - case <-time.After(libunlynx.TIMEOUT): + case <-time.After(libunlynx.DEFAULT_TIMEOUT): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } var tmp shufflingPlusDDTBytesStruct select { case tmp = <-p.PreviousNodeInPathChannel: - case <-time.After(libunlynx.TIMEOUT): + case <-time.After(libunlynx.DEFAULT_TIMEOUT): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } diff --git a/protocols/shuffling_protocol.go b/protocols/shuffling_protocol.go index 3bc90d2..f78909c 100644 --- a/protocols/shuffling_protocol.go +++ b/protocols/shuffling_protocol.go @@ -190,14 +190,14 @@ func (p *ShufflingProtocol) Dispatch() error { var shufflingBytesMessageLength shufflingBytesLengthStruct select { case shufflingBytesMessageLength = <-p.LengthNodeChannel: - case <-time.After(libunlynx.TIMEOUT): + case <-time.After(libunlynx.DEFAULT_TIMEOUT): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } var tmp shufflingBytesStruct select { case tmp = <-p.PreviousNodeInPathChannel: - case <-time.After(libunlynx.TIMEOUT): + case <-time.After(libunlynx.DEFAULT_TIMEOUT): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } diff --git a/protocols/utils/addrm_server_protocol.go b/protocols/utils/addrm_server_protocol.go index ec192c7..b0812ae 100644 --- a/protocols/utils/addrm_server_protocol.go +++ b/protocols/utils/addrm_server_protocol.go @@ -96,7 +96,7 @@ func (p *AddRmServerProtocol) Dispatch() error { var finalResultMessage []libunlynx.CipherText select { case finalResultMessage = <-finalResultAddrm: - case <-time.After(libunlynx.TIMEOUT): + case <-time.After(libunlynx.DEFAULT_TIMEOUT): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } diff --git a/protocols/utils/local_aggregation_protocol.go b/protocols/utils/local_aggregation_protocol.go index 665cb3b..bbd07a7 100644 --- a/protocols/utils/local_aggregation_protocol.go +++ b/protocols/utils/local_aggregation_protocol.go @@ -87,7 +87,7 @@ func (p *LocalAggregationProtocol) Dispatch() error { var finalResultMessage map[libunlynx.GroupingKey]libunlynx.FilteredResponse select { case finalResultMessage = <-finalResultAggr: - case <-time.After(libunlynx.TIMEOUT): + case <-time.After(libunlynx.DEFAULT_TIMEOUT): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } diff --git a/protocols/utils/local_clear_aggregation_protocol.go b/protocols/utils/local_clear_aggregation_protocol.go index 9e73549..f32dc38 100644 --- a/protocols/utils/local_clear_aggregation_protocol.go +++ b/protocols/utils/local_clear_aggregation_protocol.go @@ -61,7 +61,7 @@ func (p *LocalClearAggregationProtocol) Dispatch() error { var finalResultMessage []libunlynx.DpClearResponse select { case finalResultMessage = <-finalResultClearAggr: - case <-time.After(libunlynx.TIMEOUT): + case <-time.After(libunlynx.DEFAULT_TIMEOUT): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } diff --git a/protocols/utils/proofs_verification_protocol.go b/protocols/utils/proofs_verification_protocol.go index 7cbf169..02e24b0 100644 --- a/protocols/utils/proofs_verification_protocol.go +++ b/protocols/utils/proofs_verification_protocol.go @@ -112,7 +112,7 @@ func (p *ProofsVerificationProtocol) Dispatch() error { var finalResultMessage []bool select { case finalResultMessage = <-finalResult: - case <-time.After(libunlynx.TIMEOUT): + case <-time.After(libunlynx.DEFAULT_TIMEOUT): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } diff --git a/services/service.go b/services/service.go index f703fe3..1a8efd1 100644 --- a/services/service.go +++ b/services/service.go @@ -727,7 +727,7 @@ func (s *Service) ShufflingPhase(targetSurvey SurveyID) error { var tmpShufflingResult []libunlynx.CipherVector select { case tmpShufflingResult = <-pi.(*protocolsunlynx.ShufflingProtocol).FeedbackChannel: - case <-time.After(libunlynx.TIMEOUT): + case <-time.After(libunlynx.DEFAULT_TIMEOUT): return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") } @@ -762,7 +762,7 @@ func (s *Service) TaggingPhase(targetSurvey SurveyID) error { var tmpDeterministicTaggingResult []libunlynx.DeterministCipherText select { case tmpDeterministicTaggingResult = <-pi.(*protocolsunlynx.DeterministicTaggingProtocol).FeedbackChannel: - case <-time.After(libunlynx.TIMEOUT): + case <-time.After(libunlynx.DEFAULT_TIMEOUT): return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") } @@ -801,7 +801,7 @@ func (s *Service) AggregationPhase(targetSurvey SurveyID) error { var cothorityAggregatedData protocolsunlynx.CothorityAggregatedData select { case cothorityAggregatedData = <-pi.(*protocolsunlynx.CollectiveAggregationProtocol).FeedbackChannel: - case <-time.After(libunlynx.TIMEOUT): + case <-time.After(libunlynx.DEFAULT_TIMEOUT): return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") } @@ -830,7 +830,7 @@ func (s *Service) DROPhase(targetSurvey SurveyID) error { var tmpShufflingResult []libunlynx.CipherVector select { case tmpShufflingResult = <-pi.(*protocolsunlynx.ShufflingProtocol).FeedbackChannel: - case <-time.After(libunlynx.TIMEOUT): + case <-time.After(libunlynx.DEFAULT_TIMEOUT): return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") } @@ -856,7 +856,7 @@ func (s *Service) KeySwitchingPhase(targetSurvey SurveyID) error { var tmpKeySwitchedAggregatedResponses libunlynx.CipherVector select { case tmpKeySwitchedAggregatedResponses = <-pi.(*protocolsunlynx.KeySwitchingProtocol).FeedbackChannel: - case <-time.After(libunlynx.TIMEOUT): + case <-time.After(libunlynx.DEFAULT_TIMEOUT): return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") } diff --git a/simul/addrm_server_simul.go b/simul/addrm_server_simul.go index 512a7ac..9bca364 100644 --- a/simul/addrm_server_simul.go +++ b/simul/addrm_server_simul.go @@ -90,7 +90,7 @@ func (sim *AddRmSimulation) Run(config *onet.SimulationConfig) error { case results := <-root.ProtocolInstance().(*protocolsunlynxutils.AddRmServerProtocol).FeedbackChannel: log.Lvl1("Number of aggregated lines: ", len(results)) libunlynx.EndTimer(round) - case <-time.After(libunlynx.TIMEOUT): + case <-time.After(libunlynx.DEFAULT_TIMEOUT): return fmt.Errorf("simulation didn't finish in time") } } diff --git a/simul/local_aggregation_simul.go b/simul/local_aggregation_simul.go index 3ec5ce4..afa0ed5 100644 --- a/simul/local_aggregation_simul.go +++ b/simul/local_aggregation_simul.go @@ -120,7 +120,7 @@ func (sim *LocalAggregationSimulation) Run(config *onet.SimulationConfig) error case results := <-root.ProtocolInstance().(*protocolsunlynxutils.LocalAggregationProtocol).FeedbackChannel: log.Lvl1("Number of aggregated lines: ", len(results)) libunlynx.EndTimer(round) - case <-time.After(libunlynx.TIMEOUT): + case <-time.After(libunlynx.DEFAULT_TIMEOUT): return fmt.Errorf("simulation didn't finish in time") } } diff --git a/simul/local_clear_aggregation_simul.go b/simul/local_clear_aggregation_simul.go index 6fd7ef4..d52f53d 100644 --- a/simul/local_clear_aggregation_simul.go +++ b/simul/local_clear_aggregation_simul.go @@ -97,7 +97,7 @@ func (sim *LocalClearAggregationSimulation) Run(config *onet.SimulationConfig) e log.Lvl1("Result is wrong! :(") } round.Record() - case <-time.After(libunlynx.TIMEOUT): + case <-time.After(libunlynx.DEFAULT_TIMEOUT): return fmt.Errorf("simulation didn't finish in time") } } diff --git a/simul/proofs_verification_simul.go b/simul/proofs_verification_simul.go index 6d3f758..ddf323a 100644 --- a/simul/proofs_verification_simul.go +++ b/simul/proofs_verification_simul.go @@ -250,7 +250,7 @@ func (sim *ProofsVerificationSimulation) Run(config *onet.SimulationConfig) erro } else if results[5] == false { return fmt.Errorf("collective aggregation proofs failed") } - case <-time.After(libunlynx.TIMEOUT): + case <-time.After(libunlynx.DEFAULT_TIMEOUT): return fmt.Errorf("simulation didn't finish in time") } } From 186b6f4015507536fb7b68f94e7d671b19eef149 Mon Sep 17 00:00:00 2001 From: Joao Sa Sousa Date: Thu, 12 Mar 2020 13:39:25 +0100 Subject: [PATCH 16/22] Fixed go lint warning --- lib/constants.go | 8 ++++---- protocols/collective_aggregation_protocol.go | 2 +- protocols/deterministic_tagging_protocol.go | 4 ++-- protocols/key_switching_protocol.go | 2 +- protocols/shuffling+ddt_protocol.go | 4 ++-- protocols/shuffling_protocol.go | 4 ++-- protocols/utils/addrm_server_protocol.go | 2 +- protocols/utils/local_aggregation_protocol.go | 2 +- protocols/utils/local_clear_aggregation_protocol.go | 2 +- protocols/utils/proofs_verification_protocol.go | 2 +- services/service.go | 10 +++++----- simul/addrm_server_simul.go | 2 +- simul/local_aggregation_simul.go | 2 +- simul/local_clear_aggregation_simul.go | 2 +- simul/proofs_verification_simul.go | 2 +- 15 files changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/constants.go b/lib/constants.go index 7ea4898..e6555b5 100644 --- a/lib/constants.go +++ b/lib/constants.go @@ -12,9 +12,9 @@ import ( func init() { tmp, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) if err == nil { - DEFAULT_TIMEOUT = tmp + DefaultTimeout = tmp } else { - log.Warn("Couldn't parse MEDCO_TIMEOUT, using default value: ", DEFAULT_TIMEOUT.String()) + log.Warn("Couldn't parse MEDCO_TIMEOUT, using default value: ", DefaultTimeout.String()) } } @@ -30,8 +30,8 @@ const VPARALLELIZE = 100 // DIFFPRI enables the DRO protocol (Distributed Results Obfuscation) const DIFFPRI = false -// DEFAULT_TIMEOUT ddefines the default channel timeout -var DEFAULT_TIMEOUT = 10 * time.Minute +// DefaultTimeout ddefines the default channel timeout +var DefaultTimeout = 10 * time.Minute // StartTimer starts measurement of time func StartTimer(name string) *monitor.TimeMeasure { diff --git a/protocols/collective_aggregation_protocol.go b/protocols/collective_aggregation_protocol.go index 314854f..94732b8 100644 --- a/protocols/collective_aggregation_protocol.go +++ b/protocols/collective_aggregation_protocol.go @@ -201,7 +201,7 @@ func (p *CollectiveAggregationProtocol) aggregationAnnouncementPhase() error { if err := p.SendToChildren(&dataReferenceMessage.DataReferenceMessage); err != nil { return fmt.Errorf("error sending : %v", err) } - case <-time.After(libunlynx.DEFAULT_TIMEOUT): + case <-time.After(libunlynx.DefaultTimeout): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } return nil diff --git a/protocols/deterministic_tagging_protocol.go b/protocols/deterministic_tagging_protocol.go index fc11238..f79663d 100644 --- a/protocols/deterministic_tagging_protocol.go +++ b/protocols/deterministic_tagging_protocol.go @@ -158,7 +158,7 @@ func (p *DeterministicTaggingProtocol) Dispatch() error { var deterministicTaggingTargetBytesBef deterministicTaggingBytesStruct select { case deterministicTaggingTargetBytesBef = <-p.PreviousNodeInPathChannel: - case <-time.After(libunlynx.DEFAULT_TIMEOUT): + case <-time.After(libunlynx.DefaultTimeout): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the (first round) on time") } @@ -211,7 +211,7 @@ func (p *DeterministicTaggingProtocol) Dispatch() error { var deterministicTaggingTargetBytes deterministicTaggingBytesStruct select { case deterministicTaggingTargetBytes = <-p.PreviousNodeInPathChannel: - case <-time.After(libunlynx.DEFAULT_TIMEOUT): + case <-time.After(libunlynx.DefaultTimeout): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the (second round) on time") } diff --git a/protocols/key_switching_protocol.go b/protocols/key_switching_protocol.go index fb01692..7311e2f 100644 --- a/protocols/key_switching_protocol.go +++ b/protocols/key_switching_protocol.go @@ -233,7 +233,7 @@ func (p *KeySwitchingProtocol) announcementKSPhase() (kyber.Point, []kyber.Point var dataReferenceMessage DownBytesStruct select { case dataReferenceMessage = <-p.DownChannel: - case <-time.After(libunlynx.DEFAULT_TIMEOUT): + case <-time.After(libunlynx.DefaultTimeout): return nil, nil, fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } diff --git a/protocols/shuffling+ddt_protocol.go b/protocols/shuffling+ddt_protocol.go index cd3e146..7d80309 100644 --- a/protocols/shuffling+ddt_protocol.go +++ b/protocols/shuffling+ddt_protocol.go @@ -156,14 +156,14 @@ func (p *ShufflingPlusDDTProtocol) Dispatch() error { var shufflingPlusDDTBytesMessageLength shufflingPlusDDTBytesLengthStruct select { case shufflingPlusDDTBytesMessageLength = <-p.LengthNodeChannel: - case <-time.After(libunlynx.DEFAULT_TIMEOUT): + case <-time.After(libunlynx.DefaultTimeout): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } var tmp shufflingPlusDDTBytesStruct select { case tmp = <-p.PreviousNodeInPathChannel: - case <-time.After(libunlynx.DEFAULT_TIMEOUT): + case <-time.After(libunlynx.DefaultTimeout): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } diff --git a/protocols/shuffling_protocol.go b/protocols/shuffling_protocol.go index f78909c..34c4dcf 100644 --- a/protocols/shuffling_protocol.go +++ b/protocols/shuffling_protocol.go @@ -190,14 +190,14 @@ func (p *ShufflingProtocol) Dispatch() error { var shufflingBytesMessageLength shufflingBytesLengthStruct select { case shufflingBytesMessageLength = <-p.LengthNodeChannel: - case <-time.After(libunlynx.DEFAULT_TIMEOUT): + case <-time.After(libunlynx.DefaultTimeout): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } var tmp shufflingBytesStruct select { case tmp = <-p.PreviousNodeInPathChannel: - case <-time.After(libunlynx.DEFAULT_TIMEOUT): + case <-time.After(libunlynx.DefaultTimeout): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } diff --git a/protocols/utils/addrm_server_protocol.go b/protocols/utils/addrm_server_protocol.go index b0812ae..e27a5aa 100644 --- a/protocols/utils/addrm_server_protocol.go +++ b/protocols/utils/addrm_server_protocol.go @@ -96,7 +96,7 @@ func (p *AddRmServerProtocol) Dispatch() error { var finalResultMessage []libunlynx.CipherText select { case finalResultMessage = <-finalResultAddrm: - case <-time.After(libunlynx.DEFAULT_TIMEOUT): + case <-time.After(libunlynx.DefaultTimeout): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } diff --git a/protocols/utils/local_aggregation_protocol.go b/protocols/utils/local_aggregation_protocol.go index bbd07a7..60adc9e 100644 --- a/protocols/utils/local_aggregation_protocol.go +++ b/protocols/utils/local_aggregation_protocol.go @@ -87,7 +87,7 @@ func (p *LocalAggregationProtocol) Dispatch() error { var finalResultMessage map[libunlynx.GroupingKey]libunlynx.FilteredResponse select { case finalResultMessage = <-finalResultAggr: - case <-time.After(libunlynx.DEFAULT_TIMEOUT): + case <-time.After(libunlynx.DefaultTimeout): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } diff --git a/protocols/utils/local_clear_aggregation_protocol.go b/protocols/utils/local_clear_aggregation_protocol.go index f32dc38..287e660 100644 --- a/protocols/utils/local_clear_aggregation_protocol.go +++ b/protocols/utils/local_clear_aggregation_protocol.go @@ -61,7 +61,7 @@ func (p *LocalClearAggregationProtocol) Dispatch() error { var finalResultMessage []libunlynx.DpClearResponse select { case finalResultMessage = <-finalResultClearAggr: - case <-time.After(libunlynx.DEFAULT_TIMEOUT): + case <-time.After(libunlynx.DefaultTimeout): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } diff --git a/protocols/utils/proofs_verification_protocol.go b/protocols/utils/proofs_verification_protocol.go index 02e24b0..8d47012 100644 --- a/protocols/utils/proofs_verification_protocol.go +++ b/protocols/utils/proofs_verification_protocol.go @@ -112,7 +112,7 @@ func (p *ProofsVerificationProtocol) Dispatch() error { var finalResultMessage []bool select { case finalResultMessage = <-finalResult: - case <-time.After(libunlynx.DEFAULT_TIMEOUT): + case <-time.After(libunlynx.DefaultTimeout): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } diff --git a/services/service.go b/services/service.go index 1a8efd1..e5a2e9c 100644 --- a/services/service.go +++ b/services/service.go @@ -727,7 +727,7 @@ func (s *Service) ShufflingPhase(targetSurvey SurveyID) error { var tmpShufflingResult []libunlynx.CipherVector select { case tmpShufflingResult = <-pi.(*protocolsunlynx.ShufflingProtocol).FeedbackChannel: - case <-time.After(libunlynx.DEFAULT_TIMEOUT): + case <-time.After(libunlynx.DefaultTimeout): return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") } @@ -762,7 +762,7 @@ func (s *Service) TaggingPhase(targetSurvey SurveyID) error { var tmpDeterministicTaggingResult []libunlynx.DeterministCipherText select { case tmpDeterministicTaggingResult = <-pi.(*protocolsunlynx.DeterministicTaggingProtocol).FeedbackChannel: - case <-time.After(libunlynx.DEFAULT_TIMEOUT): + case <-time.After(libunlynx.DefaultTimeout): return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") } @@ -801,7 +801,7 @@ func (s *Service) AggregationPhase(targetSurvey SurveyID) error { var cothorityAggregatedData protocolsunlynx.CothorityAggregatedData select { case cothorityAggregatedData = <-pi.(*protocolsunlynx.CollectiveAggregationProtocol).FeedbackChannel: - case <-time.After(libunlynx.DEFAULT_TIMEOUT): + case <-time.After(libunlynx.DefaultTimeout): return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") } @@ -830,7 +830,7 @@ func (s *Service) DROPhase(targetSurvey SurveyID) error { var tmpShufflingResult []libunlynx.CipherVector select { case tmpShufflingResult = <-pi.(*protocolsunlynx.ShufflingProtocol).FeedbackChannel: - case <-time.After(libunlynx.DEFAULT_TIMEOUT): + case <-time.After(libunlynx.DefaultTimeout): return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") } @@ -856,7 +856,7 @@ func (s *Service) KeySwitchingPhase(targetSurvey SurveyID) error { var tmpKeySwitchedAggregatedResponses libunlynx.CipherVector select { case tmpKeySwitchedAggregatedResponses = <-pi.(*protocolsunlynx.KeySwitchingProtocol).FeedbackChannel: - case <-time.After(libunlynx.DEFAULT_TIMEOUT): + case <-time.After(libunlynx.DefaultTimeout): return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") } diff --git a/simul/addrm_server_simul.go b/simul/addrm_server_simul.go index 9bca364..ad884f3 100644 --- a/simul/addrm_server_simul.go +++ b/simul/addrm_server_simul.go @@ -90,7 +90,7 @@ func (sim *AddRmSimulation) Run(config *onet.SimulationConfig) error { case results := <-root.ProtocolInstance().(*protocolsunlynxutils.AddRmServerProtocol).FeedbackChannel: log.Lvl1("Number of aggregated lines: ", len(results)) libunlynx.EndTimer(round) - case <-time.After(libunlynx.DEFAULT_TIMEOUT): + case <-time.After(libunlynx.DefaultTimeout): return fmt.Errorf("simulation didn't finish in time") } } diff --git a/simul/local_aggregation_simul.go b/simul/local_aggregation_simul.go index afa0ed5..a1ef139 100644 --- a/simul/local_aggregation_simul.go +++ b/simul/local_aggregation_simul.go @@ -120,7 +120,7 @@ func (sim *LocalAggregationSimulation) Run(config *onet.SimulationConfig) error case results := <-root.ProtocolInstance().(*protocolsunlynxutils.LocalAggregationProtocol).FeedbackChannel: log.Lvl1("Number of aggregated lines: ", len(results)) libunlynx.EndTimer(round) - case <-time.After(libunlynx.DEFAULT_TIMEOUT): + case <-time.After(libunlynx.DefaultTimeout): return fmt.Errorf("simulation didn't finish in time") } } diff --git a/simul/local_clear_aggregation_simul.go b/simul/local_clear_aggregation_simul.go index d52f53d..429be91 100644 --- a/simul/local_clear_aggregation_simul.go +++ b/simul/local_clear_aggregation_simul.go @@ -97,7 +97,7 @@ func (sim *LocalClearAggregationSimulation) Run(config *onet.SimulationConfig) e log.Lvl1("Result is wrong! :(") } round.Record() - case <-time.After(libunlynx.DEFAULT_TIMEOUT): + case <-time.After(libunlynx.DefaultTimeout): return fmt.Errorf("simulation didn't finish in time") } } diff --git a/simul/proofs_verification_simul.go b/simul/proofs_verification_simul.go index ddf323a..34c7cad 100644 --- a/simul/proofs_verification_simul.go +++ b/simul/proofs_verification_simul.go @@ -250,7 +250,7 @@ func (sim *ProofsVerificationSimulation) Run(config *onet.SimulationConfig) erro } else if results[5] == false { return fmt.Errorf("collective aggregation proofs failed") } - case <-time.After(libunlynx.DEFAULT_TIMEOUT): + case <-time.After(libunlynx.DefaultTimeout): return fmt.Errorf("simulation didn't finish in time") } } From 8563eee0a8807bb312f26e71e3dbc041cffb9550 Mon Sep 17 00:00:00 2001 From: Joao Sa Sousa Date: Thu, 12 Mar 2020 13:44:58 +0100 Subject: [PATCH 17/22] Revert name to TIMEOUT because of golang naming convention (to avoid go lint error) --- lib/constants.go | 8 ++++---- protocols/collective_aggregation_protocol.go | 2 +- protocols/deterministic_tagging_protocol.go | 4 ++-- protocols/key_switching_protocol.go | 2 +- protocols/shuffling+ddt_protocol.go | 4 ++-- protocols/shuffling_protocol.go | 4 ++-- protocols/utils/addrm_server_protocol.go | 2 +- protocols/utils/local_aggregation_protocol.go | 2 +- protocols/utils/local_clear_aggregation_protocol.go | 2 +- protocols/utils/proofs_verification_protocol.go | 2 +- services/service.go | 10 +++++----- simul/addrm_server_simul.go | 2 +- simul/local_aggregation_simul.go | 2 +- simul/local_clear_aggregation_simul.go | 2 +- simul/proofs_verification_simul.go | 2 +- 15 files changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/constants.go b/lib/constants.go index e6555b5..7f3ba19 100644 --- a/lib/constants.go +++ b/lib/constants.go @@ -12,9 +12,9 @@ import ( func init() { tmp, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) if err == nil { - DefaultTimeout = tmp + TIMEOUT = tmp } else { - log.Warn("Couldn't parse MEDCO_TIMEOUT, using default value: ", DefaultTimeout.String()) + log.Warn("Couldn't parse MEDCO_TIMEOUT, using default value: ", TIMEOUT.String()) } } @@ -30,8 +30,8 @@ const VPARALLELIZE = 100 // DIFFPRI enables the DRO protocol (Distributed Results Obfuscation) const DIFFPRI = false -// DefaultTimeout ddefines the default channel timeout -var DefaultTimeout = 10 * time.Minute +// TIMEOUT ddefines the default channel timeout +var TIMEOUT = 10 * time.Minute // StartTimer starts measurement of time func StartTimer(name string) *monitor.TimeMeasure { diff --git a/protocols/collective_aggregation_protocol.go b/protocols/collective_aggregation_protocol.go index 94732b8..43b4f00 100644 --- a/protocols/collective_aggregation_protocol.go +++ b/protocols/collective_aggregation_protocol.go @@ -201,7 +201,7 @@ func (p *CollectiveAggregationProtocol) aggregationAnnouncementPhase() error { if err := p.SendToChildren(&dataReferenceMessage.DataReferenceMessage); err != nil { return fmt.Errorf("error sending : %v", err) } - case <-time.After(libunlynx.DefaultTimeout): + case <-time.After(libunlynx.TIMEOUT): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } return nil diff --git a/protocols/deterministic_tagging_protocol.go b/protocols/deterministic_tagging_protocol.go index f79663d..047ed20 100644 --- a/protocols/deterministic_tagging_protocol.go +++ b/protocols/deterministic_tagging_protocol.go @@ -158,7 +158,7 @@ func (p *DeterministicTaggingProtocol) Dispatch() error { var deterministicTaggingTargetBytesBef deterministicTaggingBytesStruct select { case deterministicTaggingTargetBytesBef = <-p.PreviousNodeInPathChannel: - case <-time.After(libunlynx.DefaultTimeout): + case <-time.After(libunlynx.TIMEOUT): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the (first round) on time") } @@ -211,7 +211,7 @@ func (p *DeterministicTaggingProtocol) Dispatch() error { var deterministicTaggingTargetBytes deterministicTaggingBytesStruct select { case deterministicTaggingTargetBytes = <-p.PreviousNodeInPathChannel: - case <-time.After(libunlynx.DefaultTimeout): + case <-time.After(libunlynx.TIMEOUT): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the (second round) on time") } diff --git a/protocols/key_switching_protocol.go b/protocols/key_switching_protocol.go index 7311e2f..a774605 100644 --- a/protocols/key_switching_protocol.go +++ b/protocols/key_switching_protocol.go @@ -233,7 +233,7 @@ func (p *KeySwitchingProtocol) announcementKSPhase() (kyber.Point, []kyber.Point var dataReferenceMessage DownBytesStruct select { case dataReferenceMessage = <-p.DownChannel: - case <-time.After(libunlynx.DefaultTimeout): + case <-time.After(libunlynx.TIMEOUT): return nil, nil, fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } diff --git a/protocols/shuffling+ddt_protocol.go b/protocols/shuffling+ddt_protocol.go index 7d80309..20759fd 100644 --- a/protocols/shuffling+ddt_protocol.go +++ b/protocols/shuffling+ddt_protocol.go @@ -156,14 +156,14 @@ func (p *ShufflingPlusDDTProtocol) Dispatch() error { var shufflingPlusDDTBytesMessageLength shufflingPlusDDTBytesLengthStruct select { case shufflingPlusDDTBytesMessageLength = <-p.LengthNodeChannel: - case <-time.After(libunlynx.DefaultTimeout): + case <-time.After(libunlynx.TIMEOUT): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } var tmp shufflingPlusDDTBytesStruct select { case tmp = <-p.PreviousNodeInPathChannel: - case <-time.After(libunlynx.DefaultTimeout): + case <-time.After(libunlynx.TIMEOUT): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } diff --git a/protocols/shuffling_protocol.go b/protocols/shuffling_protocol.go index 34c4dcf..3bc90d2 100644 --- a/protocols/shuffling_protocol.go +++ b/protocols/shuffling_protocol.go @@ -190,14 +190,14 @@ func (p *ShufflingProtocol) Dispatch() error { var shufflingBytesMessageLength shufflingBytesLengthStruct select { case shufflingBytesMessageLength = <-p.LengthNodeChannel: - case <-time.After(libunlynx.DefaultTimeout): + case <-time.After(libunlynx.TIMEOUT): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } var tmp shufflingBytesStruct select { case tmp = <-p.PreviousNodeInPathChannel: - case <-time.After(libunlynx.DefaultTimeout): + case <-time.After(libunlynx.TIMEOUT): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } diff --git a/protocols/utils/addrm_server_protocol.go b/protocols/utils/addrm_server_protocol.go index e27a5aa..ec192c7 100644 --- a/protocols/utils/addrm_server_protocol.go +++ b/protocols/utils/addrm_server_protocol.go @@ -96,7 +96,7 @@ func (p *AddRmServerProtocol) Dispatch() error { var finalResultMessage []libunlynx.CipherText select { case finalResultMessage = <-finalResultAddrm: - case <-time.After(libunlynx.DefaultTimeout): + case <-time.After(libunlynx.TIMEOUT): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } diff --git a/protocols/utils/local_aggregation_protocol.go b/protocols/utils/local_aggregation_protocol.go index 60adc9e..665cb3b 100644 --- a/protocols/utils/local_aggregation_protocol.go +++ b/protocols/utils/local_aggregation_protocol.go @@ -87,7 +87,7 @@ func (p *LocalAggregationProtocol) Dispatch() error { var finalResultMessage map[libunlynx.GroupingKey]libunlynx.FilteredResponse select { case finalResultMessage = <-finalResultAggr: - case <-time.After(libunlynx.DefaultTimeout): + case <-time.After(libunlynx.TIMEOUT): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } diff --git a/protocols/utils/local_clear_aggregation_protocol.go b/protocols/utils/local_clear_aggregation_protocol.go index 287e660..9e73549 100644 --- a/protocols/utils/local_clear_aggregation_protocol.go +++ b/protocols/utils/local_clear_aggregation_protocol.go @@ -61,7 +61,7 @@ func (p *LocalClearAggregationProtocol) Dispatch() error { var finalResultMessage []libunlynx.DpClearResponse select { case finalResultMessage = <-finalResultClearAggr: - case <-time.After(libunlynx.DefaultTimeout): + case <-time.After(libunlynx.TIMEOUT): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } diff --git a/protocols/utils/proofs_verification_protocol.go b/protocols/utils/proofs_verification_protocol.go index 8d47012..7cbf169 100644 --- a/protocols/utils/proofs_verification_protocol.go +++ b/protocols/utils/proofs_verification_protocol.go @@ -112,7 +112,7 @@ func (p *ProofsVerificationProtocol) Dispatch() error { var finalResultMessage []bool select { case finalResultMessage = <-finalResult: - case <-time.After(libunlynx.DefaultTimeout): + case <-time.After(libunlynx.TIMEOUT): return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } diff --git a/services/service.go b/services/service.go index e5a2e9c..f703fe3 100644 --- a/services/service.go +++ b/services/service.go @@ -727,7 +727,7 @@ func (s *Service) ShufflingPhase(targetSurvey SurveyID) error { var tmpShufflingResult []libunlynx.CipherVector select { case tmpShufflingResult = <-pi.(*protocolsunlynx.ShufflingProtocol).FeedbackChannel: - case <-time.After(libunlynx.DefaultTimeout): + case <-time.After(libunlynx.TIMEOUT): return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") } @@ -762,7 +762,7 @@ func (s *Service) TaggingPhase(targetSurvey SurveyID) error { var tmpDeterministicTaggingResult []libunlynx.DeterministCipherText select { case tmpDeterministicTaggingResult = <-pi.(*protocolsunlynx.DeterministicTaggingProtocol).FeedbackChannel: - case <-time.After(libunlynx.DefaultTimeout): + case <-time.After(libunlynx.TIMEOUT): return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") } @@ -801,7 +801,7 @@ func (s *Service) AggregationPhase(targetSurvey SurveyID) error { var cothorityAggregatedData protocolsunlynx.CothorityAggregatedData select { case cothorityAggregatedData = <-pi.(*protocolsunlynx.CollectiveAggregationProtocol).FeedbackChannel: - case <-time.After(libunlynx.DefaultTimeout): + case <-time.After(libunlynx.TIMEOUT): return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") } @@ -830,7 +830,7 @@ func (s *Service) DROPhase(targetSurvey SurveyID) error { var tmpShufflingResult []libunlynx.CipherVector select { case tmpShufflingResult = <-pi.(*protocolsunlynx.ShufflingProtocol).FeedbackChannel: - case <-time.After(libunlynx.DefaultTimeout): + case <-time.After(libunlynx.TIMEOUT): return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") } @@ -856,7 +856,7 @@ func (s *Service) KeySwitchingPhase(targetSurvey SurveyID) error { var tmpKeySwitchedAggregatedResponses libunlynx.CipherVector select { case tmpKeySwitchedAggregatedResponses = <-pi.(*protocolsunlynx.KeySwitchingProtocol).FeedbackChannel: - case <-time.After(libunlynx.DefaultTimeout): + case <-time.After(libunlynx.TIMEOUT): return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") } diff --git a/simul/addrm_server_simul.go b/simul/addrm_server_simul.go index ad884f3..512a7ac 100644 --- a/simul/addrm_server_simul.go +++ b/simul/addrm_server_simul.go @@ -90,7 +90,7 @@ func (sim *AddRmSimulation) Run(config *onet.SimulationConfig) error { case results := <-root.ProtocolInstance().(*protocolsunlynxutils.AddRmServerProtocol).FeedbackChannel: log.Lvl1("Number of aggregated lines: ", len(results)) libunlynx.EndTimer(round) - case <-time.After(libunlynx.DefaultTimeout): + case <-time.After(libunlynx.TIMEOUT): return fmt.Errorf("simulation didn't finish in time") } } diff --git a/simul/local_aggregation_simul.go b/simul/local_aggregation_simul.go index a1ef139..3ec5ce4 100644 --- a/simul/local_aggregation_simul.go +++ b/simul/local_aggregation_simul.go @@ -120,7 +120,7 @@ func (sim *LocalAggregationSimulation) Run(config *onet.SimulationConfig) error case results := <-root.ProtocolInstance().(*protocolsunlynxutils.LocalAggregationProtocol).FeedbackChannel: log.Lvl1("Number of aggregated lines: ", len(results)) libunlynx.EndTimer(round) - case <-time.After(libunlynx.DefaultTimeout): + case <-time.After(libunlynx.TIMEOUT): return fmt.Errorf("simulation didn't finish in time") } } diff --git a/simul/local_clear_aggregation_simul.go b/simul/local_clear_aggregation_simul.go index 429be91..6fd7ef4 100644 --- a/simul/local_clear_aggregation_simul.go +++ b/simul/local_clear_aggregation_simul.go @@ -97,7 +97,7 @@ func (sim *LocalClearAggregationSimulation) Run(config *onet.SimulationConfig) e log.Lvl1("Result is wrong! :(") } round.Record() - case <-time.After(libunlynx.DefaultTimeout): + case <-time.After(libunlynx.TIMEOUT): return fmt.Errorf("simulation didn't finish in time") } } diff --git a/simul/proofs_verification_simul.go b/simul/proofs_verification_simul.go index 34c7cad..6d3f758 100644 --- a/simul/proofs_verification_simul.go +++ b/simul/proofs_verification_simul.go @@ -250,7 +250,7 @@ func (sim *ProofsVerificationSimulation) Run(config *onet.SimulationConfig) erro } else if results[5] == false { return fmt.Errorf("collective aggregation proofs failed") } - case <-time.After(libunlynx.DefaultTimeout): + case <-time.After(libunlynx.TIMEOUT): return fmt.Errorf("simulation didn't finish in time") } } From a4d36eb6b7704a764920aea9a082a097be44028c Mon Sep 17 00:00:00 2001 From: Joao Sa Sousa Date: Thu, 12 Mar 2020 14:36:02 +0100 Subject: [PATCH 18/22] Cleaned some of the tmp variables --- app/client.go | 8 +-- lib/aggregation/aggregation_proofs.go | 6 +-- lib/constants.go | 4 +- .../deterministic_tag_test.go | 3 +- lib/shuffle/shuffle.go | 28 +++++----- lib/shuffle/shuffle_proofs.go | 34 ++++++------ lib/store/store.go | 6 +-- lib/structs.go | 16 +++--- protocols/collective_aggregation_protocol.go | 6 +-- protocols/collective_aggregation_test.go | 4 +- protocols/deterministic_tagging_protocol.go | 18 +++---- protocols/shuffling+ddt_protocol.go | 22 ++++---- protocols/shuffling_protocol.go | 8 +-- protocols/utils/addrm_server_protocol.go | 5 +- protocols/utils/proofs_verification_test.go | 8 +-- services/service.go | 54 +++++++++---------- simul/local_aggregation_simul.go | 6 +-- simul/proofs_verification_simul.go | 10 ++-- 18 files changed, 121 insertions(+), 125 deletions(-) diff --git a/app/client.go b/app/client.go index 3fe022a..4402fad 100644 --- a/app/client.go +++ b/app/client.go @@ -125,17 +125,17 @@ func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, group where = strings.Replace(where, " ", "", -1) where = strings.Replace(where, "{", "", -1) where = strings.Replace(where, "}", "", -1) - tmp := strings.Split(where, ",") + whereTokens := strings.Split(where, ",") whereFinal := make([]libunlynx.WhereQueryAttribute, 0) var variable string - for i := range tmp { + for i := range whereTokens { // if is a variable (w1, w2...) if i%2 == 0 { - variable = tmp[i] + variable = whereTokens[i] } else { // if it is a value - value, err := strconv.Atoi(tmp[i]) + value, err := strconv.Atoi(whereTokens[i]) if err != nil { return nil, false, nil, "", nil, err } diff --git a/lib/aggregation/aggregation_proofs.go b/lib/aggregation/aggregation_proofs.go index a74b7a5..3658644 100644 --- a/lib/aggregation/aggregation_proofs.go +++ b/lib/aggregation/aggregation_proofs.go @@ -164,15 +164,15 @@ func (palp *PublishedAggregationListProof) FromBytes(palpb PublishedAggregationL for i, papb := range palpb.List { go func(index int, papb PublishedAggregationProofBytes) { defer wg.Done() - tmp := PublishedAggregationProof{} - tmpErr := tmp.FromBytes(papb) + pap := PublishedAggregationProof{} + tmpErr := pap.FromBytes(papb) if tmpErr != nil { mutex.Lock() err = tmpErr mutex.Unlock() return } - palp.List[index] = tmp + palp.List[index] = pap }(i, papb) } libunlynx.EndParallelize(wg) diff --git a/lib/constants.go b/lib/constants.go index 7f3ba19..824ce33 100644 --- a/lib/constants.go +++ b/lib/constants.go @@ -10,9 +10,9 @@ import ( ) func init() { - tmp, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) + timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) if err == nil { - TIMEOUT = tmp + TIMEOUT = timeout } else { log.Warn("Couldn't parse MEDCO_TIMEOUT, using default value: ", TIMEOUT.String()) } diff --git a/lib/deterministic_tag/deterministic_tag_test.go b/lib/deterministic_tag/deterministic_tag_test.go index 0fe2068..a0f25a6 100644 --- a/lib/deterministic_tag/deterministic_tag_test.go +++ b/lib/deterministic_tag/deterministic_tag_test.go @@ -19,8 +19,7 @@ func TestDeterministicTagSequence(t *testing.T) { target := []int64{-8358645081376817152, -8358645081376817152, 2, 3, 2, 5} cv := *libunlynx.EncryptIntVector(K, target) for n := 0; n < N; n++ { - tmp := libunlynxdetertag.DeterministicTagSequence(cv, private[n], secretPrivate[n]) - cv = tmp + cv = libunlynxdetertag.DeterministicTagSequence(cv, private[n], secretPrivate[n]) } assert.True(t, cv[0].C.Equal(cv[1].C)) diff --git a/lib/shuffle/shuffle.go b/lib/shuffle/shuffle.go index a91414c..2044f7a 100644 --- a/lib/shuffle/shuffle.go +++ b/lib/shuffle/shuffle.go @@ -63,15 +63,15 @@ func shuffle(pi []int, i int, inputList, outputList []libunlynx.CipherVector, NQ wg := libunlynx.StartParallelize(NQ) for j := 0; j < NQ; j++ { var b kyber.Scalar - var tmpCipher libunlynx.CipherText + var ct libunlynx.CipherText if len(precomputedPoints[0]) == 0 { b = beta[index][j] } else { - tmpCipher = precomputedPoints[index][j] + ct = precomputedPoints[index][j] } go func(j int) { defer wg.Done() - outputList[i][j] = rerandomize(inputList[index], b, b, tmpCipher, g, h, j) + outputList[i][j] = rerandomize(inputList[index], b, b, ct, g, h, j) }(j) } libunlynx.EndParallelize(wg) @@ -80,19 +80,19 @@ func shuffle(pi []int, i int, inputList, outputList []libunlynx.CipherVector, NQ // rerandomize rerandomizes an element in a ciphervector at position j, following the Neff Shuffling algorithm func rerandomize(cv libunlynx.CipherVector, a, b kyber.Scalar, cipher libunlynx.CipherText, g, h kyber.Point, j int) libunlynx.CipherText { ct := libunlynx.NewCipherText() - var tmp1, tmp2 kyber.Point + var point1, point2 kyber.Point if cipher.C == nil { //no precomputed value - tmp1 = libunlynx.SuiTe.Point().Mul(a, g) - tmp2 = libunlynx.SuiTe.Point().Mul(b, h) + point1 = libunlynx.SuiTe.Point().Mul(a, g) + point2 = libunlynx.SuiTe.Point().Mul(b, h) } else { - tmp1 = cipher.K - tmp2 = cipher.C + point1 = cipher.K + point2 = cipher.C } - ct.K = libunlynx.SuiTe.Point().Add(cv[j].K, tmp1) - ct.C = libunlynx.SuiTe.Point().Add(cv[j].C, tmp2) + ct.K = libunlynx.SuiTe.Point().Add(cv[j].K, point1) + ct.C = libunlynx.SuiTe.Point().Add(cv[j].C, point2) return *ct } @@ -113,12 +113,12 @@ func CreatePrecomputedRandomize(g, h kyber.Point, rand cipher.Stream, lineSize, for w := range result[i].CipherV { mutex.Lock() - tmp := libunlynx.SuiTe.Scalar().Pick(rand) + scalar := libunlynx.SuiTe.Scalar().Pick(rand) mutex.Unlock() - result[i].S[w] = tmp - result[i].CipherV[w].K = libunlynx.SuiTe.Point().Mul(tmp, g) - result[i].CipherV[w].C = libunlynx.SuiTe.Point().Mul(tmp, h) + result[i].S[w] = scalar + result[i].CipherV[w].K = libunlynx.SuiTe.Point().Mul(scalar, g) + result[i].CipherV[w].C = libunlynx.SuiTe.Point().Mul(scalar, h) } }(i) diff --git a/lib/shuffle/shuffle_proofs.go b/lib/shuffle/shuffle_proofs.go index 78be8fa..e0873b0 100644 --- a/lib/shuffle/shuffle_proofs.go +++ b/lib/shuffle/shuffle_proofs.go @@ -343,7 +343,7 @@ func compressCipherVectorMultiple(inputList, outputList []libunlynx.CipherVector wg := libunlynx.StartParallelize(2) go func() { defer wg.Done() - tmp, tmpErr := compressCipherVector(inputList[i], e) + cv, tmpErr := compressCipherVector(inputList[i], e) if tmpErr != nil { mutex.Lock() err = tmpErr @@ -351,12 +351,12 @@ func compressCipherVectorMultiple(inputList, outputList []libunlynx.CipherVector return } - Xhat[i] = tmp.K - Yhat[i] = tmp.C + Xhat[i] = cv.K + Yhat[i] = cv.C }() go func() { defer wg.Done() - tmpBar, tmpErr := compressCipherVector(outputList[i], e) + cv, tmpErr := compressCipherVector(outputList[i], e) if tmpErr != nil { mutex.Lock() err = tmpErr @@ -364,8 +364,8 @@ func compressCipherVectorMultiple(inputList, outputList []libunlynx.CipherVector return } - XhatBar[i] = tmpBar.K - YhatBar[i] = tmpBar.C + XhatBar[i] = cv.K + YhatBar[i] = cv.C }() libunlynx.EndParallelize(wg) @@ -388,8 +388,8 @@ func compressBeta(beta [][]kyber.Scalar, e []kyber.Scalar) []kyber.Scalar { go func(i int) { defer wg.Done() for j := 0; j < NQ; j++ { - tmp := libunlynx.SuiTe.Scalar().Mul(beta[i][j], e[j]) - betaCompressed[i] = libunlynx.SuiTe.Scalar().Add(betaCompressed[i], tmp) + betaMulE := libunlynx.SuiTe.Scalar().Mul(beta[i][j], e[j]) + betaCompressed[i] = libunlynx.SuiTe.Scalar().Add(betaCompressed[i], betaMulE) } }(i) } @@ -412,7 +412,7 @@ func (psp *PublishedShufflingProof) ToBytes() (PublishedShufflingProofBytes, err wg := libunlynx.StartParallelize(3) go func(data []libunlynx.CipherVector) { defer wg.Done() - tmp, tmpLength, tmpErr := libunlynx.ArrayCipherVectorToBytes(data) + cvBytes, cvLengthBytes, tmpErr := libunlynx.ArrayCipherVectorToBytes(data) if tmpErr != nil { mutex.Lock() err = tmpErr @@ -420,14 +420,14 @@ func (psp *PublishedShufflingProof) ToBytes() (PublishedShufflingProofBytes, err return } - pspb.OriginalList = &tmp - pspb.OriginalListLength = &tmpLength + pspb.OriginalList = &cvBytes + pspb.OriginalListLength = &cvLengthBytes }(psp.OriginalList) // convert ShuffledList go func(data []libunlynx.CipherVector) { defer wg.Done() - tmp, tmpLength, tmpErr := libunlynx.ArrayCipherVectorToBytes(data) + cvBytes, cvLengthBytes, tmpErr := libunlynx.ArrayCipherVectorToBytes(data) if tmpErr != nil { mutex.Lock() err = tmpErr @@ -435,8 +435,8 @@ func (psp *PublishedShufflingProof) ToBytes() (PublishedShufflingProofBytes, err return } - pspb.ShuffledList = &tmp - pspb.ShuffledListLength = &tmpLength + pspb.ShuffledList = &cvBytes + pspb.ShuffledListLength = &cvLengthBytes }(psp.ShuffledList) // convert 'the rest' @@ -450,8 +450,7 @@ func (psp *PublishedShufflingProof) ToBytes() (PublishedShufflingProofBytes, err mutex.Unlock() return } - tmpGBytes := dataG - pspb.G = &tmpGBytes + pspb.G = &dataG dataH, tmpErr := libunlynx.AbstractPointsToBytes([]kyber.Point{H}) if tmpErr != nil { @@ -460,8 +459,7 @@ func (psp *PublishedShufflingProof) ToBytes() (PublishedShufflingProofBytes, err mutex.Unlock() return } - tmpHBytes := dataH - pspb.H = &tmpHBytes + pspb.H = &dataH pspb.HashProof = psp.HashProof }(psp.G, psp.H, psp.HashProof) diff --git a/lib/store/store.go b/lib/store/store.go index 2fe0266..6c505c0 100644 --- a/lib/store/store.go +++ b/lib/store/store.go @@ -85,10 +85,10 @@ func (s *Store) InsertDpResponse(cr libunlynx.DpResponse, proofsB bool, groupBy, } else { value, ok := s.DpResponsesAggr[GroupingKeyTuple{libunlynx.Key(clearGrp), libunlynx.Key(clearWhr)}] if ok { - tmp := libunlynx.NewCipherVector(len(value.AggregatingAttributes)) - tmp.Add(value.AggregatingAttributes, newResp.AggregatingAttributes) + cv := libunlynx.NewCipherVector(len(value.AggregatingAttributes)) + cv.Add(value.AggregatingAttributes, newResp.AggregatingAttributes) mapValue := s.DpResponsesAggr[GroupingKeyTuple{libunlynx.Key(clearGrp), libunlynx.Key(clearWhr)}] - mapValue.AggregatingAttributes = *tmp + mapValue.AggregatingAttributes = *cv s.DpResponsesAggr[GroupingKeyTuple{libunlynx.Key(clearGrp), libunlynx.Key(clearWhr)}] = mapValue if proofsB { diff --git a/lib/structs.go b/lib/structs.go index 9bb1273..0e1a733 100644 --- a/lib/structs.go +++ b/lib/structs.go @@ -105,8 +105,8 @@ func AddInMap(s map[GroupingKey]FilteredResponse, key GroupingKey, added Filtere if localResult, ok := s[key]; !ok { s[key] = added } else { - tmp := NewFilteredResponse(len(added.GroupByEnc), len(added.AggregatingAttributes)) - s[key] = *tmp.Add(localResult, added) + nfr := NewFilteredResponse(len(added.GroupByEnc), len(added.AggregatingAttributes)) + s[key] = *nfr.Add(localResult, added) } } @@ -141,9 +141,9 @@ func (crd *FilteredResponseDet) FormatAggregationProofs(res map[GroupingKey][]Ci } else { // if no elements are in the map yet container := make([]CipherVector, len(crd.Fr.AggregatingAttributes)) for i, ct := range crd.Fr.AggregatingAttributes { - tmp := make(CipherVector, 0) - tmp = append(tmp, ct) - container[i] = tmp + cv := make(CipherVector, 0) + cv = append(cv, ct) + container[i] = cv res[crd.DetTagGroupBy] = container } } @@ -205,7 +205,7 @@ func Key(ga []int64) GroupingKey { return GroupingKey(strings.Join(key, "")) } -// UnKey permits to go from a tag non-encrypted grouping attributes to grouping attributes +// UnKey permits to go from a tag non-encrypted grouping attributes to grouping attributes func UnKey(gk GroupingKey) ([]int64, error) { tab := make([]int64, 0) count := 0 @@ -214,11 +214,11 @@ func UnKey(gk GroupingKey) ([]int64, error) { if a != ',' { nbrString[0] = string(a) } else { - tmp, err := strconv.Atoi(strings.Join(nbrString, "")) + key, err := strconv.Atoi(strings.Join(nbrString, "")) if err != nil { return nil, err } - tab = append(tab, int64(tmp)) + tab = append(tab, int64(key)) nbrString = make([]string, 1) count++ } diff --git a/protocols/collective_aggregation_protocol.go b/protocols/collective_aggregation_protocol.go index 43b4f00..40fb36b 100644 --- a/protocols/collective_aggregation_protocol.go +++ b/protocols/collective_aggregation_protocol.go @@ -238,10 +238,10 @@ func (p *CollectiveAggregationProtocol) ascendingAggregationPhase(cvMap map[libu } if ok { - tmp := libunlynx.NewCipherVector(len(localAggr.AggregatingAttributes)) - tmp.Add(localAggr.AggregatingAttributes, aggr.Fr.AggregatingAttributes) + cv := libunlynx.NewCipherVector(len(localAggr.AggregatingAttributes)) + cv.Add(localAggr.AggregatingAttributes, aggr.Fr.AggregatingAttributes) - localAggr.AggregatingAttributes = *tmp + localAggr.AggregatingAttributes = *cv } else { localAggr = aggr.Fr } diff --git a/protocols/collective_aggregation_test.go b/protocols/collective_aggregation_test.go index d634faa..120c0c3 100644 --- a/protocols/collective_aggregation_test.go +++ b/protocols/collective_aggregation_test.go @@ -138,8 +138,8 @@ func TestCollectiveAggregationSimple(t *testing.T) { case encryptedResult := <-feedback: log.Lvl1("Received results:") resultData := make([]int64, len(encryptedResult.GroupedData[protocolsunlynx.EMPTYKEY].AggregatingAttributes)) - tmp := encryptedResult.GroupedData[protocolsunlynx.EMPTYKEY].AggregatingAttributes - resultData = libunlynx.DecryptIntVector(clientPrivate, &tmp) + aggrAttr := encryptedResult.GroupedData[protocolsunlynx.EMPTYKEY].AggregatingAttributes + resultData = libunlynx.DecryptIntVector(clientPrivate, &aggrAttr) log.Lvl1(resultData) assert.Equal(t, expectedResults, resultData) case <-time.After(timeout): diff --git a/protocols/deterministic_tagging_protocol.go b/protocols/deterministic_tagging_protocol.go index 047ed20..a457f8c 100644 --- a/protocols/deterministic_tagging_protocol.go +++ b/protocols/deterministic_tagging_protocol.go @@ -178,9 +178,9 @@ func (p *DeterministicTaggingProtocol) Dispatch() error { go func(i int) { defer wg.Done() for j := 0; j < libunlynx.VPARALLELIZE && (i+j) < len(deterministicTaggingTargetBef.Data); j++ { - tmp := libunlynx.SuiTe.Point().Add(deterministicTaggingTargetBef.Data[i+j].C, toAdd) + r := libunlynx.SuiTe.Point().Add(deterministicTaggingTargetBef.Data[i+j].C, toAdd) if p.Proofs { - _, tmpErr := libunlynxdetertag.DeterministicTagAdditionProofCreation(deterministicTaggingTargetBef.Data[i+j].C, *p.SurveySecretKey, toAdd, tmp) + _, tmpErr := libunlynxdetertag.DeterministicTagAdditionProofCreation(deterministicTaggingTargetBef.Data[i+j].C, *p.SurveySecretKey, toAdd, r) if tmpErr != nil { mutex.Lock() err = tmpErr @@ -188,7 +188,7 @@ func (p *DeterministicTaggingProtocol) Dispatch() error { return } } - deterministicTaggingTargetBef.Data[i+j].C = tmp + deterministicTaggingTargetBef.Data[i+j].C = r } }(i) } @@ -233,15 +233,15 @@ func (p *DeterministicTaggingProtocol) Dispatch() error { if j > len(deterministicTaggingTarget.Data) { j = len(deterministicTaggingTarget.Data) } - tmp := deterministicTaggingTarget.Data[i:j] - tmpErr := TaggingDet(&tmp, p.Private(), *p.SurveySecretKey, p.Public(), p.Proofs) + cv := deterministicTaggingTarget.Data[i:j] + tmpErr := TaggingDet(&cv, p.Private(), *p.SurveySecretKey, p.Public(), p.Proofs) if tmpErr != nil { mutex.Lock() err = tmpErr mutex.Unlock() return } - copy(deterministicTaggingTarget.Data[i:j], tmp) + copy(deterministicTaggingTarget.Data[i:j], cv) }(i) } wg.Wait() @@ -394,9 +394,9 @@ func (dtm *DeterministicTaggingMessage) FromBytes(data []byte) error { go func(i int) { defer wg.Done() for j := 0; j < elementSize*libunlynx.VPARALLELIZE && i+j < len(data); j += elementSize { - tmp := make([]byte, elementSize) - copy(tmp, data[i+j:i+j+elementSize]) - tmpErr := (*dtm).Data[(i+j)/elementSize].FromBytes(tmp) + dataCopy := make([]byte, elementSize) + copy(dataCopy, data[i+j:i+j+elementSize]) + tmpErr := (*dtm).Data[(i+j)/elementSize].FromBytes(dataCopy) if tmpErr != nil { mutex.Lock() err = tmpErr diff --git a/protocols/shuffling+ddt_protocol.go b/protocols/shuffling+ddt_protocol.go index 20759fd..369d0ac 100644 --- a/protocols/shuffling+ddt_protocol.go +++ b/protocols/shuffling+ddt_protocol.go @@ -160,16 +160,16 @@ func (p *ShufflingPlusDDTProtocol) Dispatch() error { return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } - var tmp shufflingPlusDDTBytesStruct + var spDDTbs shufflingPlusDDTBytesStruct select { - case tmp = <-p.PreviousNodeInPathChannel: + case spDDTbs = <-p.PreviousNodeInPathChannel: case <-time.After(libunlynx.TIMEOUT): - return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") + return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } readData := libunlynx.StartTimer(p.Name() + "_ShufflingPlusDDT(ReadData)") sm := ShufflingPlusDDTMessage{} - err := sm.FromBytes(tmp.Data, tmp.ShuffKey, shufflingPlusDDTBytesMessageLength.CVLengths) + err := sm.FromBytes(spDDTbs.Data, spDDTbs.ShuffKey, shufflingPlusDDTBytesMessageLength.CVLengths) if err != nil { return err } @@ -202,9 +202,9 @@ func (p *ShufflingPlusDDTProtocol) Dispatch() error { defer wg.Done() for j := 0; j < libunlynx.VPARALLELIZE && (i+j) < len(shuffledData); j++ { for k := range shuffledData[i+j] { - tmp := libunlynx.SuiTe.Point().Add(shuffledData[i+j][k].C, toAdd) + r := libunlynx.SuiTe.Point().Add(shuffledData[i+j][k].C, toAdd) if p.Proofs { - _, tmpErr := libunlynxdetertag.DeterministicTagAdditionProofCreation(shuffledData[i+j][k].C, *p.SurveySecretKey, toAdd, tmp) + _, tmpErr := libunlynxdetertag.DeterministicTagAdditionProofCreation(shuffledData[i+j][k].C, *p.SurveySecretKey, toAdd, r) if tmpErr != nil { mutex.Lock() err = tmpErr @@ -212,7 +212,7 @@ func (p *ShufflingPlusDDTProtocol) Dispatch() error { return } } - shuffledData[i+j][k].C = tmp + shuffledData[i+j][k].C = r } } }(i) @@ -235,10 +235,10 @@ func (p *ShufflingPlusDDTProtocol) Dispatch() error { go func(i int) { defer wg.Done() for j := 0; j < libunlynx.VPARALLELIZE && (i+j) < len(shuffledData); j++ { - tmp := shuffledData[i+j] - switchedVect := libunlynxdetertag.DeterministicTagSequence(tmp, p.Private(), *p.SurveySecretKey) + vBef := shuffledData[i+j] + vAft := libunlynxdetertag.DeterministicTagSequence(vBef, p.Private(), *p.SurveySecretKey) if p.Proofs { - _, tmpErr := libunlynxdetertag.DeterministicTagCrListProofCreation(tmp, switchedVect, p.Public(), *p.SurveySecretKey, p.Private()) + _, tmpErr := libunlynxdetertag.DeterministicTagCrListProofCreation(vBef, vAft, p.Public(), *p.SurveySecretKey, p.Private()) if tmpErr != nil { mutex.Lock() err = tmpErr @@ -246,7 +246,7 @@ func (p *ShufflingPlusDDTProtocol) Dispatch() error { return } } - copy(shuffledData[i+j], switchedVect) + copy(shuffledData[i+j], vAft) } }(i) } diff --git a/protocols/shuffling_protocol.go b/protocols/shuffling_protocol.go index 3bc90d2..acc6fc7 100644 --- a/protocols/shuffling_protocol.go +++ b/protocols/shuffling_protocol.go @@ -194,15 +194,15 @@ func (p *ShufflingProtocol) Dispatch() error { return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } - var tmp shufflingBytesStruct + var sbs shufflingBytesStruct select { - case tmp = <-p.PreviousNodeInPathChannel: + case sbs = <-p.PreviousNodeInPathChannel: case <-time.After(libunlynx.TIMEOUT): - return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") + return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } sm := ShufflingMessage{} - if err := sm.FromBytes(tmp.Data, shufflingBytesMessageLength.CVLengths); err != nil { + if err := sm.FromBytes(sbs.Data, shufflingBytesMessageLength.CVLengths); err != nil { return err } shuffleTarget := sm.Data diff --git a/protocols/utils/addrm_server_protocol.go b/protocols/utils/addrm_server_protocol.go index ec192c7..9fbcc91 100644 --- a/protocols/utils/addrm_server_protocol.go +++ b/protocols/utils/addrm_server_protocol.go @@ -123,13 +123,12 @@ func changeEncryption(cipherTexts []libunlynx.CipherText, serverAddRmKey kyber.S } func changeEncryptionKeyCipherTexts(cipherText libunlynx.CipherText, serverAddRmKey kyber.Scalar, toAdd bool) libunlynx.CipherText { - tmp := libunlynx.SuiTe.Point().Mul(serverAddRmKey, cipherText.K) result := libunlynx.CipherText{} result.K = cipherText.K if toAdd { - result.C = libunlynx.SuiTe.Point().Add(cipherText.C, tmp) + result.C = libunlynx.SuiTe.Point().Add(cipherText.C, libunlynx.SuiTe.Point().Mul(serverAddRmKey, cipherText.K)) } else { - result.C = libunlynx.SuiTe.Point().Sub(cipherText.C, tmp) + result.C = libunlynx.SuiTe.Point().Sub(cipherText.C, libunlynx.SuiTe.Point().Mul(serverAddRmKey, cipherText.K)) } return result } diff --git a/protocols/utils/proofs_verification_test.go b/protocols/utils/proofs_verification_test.go index 211dde2..07283e5 100644 --- a/protocols/utils/proofs_verification_test.go +++ b/protocols/utils/proofs_verification_test.go @@ -67,14 +67,14 @@ func TestProofsVerification(t *testing.T) { toAddWrong := libunlynx.SuiTe.Point().Mul(secKey, libunlynx.SuiTe.Point().Base()) for j := 0; j < 2; j++ { for i := range cipherVect { - tmp := libunlynx.SuiTe.Point() + point := libunlynx.SuiTe.Point() if j%2 == 0 { - tmp = libunlynx.SuiTe.Point().Add(cipherVect[i].C, toAdd) + point = libunlynx.SuiTe.Point().Add(cipherVect[i].C, toAdd) } else { - tmp = libunlynx.SuiTe.Point().Add(cipherVect[i].C, toAddWrong) + point = libunlynx.SuiTe.Point().Add(cipherVect[i].C, toAddWrong) } - prf, err := libunlynxdetertag.DeterministicTagAdditionProofCreation(cipherVect[i].C, secKeyNew, toAdd, tmp) + prf, err := libunlynxdetertag.DeterministicTagAdditionProofCreation(cipherVect[i].C, secKeyNew, toAdd, point) assert.NoError(t, err) deterministicTaggingAddProofs.List = append(deterministicTaggingAddProofs.List, prf) } diff --git a/services/service.go b/services/service.go index f703fe3..0a8ba8d 100644 --- a/services/service.go +++ b/services/service.go @@ -179,26 +179,26 @@ func NewService(c *onet.Context) (onet.Service, error) { // Process implements the processor interface and is used to recognize messages broadcasted between servers func (s *Service) Process(msg *network.Envelope) { if msg.MsgType.Equal(msgTypes.msgSurveyCreationQuery) { - tmp := (msg.Msg).(*SurveyCreationQuery) - _, err := s.HandleSurveyCreationQuery(tmp) + msgSurveyCreationQuery := (msg.Msg).(*SurveyCreationQuery) + _, err := s.HandleSurveyCreationQuery(msgSurveyCreationQuery) if err != nil { log.Error(err) } } else if msg.MsgType.Equal(msgTypes.msgSurveyResultsQuery) { - tmp := (msg.Msg).(*SurveyResultsQuery) - _, err := s.HandleSurveyResultsQuery(tmp) + msgSurveyResultsQuery := (msg.Msg).(*SurveyResultsQuery) + _, err := s.HandleSurveyResultsQuery(msgSurveyResultsQuery) if err != nil { log.Error(err) } } else if msg.MsgType.Equal(msgTypes.msgQueryBroadcastFinished) { - tmp := (msg.Msg).(*QueryBroadcastFinished) - _, err := s.HandleQueryBroadcastFinished(tmp) + msgQueryBroadcastFinished := (msg.Msg).(*QueryBroadcastFinished) + _, err := s.HandleQueryBroadcastFinished(msgQueryBroadcastFinished) if err != nil { log.Error(err) } } else if msg.MsgType.Equal(msgTypes.msgDDTfinished) { - tmp := (msg.Msg).(*DDTfinished) - _, err := s.HandleDDTfinished(tmp) + msgDDTfinished := (msg.Msg).(*DDTfinished) + _, err := s.HandleDDTfinished(msgDDTfinished) if err != nil { log.Error(err) } @@ -469,18 +469,18 @@ func (s *Service) NewProtocol(tn *onet.TreeNodeInstance, conf *onet.GenericConfi var queryWhereToTag []libunlynx.ProcessResponse for _, v := range survey.Query.Where { - tmp := libunlynx.CipherVector{v.Value} - queryWhereToTag = append(queryWhereToTag, libunlynx.ProcessResponse{WhereEnc: tmp, GroupByEnc: nil, AggregatingAttributes: nil}) + cv := libunlynx.CipherVector{v.Value} + queryWhereToTag = append(queryWhereToTag, libunlynx.ProcessResponse{WhereEnc: cv, GroupByEnc: nil, AggregatingAttributes: nil}) } shuffledClientResponses = append(queryWhereToTag, shuffledClientResponses...) - tmpDeterministicTOS := protocolsunlynx.ProcessResponseToCipherVector(shuffledClientResponses) + deterministicTOS := protocolsunlynx.ProcessResponseToCipherVector(shuffledClientResponses) survey.TargetOfSwitch = shuffledClientResponses err = s.putSurvey(target, survey) if err != nil { return nil, err } - hashCreation.TargetOfSwitch = &tmpDeterministicTOS + hashCreation.TargetOfSwitch = &deterministicTOS } case protocolsunlynx.CollectiveAggregationProtocolName: @@ -562,11 +562,11 @@ func (s *Service) NewProtocol(tn *onet.TreeNodeInstance, conf *onet.GenericConfi } else { coaggr = survey.PullCothorityAggregatedFilteredResponses(false, libunlynx.CipherText{}) } - var tmpKeySwitchingCV libunlynx.CipherVector - tmpKeySwitchingCV, survey.Lengths = protocolsunlynx.FilteredResponseToCipherVector(coaggr) - keySwitch.TargetOfSwitch = &tmpKeySwitchingCV - tmp := survey.Query.ClientPubKey - keySwitch.TargetPublicKey = &tmp + var cv libunlynx.CipherVector + cv, survey.Lengths = protocolsunlynx.FilteredResponseToCipherVector(coaggr) + keySwitch.TargetOfSwitch = &cv + cpk := survey.Query.ClientPubKey + keySwitch.TargetPublicKey = &cpk err = s.putSurvey(target, survey) if err != nil { @@ -581,11 +581,11 @@ func (s *Service) NewProtocol(tn *onet.TreeNodeInstance, conf *onet.GenericConfi // StartProtocol starts a specific protocol (Pipeline, Shuffling, etc.) func (s *Service) StartProtocol(name string, targetSurvey SurveyID) (onet.ProtocolInstance, error) { - tmp, err := s.getSurvey(targetSurvey) + survey, err := s.getSurvey(targetSurvey) if err != nil { return nil, err } - tree := tmp.Query.Roster.GenerateNaryTreeWithRoot(2, s.ServerIdentity()) + tree := survey.Query.Roster.GenerateNaryTreeWithRoot(2, s.ServerIdentity()) var tn *onet.TreeNodeInstance tn = s.NewTreeNodeInstance(tree, tree.Root, name) @@ -798,11 +798,11 @@ func (s *Service) AggregationPhase(targetSurvey SurveyID) error { return err } - var cothorityAggregatedData protocolsunlynx.CothorityAggregatedData + var tmpAggreagtionResult protocolsunlynx.CothorityAggregatedData select { - case cothorityAggregatedData = <-pi.(*protocolsunlynx.CollectiveAggregationProtocol).FeedbackChannel: + case tmpAggreagtionResult = <-pi.(*protocolsunlynx.CollectiveAggregationProtocol).FeedbackChannel: case <-time.After(libunlynx.TIMEOUT): - return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") + return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") } survey, err := s.getSurvey(targetSurvey) @@ -810,7 +810,7 @@ func (s *Service) AggregationPhase(targetSurvey SurveyID) error { return err } - survey.PushCothorityAggregatedFilteredResponses(cothorityAggregatedData.GroupedData) + survey.PushCothorityAggregatedFilteredResponses(tmpAggreagtionResult.GroupedData) err = s.putSurvey(targetSurvey, survey) return err } @@ -853,14 +853,14 @@ func (s *Service) KeySwitchingPhase(targetSurvey SurveyID) error { return err } - var tmpKeySwitchedAggregatedResponses libunlynx.CipherVector + var tmpKeySwitchingResult libunlynx.CipherVector select { - case tmpKeySwitchedAggregatedResponses = <-pi.(*protocolsunlynx.KeySwitchingProtocol).FeedbackChannel: + case tmpKeySwitchingResult = <-pi.(*protocolsunlynx.KeySwitchingProtocol).FeedbackChannel: case <-time.After(libunlynx.TIMEOUT): - return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") + return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") } - keySwitchedAggregatedResponses := protocolsunlynx.CipherVectorToFilteredResponse(tmpKeySwitchedAggregatedResponses, survey.Lengths) + keySwitchedAggregatedResponses := protocolsunlynx.CipherVectorToFilteredResponse(tmpKeySwitchingResult, survey.Lengths) survey.PushQuerierKeyEncryptedResponses(keySwitchedAggregatedResponses) err = s.putSurvey(targetSurvey, survey) diff --git a/simul/local_aggregation_simul.go b/simul/local_aggregation_simul.go index 3ec5ce4..8d90800 100644 --- a/simul/local_aggregation_simul.go +++ b/simul/local_aggregation_simul.go @@ -84,9 +84,9 @@ func (sim *LocalAggregationSimulation) Run(config *onet.SimulationConfig) error groupCipherVect := *libunlynx.EncryptIntVector(pubKey, tabGr) detResponses := make([]libunlynx.FilteredResponseDet, 0) for i := 0; i < sim.NbrGroups; i++ { - tmp := libunlynx.NewCipherVector(sim.NbrGroupAttributes) - tmp.Add(groupCipherVect, groupCipherVect) - groupCipherVect = *tmp + cv := libunlynx.NewCipherVector(sim.NbrGroupAttributes) + cv.Add(groupCipherVect, groupCipherVect) + groupCipherVect = *cv cr := libunlynx.FilteredResponse{GroupByEnc: testCipherVect1, AggregatingAttributes: testCipherVect1} det1 := groupCipherVect if err := protocolsunlynx.TaggingDet(&det1, secKey, newSecKey, pubKey, sim.Proofs); err != nil { diff --git a/simul/proofs_verification_simul.go b/simul/proofs_verification_simul.go index 6d3f758..faf6fff 100644 --- a/simul/proofs_verification_simul.go +++ b/simul/proofs_verification_simul.go @@ -115,8 +115,8 @@ func (sim *ProofsVerificationSimulation) Run(config *onet.SimulationConfig) erro toAdd := libunlynx.SuiTe.Point().Mul(secKeyNew, libunlynx.SuiTe.Point().Base()) for i := range cipherVect { - tmp := libunlynx.SuiTe.Point().Add(cipherVect[i].C, toAdd) - prf, err := libunlynxdetertag.DeterministicTagAdditionProofCreation(cipherVect[i].C, secKeyNew, toAdd, tmp) + r := libunlynx.SuiTe.Point().Add(cipherVect[i].C, toAdd) + prf, err := libunlynxdetertag.DeterministicTagAdditionProofCreation(cipherVect[i].C, secKeyNew, toAdd, r) if err != nil { return err } @@ -145,10 +145,10 @@ func (sim *ProofsVerificationSimulation) Run(config *onet.SimulationConfig) erro detResponses := make([]libunlynx.FilteredResponseDet, 0) for i := 0; i < sim.NbrGroups; i++ { - tmp := libunlynx.NewCipherVector(sim.NbrGroupAttributes) - tmp.Add(cipherVectGr, cipherVectGr) + cv := libunlynx.NewCipherVector(sim.NbrGroupAttributes) + cv.Add(cipherVectGr, cipherVectGr) - cipherVectGr = *tmp + cipherVectGr = *cv det1 := cipherVectGr if err := protocolsunlynx.TaggingDet(&det1, secKey, secKey, pubKey, false); err != nil { return err From c5dddb89cbe0f20e58ac362e4f749bac2b9096a9 Mon Sep 17 00:00:00 2001 From: Joao Sa Sousa Date: Thu, 12 Mar 2020 14:54:42 +0100 Subject: [PATCH 19/22] Corrected if negative conditions --- app/client.go | 8 ++++---- data/handle_data.go | 4 ++-- lib/crypto.go | 12 ++++++------ lib/crypto_test.go | 6 +++--- lib/shuffle/shuffle.go | 2 +- lib/store/store.go | 4 ++-- lib/structs.go | 2 +- lib/tools/tools.go | 2 +- protocols/collective_aggregation_protocol.go | 6 +++--- protocols/deterministic_tagging_test.go | 2 +- protocols/key_switching_protocol.go | 6 +++--- protocols/key_switching_protocol_test.go | 2 +- protocols/shuffling_protocol.go | 2 +- services/service_test.go | 18 +++++++++--------- 14 files changed, 38 insertions(+), 38 deletions(-) diff --git a/app/client.go b/app/client.go index 4402fad..b24f7c7 100644 --- a/app/client.go +++ b/app/client.go @@ -98,7 +98,7 @@ func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, group whereRegex := "{(w[0-9]+(,\\s*[0-9]+))*(,\\s*w[0-9]+(,\\s*[0-9]+))*}" groupByRegex := "{g[0-9]+(,\\s*g[0-9]+)*}" - if !checkRegex(sum, sumRegex) { + if checkRegex(sum, sumRegex) == false { return nil, false, nil, "", nil, fmt.Errorf("error parsing the sum parameter(s)") } sum = strings.Replace(sum, " ", "", -1) @@ -114,12 +114,12 @@ func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, group } } - if !check { + if check == false { return nil, false, nil, "", nil, fmt.Errorf("no 'count' attribute in the sum variables") } } - if !checkRegex(where, whereRegex) { + if checkRegex(where, whereRegex) == false { return nil, false, nil, "", nil, fmt.Errorf("error parsing the where parameter(s)") } where = strings.Replace(where, " ", "", -1) @@ -144,7 +144,7 @@ func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, group } } - if !checkRegex(groupBy, groupByRegex) { + if checkRegex(groupBy, groupByRegex) == false { return nil, false, nil, "", nil, fmt.Errorf("error parsing the groupBy parameter(s)") } groupBy = strings.Replace(groupBy, " ", "", -1) diff --git a/data/handle_data.go b/data/handle_data.go index 913b07f..61d1fc7 100644 --- a/data/handle_data.go +++ b/data/handle_data.go @@ -82,7 +82,7 @@ func GenerateData(numDPs, numEntries, numEntriesFiltered, numGroupsClear, numGro testData := make(map[string][]libunlynx.DpClearResponse) - if !randomGroups { + if randomGroups == false { numElem := 1 for _, el := range numType { numElem = numElem * int(el) @@ -362,7 +362,7 @@ func CompareClearResponses(x []libunlynx.DpClearResponse, y []libunlynx.DpClearR } } - if !test { + if test == false { break } } diff --git a/lib/crypto.go b/lib/crypto.go index 9b85049..665b4cc 100644 --- a/lib/crypto.go +++ b/lib/crypto.go @@ -343,9 +343,9 @@ func discreteLog(P kyber.Point, checkNeg bool) (int64, error) { guessIntMinus := int64(0) start := true - for i := guessInt; i < MaxHomomorphicInt && !foundPos && !foundNeg; i = i + 1 { + for i := guessInt; i < MaxHomomorphicInt && foundPos == false && foundNeg == false; i = i + 1 { // check for 0 first - if !start { + if start == false { guess = SuiTe.Point().Add(guess, B) } start = false @@ -365,7 +365,7 @@ func discreteLog(P kyber.Point, checkNeg bool) (int64, error) { foundNeg = true } } - if !foundNeg && guess.Equal(P) { + if foundNeg == false && guess.Equal(P) { foundPos = true } } @@ -373,7 +373,7 @@ func discreteLog(P kyber.Point, checkNeg bool) (int64, error) { currentGreatestInt = guessInt mutex.Unlock() - if !foundPos && !foundNeg { + if foundPos == false && foundNeg == false { log.Error("out of bound encryption, bound is ", MaxHomomorphicInt) return 0, nil } @@ -451,7 +451,7 @@ func (cv *CipherVector) Equal(cv2 *CipherVector) bool { } for i := range *cv2 { - if !(*cv)[i].Equal(&(*cv2)[i]) { + if (*cv)[i].Equal(&(*cv2)[i]) == false { return false } } @@ -490,7 +490,7 @@ func (dcv *DeterministCipherVector) Equal(dcv2 *DeterministCipherVector) bool { } for i := range *dcv2 { - if !(*dcv)[i].Equal(&(*dcv2)[i]) { + if (*dcv)[i].Equal(&(*dcv2)[i]) == false { return false } } diff --git a/lib/crypto_test.go b/lib/crypto_test.go index 14e0d0d..74f1382 100644 --- a/lib/crypto_test.go +++ b/lib/crypto_test.go @@ -119,7 +119,7 @@ func TestNullCipherVector(t *testing.T) { nullVectDec := libunlynx.DecryptIntVector(secKey, &nullVectEnc) target := []int64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0} - if !reflect.DeepEqual(nullVectDec, target) { + if reflect.DeepEqual(nullVectDec, target) == false { t.Fatal("Null vector of dimension 4 should be ", target, "got", nullVectDec) } @@ -127,7 +127,7 @@ func TestNullCipherVector(t *testing.T) { twoTimesNullEnc.Add(nullVectEnc, nullVectEnc) twoTimesNullDec := libunlynx.DecryptIntVector(secKey, twoTimesNullEnc) - if !reflect.DeepEqual(twoTimesNullDec, target) { + if reflect.DeepEqual(twoTimesNullDec, target) == false { t.Fatal("Null vector + Null vector should be ", target, "got", twoTimesNullDec) } } @@ -198,7 +198,7 @@ func TestAbstractPointsConverter(t *testing.T) { } for i, el := range aps { - if !reflect.DeepEqual(el.String(), newAps[i].String()) { + if reflect.DeepEqual(el.String(), newAps[i].String()) == false { t.Fatal("Wrong results, expected", el, "but got", newAps[i]) } } diff --git a/lib/shuffle/shuffle.go b/lib/shuffle/shuffle.go index 2044f7a..a4af8cb 100644 --- a/lib/shuffle/shuffle.go +++ b/lib/shuffle/shuffle.go @@ -183,7 +183,7 @@ func PrecomputationWritingForShuffling(appFlag bool, gobFile, serverName string, // ReadPrecomputedFile reads the precomputation data from a .gob file func ReadPrecomputedFile(fileName string) ([]CipherVectorScalar, error) { - if _, err := os.Stat(fileName); !os.IsNotExist(err) { + if _, err := os.Stat(fileName); os.IsNotExist(err) == false { var encoded []CipherVectorScalarBytes err := libunlynxtools.ReadFromGobFile(fileName, &encoded) if err != nil { diff --git a/lib/store/store.go b/lib/store/store.go index 6c505c0..490ffd2 100644 --- a/lib/store/store.go +++ b/lib/store/store.go @@ -53,7 +53,7 @@ func proccessParameters(data []string, clear map[string]int64, encrypted map[str // all where and group by attributes are in clear if noEnc { containerClear = append(containerClear, clear[v]) - } else if !noEnc { + } else if noEnc == false { if value, ok := encrypted[v]; ok { containerEnc = append(containerEnc, value) } else { @@ -80,7 +80,7 @@ func (s *Store) InsertDpResponse(cr libunlynx.DpResponse, proofsB bool, groupBy, clearWhr, newResp.WhereEnc = proccessParameters(whereStrings, cr.WhereClear, cr.WhereEnc, noEnc) _, newResp.AggregatingAttributes = proccessParameters(sum, cr.AggregatingAttributesClear, cr.AggregatingAttributesEnc, false) - if !noEnc { + if noEnc == false { s.DpResponses = append(s.DpResponses, newResp) } else { value, ok := s.DpResponsesAggr[GroupingKeyTuple{libunlynx.Key(clearGrp), libunlynx.Key(clearWhr)}] diff --git a/lib/structs.go b/lib/structs.go index 0e1a733..af99a0e 100644 --- a/lib/structs.go +++ b/lib/structs.go @@ -102,7 +102,7 @@ func (cv *FilteredResponse) Add(cv1, cv2 FilteredResponse) *FilteredResponse { // AddInMap permits to add a filtered response with its deterministic tag in a map func AddInMap(s map[GroupingKey]FilteredResponse, key GroupingKey, added FilteredResponse) { - if localResult, ok := s[key]; !ok { + if localResult, ok := s[key]; ok == false { s[key] = added } else { nfr := NewFilteredResponse(len(added.GroupByEnc), len(added.AggregatingAttributes)) diff --git a/lib/tools/tools.go b/lib/tools/tools.go index 0aa8f29..4b57898 100644 --- a/lib/tools/tools.go +++ b/lib/tools/tools.go @@ -16,7 +16,7 @@ import ( func SendISMOthers(s *onet.ServiceProcessor, el *onet.Roster, msg interface{}) error { var errStrs []string for _, e := range el.List { - if !e.ID.Equal(s.ServerIdentity().ID) { + if e.ID.Equal(s.ServerIdentity().ID) == false { log.Lvl3("Sending to", e) err := s.SendRaw(e, msg) if err != nil { diff --git a/protocols/collective_aggregation_protocol.go b/protocols/collective_aggregation_protocol.go index 40fb36b..599b830 100644 --- a/protocols/collective_aggregation_protocol.go +++ b/protocols/collective_aggregation_protocol.go @@ -151,7 +151,7 @@ func (p *CollectiveAggregationProtocol) Dispatch() error { } // 1. Aggregation announcement phase - if !p.IsRoot() { + if p.IsRoot() == false { err := p.aggregationAnnouncementPhase() if err != nil { return err @@ -211,7 +211,7 @@ func (p *CollectiveAggregationProtocol) aggregationAnnouncementPhase() error { func (p *CollectiveAggregationProtocol) ascendingAggregationPhase(cvMap map[libunlynx.GroupingKey][]libunlynx.CipherVector) (*map[libunlynx.GroupingKey]libunlynx.FilteredResponse, error) { roundTotComput := libunlynx.StartTimer(p.Name() + "_CollectiveAggregation(ascendingAggregation)") - if !p.IsLeaf() { + if p.IsLeaf() == false { length := make([]cadmbLengthStruct, 0) for _, v := range <-p.LengthNodeChannel { length = append(length, v) @@ -257,7 +257,7 @@ func (p *CollectiveAggregationProtocol) ascendingAggregationPhase(cvMap map[libu libunlynx.EndTimer(roundTotComput) - if !p.IsRoot() { + if p.IsRoot() == false { detAggrResponses := make([]libunlynx.FilteredResponseDet, len(*p.GroupedData)) count := 0 for i, v := range *p.GroupedData { diff --git a/protocols/deterministic_tagging_test.go b/protocols/deterministic_tagging_test.go index 7f1fbbd..77c811d 100644 --- a/protocols/deterministic_tagging_test.go +++ b/protocols/deterministic_tagging_test.go @@ -81,7 +81,7 @@ func TestDeterministicTagging(t *testing.T) { present = true } } - if !present { + if present == false { t.Fatal("DP responses changed and shouldn't") } } diff --git a/protocols/key_switching_protocol.go b/protocols/key_switching_protocol.go index a774605..0e17607 100644 --- a/protocols/key_switching_protocol.go +++ b/protocols/key_switching_protocol.go @@ -191,7 +191,7 @@ func (p *KeySwitchingProtocol) Dispatch() error { defer p.Done() // 1. Key switching announcement phase - if !p.IsRoot() { + if p.IsRoot() == false { targetPublicKey, rbs, err := p.announcementKSPhase() if err != nil { return err @@ -253,7 +253,7 @@ func (p *KeySwitchingProtocol) ascendingKSPhase() (*libunlynx.CipherVector, erro keySwitchingAscendingAggregation := libunlynx.StartTimer(p.Name() + "_KeySwitching(ascendingAggregation)") - if !p.IsLeaf() { + if p.IsLeaf() == false { length := make([]LengthStruct, 0) for _, v := range <-p.LengthChannel { length = append(length, v) @@ -278,7 +278,7 @@ func (p *KeySwitchingProtocol) ascendingKSPhase() (*libunlynx.CipherVector, erro } libunlynx.EndTimer(keySwitchingAscendingAggregation) - if !p.IsRoot() { + if p.IsRoot() == false { if err := p.SendToParent(&LengthMessage{Length: libunlynxtools.UnsafeCastIntsToBytes([]int{len(*p.NodeContribution)})}); err != nil { return nil, fmt.Errorf("Node "+p.ServerIdentity().String()+" failed to broadcast LengthMessage: %v", err) } diff --git a/protocols/key_switching_protocol_test.go b/protocols/key_switching_protocol_test.go index c9a4a47..c43dc60 100644 --- a/protocols/key_switching_protocol_test.go +++ b/protocols/key_switching_protocol_test.go @@ -74,7 +74,7 @@ func TestCTKS(t *testing.T) { res := libunlynx.DecryptIntVector(clientPrivate, &cv1) log.Lvl2("Received results (attributes) ", res) - if !reflect.DeepEqual(res, append(data1, data2...)) { + if reflect.DeepEqual(res, append(data1, data2...)) == false { t.Fatal("Wrong results, expected", data1, "but got", res) } else { t.Log("Good results") diff --git a/protocols/shuffling_protocol.go b/protocols/shuffling_protocol.go index acc6fc7..ebb1aff 100644 --- a/protocols/shuffling_protocol.go +++ b/protocols/shuffling_protocol.go @@ -224,7 +224,7 @@ func (p *ShufflingProtocol) Dispatch() error { var pi []int var beta [][]kyber.Scalar - if !p.IsRoot() { + if p.IsRoot() == false { shufflingDispatchNoProof := libunlynx.StartTimer(p.Name() + "_Shuffling(DISPATCH-noProof)") shuffledData, pi, beta = libunlynxshuffle.ShuffleSequence(shuffleTarget, libunlynx.SuiTe.Point().Base(), collectiveKey, p.Precomputed) diff --git a/services/service_test.go b/services/service_test.go index ae8fcd1..59cb5cf 100644 --- a/services/service_test.go +++ b/services/service_test.go @@ -198,7 +198,7 @@ func TestServiceClearAttr(t *testing.T) { grpTab[ind] = v } data, ok := expectedResults[grpTab] - if !ok || !reflect.DeepEqual(data, (*aggr)[i]) { + if ok == false || reflect.DeepEqual(data, (*aggr)[i]) == false { t.Error("Not expected results, got ", (*aggr)[i], " when expected ", data) } } @@ -302,7 +302,7 @@ func TestServiceClearGrpEncWhereAttr(t *testing.T) { grpTab[ind] = v } data, ok := expectedResults[grpTab] - if !ok || !reflect.DeepEqual(data, (*aggr)[i]) { + if ok == false || reflect.DeepEqual(data, (*aggr)[i]) == false { t.Error("Not expected results, got ", (*aggr)[i], " when expected ", data) } } @@ -407,7 +407,7 @@ func TestServiceEncGrpClearWhereAttr(t *testing.T) { grpTab[ind] = v } data, ok := expectedResults[grpTab] - if !ok || !reflect.DeepEqual(data, (*aggr)[i]) { + if ok == false || reflect.DeepEqual(data, (*aggr)[i]) == false { t.Error("Not expected results, got ", (*aggr)[i], " when expected ", data) } } @@ -515,7 +515,7 @@ func TestServiceEncGrpAndWhereAttr(t *testing.T) { grpTab[ind] = v } data, ok := expectedResults[grpTab] - if !ok || !reflect.DeepEqual(data, (*aggr)[i]) { + if ok == false || reflect.DeepEqual(data, (*aggr)[i]) == false { t.Error("Not expected results, got ", (*aggr)[i], " when expected ", data) } } @@ -619,7 +619,7 @@ func TestServiceEverything(t *testing.T) { grpTab[ind] = v } data, ok := expectedResults[grpTab] - if !ok || !reflect.DeepEqual(data, (*aggr)[i]) { + if ok == false || reflect.DeepEqual(data, (*aggr)[i]) == false { t.Error("Not expected results, got ", (*aggr)[i], " when expected ", data) } } @@ -723,7 +723,7 @@ func TestServiceEncGrpAndWhereAttrWithCount(t *testing.T) { grpTab[ind] = v } data, ok := expectedResults[grpTab] - if !ok || !reflect.DeepEqual(data, (*aggr)[i]) { + if ok == false || reflect.DeepEqual(data, (*aggr)[i]) == false { t.Error("Not expected results, got ", (*aggr)[i], " when expected ", data) } } @@ -833,7 +833,7 @@ func TestAllServersNoDPs(t *testing.T) { grpTab[ind] = v } data, ok := expectedResults[grpTab] - if !ok || !reflect.DeepEqual(data, (*aggr)[i]) { + if ok == false || reflect.DeepEqual(data, (*aggr)[i]) == false { t.Error("Not expected results, got ", (*aggr)[i], " when expected ", data) } } @@ -947,7 +947,7 @@ func TestAllServersRandomDPs(t *testing.T) { grpTab[ind] = v } data, ok := expectedResults[grpTab] - if !ok || !reflect.DeepEqual(data, (*aggr)[i]) { + if ok == false || reflect.DeepEqual(data, (*aggr)[i]) == false { t.Error("Not expected results, got ", (*aggr)[i], " when expected ", data) } } @@ -1072,7 +1072,7 @@ func TestConcurrentSurveys(t *testing.T) { grpTab[ind] = v } data, ok := expectedResults[grpTab] - if !ok || !reflect.DeepEqual(data, (*aggr)[i]) { + if ok == false || reflect.DeepEqual(data, (*aggr)[i]) == false { t.Error("Not expected results, got ", (*aggr)[i], " when expected ", data) } } From 7f37465c0fccb3d46fc5aa71ea9187c635f767ec Mon Sep 17 00:00:00 2001 From: Joao Sa Sousa Date: Thu, 12 Mar 2020 15:00:06 +0100 Subject: [PATCH 20/22] Added error condition of tn.SetConfig for debug --- services/service.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/services/service.go b/services/service.go index 0a8ba8d..9f02738 100644 --- a/services/service.go +++ b/services/service.go @@ -2,6 +2,7 @@ package servicesunlynx import ( "fmt" + "golang.org/x/xerrors" "strconv" "time" @@ -416,7 +417,9 @@ func (s *Service) HandleQueryBroadcastFinished(recq *QueryBroadcastFinished) (ne // NewProtocol creates a protocol instance executed by all nodes func (s *Service) NewProtocol(tn *onet.TreeNodeInstance, conf *onet.GenericConfig) (onet.ProtocolInstance, error) { - tn.SetConfig(conf) + if err := tn.SetConfig(conf); err != nil { + return nil, xerrors.Errorf("couldn't set config: %+v", err) + } var pi onet.ProtocolInstance target := SurveyID(string(conf.Data)) From 634008448825d778a06b73aed5af4a5dd91cab18 Mon Sep 17 00:00:00 2001 From: Joao Sa Sousa Date: Thu, 12 Mar 2020 15:46:51 +0100 Subject: [PATCH 21/22] Fixed tn.SetConfig bug --- services/service.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/services/service.go b/services/service.go index 9f02738..91a6c51 100644 --- a/services/service.go +++ b/services/service.go @@ -417,10 +417,6 @@ func (s *Service) HandleQueryBroadcastFinished(recq *QueryBroadcastFinished) (ne // NewProtocol creates a protocol instance executed by all nodes func (s *Service) NewProtocol(tn *onet.TreeNodeInstance, conf *onet.GenericConfig) (onet.ProtocolInstance, error) { - if err := tn.SetConfig(conf); err != nil { - return nil, xerrors.Errorf("couldn't set config: %+v", err) - } - var pi onet.ProtocolInstance target := SurveyID(string(conf.Data)) survey, err := s.getSurvey(SurveyID(conf.Data)) @@ -595,6 +591,9 @@ func (s *Service) StartProtocol(name string, targetSurvey SurveyID) (onet.Protoc conf := onet.GenericConfig{Data: []byte(string(targetSurvey))} + if err := tn.SetConfig(&conf); err != nil { + return nil, xerrors.Errorf("couldn't set config: %+v", err) + } pi, err := s.NewProtocol(tn, &conf) if err != nil { return nil, fmt.Errorf("error running "+name+" : %v", err) From e5509ba70d9ad1605e41d199ed7ea45fc52d2c31 Mon Sep 17 00:00:00 2001 From: Joao Sa Sousa Date: Mon, 16 Mar 2020 17:43:15 +0100 Subject: [PATCH 22/22] Reverted if conditions to the correct way --- cmd/unlynx/client.go | 8 ++++---- data/handle_data.go | 4 ++-- lib/crypto.go | 12 ++++++------ lib/crypto_test.go | 6 +++--- lib/shuffle/shuffle.go | 2 +- lib/store/store.go | 10 +++++----- lib/structs.go | 2 +- lib/tools/tools.go | 2 +- protocols/collective_aggregation_protocol.go | 6 +++--- protocols/deterministic_tagging_test.go | 2 +- protocols/key_switching_protocol.go | 6 +++--- protocols/key_switching_protocol_test.go | 2 +- protocols/shuffling_protocol.go | 2 +- services/service.go | 16 ++++++++-------- services/service_test.go | 18 +++++++++--------- simul/proofs_verification_simul.go | 12 ++++++------ simul/test_data/time_data/parse_time_data.go | 2 +- 17 files changed, 56 insertions(+), 56 deletions(-) diff --git a/cmd/unlynx/client.go b/cmd/unlynx/client.go index 6be3528..7709fff 100644 --- a/cmd/unlynx/client.go +++ b/cmd/unlynx/client.go @@ -98,7 +98,7 @@ func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, group whereRegex := "{(w[0-9]+(,\\s*[0-9]+))*(,\\s*w[0-9]+(,\\s*[0-9]+))*}" groupByRegex := "{g[0-9]+(,\\s*g[0-9]+)*}" - if checkRegex(sum, sumRegex) == false { + if !checkRegex(sum, sumRegex) { return nil, false, nil, "", nil, fmt.Errorf("error parsing the sum parameter(s)") } sum = strings.Replace(sum, " ", "", -1) @@ -114,12 +114,12 @@ func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, group } } - if check == false { + if !check { return nil, false, nil, "", nil, fmt.Errorf("no 'count' attribute in the sum variables") } } - if checkRegex(where, whereRegex) == false { + if !checkRegex(where, whereRegex) { return nil, false, nil, "", nil, fmt.Errorf("error parsing the where parameter(s)") } where = strings.Replace(where, " ", "", -1) @@ -144,7 +144,7 @@ func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, group } } - if checkRegex(groupBy, groupByRegex) == false { + if !checkRegex(groupBy, groupByRegex) { return nil, false, nil, "", nil, fmt.Errorf("error parsing the groupBy parameter(s)") } groupBy = strings.Replace(groupBy, " ", "", -1) diff --git a/data/handle_data.go b/data/handle_data.go index 61d1fc7..913b07f 100644 --- a/data/handle_data.go +++ b/data/handle_data.go @@ -82,7 +82,7 @@ func GenerateData(numDPs, numEntries, numEntriesFiltered, numGroupsClear, numGro testData := make(map[string][]libunlynx.DpClearResponse) - if randomGroups == false { + if !randomGroups { numElem := 1 for _, el := range numType { numElem = numElem * int(el) @@ -362,7 +362,7 @@ func CompareClearResponses(x []libunlynx.DpClearResponse, y []libunlynx.DpClearR } } - if test == false { + if !test { break } } diff --git a/lib/crypto.go b/lib/crypto.go index 665b4cc..9b85049 100644 --- a/lib/crypto.go +++ b/lib/crypto.go @@ -343,9 +343,9 @@ func discreteLog(P kyber.Point, checkNeg bool) (int64, error) { guessIntMinus := int64(0) start := true - for i := guessInt; i < MaxHomomorphicInt && foundPos == false && foundNeg == false; i = i + 1 { + for i := guessInt; i < MaxHomomorphicInt && !foundPos && !foundNeg; i = i + 1 { // check for 0 first - if start == false { + if !start { guess = SuiTe.Point().Add(guess, B) } start = false @@ -365,7 +365,7 @@ func discreteLog(P kyber.Point, checkNeg bool) (int64, error) { foundNeg = true } } - if foundNeg == false && guess.Equal(P) { + if !foundNeg && guess.Equal(P) { foundPos = true } } @@ -373,7 +373,7 @@ func discreteLog(P kyber.Point, checkNeg bool) (int64, error) { currentGreatestInt = guessInt mutex.Unlock() - if foundPos == false && foundNeg == false { + if !foundPos && !foundNeg { log.Error("out of bound encryption, bound is ", MaxHomomorphicInt) return 0, nil } @@ -451,7 +451,7 @@ func (cv *CipherVector) Equal(cv2 *CipherVector) bool { } for i := range *cv2 { - if (*cv)[i].Equal(&(*cv2)[i]) == false { + if !(*cv)[i].Equal(&(*cv2)[i]) { return false } } @@ -490,7 +490,7 @@ func (dcv *DeterministCipherVector) Equal(dcv2 *DeterministCipherVector) bool { } for i := range *dcv2 { - if (*dcv)[i].Equal(&(*dcv2)[i]) == false { + if !(*dcv)[i].Equal(&(*dcv2)[i]) { return false } } diff --git a/lib/crypto_test.go b/lib/crypto_test.go index 74f1382..14e0d0d 100644 --- a/lib/crypto_test.go +++ b/lib/crypto_test.go @@ -119,7 +119,7 @@ func TestNullCipherVector(t *testing.T) { nullVectDec := libunlynx.DecryptIntVector(secKey, &nullVectEnc) target := []int64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0} - if reflect.DeepEqual(nullVectDec, target) == false { + if !reflect.DeepEqual(nullVectDec, target) { t.Fatal("Null vector of dimension 4 should be ", target, "got", nullVectDec) } @@ -127,7 +127,7 @@ func TestNullCipherVector(t *testing.T) { twoTimesNullEnc.Add(nullVectEnc, nullVectEnc) twoTimesNullDec := libunlynx.DecryptIntVector(secKey, twoTimesNullEnc) - if reflect.DeepEqual(twoTimesNullDec, target) == false { + if !reflect.DeepEqual(twoTimesNullDec, target) { t.Fatal("Null vector + Null vector should be ", target, "got", twoTimesNullDec) } } @@ -198,7 +198,7 @@ func TestAbstractPointsConverter(t *testing.T) { } for i, el := range aps { - if reflect.DeepEqual(el.String(), newAps[i].String()) == false { + if !reflect.DeepEqual(el.String(), newAps[i].String()) { t.Fatal("Wrong results, expected", el, "but got", newAps[i]) } } diff --git a/lib/shuffle/shuffle.go b/lib/shuffle/shuffle.go index a4af8cb..2044f7a 100644 --- a/lib/shuffle/shuffle.go +++ b/lib/shuffle/shuffle.go @@ -183,7 +183,7 @@ func PrecomputationWritingForShuffling(appFlag bool, gobFile, serverName string, // ReadPrecomputedFile reads the precomputation data from a .gob file func ReadPrecomputedFile(fileName string) ([]CipherVectorScalar, error) { - if _, err := os.Stat(fileName); os.IsNotExist(err) == false { + if _, err := os.Stat(fileName); !os.IsNotExist(err) { var encoded []CipherVectorScalarBytes err := libunlynxtools.ReadFromGobFile(fileName, &encoded) if err != nil { diff --git a/lib/store/store.go b/lib/store/store.go index 490ffd2..98bdc10 100644 --- a/lib/store/store.go +++ b/lib/store/store.go @@ -53,7 +53,7 @@ func proccessParameters(data []string, clear map[string]int64, encrypted map[str // all where and group by attributes are in clear if noEnc { containerClear = append(containerClear, clear[v]) - } else if noEnc == false { + } else if !noEnc { if value, ok := encrypted[v]; ok { containerEnc = append(containerEnc, value) } else { @@ -80,7 +80,7 @@ func (s *Store) InsertDpResponse(cr libunlynx.DpResponse, proofsB bool, groupBy, clearWhr, newResp.WhereEnc = proccessParameters(whereStrings, cr.WhereClear, cr.WhereEnc, noEnc) _, newResp.AggregatingAttributes = proccessParameters(sum, cr.AggregatingAttributesClear, cr.AggregatingAttributesEnc, false) - if noEnc == false { + if !noEnc { s.DpResponses = append(s.DpResponses, newResp) } else { value, ok := s.DpResponsesAggr[GroupingKeyTuple{libunlynx.Key(clearGrp), libunlynx.Key(clearWhr)}] @@ -199,7 +199,7 @@ func AddInClear(s []libunlynx.DpClearResponse) []libunlynx.DpClearResponse { cpy = append(cpy, libunlynxtools.ConvertMapToData(elem.AggregatingAttributesClear, "s", 0)...) cpy = append(cpy, libunlynxtools.ConvertMapToData(elem.AggregatingAttributesEnc, "s", len(elem.AggregatingAttributesClear))...) - if _, ok := dataMap[key]; ok == false { + if _, ok := dataMap[key]; !ok { dataMap[key] = cpy } else { for i := 0; i < len(dataMap[key]); i = i + libunlynx.VPARALLELIZE { @@ -272,7 +272,7 @@ func (s *Store) PullCothorityAggregatedFilteredResponses(diffPri bool, noise lib s.GroupedDeterministicFilteredResponses = make(map[libunlynx.GroupingKey]libunlynx.FilteredResponse) - if diffPri == true { + if diffPri { for _, v := range aggregatedResults { for _, aggr := range v.AggregatingAttributes { aggr.Add(aggr, noise) @@ -293,7 +293,7 @@ func (s *Store) PullDeliverableResults(diffPri bool, noise libunlynx.CipherText) results := s.DeliverableResults s.DeliverableResults = s.DeliverableResults[:0] - if diffPri == true { + if diffPri { for _, v := range results { for _, aggr := range v.AggregatingAttributes { aggr.Add(aggr, noise) diff --git a/lib/structs.go b/lib/structs.go index af99a0e..0e1a733 100644 --- a/lib/structs.go +++ b/lib/structs.go @@ -102,7 +102,7 @@ func (cv *FilteredResponse) Add(cv1, cv2 FilteredResponse) *FilteredResponse { // AddInMap permits to add a filtered response with its deterministic tag in a map func AddInMap(s map[GroupingKey]FilteredResponse, key GroupingKey, added FilteredResponse) { - if localResult, ok := s[key]; ok == false { + if localResult, ok := s[key]; !ok { s[key] = added } else { nfr := NewFilteredResponse(len(added.GroupByEnc), len(added.AggregatingAttributes)) diff --git a/lib/tools/tools.go b/lib/tools/tools.go index 4b57898..0aa8f29 100644 --- a/lib/tools/tools.go +++ b/lib/tools/tools.go @@ -16,7 +16,7 @@ import ( func SendISMOthers(s *onet.ServiceProcessor, el *onet.Roster, msg interface{}) error { var errStrs []string for _, e := range el.List { - if e.ID.Equal(s.ServerIdentity().ID) == false { + if !e.ID.Equal(s.ServerIdentity().ID) { log.Lvl3("Sending to", e) err := s.SendRaw(e, msg) if err != nil { diff --git a/protocols/collective_aggregation_protocol.go b/protocols/collective_aggregation_protocol.go index 599b830..40fb36b 100644 --- a/protocols/collective_aggregation_protocol.go +++ b/protocols/collective_aggregation_protocol.go @@ -151,7 +151,7 @@ func (p *CollectiveAggregationProtocol) Dispatch() error { } // 1. Aggregation announcement phase - if p.IsRoot() == false { + if !p.IsRoot() { err := p.aggregationAnnouncementPhase() if err != nil { return err @@ -211,7 +211,7 @@ func (p *CollectiveAggregationProtocol) aggregationAnnouncementPhase() error { func (p *CollectiveAggregationProtocol) ascendingAggregationPhase(cvMap map[libunlynx.GroupingKey][]libunlynx.CipherVector) (*map[libunlynx.GroupingKey]libunlynx.FilteredResponse, error) { roundTotComput := libunlynx.StartTimer(p.Name() + "_CollectiveAggregation(ascendingAggregation)") - if p.IsLeaf() == false { + if !p.IsLeaf() { length := make([]cadmbLengthStruct, 0) for _, v := range <-p.LengthNodeChannel { length = append(length, v) @@ -257,7 +257,7 @@ func (p *CollectiveAggregationProtocol) ascendingAggregationPhase(cvMap map[libu libunlynx.EndTimer(roundTotComput) - if p.IsRoot() == false { + if !p.IsRoot() { detAggrResponses := make([]libunlynx.FilteredResponseDet, len(*p.GroupedData)) count := 0 for i, v := range *p.GroupedData { diff --git a/protocols/deterministic_tagging_test.go b/protocols/deterministic_tagging_test.go index 77c811d..7f1fbbd 100644 --- a/protocols/deterministic_tagging_test.go +++ b/protocols/deterministic_tagging_test.go @@ -81,7 +81,7 @@ func TestDeterministicTagging(t *testing.T) { present = true } } - if present == false { + if !present { t.Fatal("DP responses changed and shouldn't") } } diff --git a/protocols/key_switching_protocol.go b/protocols/key_switching_protocol.go index 0e17607..a774605 100644 --- a/protocols/key_switching_protocol.go +++ b/protocols/key_switching_protocol.go @@ -191,7 +191,7 @@ func (p *KeySwitchingProtocol) Dispatch() error { defer p.Done() // 1. Key switching announcement phase - if p.IsRoot() == false { + if !p.IsRoot() { targetPublicKey, rbs, err := p.announcementKSPhase() if err != nil { return err @@ -253,7 +253,7 @@ func (p *KeySwitchingProtocol) ascendingKSPhase() (*libunlynx.CipherVector, erro keySwitchingAscendingAggregation := libunlynx.StartTimer(p.Name() + "_KeySwitching(ascendingAggregation)") - if p.IsLeaf() == false { + if !p.IsLeaf() { length := make([]LengthStruct, 0) for _, v := range <-p.LengthChannel { length = append(length, v) @@ -278,7 +278,7 @@ func (p *KeySwitchingProtocol) ascendingKSPhase() (*libunlynx.CipherVector, erro } libunlynx.EndTimer(keySwitchingAscendingAggregation) - if p.IsRoot() == false { + if !p.IsRoot() { if err := p.SendToParent(&LengthMessage{Length: libunlynxtools.UnsafeCastIntsToBytes([]int{len(*p.NodeContribution)})}); err != nil { return nil, fmt.Errorf("Node "+p.ServerIdentity().String()+" failed to broadcast LengthMessage: %v", err) } diff --git a/protocols/key_switching_protocol_test.go b/protocols/key_switching_protocol_test.go index c43dc60..c9a4a47 100644 --- a/protocols/key_switching_protocol_test.go +++ b/protocols/key_switching_protocol_test.go @@ -74,7 +74,7 @@ func TestCTKS(t *testing.T) { res := libunlynx.DecryptIntVector(clientPrivate, &cv1) log.Lvl2("Received results (attributes) ", res) - if reflect.DeepEqual(res, append(data1, data2...)) == false { + if !reflect.DeepEqual(res, append(data1, data2...)) { t.Fatal("Wrong results, expected", data1, "but got", res) } else { t.Log("Good results") diff --git a/protocols/shuffling_protocol.go b/protocols/shuffling_protocol.go index ebb1aff..acc6fc7 100644 --- a/protocols/shuffling_protocol.go +++ b/protocols/shuffling_protocol.go @@ -224,7 +224,7 @@ func (p *ShufflingProtocol) Dispatch() error { var pi []int var beta [][]kyber.Scalar - if p.IsRoot() == false { + if !p.IsRoot() { shufflingDispatchNoProof := libunlynx.StartTimer(p.Name() + "_Shuffling(DISPATCH-noProof)") shuffledData, pi, beta = libunlynxshuffle.ShuffleSequence(shuffleTarget, libunlynx.SuiTe.Point().Base(), collectiveKey, p.Precomputed) diff --git a/services/service.go b/services/service.go index 91a6c51..dddecc0 100644 --- a/services/service.go +++ b/services/service.go @@ -237,7 +237,7 @@ func (s *Service) HandleSurveyCreationQuery(recq *SurveyCreationQuery) (network. log.Lvl1(s.ServerIdentity().String(), " received a Survey Creation Query") // if this server is the one receiving the query from the client - if recq.IntraMessage == false { + if !recq.IntraMessage { id := uuid.NewV4() newID := SurveyID(id.String()) recq.SurveyID = newID @@ -271,7 +271,7 @@ func (s *Service) HandleSurveyCreationQuery(recq *SurveyCreationQuery) (network. } log.Lvl1(s.ServerIdentity(), " initiated the survey ", recq.SurveyID) - if recq.IntraMessage == false { + if !recq.IntraMessage { recq.IntraMessage = true recq.Source = s.ServerIdentity() // broadcasts the query @@ -318,7 +318,7 @@ func (s *Service) HandleSurveyCreationQuery(recq *SurveyCreationQuery) (network. survey.DpChannel <- 1 } - if recq.IntraMessage == false { + if !recq.IntraMessage { survey, err := s.getSurvey(recq.SurveyID) if err != nil { return nil, err @@ -362,7 +362,7 @@ func (s *Service) HandleSurveyResultsQuery(resq *SurveyResultsQuery) (network.Me return nil, err } - if resq.IntraMessage == false { + if !resq.IntraMessage { resq.IntraMessage = true err := libunlynxtools.SendISMOthers(s.ServiceProcessor, &survey.Query.Roster, resq) @@ -556,7 +556,7 @@ func (s *Service) NewProtocol(tn *onet.TreeNodeInstance, conf *onet.GenericConfi if tn.IsRoot() { var coaggr []libunlynx.FilteredResponse - if libunlynx.DIFFPRI == true { + if libunlynx.DIFFPRI { coaggr = survey.PullCothorityAggregatedFilteredResponses(true, survey.Noise) } else { coaggr = survey.PullCothorityAggregatedFilteredResponses(false, libunlynx.CipherText{}) @@ -671,7 +671,7 @@ func (s *Service) StartService(targetSurvey SurveyID, root bool) error { libunlynx.EndTimer(start) // Aggregation Phase - if root == true { + if root { start := libunlynx.StartTimer(s.ServerIdentity().String() + "_AggregationPhase") err = s.AggregationPhase(target.Query.SurveyID) @@ -683,7 +683,7 @@ func (s *Service) StartService(targetSurvey SurveyID, root bool) error { } // DRO Phase - if root == true && libunlynx.DIFFPRI == true { + if root && libunlynx.DIFFPRI { start := libunlynx.StartTimer(s.ServerIdentity().String() + "_DROPhase") err := s.DROPhase(target.Query.SurveyID) @@ -695,7 +695,7 @@ func (s *Service) StartService(targetSurvey SurveyID, root bool) error { } // Key Switch Phase - if root == true { + if root { start := libunlynx.StartTimer(s.ServerIdentity().String() + "_KeySwitchingPhase") err := s.KeySwitchingPhase(target.Query.SurveyID) diff --git a/services/service_test.go b/services/service_test.go index 59cb5cf..ae8fcd1 100644 --- a/services/service_test.go +++ b/services/service_test.go @@ -198,7 +198,7 @@ func TestServiceClearAttr(t *testing.T) { grpTab[ind] = v } data, ok := expectedResults[grpTab] - if ok == false || reflect.DeepEqual(data, (*aggr)[i]) == false { + if !ok || !reflect.DeepEqual(data, (*aggr)[i]) { t.Error("Not expected results, got ", (*aggr)[i], " when expected ", data) } } @@ -302,7 +302,7 @@ func TestServiceClearGrpEncWhereAttr(t *testing.T) { grpTab[ind] = v } data, ok := expectedResults[grpTab] - if ok == false || reflect.DeepEqual(data, (*aggr)[i]) == false { + if !ok || !reflect.DeepEqual(data, (*aggr)[i]) { t.Error("Not expected results, got ", (*aggr)[i], " when expected ", data) } } @@ -407,7 +407,7 @@ func TestServiceEncGrpClearWhereAttr(t *testing.T) { grpTab[ind] = v } data, ok := expectedResults[grpTab] - if ok == false || reflect.DeepEqual(data, (*aggr)[i]) == false { + if !ok || !reflect.DeepEqual(data, (*aggr)[i]) { t.Error("Not expected results, got ", (*aggr)[i], " when expected ", data) } } @@ -515,7 +515,7 @@ func TestServiceEncGrpAndWhereAttr(t *testing.T) { grpTab[ind] = v } data, ok := expectedResults[grpTab] - if ok == false || reflect.DeepEqual(data, (*aggr)[i]) == false { + if !ok || !reflect.DeepEqual(data, (*aggr)[i]) { t.Error("Not expected results, got ", (*aggr)[i], " when expected ", data) } } @@ -619,7 +619,7 @@ func TestServiceEverything(t *testing.T) { grpTab[ind] = v } data, ok := expectedResults[grpTab] - if ok == false || reflect.DeepEqual(data, (*aggr)[i]) == false { + if !ok || !reflect.DeepEqual(data, (*aggr)[i]) { t.Error("Not expected results, got ", (*aggr)[i], " when expected ", data) } } @@ -723,7 +723,7 @@ func TestServiceEncGrpAndWhereAttrWithCount(t *testing.T) { grpTab[ind] = v } data, ok := expectedResults[grpTab] - if ok == false || reflect.DeepEqual(data, (*aggr)[i]) == false { + if !ok || !reflect.DeepEqual(data, (*aggr)[i]) { t.Error("Not expected results, got ", (*aggr)[i], " when expected ", data) } } @@ -833,7 +833,7 @@ func TestAllServersNoDPs(t *testing.T) { grpTab[ind] = v } data, ok := expectedResults[grpTab] - if ok == false || reflect.DeepEqual(data, (*aggr)[i]) == false { + if !ok || !reflect.DeepEqual(data, (*aggr)[i]) { t.Error("Not expected results, got ", (*aggr)[i], " when expected ", data) } } @@ -947,7 +947,7 @@ func TestAllServersRandomDPs(t *testing.T) { grpTab[ind] = v } data, ok := expectedResults[grpTab] - if ok == false || reflect.DeepEqual(data, (*aggr)[i]) == false { + if !ok || !reflect.DeepEqual(data, (*aggr)[i]) { t.Error("Not expected results, got ", (*aggr)[i], " when expected ", data) } } @@ -1072,7 +1072,7 @@ func TestConcurrentSurveys(t *testing.T) { grpTab[ind] = v } data, ok := expectedResults[grpTab] - if ok == false || reflect.DeepEqual(data, (*aggr)[i]) == false { + if !ok || !reflect.DeepEqual(data, (*aggr)[i]) { t.Error("Not expected results, got ", (*aggr)[i], " when expected ", data) } } diff --git a/simul/proofs_verification_simul.go b/simul/proofs_verification_simul.go index faf6fff..f2e75a4 100644 --- a/simul/proofs_verification_simul.go +++ b/simul/proofs_verification_simul.go @@ -237,17 +237,17 @@ func (sim *ProofsVerificationSimulation) Run(config *onet.SimulationConfig) erro log.Lvl1(len(results), " proofs verified") - if results[0] == false { + if !results[0] { return fmt.Errorf("key switching proofs failed") - } else if results[1] == false { + } else if !results[1] { return fmt.Errorf("deterministic tagging (creation) proofs failed") - } else if results[2] == false { + } else if !results[2] { return fmt.Errorf("deterministic tagging (addition) proofs failed") - } else if results[3] == false { + } else if !results[3] { return fmt.Errorf("local aggregation proofs failed") - } else if results[4] == false { + } else if !results[4] { return fmt.Errorf("shuffling proofs failed") - } else if results[5] == false { + } else if !results[5] { return fmt.Errorf("collective aggregation proofs failed") } case <-time.After(libunlynx.TIMEOUT): diff --git a/simul/test_data/time_data/parse_time_data.go b/simul/test_data/time_data/parse_time_data.go index 3862ca0..f97de1b 100644 --- a/simul/test_data/time_data/parse_time_data.go +++ b/simul/test_data/time_data/parse_time_data.go @@ -56,7 +56,7 @@ func ReadTomlSetup(filename string, setupNbr int) (map[string]string, error) { c := strings.Split(line, ", ") - if flag == true { + if flag { if pos == setupNbr { for i, el := range c { setup[parameters[i]] = el