[#645] *: Construct clients from client.NodeInfo in API client cache

There is a need to have the ability to expand the data needed for client
construction.

Replace `network.AddressGroup` parameter of client cache interfaces with
`client.NodeInfo`.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-09-28 07:46:10 +03:00 committed by Alex Vanin
parent 91cc33bdb9
commit 7b228b7603
25 changed files with 114 additions and 72 deletions

View file

@ -16,6 +16,7 @@ import (
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
containerV2 "github.com/nspcc-dev/neofs-api-go/v2/container"
containerGRPC "github.com/nspcc-dev/neofs-api-go/v2/container/grpc"
"github.com/nspcc-dev/neofs-node/pkg/core/client"
containerCore "github.com/nspcc-dev/neofs-node/pkg/core/container"
netmapCore "github.com/nspcc-dev/neofs-node/pkg/core/netmap"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
@ -244,7 +245,7 @@ type remoteLoadAnnounceProvider struct {
netmapKeys netmapCore.AnnouncedKeys
clientCache interface {
Get(network.AddressGroup) (apiClient.Client, error)
Get(client.NodeInfo) (apiClient.Client, error)
}
deadEndProvider loadcontroller.WriterProvider
@ -267,7 +268,11 @@ func (r *remoteLoadAnnounceProvider) InitRemote(srv loadroute.ServerInfo) (loadc
return nil, fmt.Errorf("could not convert address to IP format: %w", err)
}
c, err := r.clientCache.Get(netAddr)
var info client.NodeInfo
info.SetAddressGroup(netAddr)
c, err := r.clientCache.Get(info)
if err != nil {
return nil, fmt.Errorf("could not initialize API client: %w", err)
}

View file

@ -166,8 +166,8 @@ func (f *innerRingFetcherWithoutNotary) InnerRingKeys() ([][]byte, error) {
type coreClientConstructor reputationClientConstructor
func (x *coreClientConstructor) Get(addrGroup network.AddressGroup) (coreclient.Client, error) {
c, err := (*reputationClientConstructor)(x).Get(addrGroup)
func (x *coreClientConstructor) Get(info coreclient.NodeInfo) (coreclient.Client, error) {
c, err := (*reputationClientConstructor)(x).Get(info)
if err != nil {
return nil, err
}
@ -442,7 +442,7 @@ type reputationClientConstructor struct {
trustStorage *truststorage.Storage
basicConstructor interface {
Get(network.AddressGroup) (client.Client, error)
Get(coreclient.NodeInfo) (client.Client, error)
}
}
@ -526,14 +526,16 @@ func (c *reputationClient) SearchObject(ctx context.Context, prm *client.SearchO
return ids, err
}
func (c *reputationClientConstructor) Get(addr network.AddressGroup) (client.Client, error) {
cl, err := c.basicConstructor.Get(addr)
func (c *reputationClientConstructor) Get(info coreclient.NodeInfo) (client.Client, error) {
cl, err := c.basicConstructor.Get(info)
if err != nil {
return nil, err
}
nm, err := netmap.GetLatestNetworkMap(c.nmSrc)
if err == nil {
addr := info.AddressGroup()
for i := range nm.Nodes {
var netAddr network.AddressGroup

View file

@ -4,6 +4,7 @@ import (
"fmt"
apiClient "github.com/nspcc-dev/neofs-api-go/pkg/client"
"github.com/nspcc-dev/neofs-node/pkg/core/client"
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
"github.com/nspcc-dev/neofs-node/pkg/network"
reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
@ -12,7 +13,7 @@ import (
)
type clientCache interface {
Get(network.AddressGroup) (apiClient.Client, error)
Get(client.NodeInfo) (apiClient.Client, error)
}
// clientKeyRemoteProvider must provide remote writer and take into account
@ -83,7 +84,11 @@ func (rtp *remoteTrustProvider) InitRemote(srv reputationcommon.ServerInfo) (rep
return nil, fmt.Errorf("could not convert address to IP format: %w", err)
}
c, err := rtp.clientCache.Get(netAddr)
var info client.NodeInfo
info.SetAddressGroup(netAddr)
c, err := rtp.clientCache.Get(info)
if err != nil {
return nil, fmt.Errorf("could not initialize API client: %w", err)
}