[#607] network: Make ClientCache to accept AddressGroup
Change type of the `ClientCache.Get` method's parameter to `AddressGroup`. Use `GroupFromAddress` to call the method from the wrappers in order to no change their interface. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
5db7c5c2a8
commit
e11f50ec8e
5 changed files with 16 additions and 11 deletions
|
@ -205,7 +205,7 @@ type remoteLoadAnnounceProvider struct {
|
||||||
loadAddrSrc network.LocalAddressSource
|
loadAddrSrc network.LocalAddressSource
|
||||||
|
|
||||||
clientCache interface {
|
clientCache interface {
|
||||||
Get(network.Address) (apiClient.Client, error)
|
Get(network.AddressGroup) (apiClient.Client, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
deadEndProvider loadcontroller.WriterProvider
|
deadEndProvider loadcontroller.WriterProvider
|
||||||
|
@ -230,7 +230,7 @@ func (r *remoteLoadAnnounceProvider) InitRemote(srv loadroute.ServerInfo) (loadc
|
||||||
return loadcontroller.SimpleWriterProvider(new(nopLoadWriter)), nil
|
return loadcontroller.SimpleWriterProvider(new(nopLoadWriter)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := r.clientCache.Get(netAddr)
|
c, err := r.clientCache.Get(network.GroupFromAddress(netAddr))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not initialize API client: %w", err)
|
return nil, fmt.Errorf("could not initialize API client: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -422,7 +422,7 @@ type reputationClientConstructor struct {
|
||||||
trustStorage *truststorage.Storage
|
trustStorage *truststorage.Storage
|
||||||
|
|
||||||
basicConstructor interface {
|
basicConstructor interface {
|
||||||
Get(network.Address) (client.Client, error)
|
Get(network.AddressGroup) (client.Client, error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -507,7 +507,7 @@ func (c *reputationClient) SearchObject(ctx context.Context, prm *client.SearchO
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *reputationClientConstructor) Get(addr network.Address) (client.Client, error) {
|
func (c *reputationClientConstructor) Get(addr network.Address) (client.Client, error) {
|
||||||
cl, err := c.basicConstructor.Get(addr)
|
cl, err := c.basicConstructor.Get(network.GroupFromAddress(addr))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type clientCache interface {
|
type clientCache interface {
|
||||||
Get(network.Address) (apiClient.Client, error)
|
Get(network.AddressGroup) (apiClient.Client, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// clientKeyRemoteProvider must provide remote writer and take into account
|
// clientKeyRemoteProvider must provide remote writer and take into account
|
||||||
|
@ -84,7 +84,7 @@ func (rtp *remoteTrustProvider) InitRemote(srv reputationcommon.ServerInfo) (rep
|
||||||
return trustcontroller.SimpleWriterProvider(new(NopReputationWriter)), nil
|
return trustcontroller.SimpleWriterProvider(new(NopReputationWriter)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := rtp.clientCache.Get(netAddr)
|
c, err := rtp.clientCache.Get(network.GroupFromAddress(netAddr))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not initialize API client: %w", err)
|
return nil, fmt.Errorf("could not initialize API client: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ type (
|
||||||
ClientCache struct {
|
ClientCache struct {
|
||||||
log *zap.Logger
|
log *zap.Logger
|
||||||
cache interface {
|
cache interface {
|
||||||
Get(address network.Address) (client.Client, error)
|
Get(address network.AddressGroup) (client.Client, error)
|
||||||
CloseAll()
|
CloseAll()
|
||||||
}
|
}
|
||||||
key *ecdsa.PrivateKey
|
key *ecdsa.PrivateKey
|
||||||
|
@ -52,7 +52,7 @@ func newClientCache(p *clientCacheParams) *ClientCache {
|
||||||
func (c *ClientCache) Get(address network.Address) (client.Client, error) {
|
func (c *ClientCache) Get(address network.Address) (client.Client, error) {
|
||||||
// Because cache is used by `ClientCache` exclusively,
|
// Because cache is used by `ClientCache` exclusively,
|
||||||
// client will always have valid key.
|
// client will always have valid key.
|
||||||
return c.cache.Get(address)
|
return c.cache.Get(network.GroupFromAddress(address))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSG polls the container from audit task to get the object by id.
|
// GetSG polls the container from audit task to get the object by id.
|
||||||
|
|
11
pkg/network/cache/client.go
vendored
11
pkg/network/cache/client.go
vendored
|
@ -28,11 +28,16 @@ func NewSDKClientCache(opts ...client.Option) *ClientCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get function returns existing client or creates a new one.
|
// Get function returns existing client or creates a new one.
|
||||||
func (c *ClientCache) Get(netAddr network.Address) (client.Client, error) {
|
func (c *ClientCache) Get(netAddr network.AddressGroup) (client.Client, error) {
|
||||||
// multiaddr is used as a key in client cache since
|
// multiaddr is used as a key in client cache since
|
||||||
// same host may have different connections(with tls or not),
|
// same host may have different connections(with tls or not),
|
||||||
// therefore, host+port pair is not unique
|
// therefore, host+port pair is not unique
|
||||||
mAddr := netAddr.String()
|
|
||||||
|
// FIXME: we should calculate map key regardless of the address order,
|
||||||
|
// but network.StringifyGroup is order-dependent.
|
||||||
|
// This works until the same mixed group is transmitted
|
||||||
|
// (for a network map, it seems to be true).
|
||||||
|
mAddr := network.StringifyGroup(netAddr)
|
||||||
|
|
||||||
c.mu.RLock()
|
c.mu.RLock()
|
||||||
if cli, ok := c.clients[mAddr]; ok {
|
if cli, ok := c.clients[mAddr]; ok {
|
||||||
|
@ -53,7 +58,7 @@ func (c *ClientCache) Get(netAddr network.Address) (client.Client, error) {
|
||||||
return cli, nil
|
return cli, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
cli := newMultiClient(network.GroupFromAddress(netAddr), c.opts)
|
cli := newMultiClient(netAddr, c.opts)
|
||||||
|
|
||||||
c.clients[mAddr] = cli
|
c.clients[mAddr] = cli
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue