From aedd468c1842e7eb8f057bd7d6724293ae0b2a34 Mon Sep 17 00:00:00 2001 From: Pavel Korotkov Date: Wed, 31 Mar 2021 22:15:10 +0300 Subject: [PATCH] [#19] Move connection list sorting to a proper place Signed-off-by: Pavel Korotkov --- app.go | 2 -- neofs/client-plant.go | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app.go b/app.go index cd7c9b9..1b0f981 100644 --- a/app.go +++ b/app.go @@ -2,7 +2,6 @@ package main import ( "context" - "sort" "strconv" "github.com/fasthttp/router" @@ -99,7 +98,6 @@ func newApp(ctx context.Context, opt ...Option) App { cl.Add(address, weight) a.log.Info("add connection", zap.String("address", address), zap.Float64("weight", weight)) } - sort.Sort(sort.Reverse(cl)) creds, err := neofs.NewCredentials(a.cfg.GetString(cmdNeoFSKey)) if err != nil { a.log.Fatal("could not get neofs credentials", zap.Error(err)) diff --git a/neofs/client-plant.go b/neofs/client-plant.go index babcaff..7ce4824 100644 --- a/neofs/client-plant.go +++ b/neofs/client-plant.go @@ -6,6 +6,7 @@ import ( "crypto/ecdsa" "io" "math" + "sort" "time" "github.com/nspcc-dev/neofs-api-go/pkg/client" @@ -121,6 +122,7 @@ func (cl *ConnectionList) Add(address string, weight float64) ConnectionList { func NewClientPlant(ctx context.Context, connectionList ConnectionList, creds Credentials) (ClientPlant, error) { toctx, c := context.WithTimeout(ctx, nodeConnectionTimeout) defer c() + sort.Sort(sort.Reverse(connectionList)) // TODO: Use connection pool here. address := connectionList[0].address conn, err := grpc.DialContext(toctx, address, grpc.WithInsecure(), grpc.WithBlock())