forked from TrueCloudLab/frostfs-api-go
[#312] netmap: Support multiple addresses in NodeInfo
In latest NeoFS API changes `NodeInfo` message carries list of network addresses. There is a need Add `SetAddresses` / `IterateAddresses` / `NumberOfAddresses` methods to provide the access to node's address group. Mark `Address` / `SetAddress` methods as deprecated. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
6d531a07a5
commit
07fcaa4ba5
9 changed files with 159 additions and 70 deletions
|
@ -332,15 +332,52 @@ func (i *NodeInfo) SetPublicKey(key []byte) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Address returns network endpoint address of the node.
|
// Address returns network endpoint address of the node.
|
||||||
func (i *NodeInfo) Address() string {
|
//
|
||||||
return (*netmap.NodeInfo)(i).
|
// Deprecated: use IterateAddresses method.
|
||||||
GetAddress()
|
func (i *NodeInfo) Address() (addr string) {
|
||||||
|
i.IterateAddresses(func(s string) bool {
|
||||||
|
addr = s
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetAddress sets network endpoint address of the node.
|
// SetAddress sets network endpoint address of the node.
|
||||||
|
//
|
||||||
|
// Deprecated: use SetAddresses method.
|
||||||
func (i *NodeInfo) SetAddress(addr string) {
|
func (i *NodeInfo) SetAddress(addr string) {
|
||||||
|
i.SetAddresses(addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NumberOfAddresses returns number of network addresses of the node.
|
||||||
|
func (i *NodeInfo) NumberOfAddresses() int {
|
||||||
|
return (*netmap.NodeInfo)(i).
|
||||||
|
NumberOfAddresses()
|
||||||
|
}
|
||||||
|
|
||||||
|
// IterateAddresses iterates over network addresses of the node.
|
||||||
|
// Breaks iteration on f's true return.
|
||||||
|
//
|
||||||
|
// Handler should not be nil.
|
||||||
|
func (i *NodeInfo) IterateAddresses(f func(string) bool) {
|
||||||
(*netmap.NodeInfo)(i).
|
(*netmap.NodeInfo)(i).
|
||||||
SetAddress(addr)
|
IterateAddresses(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IterateAllAddresses is a helper function to unconditionally
|
||||||
|
// iterate over all node addresses.
|
||||||
|
func IterateAllAddresses(i *NodeInfo, f func(string)) {
|
||||||
|
i.IterateAddresses(func(addr string) bool {
|
||||||
|
f(addr)
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAddresses sets list of network addresses of the node.
|
||||||
|
func (i *NodeInfo) SetAddresses(v ...string) {
|
||||||
|
(*netmap.NodeInfo)(i).
|
||||||
|
SetAddresses(v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attributes returns list of the node attributes.
|
// Attributes returns list of the node attributes.
|
||||||
|
|
|
@ -124,13 +124,21 @@ func TestNodeInfo_PublicKey(t *testing.T) {
|
||||||
require.Equal(t, key, i.PublicKey())
|
require.Equal(t, key, i.PublicKey())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNodeInfo_Address(t *testing.T) {
|
func TestNodeInfo_IterateAddresses(t *testing.T) {
|
||||||
i := new(NodeInfo)
|
i := new(NodeInfo)
|
||||||
a := "127.0.0.1:8080"
|
|
||||||
|
|
||||||
i.SetAddress(a)
|
as := []string{"127.0.0.1:8080", "127.0.0.1:8081"}
|
||||||
|
|
||||||
require.Equal(t, a, i.Address())
|
i.SetAddresses(as...)
|
||||||
|
|
||||||
|
as2 := make([]string, 0, i.NumberOfAddresses())
|
||||||
|
|
||||||
|
IterateAllAddresses(i, func(addr string) {
|
||||||
|
as2 = append(as2, addr)
|
||||||
|
})
|
||||||
|
|
||||||
|
require.Equal(t, as, as2)
|
||||||
|
require.EqualValues(t, len(as), i.NumberOfAddresses())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNodeInfo_State(t *testing.T) {
|
func TestNodeInfo_State(t *testing.T) {
|
||||||
|
@ -178,7 +186,7 @@ func TestNodeAttributeEncoding(t *testing.T) {
|
||||||
func TestNodeInfoEncoding(t *testing.T) {
|
func TestNodeInfoEncoding(t *testing.T) {
|
||||||
i := NewNodeInfo()
|
i := NewNodeInfo()
|
||||||
i.SetPublicKey([]byte{1, 2, 3})
|
i.SetPublicKey([]byte{1, 2, 3})
|
||||||
i.SetAddress("192.168.0.1")
|
i.SetAddresses("192.168.0.1", "192.168.0.2")
|
||||||
i.SetState(NodeStateOnline)
|
i.SetState(NodeStateOnline)
|
||||||
i.SetAttributes(testNodeAttribute())
|
i.SetAttributes(testNodeAttribute())
|
||||||
|
|
||||||
|
@ -227,7 +235,8 @@ func TestNewNodeInfo(t *testing.T) {
|
||||||
|
|
||||||
// check initial values
|
// check initial values
|
||||||
require.Nil(t, ni.PublicKey())
|
require.Nil(t, ni.PublicKey())
|
||||||
require.Empty(t, ni.Address())
|
|
||||||
|
require.Zero(t, ni.NumberOfAddresses())
|
||||||
require.Nil(t, ni.Attributes())
|
require.Nil(t, ni.Attributes())
|
||||||
require.Zero(t, ni.State())
|
require.Zero(t, ni.State())
|
||||||
|
|
||||||
|
@ -235,7 +244,7 @@ func TestNewNodeInfo(t *testing.T) {
|
||||||
niV2 := ni.ToV2()
|
niV2 := ni.ToV2()
|
||||||
|
|
||||||
require.Nil(t, niV2.GetPublicKey())
|
require.Nil(t, niV2.GetPublicKey())
|
||||||
require.Empty(t, niV2.GetAddress())
|
require.Zero(t, niV2.NumberOfAddresses())
|
||||||
require.Nil(t, niV2.GetAttributes())
|
require.Nil(t, niV2.GetAttributes())
|
||||||
require.EqualValues(t, netmap.UnspecifiedState, niV2.GetState())
|
require.EqualValues(t, netmap.UnspecifiedState, niV2.GetState())
|
||||||
})
|
})
|
||||||
|
|
|
@ -84,7 +84,7 @@ func NodeAttribute() *netmap.NodeAttribute {
|
||||||
func NodeInfo() *netmap.NodeInfo {
|
func NodeInfo() *netmap.NodeInfo {
|
||||||
x := netmap.NewNodeInfo()
|
x := netmap.NewNodeInfo()
|
||||||
|
|
||||||
x.SetAddress("address")
|
x.SetAddresses("address 1", "address 2")
|
||||||
x.SetPublicKey([]byte("public key"))
|
x.SetPublicKey([]byte("public key"))
|
||||||
x.SetState(netmap.NodeStateOnline)
|
x.SetState(netmap.NodeStateOnline)
|
||||||
x.SetAttributes(NodeAttribute(), NodeAttribute())
|
x.SetAttributes(NodeAttribute(), NodeAttribute())
|
||||||
|
|
|
@ -342,7 +342,7 @@ func (ni *NodeInfo) ToGRPCMessage() grpc.Message {
|
||||||
m = new(netmap.NodeInfo)
|
m = new(netmap.NodeInfo)
|
||||||
|
|
||||||
m.SetPublicKey(ni.publicKey)
|
m.SetPublicKey(ni.publicKey)
|
||||||
m.SetAddress(ni.address)
|
m.SetAddresses(ni.addresses)
|
||||||
m.SetState(NodeStateToGRPCMessage(ni.state))
|
m.SetState(NodeStateToGRPCMessage(ni.state))
|
||||||
m.SetAttributes(AttributesToGRPC(ni.attributes))
|
m.SetAttributes(AttributesToGRPC(ni.attributes))
|
||||||
}
|
}
|
||||||
|
@ -364,7 +364,7 @@ func (ni *NodeInfo) FromGRPCMessage(m grpc.Message) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
ni.publicKey = v.GetPublicKey()
|
ni.publicKey = v.GetPublicKey()
|
||||||
ni.address = v.GetAddress()
|
ni.addresses = v.GetAddresses()
|
||||||
ni.state = NodeStateFromRPCMessage(v.GetState())
|
ni.state = NodeStateFromRPCMessage(v.GetState())
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -134,9 +134,16 @@ func (m *NodeInfo_Attribute) SetParents(v []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetAddress sets node network address.
|
// SetAddress sets node network address.
|
||||||
|
//
|
||||||
|
// Deprecated: use SetAddresses.
|
||||||
func (m *NodeInfo) SetAddress(v string) {
|
func (m *NodeInfo) SetAddress(v string) {
|
||||||
|
m.SetAddresses([]string{v})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAddresses sets list of network addresses of the node.
|
||||||
|
func (m *NodeInfo) SetAddresses(v []string) {
|
||||||
if m != nil {
|
if m != nil {
|
||||||
m.Address = v
|
m.Addresses = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
90
v2/netmap/grpc/types.pb.go
generated
90
v2/netmap/grpc/types.pb.go
generated
|
@ -535,7 +535,7 @@ type NodeInfo struct {
|
||||||
// Public key of the NeoFS node in a binary format.
|
// Public key of the NeoFS node in a binary format.
|
||||||
PublicKey []byte `protobuf:"bytes,1,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"`
|
PublicKey []byte `protobuf:"bytes,1,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"`
|
||||||
// Ways to connect to a node
|
// Ways to connect to a node
|
||||||
Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"`
|
Addresses []string `protobuf:"bytes,2,rep,name=addresses,proto3" json:"addresses,omitempty"`
|
||||||
// Carries list of the NeoFS node attributes in a key-value form. Key name
|
// Carries list of the NeoFS node attributes in a key-value form. Key name
|
||||||
// must be a node-unique valid UTF-8 string. Value can't be empty. NodeInfo
|
// must be a node-unique valid UTF-8 string. Value can't be empty. NodeInfo
|
||||||
// structures with duplicated attribute names or attributes with empty values
|
// structures with duplicated attribute names or attributes with empty values
|
||||||
|
@ -584,11 +584,11 @@ func (x *NodeInfo) GetPublicKey() []byte {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *NodeInfo) GetAddress() string {
|
func (x *NodeInfo) GetAddresses() []string {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.Address
|
return x.Addresses
|
||||||
}
|
}
|
||||||
return ""
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *NodeInfo) GetAttributes() []*NodeInfo_Attribute {
|
func (x *NodeInfo) GetAttributes() []*NodeInfo_Attribute {
|
||||||
|
@ -830,49 +830,49 @@ var file_v2_netmap_grpc_types_proto_rawDesc = []byte{
|
||||||
0x32, 0x0a, 0x07, 0x66, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b,
|
0x32, 0x0a, 0x07, 0x66, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b,
|
||||||
0x32, 0x18, 0x2e, 0x6e, 0x65, 0x6f, 0x2e, 0x66, 0x73, 0x2e, 0x76, 0x32, 0x2e, 0x6e, 0x65, 0x74,
|
0x32, 0x18, 0x2e, 0x6e, 0x65, 0x6f, 0x2e, 0x66, 0x73, 0x2e, 0x76, 0x32, 0x2e, 0x6e, 0x65, 0x74,
|
||||||
0x6d, 0x61, 0x70, 0x2e, 0x46, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x52, 0x07, 0x66, 0x69, 0x6c, 0x74,
|
0x6d, 0x61, 0x70, 0x2e, 0x46, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x52, 0x07, 0x66, 0x69, 0x6c, 0x74,
|
||||||
0x65, 0x72, 0x73, 0x22, 0xc3, 0x02, 0x0a, 0x08, 0x4e, 0x6f, 0x64, 0x65, 0x49, 0x6e, 0x66, 0x6f,
|
0x65, 0x72, 0x73, 0x22, 0xc7, 0x02, 0x0a, 0x08, 0x4e, 0x6f, 0x64, 0x65, 0x49, 0x6e, 0x66, 0x6f,
|
||||||
0x12, 0x1d, 0x0a, 0x0a, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x01,
|
0x12, 0x1d, 0x0a, 0x0a, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x01,
|
||||||
0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x12,
|
0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x12,
|
||||||
0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
|
0x1c, 0x0a, 0x09, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03,
|
||||||
0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x44, 0x0a, 0x0a, 0x61, 0x74, 0x74,
|
0x28, 0x09, 0x52, 0x09, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x12, 0x44, 0x0a,
|
||||||
0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x24, 0x2e,
|
0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28,
|
||||||
0x6e, 0x65, 0x6f, 0x2e, 0x66, 0x73, 0x2e, 0x76, 0x32, 0x2e, 0x6e, 0x65, 0x74, 0x6d, 0x61, 0x70,
|
0x0b, 0x32, 0x24, 0x2e, 0x6e, 0x65, 0x6f, 0x2e, 0x66, 0x73, 0x2e, 0x76, 0x32, 0x2e, 0x6e, 0x65,
|
||||||
0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x2e, 0x41, 0x74, 0x74, 0x72, 0x69, 0x62,
|
0x74, 0x6d, 0x61, 0x70, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x2e, 0x41, 0x74,
|
||||||
0x75, 0x74, 0x65, 0x52, 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x12,
|
0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x52, 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75,
|
||||||
0x36, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x20,
|
0x74, 0x65, 0x73, 0x12, 0x36, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x04, 0x20, 0x01,
|
||||||
0x2e, 0x6e, 0x65, 0x6f, 0x2e, 0x66, 0x73, 0x2e, 0x76, 0x32, 0x2e, 0x6e, 0x65, 0x74, 0x6d, 0x61,
|
0x28, 0x0e, 0x32, 0x20, 0x2e, 0x6e, 0x65, 0x6f, 0x2e, 0x66, 0x73, 0x2e, 0x76, 0x32, 0x2e, 0x6e,
|
||||||
0x70, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x65,
|
0x65, 0x74, 0x6d, 0x61, 0x70, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x2e, 0x53,
|
||||||
0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x1a, 0x4d, 0x0a, 0x09, 0x41, 0x74, 0x74, 0x72, 0x69,
|
0x74, 0x61, 0x74, 0x65, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x1a, 0x4d, 0x0a, 0x09, 0x41,
|
||||||
0x62, 0x75, 0x74, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28,
|
0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18,
|
||||||
0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18,
|
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61,
|
||||||
0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x18, 0x0a, 0x07,
|
0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65,
|
||||||
0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x70,
|
0x12, 0x18, 0x0a, 0x07, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28,
|
||||||
0x61, 0x72, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x31, 0x0a, 0x05, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12,
|
0x09, 0x52, 0x07, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x31, 0x0a, 0x05, 0x53, 0x74,
|
||||||
0x0f, 0x0a, 0x0b, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00,
|
0x61, 0x74, 0x65, 0x12, 0x0f, 0x0a, 0x0b, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49,
|
||||||
0x12, 0x0a, 0x0a, 0x06, 0x4f, 0x4e, 0x4c, 0x49, 0x4e, 0x45, 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07,
|
0x45, 0x44, 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x4f, 0x4e, 0x4c, 0x49, 0x4e, 0x45, 0x10, 0x01,
|
||||||
0x4f, 0x46, 0x46, 0x4c, 0x49, 0x4e, 0x45, 0x10, 0x02, 0x22, 0x55, 0x0a, 0x0b, 0x4e, 0x65, 0x74,
|
0x12, 0x0b, 0x0a, 0x07, 0x4f, 0x46, 0x46, 0x4c, 0x49, 0x4e, 0x45, 0x10, 0x02, 0x22, 0x55, 0x0a,
|
||||||
0x77, 0x6f, 0x72, 0x6b, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x23, 0x0a, 0x0d, 0x63, 0x75, 0x72, 0x72,
|
0x0b, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x23, 0x0a, 0x0d,
|
||||||
0x65, 0x6e, 0x74, 0x5f, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52,
|
0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x18, 0x01, 0x20,
|
||||||
0x0c, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x45, 0x70, 0x6f, 0x63, 0x68, 0x12, 0x21, 0x0a,
|
0x01, 0x28, 0x04, 0x52, 0x0c, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x45, 0x70, 0x6f, 0x63,
|
||||||
0x0c, 0x6d, 0x61, 0x67, 0x69, 0x63, 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x02, 0x20,
|
0x68, 0x12, 0x21, 0x0a, 0x0c, 0x6d, 0x61, 0x67, 0x69, 0x63, 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65,
|
||||||
0x01, 0x28, 0x04, 0x52, 0x0b, 0x6d, 0x61, 0x67, 0x69, 0x63, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72,
|
0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x6d, 0x61, 0x67, 0x69, 0x63, 0x4e, 0x75,
|
||||||
0x2a, 0x67, 0x0a, 0x09, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x19, 0x0a,
|
0x6d, 0x62, 0x65, 0x72, 0x2a, 0x67, 0x0a, 0x09, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f,
|
||||||
0x15, 0x4f, 0x50, 0x45, 0x52, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45,
|
0x6e, 0x12, 0x19, 0x0a, 0x15, 0x4f, 0x50, 0x45, 0x52, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x55,
|
||||||
0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x06, 0x0a, 0x02, 0x45, 0x51, 0x10, 0x01,
|
0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x06, 0x0a, 0x02,
|
||||||
0x12, 0x06, 0x0a, 0x02, 0x4e, 0x45, 0x10, 0x02, 0x12, 0x06, 0x0a, 0x02, 0x47, 0x54, 0x10, 0x03,
|
0x45, 0x51, 0x10, 0x01, 0x12, 0x06, 0x0a, 0x02, 0x4e, 0x45, 0x10, 0x02, 0x12, 0x06, 0x0a, 0x02,
|
||||||
0x12, 0x06, 0x0a, 0x02, 0x47, 0x45, 0x10, 0x04, 0x12, 0x06, 0x0a, 0x02, 0x4c, 0x54, 0x10, 0x05,
|
0x47, 0x54, 0x10, 0x03, 0x12, 0x06, 0x0a, 0x02, 0x47, 0x45, 0x10, 0x04, 0x12, 0x06, 0x0a, 0x02,
|
||||||
0x12, 0x06, 0x0a, 0x02, 0x4c, 0x45, 0x10, 0x06, 0x12, 0x06, 0x0a, 0x02, 0x4f, 0x52, 0x10, 0x07,
|
0x4c, 0x54, 0x10, 0x05, 0x12, 0x06, 0x0a, 0x02, 0x4c, 0x45, 0x10, 0x06, 0x12, 0x06, 0x0a, 0x02,
|
||||||
0x12, 0x07, 0x0a, 0x03, 0x41, 0x4e, 0x44, 0x10, 0x08, 0x2a, 0x38, 0x0a, 0x06, 0x43, 0x6c, 0x61,
|
0x4f, 0x52, 0x10, 0x07, 0x12, 0x07, 0x0a, 0x03, 0x41, 0x4e, 0x44, 0x10, 0x08, 0x2a, 0x38, 0x0a,
|
||||||
0x75, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x12, 0x43, 0x4c, 0x41, 0x55, 0x53, 0x45, 0x5f, 0x55, 0x4e,
|
0x06, 0x43, 0x6c, 0x61, 0x75, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x12, 0x43, 0x4c, 0x41, 0x55, 0x53,
|
||||||
0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x53,
|
0x45, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12,
|
||||||
0x41, 0x4d, 0x45, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x44, 0x49, 0x53, 0x54, 0x49, 0x4e, 0x43,
|
0x08, 0x0a, 0x04, 0x53, 0x41, 0x4d, 0x45, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x44, 0x49, 0x53,
|
||||||
0x54, 0x10, 0x02, 0x42, 0x56, 0x5a, 0x37, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f,
|
0x54, 0x49, 0x4e, 0x43, 0x54, 0x10, 0x02, 0x42, 0x56, 0x5a, 0x37, 0x67, 0x69, 0x74, 0x68, 0x75,
|
||||||
0x6d, 0x2f, 0x6e, 0x73, 0x70, 0x63, 0x63, 0x2d, 0x64, 0x65, 0x76, 0x2f, 0x6e, 0x65, 0x6f, 0x66,
|
0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6e, 0x73, 0x70, 0x63, 0x63, 0x2d, 0x64, 0x65, 0x76, 0x2f,
|
||||||
0x73, 0x2d, 0x61, 0x70, 0x69, 0x2d, 0x67, 0x6f, 0x2f, 0x76, 0x32, 0x2f, 0x6e, 0x65, 0x74, 0x6d,
|
0x6e, 0x65, 0x6f, 0x66, 0x73, 0x2d, 0x61, 0x70, 0x69, 0x2d, 0x67, 0x6f, 0x2f, 0x76, 0x32, 0x2f,
|
||||||
0x61, 0x70, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x3b, 0x6e, 0x65, 0x74, 0x6d, 0x61, 0x70, 0xaa, 0x02,
|
0x6e, 0x65, 0x74, 0x6d, 0x61, 0x70, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x3b, 0x6e, 0x65, 0x74, 0x6d,
|
||||||
0x1a, 0x4e, 0x65, 0x6f, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65,
|
0x61, 0x70, 0xaa, 0x02, 0x1a, 0x4e, 0x65, 0x6f, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x53, 0x74, 0x6f,
|
||||||
0x2e, 0x41, 0x50, 0x49, 0x2e, 0x4e, 0x65, 0x74, 0x6d, 0x61, 0x70, 0x62, 0x06, 0x70, 0x72, 0x6f,
|
0x72, 0x61, 0x67, 0x65, 0x2e, 0x41, 0x50, 0x49, 0x2e, 0x4e, 0x65, 0x74, 0x6d, 0x61, 0x70, 0x62,
|
||||||
0x74, 0x6f, 0x33,
|
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -367,7 +367,7 @@ func (ni *NodeInfo) StableMarshal(buf []byte) ([]byte, error) {
|
||||||
|
|
||||||
offset += n
|
offset += n
|
||||||
|
|
||||||
n, err = protoutil.StringMarshal(addressNodeInfoField, buf[offset:], ni.address)
|
n, err = protoutil.RepeatedStringMarshal(addressNodeInfoField, buf[offset:], ni.addresses)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -397,7 +397,8 @@ func (ni *NodeInfo) StableSize() (size int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
size += protoutil.BytesSize(keyNodeInfoField, ni.publicKey)
|
size += protoutil.BytesSize(keyNodeInfoField, ni.publicKey)
|
||||||
size += protoutil.StringSize(addressNodeInfoField, ni.address)
|
size += protoutil.RepeatedStringSize(addressNodeInfoField, ni.addresses)
|
||||||
|
|
||||||
for i := range ni.attributes {
|
for i := range ni.attributes {
|
||||||
size += protoutil.NestedStructureSize(attributesNodeInfoField, ni.attributes[i])
|
size += protoutil.NestedStructureSize(attributesNodeInfoField, ni.attributes[i])
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,7 +135,7 @@ func GenerateNodeInfo(empty bool) *netmap.NodeInfo {
|
||||||
m := new(netmap.NodeInfo)
|
m := new(netmap.NodeInfo)
|
||||||
|
|
||||||
if !empty {
|
if !empty {
|
||||||
m.SetAddress("node address")
|
m.SetAddresses("node address", "node address 2")
|
||||||
m.SetPublicKey([]byte{1, 2, 3})
|
m.SetPublicKey([]byte{1, 2, 3})
|
||||||
m.SetState(33)
|
m.SetState(33)
|
||||||
m.SetAttributes(GenerateAttributes(empty))
|
m.SetAttributes(GenerateAttributes(empty))
|
||||||
|
|
|
@ -71,7 +71,7 @@ type Attribute struct {
|
||||||
// NodeInfo of storage node.
|
// NodeInfo of storage node.
|
||||||
type NodeInfo struct {
|
type NodeInfo struct {
|
||||||
publicKey []byte
|
publicKey []byte
|
||||||
address string
|
addresses []string
|
||||||
attributes []*Attribute
|
attributes []*Attribute
|
||||||
state NodeState
|
state NodeState
|
||||||
}
|
}
|
||||||
|
@ -386,17 +386,52 @@ func (ni *NodeInfo) SetPublicKey(v []byte) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ni *NodeInfo) GetAddress() string {
|
// GetAddress returns node's network address.
|
||||||
if ni != nil {
|
//
|
||||||
return ni.address
|
// Deprecated: use IterateAddresses.
|
||||||
}
|
func (ni *NodeInfo) GetAddress() (addr string) {
|
||||||
|
ni.IterateAddresses(func(s string) bool {
|
||||||
return ""
|
addr = s
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetAddress sets node's network address.
|
||||||
|
//
|
||||||
|
// Deprecated: use SetAddresses.
|
||||||
func (ni *NodeInfo) SetAddress(v string) {
|
func (ni *NodeInfo) SetAddress(v string) {
|
||||||
|
ni.SetAddresses(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAddresses sets list of network addresses of the node.
|
||||||
|
func (ni *NodeInfo) SetAddresses(v ...string) {
|
||||||
if ni != nil {
|
if ni != nil {
|
||||||
ni.address = v
|
ni.addresses = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NumberOfAddresses returns number of network addresses of the node.
|
||||||
|
func (ni *NodeInfo) NumberOfAddresses() int {
|
||||||
|
if ni != nil {
|
||||||
|
return len(ni.addresses)
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// IterateAddresses iterates over network addresses of the node.
|
||||||
|
// Breaks iteration on f's true return.
|
||||||
|
//
|
||||||
|
// Handler should not be nil.
|
||||||
|
func (ni *NodeInfo) IterateAddresses(f func(string) bool) {
|
||||||
|
if ni != nil {
|
||||||
|
for i := range ni.addresses {
|
||||||
|
if f(ni.addresses[i]) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue