Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpcs
dfss
Commits
7e697f8d
Commit
7e697f8d
authored
May 22, 2016
by
Richer Maximilien
Committed by
Loïck Bonniot
May 24, 2016
Browse files
[c] Add timeout flag support
parent
dd9b187b
Changes
5
Hide whitespace changes
Inline
Side-by-side
dfssc/cmd/root.go
View file @
7e697f8d
...
...
@@ -2,6 +2,8 @@
package
cmd
import
(
"time"
"dfss"
dapi
"dfss/dfssd/api"
"github.com/spf13/cobra"
...
...
@@ -39,6 +41,7 @@ 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
(
"timeout"
,
time
.
Minute
,
"time to wait before fallback"
)
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)"
)
...
...
dfssc/cmd/sign.go
View file @
7e697f8d
...
...
@@ -18,6 +18,7 @@ var signCmd = &cobra.Command{
os
.
Exit
(
1
)
}
_
=
viper
.
BindPFlag
(
"timeout"
,
cmd
.
Flags
()
.
Lookup
(
"timeout"
))
_
=
viper
.
BindPFlag
(
"slowdown"
,
cmd
.
Flags
()
.
Lookup
(
"slowdown"
))
_
=
viper
.
BindPFlag
(
"stopbefore"
,
cmd
.
Flags
()
.
Lookup
(
"stopbefore"
))
...
...
dfssc/sign/promises.go
View file @
7e697f8d
...
...
@@ -3,11 +3,11 @@ package sign
import
(
"encoding/hex"
"errors"
"time"
cAPI
"dfss/dfssc/api"
dAPI
"dfss/dfssd/api"
pAPI
"dfss/dfssp/api"
"github.com/spf13/viper"
"golang.org/x/net/context"
)
...
...
@@ -59,7 +59,7 @@ func (m *SignatureManager) SendEvidence(promise *cAPI.Promise, signature *cAPI.S
return
}
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Minute
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
viper
.
GetDuration
(
"timeout"
)
)
defer
cancel
()
var
result
*
pAPI
.
ErrorCode
...
...
dfssc/sign/signatures.go
View file @
7e697f8d
...
...
@@ -6,6 +6,7 @@ import (
cAPI
"dfss/dfssc/api"
"dfss/dfssc/common"
"github.com/spf13/viper"
)
// ExchangeAllSignatures creates and sends signatures to all the signers of the contract
...
...
@@ -83,7 +84,7 @@ func (m *SignatureManager) ReceiveAllSignatures(out chan error) {
m
.
archives
.
receivedSignatures
=
append
(
m
.
archives
.
receivedSignatures
,
signature
)
}
case
<-
time
.
After
(
time
.
Minute
)
:
case
<-
time
.
After
(
viper
.
GetDuration
(
"timeout"
)
)
:
out
<-
fmt
.
Errorf
(
"Signature reception timeout!"
)
return
}
...
...
dfssc/sign/starter.go
View file @
7e697f8d
...
...
@@ -5,7 +5,6 @@ import (
"fmt"
"strconv"
"sync"
"time"
"dfss"
cAPI
"dfss/dfssc/api"
...
...
@@ -210,7 +209,7 @@ func (m *SignatureManager) addPeer(user *pAPI.User) (ready bool, err error) {
// need to create another way to access it
m
.
peersConn
[
user
.
Email
]
=
conn
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Minute
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
viper
.
GetDuration
(
"timeout"
)
)
defer
cancel
()
msg
,
err
:=
client
.
Discover
(
ctx
,
&
cAPI
.
Hello
{
Version
:
dfss
.
Version
})
if
err
!=
nil
{
...
...
@@ -235,7 +234,7 @@ func (m *SignatureManager) addPeer(user *pAPI.User) (ready bool, err error) {
// SendReadySign sends the READY signal to the platform, and wait (potentially a long time) for START signal.
func
(
m
*
SignatureManager
)
SendReadySign
()
(
signatureUUID
string
,
err
error
)
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
10
*
time
.
Minute
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
10
*
viper
.
GetDuration
(
"timeout"
)
)
defer
cancel
()
c
:=
make
(
chan
*
pAPI
.
LaunchSignature
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment