[#271] pkg/network: Add multiaddr to ipaddr converter
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
2ebcbe70fb
commit
a8c26378b1
2 changed files with 13 additions and 10 deletions
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue