[#549] network/cache: Change Get signature

Make network cache's `Get` method accept
`network.Address` argument instead of
string.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-05-20 18:17:16 +03:00 committed by Alex Vanin
parent e10981a7d3
commit 33bef46f31
19 changed files with 83 additions and 85 deletions

View file

@ -22,7 +22,7 @@ type (
ClientCache struct {
log *zap.Logger
cache interface {
Get(string) (client.Client, error)
Get(address *network.Address) (client.Client, error)
}
key *ecdsa.PrivateKey
@ -48,7 +48,7 @@ func newClientCache(p *clientCacheParams) *ClientCache {
}
}
func (c *ClientCache) Get(address string) (client.Client, error) {
func (c *ClientCache) Get(address *network.Address) (client.Client, error) {
// Because cache is used by `ClientCache` exclusively,
// client will always have valid key.
return c.cache.Get(address)
@ -74,7 +74,7 @@ func (c *ClientCache) getSG(ctx context.Context, addr *object.Address, nm *netma
getParams.WithAddress(addr)
for _, node := range placement.FlattenNodes(nodes) {
addr, err := network.HostAddrFromMultiaddr(node.Address())
netAddr, err := network.AddressFromString(node.Address())
if err != nil {
c.log.Warn("can't parse remote address",
zap.String("address", node.Address()),
@ -83,10 +83,10 @@ func (c *ClientCache) getSG(ctx context.Context, addr *object.Address, nm *netma
continue
}
cli, err := c.Get(addr)
cli, err := c.Get(netAddr)
if err != nil {
c.log.Warn("can't setup remote connection",
zap.String("address", addr),
zap.String("address", netAddr.String()),
zap.String("error", err.Error()))
continue
@ -136,14 +136,14 @@ func (c *ClientCache) GetHeader(task *audit.Task, node *netmap.Node, id *object.
headParams.WithMainFields()
headParams.WithAddress(objAddress)
addr, err := network.HostAddrFromMultiaddr(node.Address())
netAddr, err := network.AddressFromString(node.Address())
if err != nil {
return nil, fmt.Errorf("can't parse remote address %s: %w", node.Address(), err)
}
cli, err := c.Get(addr)
cli, err := c.Get(netAddr)
if err != nil {
return nil, fmt.Errorf("can't setup remote connection with %s: %w", addr, err)
return nil, fmt.Errorf("can't setup remote connection with %s: %w", netAddr, err)
}
cctx, cancel := context.WithTimeout(task.AuditContext(), c.headTimeout)
@ -172,14 +172,14 @@ func (c *ClientCache) GetRangeHash(task *audit.Task, node *netmap.Node, id *obje
rangeParams.WithRangeList(rng)
rangeParams.WithSalt(nil) // it MUST be nil for correct hash concatenation in PDP game
addr, err := network.HostAddrFromMultiaddr(node.Address())
netAddr, err := network.AddressFromString(node.Address())
if err != nil {
return nil, fmt.Errorf("can't parse remote address %s: %w", node.Address(), err)
}
cli, err := c.Get(addr)
cli, err := c.Get(netAddr)
if err != nil {
return nil, fmt.Errorf("can't setup remote connection with %s: %w", addr, err)
return nil, fmt.Errorf("can't setup remote connection with %s: %w", netAddr, err)
}
cctx, cancel := context.WithTimeout(task.AuditContext(), c.rangeTimeout)