From a8c26378b16c6d27449c395f23e46b5c53ef0f2d Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 23 Dec 2020 11:45:36 +0300 Subject: [PATCH] [#271] pkg/network: Add multiaddr to ipaddr converter Signed-off-by: Alex Vanin --- pkg/innerring/processors/audit/process.go | 13 +++---------- pkg/network/address.go | 10 ++++++++++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/pkg/innerring/processors/audit/process.go b/pkg/innerring/processors/audit/process.go index 17e6138e..bb430e39 100644 --- a/pkg/innerring/processors/audit/process.go +++ b/pkg/innerring/processors/audit/process.go @@ -113,9 +113,11 @@ func (ap *Processor) findStorageGroups(cid *container.ID, shuffled netmap.Nodes) zap.Int("total_tries", ln), ) - addr, err := ipAddr(shuffled[i].Address()) + addr, err := network.IPAddrFromMultiaddr(shuffled[i].Address()) if err != nil { log.Warn("can't parse remote address", zap.String("error", err.Error())) + + continue } cli, err := ap.clientCache.Get(addr) @@ -146,12 +148,3 @@ func (ap *Processor) findStorageGroups(cid *container.ID, shuffled netmap.Nodes) return sg } - -func ipAddr(multiaddr string) (string, error) { - address, err := network.AddressFromString(multiaddr) - if err != nil { - return "", err - } - - return address.IPAddrString() -} diff --git a/pkg/network/address.go b/pkg/network/address.go index 1e882bc7..3f512f33 100644 --- a/pkg/network/address.go +++ b/pkg/network/address.go @@ -95,3 +95,13 @@ func multiaddrStringFromHostAddr(host string) (string, error) { func IsLocalAddress(src LocalAddressSource, addr *Address) bool { return src.LocalAddress().ma.Equal(addr.ma) } + +// IPAddrFromMultiaddr converts "/dns4/localhost/tcp/8080" to "192.168.0.1:8080". +func IPAddrFromMultiaddr(multiaddr string) (string, error) { + address, err := AddressFromString(multiaddr) + if err != nil { + return "", err + } + + return address.IPAddrString() +}