[#43] pkg/network: Do not panic at multiaddr to net.Addr conversion

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-09-24 10:37:42 +03:00
parent 8585e147d0
commit f930993e3a
7 changed files with 27 additions and 10 deletions

View file

@ -23,13 +23,13 @@ func (a Address) String() string {
}
// NetAddr returns network endpoint address in string format.
func (a Address) NetAddr() string {
func (a Address) NetAddr() (string, error) {
ip, err := manet.ToNetAddr(a.ma)
if err != nil {
panic(errors.Wrap(err, "could not get net addr"))
return "", errors.Wrap(err, "could not get net addr")
}
return ip.String()
return ip.String(), nil
}
// AddressFromString restores address from a string representation.
@ -47,5 +47,5 @@ func AddressFromString(s string) (*Address, error) {
// IsLocalAddress returns true if network endpoint from local address
// source is equal to network endpoint of passed address.
func IsLocalAddress(src LocalAddressSource, addr *Address) bool {
return src.LocalAddress().NetAddr() == addr.NetAddr()
return src.LocalAddress().ma.Equal(addr.ma)
}