[#19] Move connection list sorting to a proper place

Signed-off-by: Pavel Korotkov <pavel@nspcc.ru>
This commit is contained in:
Pavel Korotkov 2021-03-31 22:15:10 +03:00 committed by Pavel Korotkov
parent 0b6e138270
commit aedd468c18
2 changed files with 2 additions and 2 deletions

2
app.go
View file

@ -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))

View file

@ -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())