Commit 7db9f833 authored by Loïck Bonniot's avatar Loïck Bonniot

Merge branch 'master' into 218_promesses_client

parents 8ade9e29 af6a6448
Pipeline #1923 passed with stage
......@@ -73,7 +73,6 @@ Code lint:
stage: test
except:
- /^[0-9]+\./
allow_failure: True
tags:
- golang
- lint
......
......@@ -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,9 @@ 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 (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"))
_ = viper.BindPFlag("file_ca", RootCmd.PersistentFlags().Lookup("ca"))
......
......@@ -6,6 +6,7 @@ import (
"dfss/dfssc/sign"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var signCmd = &cobra.Command{
......@@ -17,6 +18,9 @@ var signCmd = &cobra.Command{
os.Exit(1)
}
_ = 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:")
showContract(cmd, args)
......
......@@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"os"
"time"
cAPI "dfss/dfssc/api"
......@@ -15,6 +16,7 @@ import (
"dfss/net"
"golang.org/x/net/context"
"google.golang.org/grpc"
"github.com/spf13/viper"
)
// Sign performs all the message exchanges for the contract to be signed
......@@ -48,7 +50,9 @@ 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))
// Set of promises we are waiting for
......@@ -78,16 +82,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 m.PersistSignaturesToFile()
}
......@@ -271,3 +276,14 @@ func (m *SignatureManager) checkPromise(expected []common.SequenceCoordinate, pr
return false, 0
}
func stopIfNeeded(index int) {
s := viper.GetInt("stopbefore")
if s == 0 {
return
}
if index == -1 && s == -1 || index+1 == s {
os.Exit(0)
}
}
\ No newline at end of file
......@@ -91,6 +91,7 @@ func (w *Window) initTimer() {
w.timer.OnTimeout(func() {
nbEvents := len(w.scene.Events)
if w.scene.currentEvent >= nbEvents {
w.stopButton.Click()
w.replayButton.Click()
return
}
......@@ -116,6 +117,7 @@ func (w *Window) initTimer() {
quantum := time.Duration(w.quantumField.Value()) * time.Microsecond
endOfQuantum := w.scene.currentTime.Add(quantum)
drawnEvents := 0
for i := w.scene.currentEvent; i < nbEvents; i++ {
e := w.scene.Events[i]
......@@ -125,10 +127,15 @@ func (w *Window) initTimer() {
w.DrawEvent(&e)
w.scene.currentEvent++
drawnEvents++
}
w.PrintQuantumInformation()
w.scene.currentTime = endOfQuantum
if w.speedSlider.Value() == 0 && drawnEvents > 0 {
w.stopButton.Click() // step-by-step
}
})
}
......
......@@ -187,7 +187,7 @@
<enum>Qt::TabFocus</enum>
</property>
<property name="minimum">
<number>1</number>
<number>0</number>
</property>
<property name="maximum">
<number>20</number>
......
......@@ -122,7 +122,11 @@ func (w *Window) addActions() {
w.playButton.OnClicked(func() {
w.playButton.SetDisabled(true)
w.stopButton.SetDisabled(false)
speed := 2000 / w.speedSlider.Value()
s := w.speedSlider.Value()
if s == 0 {
s = 100 // step-by-step arbitrary speed value
}
speed := 2000 / s
w.timer.StartWithMsec(speed)
})
......
......@@ -75,6 +75,7 @@ func TestNewContract(t *testing.T) {
assert.Equal(t, nil, err)
// Check database²
time.Sleep(time.Second) // Allowed delay to let some time to propagate the contract readiness
contract = getContract("contract.txt", 0)
assert.Equal(t, true, contract.Ready)
assert.True(t, len(contract.Signers[0].Hash) > 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