From 44def45ff4ccfe56bd65bb1083760b53f5d91441 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 17 Sep 2020 12:09:49 +0300 Subject: [PATCH] [#31] network: Make the address a separate type Signed-off-by: Leonard Lyubich --- pkg/network/address.go | 23 +++++++++++++++++++---- pkg/network/listen.go | 3 ++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/pkg/network/address.go b/pkg/network/address.go index 5cc4e71c1..465a26aba 100644 --- a/pkg/network/address.go +++ b/pkg/network/address.go @@ -6,7 +6,22 @@ import ( // Address represents the NeoFS node // network address. -// -// It is a type alias of -// github.com/multiformats/go-multiaddr.Multiaddr. -type Address = multiaddr.Multiaddr +type Address struct { + ma 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 +} diff --git a/pkg/network/listen.go b/pkg/network/listen.go index 14cd11224..0834ac586 100644 --- a/pkg/network/listen.go +++ b/pkg/network/listen.go @@ -3,11 +3,12 @@ package network import ( "net" + "github.com/multiformats/go-multiaddr" manet "github.com/multiformats/go-multiaddr-net" ) // 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) if err != nil { return nil, err