forked from TrueCloudLab/frostfs-node
[#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:
parent
8585e147d0
commit
f930993e3a
7 changed files with 27 additions and 10 deletions
|
@ -23,13 +23,13 @@ func (a Address) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NetAddr returns network endpoint address in string format.
|
// 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)
|
ip, err := manet.ToNetAddr(a.ma)
|
||||||
if err != nil {
|
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.
|
// 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
|
// IsLocalAddress returns true if network endpoint from local address
|
||||||
// source is equal to network endpoint of passed address.
|
// source is equal to network endpoint of passed address.
|
||||||
func IsLocalAddress(src LocalAddressSource, addr *Address) bool {
|
func IsLocalAddress(src LocalAddressSource, addr *Address) bool {
|
||||||
return src.LocalAddress().NetAddr() == addr.NetAddr()
|
return src.LocalAddress().ma.Equal(addr.ma)
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,5 +24,7 @@ func TestAddress_NetAddr(t *testing.T) {
|
||||||
addr, err := AddressFromString(ma.String())
|
addr, err := AddressFromString(ma.String())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.Equal(t, ip+":"+port, addr.NetAddr())
|
netAddr, err := addr.NetAddr()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, ip+":"+port, netAddr)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,10 @@ func (h *remoteHeader) head(ctx context.Context, prm *Prm, handler func(*object.
|
||||||
return errors.Wrapf(err, "(%T) could not receive private key", h)
|
return errors.Wrapf(err, "(%T) could not receive private key", h)
|
||||||
}
|
}
|
||||||
|
|
||||||
addr := h.node.NetAddr()
|
addr, err := h.node.NetAddr()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
c, err := client.New(key,
|
c, err := client.New(key,
|
||||||
client.WithAddress(addr),
|
client.WithAddress(addr),
|
||||||
|
|
|
@ -38,7 +38,10 @@ func (t *remoteTarget) Close() (*transformer.AccessIdentifiers, error) {
|
||||||
return nil, errors.Wrapf(err, "(%T) could not receive private key", t)
|
return nil, errors.Wrapf(err, "(%T) could not receive private key", t)
|
||||||
}
|
}
|
||||||
|
|
||||||
addr := t.addr.NetAddr()
|
addr, err := t.addr.NetAddr()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
c, err := client.New(key,
|
c, err := client.New(key,
|
||||||
client.WithAddress(addr),
|
client.WithAddress(addr),
|
||||||
|
|
|
@ -32,7 +32,10 @@ func (r *remoteRangeWriter) WriteTo(w io.Writer) (int64, error) {
|
||||||
return 0, errors.Wrapf(err, "(%T) could not receive private key", r)
|
return 0, errors.Wrapf(err, "(%T) could not receive private key", r)
|
||||||
}
|
}
|
||||||
|
|
||||||
addr := r.node.NetAddr()
|
addr, err := r.node.NetAddr()
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
c, err := client.New(key,
|
c, err := client.New(key,
|
||||||
client.WithAddress(addr),
|
client.WithAddress(addr),
|
||||||
|
|
|
@ -23,7 +23,10 @@ func (h *remoteHasher) hashRange(ctx context.Context, prm *Prm, handler func([][
|
||||||
return errors.Wrapf(err, "(%T) could not receive private key", h)
|
return errors.Wrapf(err, "(%T) could not receive private key", h)
|
||||||
}
|
}
|
||||||
|
|
||||||
addr := h.node.NetAddr()
|
addr, err := h.node.NetAddr()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
c, err := client.New(key,
|
c, err := client.New(key,
|
||||||
client.WithAddress(addr),
|
client.WithAddress(addr),
|
||||||
|
|
|
@ -24,7 +24,10 @@ func (s *remoteStream) stream(ctx context.Context, ch chan<- []*object.ID) error
|
||||||
return errors.Wrapf(err, "(%T) could not receive private key", s)
|
return errors.Wrapf(err, "(%T) could not receive private key", s)
|
||||||
}
|
}
|
||||||
|
|
||||||
addr := s.addr.NetAddr()
|
addr, err := s.addr.NetAddr()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
c, err := client.New(key,
|
c, err := client.New(key,
|
||||||
client.WithAddress(addr),
|
client.WithAddress(addr),
|
||||||
|
|
Loading…
Reference in a new issue