Commit 2028516d authored by Loïck Bonniot's avatar Loïck Bonniot
Browse files

[c] Add stopbefore flag

parent 01570f85
Pipeline #1870 passed with stage
...@@ -39,7 +39,8 @@ func init() { ...@@ -39,7 +39,8 @@ 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("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 // Store flag values into viper
_ = viper.BindPFlag("verbose", RootCmd.PersistentFlags().Lookup("verbose")) _ = viper.BindPFlag("verbose", RootCmd.PersistentFlags().Lookup("verbose"))
......
...@@ -19,6 +19,7 @@ var signCmd = &cobra.Command{ ...@@ -19,6 +19,7 @@ var signCmd = &cobra.Command{
} }
_ = viper.BindPFlag("slowdown", cmd.Flags().Lookup("slowdown")) _ = viper.BindPFlag("slowdown", cmd.Flags().Lookup("slowdown"))
_ = viper.BindPFlag("stopbefore", cmd.Flags().Lookup("stopbefore"))
filename := args[0] filename := args[0]
fmt.Println("You are going to sign the following contract:") fmt.Println("You are going to sign the following contract:")
......
...@@ -3,6 +3,7 @@ package sign ...@@ -3,6 +3,7 @@ package sign
import ( import (
"fmt" "fmt"
"os"
"time" "time"
cAPI "dfss/dfssc/api" cAPI "dfss/dfssc/api"
...@@ -42,6 +43,7 @@ func (m *SignatureManager) Sign() error { ...@@ -42,6 +43,7 @@ func (m *SignatureManager) Sign() error {
// Promess rounds // Promess rounds
// Follow the sequence until there is no next occurence of me // Follow the sequence until there is no next occurence of me
for m.currentIndex >= 0 { for m.currentIndex >= 0 {
stopIfNeeded(m.currentIndex)
m.OnProgressUpdate(m.currentIndex, seqLen+1) m.OnProgressUpdate(m.currentIndex, seqLen+1)
time.Sleep(viper.GetDuration("slowdown")) time.Sleep(viper.GetDuration("slowdown"))
dAPI.DLog("starting round at index [" + fmt.Sprintf("%d", m.currentIndex) + "] with nextIndex=" + fmt.Sprintf("%d", nextIndex)) 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 { ...@@ -70,16 +72,17 @@ func (m *SignatureManager) Sign() error {
} }
} }
// Signature round
stopIfNeeded(-1)
m.OnProgressUpdate(seqLen, seqLen+1) m.OnProgressUpdate(seqLen, seqLen+1)
dAPI.DLog("entering signature round") dAPI.DLog("entering signature round")
// Signature round
err = m.ExchangeAllSignatures() err = m.ExchangeAllSignatures()
if err != nil { if err != nil {
return err return err
} }
dAPI.DLog("exiting signature round") dAPI.DLog("exiting signature round")
m.OnProgressUpdate(seqLen+1, seqLen+1) m.OnProgressUpdate(seqLen+1, seqLen+1)
return nil return nil
} }
...@@ -151,3 +154,14 @@ func (m *SignatureManager) closeConnections() { ...@@ -151,3 +154,14 @@ func (m *SignatureManager) closeConnections() {
} }
m.cServer.Stop() 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)
}
}
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