[#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:
Leonard Lyubich 2021-06-21 19:59:05 +03:00 committed by Leonard Lyubich
parent 5db7c5c2a8
commit e11f50ec8e
5 changed files with 16 additions and 11 deletions

View file

@ -28,11 +28,16 @@ func NewSDKClientCache(opts ...client.Option) *ClientCache {
}
// 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
// same host may have different connections(with tls or not),
// 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()
if cli, ok := c.clients[mAddr]; ok {
@ -53,7 +58,7 @@ func (c *ClientCache) Get(netAddr network.Address) (client.Client, error) {
return cli, nil
}
cli := newMultiClient(network.GroupFromAddress(netAddr), c.opts)
cli := newMultiClient(netAddr, c.opts)
c.clients[mAddr] = cli