[#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 <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-23 14:05:27 +03:00 committed by Alex Vanin
parent 03ac6bedb4
commit 5ee500bb43
6 changed files with 23 additions and 8 deletions

View file

@ -89,8 +89,9 @@ func v2AccountingClientFromOptions(opts *clientOptions) (cli *v2accounting.Clien
case opts.addr != "": case opts.addr != "":
cli, err = v2accounting.NewClient(v2accounting.WithGlobalOpts( cli, err = v2accounting.NewClient(v2accounting.WithGlobalOpts(
client.WithNetworkAddress(opts.addr)), client.WithNetworkAddress(opts.addr),
) client.WithDialTimeout(opts.dialTimeout),
))
default: default:
return nil, errOptionsLack("Accounting") return nil, errOptionsLack("Accounting")

View file

@ -448,8 +448,9 @@ func v2ContainerClientFromOptions(opts *clientOptions) (cli *v2container.Client,
case opts.addr != "": case opts.addr != "":
cli, err = v2container.NewClient(v2container.WithGlobalOpts( cli, err = v2container.NewClient(v2container.WithGlobalOpts(
client.WithNetworkAddress(opts.addr)), client.WithNetworkAddress(opts.addr),
) client.WithDialTimeout(opts.dialTimeout),
))
default: default:
return nil, errOptionsLack("Container") return nil, errOptionsLack("Container")

View file

@ -97,8 +97,9 @@ func v2NetmapClientFromOptions(opts *clientOptions) (cli *v2netmap.Client, err e
case opts.addr != "": case opts.addr != "":
cli, err = v2netmap.NewClient(v2netmap.WithGlobalOpts( cli, err = v2netmap.NewClient(v2netmap.WithGlobalOpts(
client.WithNetworkAddress(opts.addr)), client.WithNetworkAddress(opts.addr),
) client.WithDialTimeout(opts.dialTimeout),
))
default: default:
return nil, errOptionsLack("Netmap") return nil, errOptionsLack("Netmap")

View file

@ -1013,6 +1013,7 @@ func v2ObjectClient(proto TransportProtocol, opts *clientOptions) (*v2object.Cli
optsV2 = []v2object.Option{ optsV2 = []v2object.Option{
v2object.WithGlobalOpts( v2object.WithGlobalOpts(
client.WithNetworkAddress(opts.addr), client.WithNetworkAddress(opts.addr),
client.WithDialTimeout(opts.dialTimeout),
), ),
} }
} }

View file

@ -2,6 +2,7 @@ package client
import ( import (
"fmt" "fmt"
"time"
"github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg"
"github.com/nspcc-dev/neofs-api-go/pkg/token" "github.com/nspcc-dev/neofs-api-go/pkg/token"
@ -35,6 +36,8 @@ type (
clientOptions struct { clientOptions struct {
addr string addr string
dialTimeout time.Duration
grpcOpts *grpcOptions grpcOpts *grpcOptions
} }
@ -168,3 +171,10 @@ func WithGRPCConnection(grpcConn *grpc.ClientConn) Option {
option.grpcOpts.conn = grpcConn 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
})
}

View file

@ -97,8 +97,9 @@ func v2SessionClientFromOptions(opts *clientOptions) (cli *v2session.Client, err
case opts.addr != "": case opts.addr != "":
cli, err = v2session.NewClient(v2session.WithGlobalOpts( cli, err = v2session.NewClient(v2session.WithGlobalOpts(
client.WithNetworkAddress(opts.addr)), client.WithNetworkAddress(opts.addr),
) client.WithDialTimeout(opts.dialTimeout),
))
default: default:
return nil, errOptionsLack("Session") return nil, errOptionsLack("Session")