diff --git a/netmap/node_info.go b/netmap/node_info.go index 242807a0..58af58ed 100644 --- a/netmap/node_info.go +++ b/netmap/node_info.go @@ -371,8 +371,32 @@ const ( // attrCapacity is a key to the node attribute that indicates the // total available disk space in Gigabytes. attrCapacity = "Capacity" + + // attrExternalAddr is a key for the attribute storing node external addresses. + attrExternalAddr = "ExternalAddr" + // sepExternalAddr is a separator for multi-value ExternalAddr attribute. + sepExternalAddr = "," ) +// SetExternalAddresses sets multi-addresses to use +// to connect to this node from outside. +// +// Panics if addr is an empty list. +func (x *NodeInfo) SetExternalAddresses(addr ...string) { + x.SetAttribute(attrExternalAddr, strings.Join(addr, sepExternalAddr)) +} + +// ExternalAddresses returns list of multi-addresses to use +// to connect to this node from outside. +func (x NodeInfo) ExternalAddresses() []string { + a := x.Attribute(attrExternalAddr) + if len(a) == 0 { + return nil + } + + return strings.Split(a, sepExternalAddr) +} + // NumberOfAttributes returns number of attributes announced by the node. // // See also SetAttribute. diff --git a/netmap/node_info_test.go b/netmap/node_info_test.go index f475132a..1d1c0183 100644 --- a/netmap/node_info_test.go +++ b/netmap/node_info_test.go @@ -45,3 +45,17 @@ func TestNodeInfo_Status(t *testing.T) { require.False(t, n.IsOnline()) require.False(t, n.IsOffline()) } + +func TestNodeInfo_ExternalAddr(t *testing.T) { + var n NodeInfo + + require.Empty(t, n.ExternalAddresses()) + require.Panics(t, func() { n.SetExternalAddresses() }) + + addr := []string{"1", "2", "3"} + n.SetExternalAddresses(addr[0]) + require.Equal(t, addr[:1], n.ExternalAddresses()) + + n.SetExternalAddresses(addr[1:]...) + require.Equal(t, addr[1:], n.ExternalAddresses()) +}