Commit 7e697f8d authored by Richer Maximilien's avatar Richer Maximilien Committed by Loïck Bonniot

[c] Add timeout flag support

parent dd9b187b
......@@ -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)")
......
......@@ -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"))
......
......@@ -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
......
......@@ -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
}
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment