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

Merge branch '458_stopafter_flag' into 'master'

[c] Add stopbefore flag



See merge request !79
parents 01570f85 2028516d
Pipeline #1872 passed with stages
......@@ -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"))
......
......@@ -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:")
......
......@@ -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)
}
}
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