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 @@ ...@@ -2,6 +2,8 @@
package cmd package cmd
import ( import (
"time"
"dfss" "dfss"
dapi "dfss/dfssd/api" dapi "dfss/dfssd/api"
"github.com/spf13/cobra" "github.com/spf13/cobra"
...@@ -39,6 +41,7 @@ func init() { ...@@ -39,6 +41,7 @@ func init() {
RootCmd.PersistentFlags().String("host", "localhost:9000", "host of the dfss platform") 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") 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().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)") 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{ ...@@ -18,6 +18,7 @@ var signCmd = &cobra.Command{
os.Exit(1) os.Exit(1)
} }
_ = viper.BindPFlag("timeout", cmd.Flags().Lookup("timeout"))
_ = viper.BindPFlag("slowdown", cmd.Flags().Lookup("slowdown")) _ = viper.BindPFlag("slowdown", cmd.Flags().Lookup("slowdown"))
_ = viper.BindPFlag("stopbefore", cmd.Flags().Lookup("stopbefore")) _ = viper.BindPFlag("stopbefore", cmd.Flags().Lookup("stopbefore"))
......
...@@ -3,11 +3,11 @@ package sign ...@@ -3,11 +3,11 @@ package sign
import ( import (
"encoding/hex" "encoding/hex"
"errors" "errors"
"time"
cAPI "dfss/dfssc/api" cAPI "dfss/dfssc/api"
dAPI "dfss/dfssd/api" dAPI "dfss/dfssd/api"
pAPI "dfss/dfssp/api" pAPI "dfss/dfssp/api"
"github.com/spf13/viper"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
...@@ -59,7 +59,7 @@ func (m *SignatureManager) SendEvidence(promise *cAPI.Promise, signature *cAPI.S ...@@ -59,7 +59,7 @@ func (m *SignatureManager) SendEvidence(promise *cAPI.Promise, signature *cAPI.S
return return
} }
ctx, cancel := context.WithTimeout(context.Background(), time.Minute) ctx, cancel := context.WithTimeout(context.Background(), viper.GetDuration("timeout"))
defer cancel() defer cancel()
var result *pAPI.ErrorCode var result *pAPI.ErrorCode
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
cAPI "dfss/dfssc/api" cAPI "dfss/dfssc/api"
"dfss/dfssc/common" "dfss/dfssc/common"
"github.com/spf13/viper"
) )
// ExchangeAllSignatures creates and sends signatures to all the signers of the contract // ExchangeAllSignatures creates and sends signatures to all the signers of the contract
...@@ -83,7 +84,7 @@ func (m *SignatureManager) ReceiveAllSignatures(out chan error) { ...@@ -83,7 +84,7 @@ func (m *SignatureManager) ReceiveAllSignatures(out chan error) {
m.archives.receivedSignatures = append(m.archives.receivedSignatures, signature) 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!") out <- fmt.Errorf("Signature reception timeout!")
return return
} }
......
...@@ -5,7 +5,6 @@ import ( ...@@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"strconv" "strconv"
"sync" "sync"
"time"
"dfss" "dfss"
cAPI "dfss/dfssc/api" cAPI "dfss/dfssc/api"
...@@ -210,7 +209,7 @@ func (m *SignatureManager) addPeer(user *pAPI.User) (ready bool, err error) { ...@@ -210,7 +209,7 @@ func (m *SignatureManager) addPeer(user *pAPI.User) (ready bool, err error) {
// need to create another way to access it // need to create another way to access it
m.peersConn[user.Email] = conn m.peersConn[user.Email] = conn
ctx, cancel := context.WithTimeout(context.Background(), time.Minute) ctx, cancel := context.WithTimeout(context.Background(), viper.GetDuration("timeout"))
defer cancel() defer cancel()
msg, err := client.Discover(ctx, &cAPI.Hello{Version: dfss.Version}) msg, err := client.Discover(ctx, &cAPI.Hello{Version: dfss.Version})
if err != nil { if err != nil {
...@@ -235,7 +234,7 @@ func (m *SignatureManager) addPeer(user *pAPI.User) (ready bool, err error) { ...@@ -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. // 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) { 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() defer cancel()
c := make(chan *pAPI.LaunchSignature) 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