forked from TrueCloudLab/frostfs-node
[#31] network: Make the address a separate type
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
d6a4965841
commit
44def45ff4
2 changed files with 21 additions and 5 deletions
|
@ -6,7 +6,22 @@ import (
|
||||||
|
|
||||||
// Address represents the NeoFS node
|
// Address represents the NeoFS node
|
||||||
// network address.
|
// network address.
|
||||||
//
|
type Address struct {
|
||||||
// It is a type alias of
|
ma multiaddr.Multiaddr
|
||||||
// github.com/multiformats/go-multiaddr.Multiaddr.
|
}
|
||||||
type Address = multiaddr.Multiaddr
|
|
||||||
|
func (a Address) String() string {
|
||||||
|
return a.ma.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddressFromString restores address from a string representation.
|
||||||
|
func AddressFromString(s string) (*Address, error) {
|
||||||
|
ma, err := multiaddr.NewMultiaddr(s)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Address{
|
||||||
|
ma: ma,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
|
@ -3,11 +3,12 @@ package network
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
|
"github.com/multiformats/go-multiaddr"
|
||||||
manet "github.com/multiformats/go-multiaddr-net"
|
manet "github.com/multiformats/go-multiaddr-net"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Listen announces on the local network address.
|
// Listen announces on the local network address.
|
||||||
func Listen(addr Address) (net.Listener, error) {
|
func Listen(addr multiaddr.Multiaddr) (net.Listener, error) {
|
||||||
mLis, err := manet.Listen(addr)
|
mLis, err := manet.Listen(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in a new issue