From 10284ddd63ae734b191a2faad592c199b31660c8 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Wed, 9 Jun 2021 14:56:11 +0300 Subject: [PATCH] [#9] Dropped direct gRPC connections Using neofs-api-go client.New to create grpc connections. Signed-off-by: Denis Kirillov --- pkg/pool/pool.go | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/pkg/pool/pool.go b/pkg/pool/pool.go index 9282031d..ded752f1 100644 --- a/pkg/pool/pool.go +++ b/pkg/pool/pool.go @@ -12,8 +12,6 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg/client" "github.com/nspcc-dev/neofs-api-go/pkg/owner" "github.com/nspcc-dev/neofs-api-go/pkg/session" - "google.golang.org/grpc" - "google.golang.org/grpc/keepalive" ) // BuilderOptions contains options used to build connection pool. @@ -22,12 +20,9 @@ type BuilderOptions struct { NodeConnectionTimeout time.Duration NodeRequestTimeout time.Duration ClientRebalanceInterval time.Duration - KeepaliveTime time.Duration - KeepaliveTimeout time.Duration - KeepalivePermitWoStream bool SessionExpirationEpoch uint64 weights []float64 - connections []*grpc.ClientConn + addresses []string } // Builder is an interim structure used to collect node addresses/weights and @@ -56,28 +51,9 @@ func (pb *Builder) Build(ctx context.Context, options *BuilderOptions) (Pool, er for i, w := range pb.weights { pb.weights[i] = w / totalWeight } - var cons = make([]*grpc.ClientConn, len(pb.addresses)) - for i, address := range pb.addresses { - con, err := func() (*grpc.ClientConn, error) { - toctx, c := context.WithTimeout(ctx, options.NodeConnectionTimeout) - defer c() - return grpc.DialContext(toctx, address, - grpc.WithInsecure(), - grpc.WithBlock(), - grpc.WithKeepaliveParams(keepalive.ClientParameters{ - Time: options.KeepaliveTime, - Timeout: options.KeepaliveTimeout, - PermitWithoutStream: options.KeepalivePermitWoStream, - }), - ) - }() - if err != nil { - return nil, err - } - cons[i] = con - } + options.weights = pb.weights - options.connections = cons + options.addresses = pb.addresses return newPool(ctx, options) } @@ -102,8 +78,10 @@ type pool struct { func newPool(ctx context.Context, options *BuilderOptions) (Pool, error) { clientPacks := make([]*clientPack, len(options.weights)) - for i, con := range options.connections { - c, err := client.New(client.WithDefaultPrivateKey(options.Key), client.WithGRPCConnection(con)) + for i, address := range options.addresses { + c, err := client.New(client.WithDefaultPrivateKey(options.Key), + client.WithURIAddress(address, nil), + client.WithDialTimeout(options.NodeConnectionTimeout)) if err != nil { return nil, err }