diff --git a/dfssc/cmd/root.go b/dfssc/cmd/root.go index 3fc72bd5c3c59afd0d69df8cf3ce181360efe799..06b1573c4661c300a41ede2887c0a31f4ffaecc7 100644 --- a/dfssc/cmd/root.go +++ b/dfssc/cmd/root.go @@ -2,6 +2,8 @@ package cmd import ( + "time" + "dfss" dapi "dfss/dfssd/api" "github.com/spf13/cobra" @@ -39,6 +41,7 @@ func init() { RootCmd.PersistentFlags().String("host", "localhost:9000", "host of the dfss platform") RootCmd.PersistentFlags().IntP("port", "p", 9005, "port to use for P2P communication between clients") + signCmd.Flags().Duration("timeout", time.Minute, "time to wait before fallback") signCmd.Flags().Duration("slowdown", 0, "delay between each promises round (test only)") signCmd.Flags().Int("stopbefore", 0, "stop signature just before the promises round n, -1 to stop right before signature round (test only)") diff --git a/dfssc/cmd/sign.go b/dfssc/cmd/sign.go index f87ae1f6eb68611ddfcd3e68a4e21a88fa5ba438..bbdd5043ec412918314c4bc13d307975ca6ac9d4 100644 --- a/dfssc/cmd/sign.go +++ b/dfssc/cmd/sign.go @@ -18,6 +18,7 @@ var signCmd = &cobra.Command{ os.Exit(1) } + _ = viper.BindPFlag("timeout", cmd.Flags().Lookup("timeout")) _ = viper.BindPFlag("slowdown", cmd.Flags().Lookup("slowdown")) _ = viper.BindPFlag("stopbefore", cmd.Flags().Lookup("stopbefore")) diff --git a/dfssc/sign/promises.go b/dfssc/sign/promises.go index 87596987575f7d56a303beeccb8a3cbec86bc5f2..0db0aa07c39d77d2be289d49086fb2fe6d3c3e49 100644 --- a/dfssc/sign/promises.go +++ b/dfssc/sign/promises.go @@ -3,11 +3,11 @@ package sign import ( "encoding/hex" "errors" - "time" cAPI "dfss/dfssc/api" dAPI "dfss/dfssd/api" pAPI "dfss/dfssp/api" + "github.com/spf13/viper" "golang.org/x/net/context" ) @@ -59,7 +59,7 @@ func (m *SignatureManager) SendEvidence(promise *cAPI.Promise, signature *cAPI.S return } - ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + ctx, cancel := context.WithTimeout(context.Background(), viper.GetDuration("timeout")) defer cancel() var result *pAPI.ErrorCode diff --git a/dfssc/sign/signatures.go b/dfssc/sign/signatures.go index c367b0f1c55f76ebf201b5ebc038ebbc8e70fffc..7594b9e44b0c39dc03759697ba7f20ab22d52f53 100644 --- a/dfssc/sign/signatures.go +++ b/dfssc/sign/signatures.go @@ -6,6 +6,7 @@ import ( cAPI "dfss/dfssc/api" "dfss/dfssc/common" + "github.com/spf13/viper" ) // ExchangeAllSignatures creates and sends signatures to all the signers of the contract @@ -83,7 +84,7 @@ func (m *SignatureManager) ReceiveAllSignatures(out chan error) { m.archives.receivedSignatures = append(m.archives.receivedSignatures, signature) } - case <-time.After(time.Minute): + case <-time.After(viper.GetDuration("timeout")): out <- fmt.Errorf("Signature reception timeout!") return } diff --git a/dfssc/sign/starter.go b/dfssc/sign/starter.go index af2280410f757877579d0126d096a994b27c8234..b1685474b439962049ff44b78462c9b990684137 100644 --- a/dfssc/sign/starter.go +++ b/dfssc/sign/starter.go @@ -5,7 +5,6 @@ import ( "fmt" "strconv" "sync" - "time" "dfss" cAPI "dfss/dfssc/api" @@ -210,7 +209,7 @@ func (m *SignatureManager) addPeer(user *pAPI.User) (ready bool, err error) { // need to create another way to access it m.peersConn[user.Email] = conn - ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + ctx, cancel := context.WithTimeout(context.Background(), viper.GetDuration("timeout")) defer cancel() msg, err := client.Discover(ctx, &cAPI.Hello{Version: dfss.Version}) if err != nil { @@ -235,7 +234,7 @@ func (m *SignatureManager) addPeer(user *pAPI.User) (ready bool, err error) { // SendReadySign sends the READY signal to the platform, and wait (potentially a long time) for START signal. func (m *SignatureManager) SendReadySign() (signatureUUID string, err error) { - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute) + ctx, cancel := context.WithTimeout(context.Background(), 10*viper.GetDuration("timeout")) defer cancel() c := make(chan *pAPI.LaunchSignature)