From 2028516d214099bf43e22b70b1f7a02ed9afed6b Mon Sep 17 00:00:00 2001 From: Lesterpig Date: Fri, 20 May 2016 14:35:13 +0200 Subject: [PATCH] [c] Add stopbefore flag --- dfssc/cmd/root.go | 3 ++- dfssc/cmd/sign.go | 1 + dfssc/sign/protocol.go | 18 ++++++++++++++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/dfssc/cmd/root.go b/dfssc/cmd/root.go index 95c117d..3fc72bd 100644 --- a/dfssc/cmd/root.go +++ b/dfssc/cmd/root.go @@ -39,7 +39,8 @@ 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("slowdown", 0, "Delay between each promises round") + 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)") // Store flag values into viper _ = viper.BindPFlag("verbose", RootCmd.PersistentFlags().Lookup("verbose")) diff --git a/dfssc/cmd/sign.go b/dfssc/cmd/sign.go index 2874a89..4adfe13 100644 --- a/dfssc/cmd/sign.go +++ b/dfssc/cmd/sign.go @@ -19,6 +19,7 @@ var signCmd = &cobra.Command{ } _ = viper.BindPFlag("slowdown", cmd.Flags().Lookup("slowdown")) + _ = viper.BindPFlag("stopbefore", cmd.Flags().Lookup("stopbefore")) filename := args[0] fmt.Println("You are going to sign the following contract:") diff --git a/dfssc/sign/protocol.go b/dfssc/sign/protocol.go index 5c22fdf..7fbaa0b 100644 --- a/dfssc/sign/protocol.go +++ b/dfssc/sign/protocol.go @@ -3,6 +3,7 @@ package sign import ( "fmt" + "os" "time" cAPI "dfss/dfssc/api" @@ -42,6 +43,7 @@ func (m *SignatureManager) Sign() error { // Promess rounds // Follow the sequence until there is no next occurence of me for m.currentIndex >= 0 { + stopIfNeeded(m.currentIndex) m.OnProgressUpdate(m.currentIndex, seqLen+1) time.Sleep(viper.GetDuration("slowdown")) dAPI.DLog("starting round at index [" + fmt.Sprintf("%d", m.currentIndex) + "] with nextIndex=" + fmt.Sprintf("%d", nextIndex)) @@ -70,16 +72,17 @@ func (m *SignatureManager) Sign() error { } } + // Signature round + stopIfNeeded(-1) m.OnProgressUpdate(seqLen, seqLen+1) dAPI.DLog("entering signature round") - // Signature round err = m.ExchangeAllSignatures() if err != nil { return err } + dAPI.DLog("exiting signature round") m.OnProgressUpdate(seqLen+1, seqLen+1) - return nil } @@ -151,3 +154,14 @@ func (m *SignatureManager) closeConnections() { } m.cServer.Stop() } + +func stopIfNeeded(index int) { + s := viper.GetInt("stopbefore") + if s == 0 { + return + } + + if index == -1 && s == -1 || index+1 == s { + os.Exit(0) + } +} -- GitLab