From 62211b630dadafb885935d027dedd0eb1e882fdf Mon Sep 17 00:00:00 2001 From: Lesterpig Date: Thu, 26 May 2016 14:04:24 +0200 Subject: [PATCH] [p] Fix ready sign timeout --- dfssp/contract/ready.go | 11 +++++++++-- tests/starters_test.go | 6 +++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/dfssp/contract/ready.go b/dfssp/contract/ready.go index 97c6556..8cb64e0 100644 --- a/dfssp/contract/ready.go +++ b/dfssp/contract/ready.go @@ -21,6 +21,11 @@ type readySignal struct { sequence []uint32 // Only used to broadcast signature sequence } +// ReadySignTimeout is the delay users have to confirm the signature. +// A high value is not recommended, as there is no way to create any other signature on the same contract before the timeout +// if a client has connection issues. +var ReadySignTimeout = time.Minute + // ReadySign is the last job of the platform before the signature can occur. // When a new client is ready, it joins a waitingGroup and waits for a master broadcast announcing that everybody is ready. // @@ -45,6 +50,7 @@ func ReadySign(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, ctx *contex rooms.Broadcast(roomID, &readySignal{data: cn}) // Wait for ready signal + timeout := time.After(ReadySignTimeout) for { select { case signal, ok := <-channel: @@ -67,7 +73,7 @@ func ReadySign(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, ctx *contex case <-(*ctx).Done(): // Client's disconnection rooms.Unjoin(roomID, channel) return &api.LaunchSignature{ErrorCode: &api.ErrorCode{Code: api.ErrorCode_INVARG}} - case <-time.After(time.Minute): // Someone has not confirmed the signature within the delay + case <-timeout: // Someone has not confirmed the signature within the delay rooms.Unjoin(roomID, channel) return &api.LaunchSignature{ErrorCode: &api.ErrorCode{Code: api.ErrorCode_TIMEOUT, Message: "timeout for ready signal"}} } @@ -102,6 +108,7 @@ func masterReadyRoutine(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, co signersReady := make([]bool, len(contract.Signers)) work := true + timeout := time.After(ReadySignTimeout) for work { select { case signal, ok := <-channel: @@ -120,7 +127,7 @@ func masterReadyRoutine(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, co }) work = false } - case <-time.After(10 * time.Minute): + case <-timeout: work = false } } diff --git a/tests/starters_test.go b/tests/starters_test.go index d3a7acd..a51b7ad 100644 --- a/tests/starters_test.go +++ b/tests/starters_test.go @@ -58,13 +58,13 @@ func startPlatform(tmpDir string) (platform, ttp, demo *exec.Cmd, stop func(), c time.Sleep(time.Second) // Start platform - platform = exec.Command(path, "--db", dbURI, "--path", dir, "-p", testPort, "--ttps", ttpsPath, "-d", "localhost:9099", "-v", "start") + platform = exec.Command(path, "--db", dbURI, "--path", dir, "-p", testPort, "--ttps", ttpsPath, "-d", "localhost:9099", "start") platform.Stdout = os.Stdout platform.Stderr = os.Stderr err = platform.Start() // Start TTP - ttp = exec.Command(ttpPath, "--db", dbURI, "--port", "9098", "-d", "localhost:9099", "-v", "start") + ttp = exec.Command(ttpPath, "--db", dbURI, "--port", "9098", "-d", "localhost:9099", "start") ttp.Dir = filepath.Join(dir, "ttp") ttp.Stdout = os.Stdout ttp.Stderr = os.Stderr @@ -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), "--timeout", "3s", "-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", "-d", "localhost:9099") return cmd, nil } -- GitLab