From d4de268594fcad6506a49582ae94a9e46bd45166 Mon Sep 17 00:00:00 2001 From: Lesterpig Date: Fri, 20 May 2016 14:03:29 +0200 Subject: [PATCH] [c] Add slowdown flag --- dfssc/cmd/root.go | 5 +++-- dfssc/cmd/sign.go | 3 +++ dfssc/sign/protocol.go | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/dfssc/cmd/root.go b/dfssc/cmd/root.go index 773f407..95c117d 100644 --- a/dfssc/cmd/root.go +++ b/dfssc/cmd/root.go @@ -3,7 +3,6 @@ package cmd import ( "dfss" - dapi "dfss/dfssd/api" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -31,7 +30,7 @@ A tool to sign multiparty contract using a secure cryptographic protocol`, // All of the flags will be gathered by viper, this is why // we do not store their values func init() { - // Bind flags to the dfsst command + // Bind flags to the dfssc command RootCmd.PersistentFlags().BoolP("verbose", "v", false, "print verbose messages") RootCmd.PersistentFlags().String("ca", "ca.pem", "path to the root certificate") RootCmd.PersistentFlags().String("cert", "cert.pem", "path to the user's certificate") @@ -40,6 +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") + // Store flag values into viper _ = viper.BindPFlag("verbose", RootCmd.PersistentFlags().Lookup("verbose")) _ = viper.BindPFlag("file_ca", RootCmd.PersistentFlags().Lookup("ca")) diff --git a/dfssc/cmd/sign.go b/dfssc/cmd/sign.go index 7725a89..2874a89 100644 --- a/dfssc/cmd/sign.go +++ b/dfssc/cmd/sign.go @@ -6,6 +6,7 @@ import ( "dfss/dfssc/sign" "github.com/spf13/cobra" + "github.com/spf13/viper" ) var signCmd = &cobra.Command{ @@ -17,6 +18,8 @@ var signCmd = &cobra.Command{ os.Exit(1) } + _ = viper.BindPFlag("slowdown", cmd.Flags().Lookup("slowdown")) + filename := args[0] fmt.Println("You are going to sign the following contract:") showContract(cmd, args) diff --git a/dfssc/sign/protocol.go b/dfssc/sign/protocol.go index 21a870c..5c22fdf 100644 --- a/dfssc/sign/protocol.go +++ b/dfssc/sign/protocol.go @@ -8,6 +8,7 @@ import ( cAPI "dfss/dfssc/api" "dfss/dfssc/common" dAPI "dfss/dfssd/api" + "github.com/spf13/viper" ) // Sign performs all the message exchanges for the contract to be signed @@ -42,6 +43,7 @@ func (m *SignatureManager) Sign() error { // Follow the sequence until there is no next occurence of me for m.currentIndex >= 0 { 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)) // Set of promises we are waiting for -- GitLab