Commit d05936eb authored by Loïck Bonniot's avatar Loïck Bonniot

Merge branch '397_signature_timeout' into 'master'

397 signature timeout



See merge request !81
parents dd9b187b ef912c89
Pipeline #2123 passed with stages
......@@ -2,7 +2,10 @@
package cmd
import (
"time"
"dfss"
"dfss/net"
dapi "dfss/dfssd/api"
"github.com/spf13/cobra"
"github.com/spf13/viper"
......@@ -20,6 +23,7 @@ A tool to sign multiparty contract using a secure cryptographic protocol`,
_ = cmd.Help()
},
PersistentPreRun: func(cmd *cobra.Command, args []string) {
net.DefaultTimeout = viper.GetDuration("timeout")
dapi.Configure(viper.GetString("demo") != "", viper.GetString("demo"), "client")
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
......@@ -38,6 +42,7 @@ func init() {
RootCmd.PersistentFlags().StringP("demo", "d", "", "demonstrator address and port, empty will disable it")
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().Duration("timeout", 10*time.Second, "time to wait for connection and evidences before failing")
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)")
......@@ -50,6 +55,7 @@ func init() {
_ = viper.BindPFlag("demo", RootCmd.PersistentFlags().Lookup("demo"))
_ = viper.BindPFlag("local_port", RootCmd.PersistentFlags().Lookup("port"))
_ = viper.BindPFlag("platform_addrport", RootCmd.PersistentFlags().Lookup("host"))
_ = viper.BindPFlag("timeout", RootCmd.PersistentFlags().Lookup("timeout"))
// Bind subcommands to root
RootCmd.AddCommand(dfss.VersionCmd, registerCmd, authCmd, newCmd, showCmd, fetchCmd, importCmd, exportCmd, signCmd)
......
......@@ -3,11 +3,11 @@ package sign
import (
"encoding/hex"
"errors"
"time"
cAPI "dfss/dfssc/api"
dAPI "dfss/dfssd/api"
pAPI "dfss/dfssp/api"
"dfss/net"
"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(), net.DefaultTimeout)
defer cancel()
var result *pAPI.ErrorCode
......
......@@ -6,6 +6,7 @@ import (
cAPI "dfss/dfssc/api"
"dfss/dfssc/common"
"dfss/net"
)
// 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(net.DefaultTimeout):
out <- fmt.Errorf("Signature reception timeout!")
return
}
......
......@@ -85,7 +85,6 @@ func NewSignatureManager(passphrase string, c *contract.JSON) (*SignatureManager
m.mail = m.auth.Cert.Subject.CommonName
dAPI.SetIdentifier(m.mail)
m.cServer = m.GetServer()
go func() { _ = net.Listen("0.0.0.0:"+strconv.Itoa(viper.GetInt("local_port")), m.cServer) }()
......@@ -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(), net.DefaultTimeout)
defer cancel()
msg, err := client.Discover(ctx, &cAPI.Hello{Version: dfss.Version})
if err != nil {
......
......@@ -8,14 +8,17 @@ import (
"os"
"os/user"
"path/filepath"
"time"
"dfss/net"
"github.com/spf13/viper"
)
// Config is the structure that will be persisted in the configuration file
type Config struct {
Email string `json:"email"`
Platform string `json:"platform"`
Email string `json:"email"`
Platform string `json:"platform"`
Timeout time.Duration `json:"timeout"`
}
// Load loads the configuration file into memory.
......@@ -42,12 +45,17 @@ func Load() {
viper.Set("authenticated", isFileValid(viper.GetString("file_cert")))
viper.Set("local_port", 9005)
// Configure timeout
if t := viper.GetDuration("timeout"); t > 0 {
net.DefaultTimeout = t
}
return
}
// Save stores the current configuration object from memory.
func Save() {
c := Config{viper.GetString("email"), viper.GetString("platform")}
c := Config{viper.GetString("email"), viper.GetString("platform"), viper.GetDuration("timeout")}
data, err := json.MarshalIndent(c, "", " ")
if err != nil {
return
......
......@@ -17,7 +17,7 @@ import (
)
// DefaultTimeout should be used when a non-critical timeout is used in the application.
var DefaultTimeout = 5 * time.Second
var DefaultTimeout = 10 * time.Second
// Connect to a peer.
//
......
......@@ -107,7 +107,7 @@ func createClient(tmpDir string, ca []byte, port int) (*exec.Cmd, error) {
// Prepare the client command.
// The last argument is up to you!
cmd := exec.Command(path, "--ca", caPath, "--cert", certPath, "--host", "127.0.0.1:"+testPort, "--key", keyPath, "--port", strconv.Itoa(port), "-v", "-d", "localhost:9099")
cmd := exec.Command(path, "--ca", caPath, "--cert", certPath, "--host", "127.0.0.1:"+testPort, "--key", keyPath, "--port", strconv.Itoa(port), "--timeout", "3s" ,"-v", "-d", "localhost:9099")
return cmd, nil
}
......
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