Commit 8583369d authored by Loïck Bonniot's avatar Loïck Bonniot

[c][net] Set default timeout for connection

parent 2b63e8df
Pipeline #624 passed with stage
......@@ -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 {
......
......@@ -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 {
......
......@@ -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 {
......
......@@ -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 {
......
......@@ -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),
)
}
......
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