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
d05936eb
Commit
d05936eb
authored
May 24, 2016
by
Loïck Bonniot
Browse files
Merge branch '397_signature_timeout' into 'master'
397 signature timeout See merge request
!81
parents
dd9b187b
ef912c89
Pipeline
#2123
passed with stages
Changes
7
Pipelines
1
Show whitespace changes
Inline
Side-by-side
dfssc/cmd/root.go
View file @
d05936eb
...
...
@@ -2,7 +2,10 @@
package
cmd
import
(
"time"
"dfss"
"dfss/net"
dapi
"dfss/dfssd/api"
"github.com/spf13/cobra"
"github.com/spf13/viper"
...
...
@@ -20,6 +23,7 @@ A tool to sign multiparty contract using a secure cryptographic protocol`,
_
=
cmd
.
Help
()
},
PersistentPreRun
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
net
.
DefaultTimeout
=
viper
.
GetDuration
(
"timeout"
)
dapi
.
Configure
(
viper
.
GetString
(
"demo"
)
!=
""
,
viper
.
GetString
(
"demo"
),
"client"
)
},
PersistentPostRun
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
...
...
@@ -38,6 +42,7 @@ func init() {
RootCmd
.
PersistentFlags
()
.
StringP
(
"demo"
,
"d"
,
""
,
"demonstrator address and port, empty will disable it"
)
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
()
.
Duration
(
"timeout"
,
10
*
time
.
Second
,
"time to wait for connection and evidences before failing"
)
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)"
)
...
...
@@ -50,6 +55,7 @@ func init() {
_
=
viper
.
BindPFlag
(
"demo"
,
RootCmd
.
PersistentFlags
()
.
Lookup
(
"demo"
))
_
=
viper
.
BindPFlag
(
"local_port"
,
RootCmd
.
PersistentFlags
()
.
Lookup
(
"port"
))
_
=
viper
.
BindPFlag
(
"platform_addrport"
,
RootCmd
.
PersistentFlags
()
.
Lookup
(
"host"
))
_
=
viper
.
BindPFlag
(
"timeout"
,
RootCmd
.
PersistentFlags
()
.
Lookup
(
"timeout"
))
// Bind subcommands to root
RootCmd
.
AddCommand
(
dfss
.
VersionCmd
,
registerCmd
,
authCmd
,
newCmd
,
showCmd
,
fetchCmd
,
importCmd
,
exportCmd
,
signCmd
)
...
...
dfssc/sign/promises.go
View file @
d05936eb
...
...
@@ -3,11 +3,11 @@ package sign
import
(
"encoding/hex"
"errors"
"time"
cAPI
"dfss/dfssc/api"
dAPI
"dfss/dfssd/api"
pAPI
"dfss/dfssp/api"
"dfss/net"
"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
.
Min
ut
e
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
net
.
DefaultTimeo
ut
)
defer
cancel
()
var
result
*
pAPI
.
ErrorCode
...
...
dfssc/sign/signatures.go
View file @
d05936eb
...
...
@@ -6,6 +6,7 @@ import (
cAPI
"dfss/dfssc/api"
"dfss/dfssc/common"
"dfss/net"
)
// 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
.
Min
ut
e
)
:
case
<-
time
.
After
(
net
.
DefaultTimeo
ut
)
:
out
<-
fmt
.
Errorf
(
"Signature reception timeout!"
)
return
}
...
...
dfssc/sign/starter.go
View file @
d05936eb
...
...
@@ -85,7 +85,6 @@ func NewSignatureManager(passphrase string, c *contract.JSON) (*SignatureManager
m
.
mail
=
m
.
auth
.
Cert
.
Subject
.
CommonName
dAPI
.
SetIdentifier
(
m
.
mail
)
m
.
cServer
=
m
.
GetServer
()
go
func
()
{
_
=
net
.
Listen
(
"0.0.0.0:"
+
strconv
.
Itoa
(
viper
.
GetInt
(
"local_port"
)),
m
.
cServer
)
}()
...
...
@@ -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
.
Min
ut
e
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
net
.
DefaultTimeo
ut
)
defer
cancel
()
msg
,
err
:=
client
.
Discover
(
ctx
,
&
cAPI
.
Hello
{
Version
:
dfss
.
Version
})
if
err
!=
nil
{
...
...
gui/config/config.go
View file @
d05936eb
...
...
@@ -8,7 +8,9 @@ import (
"os"
"os/user"
"path/filepath"
"time"
"dfss/net"
"github.com/spf13/viper"
)
...
...
@@ -16,6 +18,7 @@ import (
type
Config
struct
{
Email
string
`json:"email"`
Platform
string
`json:"platform"`
Timeout
time
.
Duration
`json:"timeout"`
}
// Load loads the configuration file into memory.
...
...
@@ -42,12 +45,17 @@ func Load() {
viper
.
Set
(
"authenticated"
,
isFileValid
(
viper
.
GetString
(
"file_cert"
)))
viper
.
Set
(
"local_port"
,
9005
)
// Configure timeout
if
t
:=
viper
.
GetDuration
(
"timeout"
);
t
>
0
{
net
.
DefaultTimeout
=
t
}
return
}
// Save stores the current configuration object from memory.
func
Save
()
{
c
:=
Config
{
viper
.
GetString
(
"email"
),
viper
.
GetString
(
"platform"
)}
c
:=
Config
{
viper
.
GetString
(
"email"
),
viper
.
GetString
(
"platform"
)
,
viper
.
GetDuration
(
"timeout"
)
}
data
,
err
:=
json
.
MarshalIndent
(
c
,
""
,
" "
)
if
err
!=
nil
{
return
...
...
net/client.go
View file @
d05936eb
...
...
@@ -17,7 +17,7 @@ import (
)
// DefaultTimeout should be used when a non-critical timeout is used in the application.
var
DefaultTimeout
=
5
*
time
.
Second
var
DefaultTimeout
=
10
*
time
.
Second
// Connect to a peer.
//
...
...
tests/starters_test.go
View file @
d05936eb
...
...
@@ -107,7 +107,7 @@ func createClient(tmpDir string, ca []byte, port int) (*exec.Cmd, error) {
// Prepare the client command.
// The last argument is up to you!
cmd
:=
exec
.
Command
(
path
,
"--ca"
,
caPath
,
"--cert"
,
certPath
,
"--host"
,
"127.0.0.1:"
+
testPort
,
"--key"
,
keyPath
,
"--port"
,
strconv
.
Itoa
(
port
),
"-v"
,
"-d"
,
"localhost:9099"
)
cmd
:=
exec
.
Command
(
path
,
"--ca"
,
caPath
,
"--cert"
,
certPath
,
"--host"
,
"127.0.0.1:"
+
testPort
,
"--key"
,
keyPath
,
"--port"
,
strconv
.
Itoa
(
port
),
"--timeout"
,
"3s"
,
"-v"
,
"-d"
,
"localhost:9099"
)
return
cmd
,
nil
}
...
...
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