From 5ee500bb43c68708df323b27653f82d29bc156fd Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 23 Nov 2020 14:05:27 +0300 Subject: [PATCH] [#205] sdk/client: Support option to set dial timeout There is a need to set dial timeout in SDK client that is used in case of internal connection opening. Add DialTimeout option constructor to support this feature. Signed-off-by: Leonard Lyubich --- pkg/client/accounting.go | 5 +++-- pkg/client/container.go | 5 +++-- pkg/client/netmap.go | 5 +++-- pkg/client/object.go | 1 + pkg/client/opts.go | 10 ++++++++++ pkg/client/session.go | 5 +++-- 6 files changed, 23 insertions(+), 8 deletions(-) diff --git a/pkg/client/accounting.go b/pkg/client/accounting.go index a0cdf4b..7446233 100644 --- a/pkg/client/accounting.go +++ b/pkg/client/accounting.go @@ -89,8 +89,9 @@ func v2AccountingClientFromOptions(opts *clientOptions) (cli *v2accounting.Clien case opts.addr != "": cli, err = v2accounting.NewClient(v2accounting.WithGlobalOpts( - client.WithNetworkAddress(opts.addr)), - ) + client.WithNetworkAddress(opts.addr), + client.WithDialTimeout(opts.dialTimeout), + )) default: return nil, errOptionsLack("Accounting") diff --git a/pkg/client/container.go b/pkg/client/container.go index fff2e92..0c90d9d 100644 --- a/pkg/client/container.go +++ b/pkg/client/container.go @@ -448,8 +448,9 @@ func v2ContainerClientFromOptions(opts *clientOptions) (cli *v2container.Client, case opts.addr != "": cli, err = v2container.NewClient(v2container.WithGlobalOpts( - client.WithNetworkAddress(opts.addr)), - ) + client.WithNetworkAddress(opts.addr), + client.WithDialTimeout(opts.dialTimeout), + )) default: return nil, errOptionsLack("Container") diff --git a/pkg/client/netmap.go b/pkg/client/netmap.go index f4b0b09..749b640 100644 --- a/pkg/client/netmap.go +++ b/pkg/client/netmap.go @@ -97,8 +97,9 @@ func v2NetmapClientFromOptions(opts *clientOptions) (cli *v2netmap.Client, err e case opts.addr != "": cli, err = v2netmap.NewClient(v2netmap.WithGlobalOpts( - client.WithNetworkAddress(opts.addr)), - ) + client.WithNetworkAddress(opts.addr), + client.WithDialTimeout(opts.dialTimeout), + )) default: return nil, errOptionsLack("Netmap") diff --git a/pkg/client/object.go b/pkg/client/object.go index f30ca0d..04812da 100644 --- a/pkg/client/object.go +++ b/pkg/client/object.go @@ -1013,6 +1013,7 @@ func v2ObjectClient(proto TransportProtocol, opts *clientOptions) (*v2object.Cli optsV2 = []v2object.Option{ v2object.WithGlobalOpts( client.WithNetworkAddress(opts.addr), + client.WithDialTimeout(opts.dialTimeout), ), } } diff --git a/pkg/client/opts.go b/pkg/client/opts.go index e4dd299..9e84665 100644 --- a/pkg/client/opts.go +++ b/pkg/client/opts.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "time" "github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg/token" @@ -35,6 +36,8 @@ type ( clientOptions struct { addr string + dialTimeout time.Duration + grpcOpts *grpcOptions } @@ -168,3 +171,10 @@ func WithGRPCConnection(grpcConn *grpc.ClientConn) Option { option.grpcOpts.conn = grpcConn }) } + +// WithDialTimeout returns option to set connection timeout to the remote node. +func WithDialTimeout(dur time.Duration) Option { + return newFuncClientOption(func(option *clientOptions) { + option.dialTimeout = dur + }) +} diff --git a/pkg/client/session.go b/pkg/client/session.go index c45f784..769c517 100644 --- a/pkg/client/session.go +++ b/pkg/client/session.go @@ -97,8 +97,9 @@ func v2SessionClientFromOptions(opts *clientOptions) (cli *v2session.Client, err case opts.addr != "": cli, err = v2session.NewClient(v2session.WithGlobalOpts( - client.WithNetworkAddress(opts.addr)), - ) + client.WithNetworkAddress(opts.addr), + client.WithDialTimeout(opts.dialTimeout), + )) default: return nil, errOptionsLack("Session")