Skip to content

Commit

Permalink
Changed timeouts to use os.Getenv
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoAndreSa committed Mar 11, 2020
1 parent 3281921 commit 3dcc5b4
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 79 deletions.
6 changes: 5 additions & 1 deletion lib/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package libunlynx

import (
"sync"
"time"

"go.dedis.ch/onet/v3/simul/monitor"
)
Expand All @@ -10,14 +11,17 @@ 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

// 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 {
Expand Down
13 changes: 7 additions & 6 deletions protocols/collective_aggregation_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package protocolsunlynx

import (
"errors"
"os"
"sync"
"time"

Expand Down Expand Up @@ -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.
Expand All @@ -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
}

Expand Down Expand Up @@ -201,14 +197,19 @@ 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() {
if err := p.SendToChildren(&dataReferenceMessage.DataReferenceMessage); err != nil {
return errors.New("Error sending <DataReferenceMessage>:" + err.Error())
}
}
case <-time.After(p.Timeout):
case <-time.After(timeout):
return errors.New(p.ServerIdentity().String() + "didn't get the <dataReferenceMessage> on time.")
}
return nil
Expand Down
18 changes: 9 additions & 9 deletions protocols/deterministic_tagging_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package protocolsunlynx

import (
"errors"
"os"
"sync"
"time"

Expand Down Expand Up @@ -91,8 +92,6 @@ type DeterministicTaggingProtocol struct {
Proofs bool

ExecTime time.Duration

Timeout time.Duration
}

// NewDeterministicTaggingProtocol constructs tagging switching protocol instances.
Expand All @@ -118,10 +117,6 @@ func NewDeterministicTaggingProtocol(n *onet.TreeNodeInstance) (onet.ProtocolIns
break
}
}

// default timeout
dsp.Timeout = 10 * time.Minute

return dsp, nil
}

Expand Down Expand Up @@ -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 <deterministicTaggingTargetBytesBef> (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
}
Expand Down Expand Up @@ -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 <deterministicTaggingTargetBytes> (second round) on time.")
}

Expand Down
13 changes: 7 additions & 6 deletions protocols/key_switching_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package protocolsunlynx

import (
"errors"
"os"
"time"

"github.com/ldsec/unlynx/lib"
Expand Down Expand Up @@ -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.
Expand All @@ -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
}

Expand Down Expand Up @@ -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 <dataReferenceMessage> on time.")
}

Expand Down
18 changes: 9 additions & 9 deletions protocols/shuffling+ddt_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package protocolsunlynx

import (
"errors"
"os"
"sync"
"time"

Expand Down Expand Up @@ -82,8 +83,6 @@ type ShufflingPlusDDTProtocol struct {

// Proofs
Proofs bool

Timeout time.Duration
}

// NewShufflingPlusDDTProtocol constructs neff shuffle + ddt protocol instance.
Expand All @@ -109,10 +108,6 @@ func NewShufflingPlusDDTProtocol(n *onet.TreeNodeInstance) (onet.ProtocolInstanc
break
}
}

// default timeout
pi.Timeout = 10 * time.Minute

return pi, nil
}

Expand Down Expand Up @@ -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 <shufflingPlusDDTBytesMessageLength> 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 <tmp> 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
}
Expand Down
15 changes: 8 additions & 7 deletions protocols/shuffling_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package protocolsunlynx

import (
"errors"
"os"
"time"

"github.com/ldsec/unlynx/lib"
Expand Down Expand Up @@ -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.
Expand All @@ -119,9 +118,6 @@ func NewShufflingProtocol(n *onet.TreeNodeInstance) (onet.ProtocolInstance, erro
}
}

// default timeout
dsp.Timeout = 10 * time.Minute

return dsp, nil
}

Expand Down Expand Up @@ -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 <shufflingBytesMessageLength> 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 <tmp> on time.")
}

Expand Down
13 changes: 7 additions & 6 deletions protocols/utils/addrm_server_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package protocolsunlynxutils

import (
"errors"
"os"
"sync"
"time"

Expand Down Expand Up @@ -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.
Expand All @@ -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
}

Expand Down Expand Up @@ -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 <finalResultMessage> on time.")
}

Expand Down
14 changes: 7 additions & 7 deletions protocols/utils/local_aggregation_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/ldsec/unlynx/lib/aggregation"
"go.dedis.ch/onet/v3"
"go.dedis.ch/onet/v3/log"
"os"
"time"
)

Expand Down Expand Up @@ -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.
Expand All @@ -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
}

Expand Down Expand Up @@ -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 <finalResultMessage> on time.")
}

Expand Down
Loading

0 comments on commit 3dcc5b4

Please sign in to comment.