Skip to content
GitLab
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
8583369d
Commit
8583369d
authored
Apr 14, 2016
by
Loïck Bonniot
Browse files
[c][net] Set default timeout for connection
parent
2b63e8df
Pipeline
#624
passed with stage
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
dfssc/sign/create.go
View file @
8583369d
...
...
@@ -4,7 +4,6 @@ import (
"crypto/sha512"
"io/ioutil"
"path/filepath"
"time"
"dfss/dfssc/common"
"dfss/dfssc/security"
...
...
@@ -80,7 +79,7 @@ func (m *CreateManager) sendRequest() (*api.ErrorCode, error) {
}
client
:=
api
.
NewPlatformClient
(
conn
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
10
*
time
.
Second
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
net
.
DefaultTimeout
)
defer
cancel
()
response
,
err
:=
client
.
PostContract
(
ctx
,
request
)
if
err
!=
nil
{
...
...
dfssc/sign/fetch.go
View file @
8583369d
...
...
@@ -2,7 +2,6 @@ package sign
import
(
"io/ioutil"
"time"
"dfss/dfssc/common"
"dfss/dfssc/security"
...
...
@@ -28,7 +27,7 @@ func FetchContract(fileCA, fileCert, fileKey, addrPort, passphrase, uuid, path s
Uuid
:
uuid
,
}
client
:=
api
.
NewPlatformClient
(
conn
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
10
*
time
.
Second
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
net
.
DefaultTimeout
)
defer
cancel
()
response
,
err
:=
client
.
GetContract
(
ctx
,
request
)
if
err
!=
nil
{
...
...
dfssc/user/authentication.go
View file @
8583369d
...
...
@@ -8,6 +8,7 @@ import (
"dfss/dfssc/common"
"dfss/dfssc/security"
pb
"dfss/dfssp/api"
"dfss/net"
"errors"
"golang.org/x/net/context"
"google.golang.org/grpc"
...
...
@@ -98,7 +99,7 @@ func (m *AuthManager) sendRequest() (*pb.RegisteredUser, error) {
}
// Stop the context if it takes too long for the platform to answer
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
10
*
time
.
Second
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
net
.
DefaultTimeout
)
defer
cancel
()
response
,
err
:=
client
.
Auth
(
ctx
,
request
)
if
err
!=
nil
{
...
...
dfssc/user/register.go
View file @
8583369d
...
...
@@ -8,6 +8,7 @@ import (
"dfss/dfssc/common"
"dfss/dfssc/security"
pb
"dfss/dfssp/api"
"dfss/net"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
...
...
@@ -150,7 +151,7 @@ func (m *RegisterManager) sendRequest(certRequest string) (*pb.ErrorCode, error)
}
// Stop the context if it takes too long for the platform to answer
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
TODO
(),
10
*
time
.
Second
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
net
.
DefaultTimeout
)
defer
cancel
()
response
,
err
:=
client
.
Register
(
ctx
,
request
)
if
err
!=
nil
{
...
...
net/client.go
View file @
8583369d
...
...
@@ -13,6 +13,9 @@ import (
"google.golang.org/grpc/credentials"
)
// DefaultTimeout should be used when a non-critical timeout is used in the application.
const
DefaultTimeout
=
30
*
time
.
Second
// Connect to a peer.
//
// Given parameters cert/key/ca are PEM-encoded array of bytes.
...
...
@@ -43,6 +46,7 @@ func Connect(addrPort string, cert *x509.Certificate, key *rsa.PrivateKey, ca *x
return
grpc
.
Dial
(
addrPort
,
grpc
.
WithTransportCredentials
(
&
tlsCreds
{
config
:
conf
}),
grpc
.
WithTimeout
(
DefaultTimeout
),
)
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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