diff --git a/pkg/netmap/network_info.go b/pkg/netmap/network_info.go index 609c9cce..e8a8a94e 100644 --- a/pkg/netmap/network_info.go +++ b/pkg/netmap/network_info.go @@ -19,7 +19,9 @@ func NewNetworkInfoFromV2(iV2 *netmap.NetworkInfo) *NetworkInfo { // // Defaults: // - curEpoch: 0; -// - magicNum: 0. +// - magicNum: 0; +// - msPerBlock: 0; +// - network config: nil. func NewNetworkInfo() *NetworkInfo { return NewNetworkInfoFromV2(new(netmap.NetworkInfo)) } @@ -55,6 +57,32 @@ func (i *NetworkInfo) SetMagicNumber(epoch uint64) { SetMagicNumber(epoch) } +// MsPerBlock returns MillisecondsPerBlock network parameter. +func (i *NetworkInfo) MsPerBlock() int64 { + return (*netmap.NetworkInfo)(i). + GetMsPerBlock() +} + +// SetMsPerBlock sets MillisecondsPerBlock network parameter. +func (i *NetworkInfo) SetMsPerBlock(v int64) { + (*netmap.NetworkInfo)(i). + SetMsPerBlock(v) +} + +// NetworkConfig returns NeoFS network configuration. +func (i *NetworkInfo) NetworkConfig() *NetworkConfig { + return NewNetworkConfigFromV2( + (*netmap.NetworkInfo)(i). + GetNetworkConfig(), + ) +} + +// SetNetworkConfig sets NeoFS network configuration. +func (i *NetworkInfo) SetNetworkConfig(v *NetworkConfig) { + (*netmap.NetworkInfo)(i). + SetNetworkConfig(v.ToV2()) +} + // Marshal marshals NetworkInfo into a protobuf binary form. // // Buffer is allocated when the argument is empty. @@ -86,3 +114,112 @@ func (i *NetworkInfo) UnmarshalJSON(data []byte) error { return (*netmap.NetworkInfo)(i). UnmarshalJSON(data) } + +// NetworkParameter represents v2-compatible NeoFS network parameter. +type NetworkParameter netmap.NetworkParameter + +// NewNetworkParameterFromV2 wraps v2 NetworkParameter message to NetworkParameter. +// +// Nil netmap.NetworkParameter converts to nil. +func NewNetworkParameterFromV2(pv2 *netmap.NetworkParameter) *NetworkParameter { + return (*NetworkParameter)(pv2) +} + +// NewNetworkParameter creates and initializes blank NetworkParameter. +// +// Defaults: +// - key: nil; +// - value: nil. +func NewNetworkParameter() *NetworkParameter { + return NewNetworkParameterFromV2(new(netmap.NetworkParameter)) +} + +// ToV2 converts NetworkParameter to v2 NetworkParameter. +// +// Nil NetworkParameter converts to nil. +func (x *NetworkParameter) ToV2() *netmap.NetworkParameter { + return (*netmap.NetworkParameter)(x) +} + +// Key returns key to network parameter. +func (x *NetworkParameter) Key() []byte { + return (*netmap.NetworkParameter)(x). + GetKey() +} + +// SetKey sets key to the network parameter. +func (x *NetworkParameter) SetKey(key []byte) { + (*netmap.NetworkParameter)(x). + SetKey(key) +} + +// Value returns value of the network parameter. +func (x *NetworkParameter) Value() []byte { + return (*netmap.NetworkParameter)(x). + GetValue() +} + +// SetValue sets value of the network parameter. +func (x *NetworkParameter) SetValue(val []byte) { + (*netmap.NetworkParameter)(x). + SetValue(val) +} + +// NetworkConfig represents v2-compatible NeoFS network configuration. +type NetworkConfig netmap.NetworkConfig + +// NewNetworkConfigFromV2 wraps v2 NetworkConfig message to NetworkConfig. +// +// Nil netmap.NetworkConfig converts to nil. +func NewNetworkConfigFromV2(cv2 *netmap.NetworkConfig) *NetworkConfig { + return (*NetworkConfig)(cv2) +} + +// NewNetworkConfig creates and initializes blank NetworkConfig. +// +// Defaults: +// - parameters num: 0. +func NewNetworkConfig() *NetworkConfig { + return NewNetworkConfigFromV2(new(netmap.NetworkConfig)) +} + +// ToV2 converts NetworkConfig to v2 NetworkConfig. +// +// Nil NetworkConfig converts to nil. +func (x *NetworkConfig) ToV2() *netmap.NetworkConfig { + return (*netmap.NetworkConfig)(x) +} + +// NumberOfParameters returns number of network parameters. +func (x *NetworkConfig) NumberOfParameters() int { + return (*netmap.NetworkConfig)(x).NumberOfParameters() +} + +// IterateAddresses iterates over network parameters. +// Breaks iteration on f's true return. +// +// Handler should not be nil. +func (x *NetworkConfig) IterateParameters(f func(*NetworkParameter) bool) { + (*netmap.NetworkConfig)(x). + IterateParameters(func(p *netmap.NetworkParameter) bool { + return f(NewNetworkParameterFromV2(p)) + }) +} + +// Value returns value of the network parameter. +func (x *NetworkConfig) SetParameters(ps ...*NetworkParameter) { + var psV2 []*netmap.NetworkParameter + + if ps != nil { + ln := len(ps) + + psV2 = make([]*netmap.NetworkParameter, 0, ln) + + for i := 0; i < ln; i++ { + psV2 = append(psV2, ps[i].ToV2()) + } + } + + (*netmap.NetworkConfig)(x). + SetParameters(psV2...) +} diff --git a/pkg/netmap/network_info_test.go b/pkg/netmap/network_info_test.go index c5d9461b..c36b614d 100644 --- a/pkg/netmap/network_info_test.go +++ b/pkg/netmap/network_info_test.go @@ -1,11 +1,124 @@ -package netmap +package netmap_test import ( "testing" + . "github.com/nspcc-dev/neofs-api-go/pkg/netmap" + netmaptest "github.com/nspcc-dev/neofs-api-go/pkg/netmap/test" "github.com/stretchr/testify/require" ) +func TestNetworkParameter_Key(t *testing.T) { + i := NewNetworkParameter() + + k := []byte("key") + + i.SetKey(k) + + require.Equal(t, k, i.Key()) + require.Equal(t, k, i.ToV2().GetKey()) +} + +func TestNetworkParameter_Value(t *testing.T) { + i := NewNetworkParameter() + + v := []byte("value") + + i.SetValue(v) + + require.Equal(t, v, i.Value()) + require.Equal(t, v, i.ToV2().GetValue()) +} + +func TestNewNetworkParameterFromV2(t *testing.T) { + t.Run("nil", func(t *testing.T) { + require.Nil(t, NewNetworkParameterFromV2(nil)) + }) +} + +func TestNetworkParameter_ToV2(t *testing.T) { + t.Run("nil", func(t *testing.T) { + var x *NetworkParameter + + require.Nil(t, x.ToV2()) + }) +} + +func TestNewNetworkParameter(t *testing.T) { + x := NewNetworkParameter() + + // check initial values + require.Nil(t, x.Key()) + require.Nil(t, x.Value()) + + // convert to v2 message + xV2 := x.ToV2() + + require.Nil(t, xV2.GetKey()) + require.Nil(t, xV2.GetValue()) +} + +func TestNetworkConfig_SetParameters(t *testing.T) { + x := NewNetworkConfig() + + require.Zero(t, x.NumberOfParameters()) + + called := 0 + + x.IterateParameters(func(p *NetworkParameter) bool { + called++ + return false + }) + + require.Zero(t, called) + + pps := []*NetworkParameter{ + netmaptest.NetworkParameter(), + netmaptest.NetworkParameter(), + } + + x.SetParameters(pps...) + + require.EqualValues(t, len(pps), x.NumberOfParameters()) + + var dst []*NetworkParameter + + x.IterateParameters(func(p *NetworkParameter) bool { + dst = append(dst, p) + called++ + return false + }) + + require.Equal(t, pps, dst) + require.Equal(t, len(pps), called) +} + +func TestNewNetworkConfigFromV2(t *testing.T) { + t.Run("nil", func(t *testing.T) { + require.Nil(t, NewNetworkConfigFromV2(nil)) + }) +} + +func TestNetworkConfig_ToV2(t *testing.T) { + t.Run("nil", func(t *testing.T) { + + var x *NetworkConfig + require.Nil(t, x.ToV2()) + }) +} + +func TestNewNetworkConfig(t *testing.T) { + x := NewNetworkConfig() + + // check initial values + require.Zero(t, x.NumberOfParameters()) + + // convert to v2 message + xV2 := x.ToV2() + + require.Zero(t, xV2.NumberOfParameters()) +} + func TestNetworkInfo_CurrentEpoch(t *testing.T) { i := NewNetworkInfo() e := uint64(13) @@ -26,10 +139,29 @@ func TestNetworkInfo_MagicNumber(t *testing.T) { require.Equal(t, m, i.ToV2().GetMagicNumber()) } -func TestNetworkInfoEncoding(t *testing.T) { +func TestNetworkInfo_MsPerBlock(t *testing.T) { i := NewNetworkInfo() - i.SetCurrentEpoch(13) - i.SetMagicNumber(666) + + const ms = 987 + + i.SetMsPerBlock(ms) + + require.EqualValues(t, ms, i.MsPerBlock()) + require.EqualValues(t, ms, i.ToV2().GetMsPerBlock()) +} + +func TestNetworkInfo_Config(t *testing.T) { + i := NewNetworkInfo() + + c := netmaptest.NetworkConfig() + + i.SetNetworkConfig(c) + + require.Equal(t, c, i.NetworkConfig()) +} + +func TestNetworkInfoEncoding(t *testing.T) { + i := netmaptest.NetworkInfo() t.Run("binary", func(t *testing.T) { data, err := i.Marshal() @@ -72,10 +204,12 @@ func TestNewNetworkInfo(t *testing.T) { // check initial values require.Zero(t, ni.CurrentEpoch()) require.Zero(t, ni.MagicNumber()) + require.Zero(t, ni.MsPerBlock()) // convert to v2 message niV2 := ni.ToV2() require.Zero(t, niV2.GetCurrentEpoch()) require.Zero(t, niV2.GetMagicNumber()) + require.Zero(t, niV2.GetMsPerBlock()) } diff --git a/pkg/netmap/test/generate.go b/pkg/netmap/test/generate.go index a2a1394a..d8d431d6 100644 --- a/pkg/netmap/test/generate.go +++ b/pkg/netmap/test/generate.go @@ -59,12 +59,36 @@ func PlacementPolicy() *netmap.PlacementPolicy { return x } +// NetworkParameter returns random netmap.NetworkParameter. +func NetworkParameter() *netmap.NetworkParameter { + x := netmap.NewNetworkParameter() + + x.SetKey([]byte("key")) + x.SetValue([]byte("value")) + + return x +} + +// NetworkConfig returns random netmap.NetworkConfig. +func NetworkConfig() *netmap.NetworkConfig { + x := netmap.NewNetworkConfig() + + x.SetParameters( + NetworkParameter(), + NetworkParameter(), + ) + + return x +} + // NetworkInfo returns random netmap.NetworkInfo. func NetworkInfo() *netmap.NetworkInfo { x := netmap.NewNetworkInfo() x.SetCurrentEpoch(21) x.SetMagicNumber(32) + x.SetMsPerBlock(43) + x.SetNetworkConfig(NetworkConfig()) return x } diff --git a/pkg/version.go b/pkg/version.go index 85066ebf..c720af50 100644 --- a/pkg/version.go +++ b/pkg/version.go @@ -9,7 +9,7 @@ import ( // Version represents v2-compatible version. type Version refs.Version -const sdkMjr, sdkMnr = 2, 9 +const sdkMjr, sdkMnr = 2, 10 // NewVersionFromV2 wraps v2 Version message to Version. // diff --git a/v2/netmap/convert.go b/v2/netmap/convert.go index 06bddbf1..59c5e60b 100644 --- a/v2/netmap/convert.go +++ b/v2/netmap/convert.go @@ -514,6 +514,89 @@ func (l *LocalNodeInfoResponse) FromGRPCMessage(m grpc.Message) error { return l.ResponseHeaders.FromMessage(v) } +func (x *NetworkParameter) ToGRPCMessage() grpc.Message { + var m *netmap.NetworkConfig_Parameter + + if x != nil { + m = new(netmap.NetworkConfig_Parameter) + + m.SetKey(x.k) + m.SetValue(x.v) + } + + return m +} + +func (x *NetworkParameter) FromGRPCMessage(m grpc.Message) error { + v, ok := m.(*netmap.NetworkConfig_Parameter) + if !ok { + return message.NewUnexpectedMessageType(m, v) + } + + x.k = v.GetKey() + x.v = v.GetValue() + + return nil +} + +func (x *NetworkConfig) ToGRPCMessage() grpc.Message { + var m *netmap.NetworkConfig + + if x != nil { + m = new(netmap.NetworkConfig) + + var ps []*netmap.NetworkConfig_Parameter + + if ln := len(x.ps); ln > 0 { + ps = make([]*netmap.NetworkConfig_Parameter, 0, ln) + + for i := 0; i < ln; i++ { + ps = append(ps, x.ps[i].ToGRPCMessage().(*netmap.NetworkConfig_Parameter)) + } + } + + m.SetParameters(ps) + } + + return m +} + +func (x *NetworkConfig) FromGRPCMessage(m grpc.Message) error { + v, ok := m.(*netmap.NetworkConfig) + if !ok { + return message.NewUnexpectedMessageType(m, v) + } + + var ( + ps []*NetworkParameter + psV2 = v.GetParameters() + ) + + if psV2 != nil { + ln := len(psV2) + + ps = make([]*NetworkParameter, 0, ln) + + for i := 0; i < ln; i++ { + var p *NetworkParameter + + if psV2[i] != nil { + p = new(NetworkParameter) + + if err := p.FromGRPCMessage(psV2[i]); err != nil { + return err + } + } + + ps = append(ps, p) + } + } + + x.ps = ps + + return nil +} + func (i *NetworkInfo) ToGRPCMessage() grpc.Message { var m *netmap.NetworkInfo @@ -522,6 +605,8 @@ func (i *NetworkInfo) ToGRPCMessage() grpc.Message { m.SetMagicNumber(i.magicNum) m.SetCurrentEpoch(i.curEpoch) + m.SetMsPerBlock(i.msPerBlock) + m.SetNetworkConfig(i.netCfg.ToGRPCMessage().(*netmap.NetworkConfig)) } return m @@ -533,8 +618,25 @@ func (i *NetworkInfo) FromGRPCMessage(m grpc.Message) error { return message.NewUnexpectedMessageType(m, v) } + var err error + + netCfg := v.GetNetworkConfig() + if netCfg == nil { + i.netCfg = nil + } else { + if i.netCfg == nil { + i.netCfg = new(NetworkConfig) + } + + err = i.netCfg.FromGRPCMessage(netCfg) + if err != nil { + return err + } + } + i.magicNum = v.GetMagicNumber() i.curEpoch = v.GetCurrentEpoch() + i.msPerBlock = v.GetMsPerBlock() return nil } diff --git a/v2/netmap/grpc/types.go b/v2/netmap/grpc/types.go index 9ba148e5..e8dc6876 100644 --- a/v2/netmap/grpc/types.go +++ b/v2/netmap/grpc/types.go @@ -182,6 +182,20 @@ func (x *NetworkInfo) SetMagicNumber(v uint64) { } } +// SetMsPerBlock sets MillisecondsPerBlock network parameter. +func (x *NetworkInfo) SetMsPerBlock(v int64) { + if x != nil { + x.MsPerBlock = v + } +} + +// SetNetworkConfig sets NeoFS network configuration. +func (x *NetworkInfo) SetNetworkConfig(v *NetworkConfig) { + if x != nil { + x.NetworkConfig = v + } +} + // FromString parses Clause from a string representation, // It is a reverse action to String(). // @@ -220,3 +234,24 @@ func (x *NodeInfo_State) FromString(s string) bool { return ok } + +// SetKey sets parameter key. +func (x *NetworkConfig_Parameter) SetKey(v []byte) { + if x != nil { + x.Key = v + } +} + +// SetValue sets parameter value. +func (x *NetworkConfig_Parameter) SetValue(v []byte) { + if x != nil { + x.Value = v + } +} + +// SetParameters sets NeoFS network parameters. +func (x *NetworkConfig) SetParameters(v []*NetworkConfig_Parameter) { + if x != nil { + x.Parameters = v + } +} diff --git a/v2/netmap/grpc/types.pb.go b/v2/netmap/grpc/types.pb.go index 5b2fb516..3c640d06 100644 --- a/v2/netmap/grpc/types.pb.go +++ b/v2/netmap/grpc/types.pb.go @@ -605,6 +605,55 @@ func (x *NodeInfo) GetState() NodeInfo_State { return NodeInfo_UNSPECIFIED } +// NeoFS network configuration +type NetworkConfig struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // List of parameter values. + Parameters []*NetworkConfig_Parameter `protobuf:"bytes,1,rep,name=parameters,proto3" json:"parameters,omitempty"` +} + +func (x *NetworkConfig) Reset() { + *x = NetworkConfig{} + if protoimpl.UnsafeEnabled { + mi := &file_v2_netmap_grpc_types_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *NetworkConfig) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*NetworkConfig) ProtoMessage() {} + +func (x *NetworkConfig) ProtoReflect() protoreflect.Message { + mi := &file_v2_netmap_grpc_types_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use NetworkConfig.ProtoReflect.Descriptor instead. +func (*NetworkConfig) Descriptor() ([]byte, []int) { + return file_v2_netmap_grpc_types_proto_rawDescGZIP(), []int{5} +} + +func (x *NetworkConfig) GetParameters() []*NetworkConfig_Parameter { + if x != nil { + return x.Parameters + } + return nil +} + // Information about NeoFS network type NetworkInfo struct { state protoimpl.MessageState @@ -615,12 +664,16 @@ type NetworkInfo struct { CurrentEpoch uint64 `protobuf:"varint,1,opt,name=current_epoch,json=currentEpoch,proto3" json:"current_epoch,omitempty"` // Magic number of the sidechain of the NeoFS network. MagicNumber uint64 `protobuf:"varint,2,opt,name=magic_number,json=magicNumber,proto3" json:"magic_number,omitempty"` + // MillisecondsPerBlock network parameter of the sidechain of the NeoFS network. + MsPerBlock int64 `protobuf:"varint,3,opt,name=ms_per_block,json=msPerBlock,proto3" json:"ms_per_block,omitempty"` + // NeoFS network configuration. + NetworkConfig *NetworkConfig `protobuf:"bytes,4,opt,name=network_config,json=networkConfig,proto3" json:"network_config,omitempty"` } func (x *NetworkInfo) Reset() { *x = NetworkInfo{} if protoimpl.UnsafeEnabled { - mi := &file_v2_netmap_grpc_types_proto_msgTypes[5] + mi := &file_v2_netmap_grpc_types_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -633,7 +686,7 @@ func (x *NetworkInfo) String() string { func (*NetworkInfo) ProtoMessage() {} func (x *NetworkInfo) ProtoReflect() protoreflect.Message { - mi := &file_v2_netmap_grpc_types_proto_msgTypes[5] + mi := &file_v2_netmap_grpc_types_proto_msgTypes[6] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -646,7 +699,7 @@ func (x *NetworkInfo) ProtoReflect() protoreflect.Message { // Deprecated: Use NetworkInfo.ProtoReflect.Descriptor instead. func (*NetworkInfo) Descriptor() ([]byte, []int) { - return file_v2_netmap_grpc_types_proto_rawDescGZIP(), []int{5} + return file_v2_netmap_grpc_types_proto_rawDescGZIP(), []int{6} } func (x *NetworkInfo) GetCurrentEpoch() uint64 { @@ -663,6 +716,20 @@ func (x *NetworkInfo) GetMagicNumber() uint64 { return 0 } +func (x *NetworkInfo) GetMsPerBlock() int64 { + if x != nil { + return x.MsPerBlock + } + return 0 +} + +func (x *NetworkInfo) GetNetworkConfig() *NetworkConfig { + if x != nil { + return x.NetworkConfig + } + return nil +} + // Administrator-defined Attributes of the NeoFS Storage Node. // // `Attribute` is a Key-Value metadata pair. Key name must be a valid UTF-8 @@ -746,7 +813,7 @@ type NodeInfo_Attribute struct { func (x *NodeInfo_Attribute) Reset() { *x = NodeInfo_Attribute{} if protoimpl.UnsafeEnabled { - mi := &file_v2_netmap_grpc_types_proto_msgTypes[6] + mi := &file_v2_netmap_grpc_types_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -759,7 +826,7 @@ func (x *NodeInfo_Attribute) String() string { func (*NodeInfo_Attribute) ProtoMessage() {} func (x *NodeInfo_Attribute) ProtoReflect() protoreflect.Message { - mi := &file_v2_netmap_grpc_types_proto_msgTypes[6] + mi := &file_v2_netmap_grpc_types_proto_msgTypes[7] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -796,6 +863,64 @@ func (x *NodeInfo_Attribute) GetParents() []string { return nil } +// Single configuration parameter. +type NetworkConfig_Parameter struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Parameter key. UTF-8 encoded string. + Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + // Parameter value. + Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` +} + +func (x *NetworkConfig_Parameter) Reset() { + *x = NetworkConfig_Parameter{} + if protoimpl.UnsafeEnabled { + mi := &file_v2_netmap_grpc_types_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *NetworkConfig_Parameter) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*NetworkConfig_Parameter) ProtoMessage() {} + +func (x *NetworkConfig_Parameter) ProtoReflect() protoreflect.Message { + mi := &file_v2_netmap_grpc_types_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use NetworkConfig_Parameter.ProtoReflect.Descriptor instead. +func (*NetworkConfig_Parameter) Descriptor() ([]byte, []int) { + return file_v2_netmap_grpc_types_proto_rawDescGZIP(), []int{5, 0} +} + +func (x *NetworkConfig_Parameter) GetKey() []byte { + if x != nil { + return x.Key + } + return nil +} + +func (x *NetworkConfig_Parameter) GetValue() []byte { + if x != nil { + return x.Value + } + return nil +} + var File_v2_netmap_grpc_types_proto protoreflect.FileDescriptor var file_v2_netmap_grpc_types_proto_rawDesc = []byte{ @@ -861,29 +986,45 @@ var file_v2_netmap_grpc_types_proto_rawDesc = []byte{ 0x09, 0x52, 0x07, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x31, 0x0a, 0x05, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x0f, 0x0a, 0x0b, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x4f, 0x4e, 0x4c, 0x49, 0x4e, 0x45, 0x10, 0x01, - 0x12, 0x0b, 0x0a, 0x07, 0x4f, 0x46, 0x46, 0x4c, 0x49, 0x4e, 0x45, 0x10, 0x02, 0x22, 0x55, 0x0a, - 0x0b, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x23, 0x0a, 0x0d, - 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x04, 0x52, 0x0c, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x45, 0x70, 0x6f, 0x63, - 0x68, 0x12, 0x21, 0x0a, 0x0c, 0x6d, 0x61, 0x67, 0x69, 0x63, 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65, - 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x6d, 0x61, 0x67, 0x69, 0x63, 0x4e, 0x75, - 0x6d, 0x62, 0x65, 0x72, 0x2a, 0x67, 0x0a, 0x09, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x12, 0x19, 0x0a, 0x15, 0x4f, 0x50, 0x45, 0x52, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x55, - 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x06, 0x0a, 0x02, - 0x45, 0x51, 0x10, 0x01, 0x12, 0x06, 0x0a, 0x02, 0x4e, 0x45, 0x10, 0x02, 0x12, 0x06, 0x0a, 0x02, - 0x47, 0x54, 0x10, 0x03, 0x12, 0x06, 0x0a, 0x02, 0x47, 0x45, 0x10, 0x04, 0x12, 0x06, 0x0a, 0x02, - 0x4c, 0x54, 0x10, 0x05, 0x12, 0x06, 0x0a, 0x02, 0x4c, 0x45, 0x10, 0x06, 0x12, 0x06, 0x0a, 0x02, - 0x4f, 0x52, 0x10, 0x07, 0x12, 0x07, 0x0a, 0x03, 0x41, 0x4e, 0x44, 0x10, 0x08, 0x2a, 0x38, 0x0a, - 0x06, 0x43, 0x6c, 0x61, 0x75, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x12, 0x43, 0x4c, 0x41, 0x55, 0x53, - 0x45, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, - 0x08, 0x0a, 0x04, 0x53, 0x41, 0x4d, 0x45, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x44, 0x49, 0x53, - 0x54, 0x49, 0x4e, 0x43, 0x54, 0x10, 0x02, 0x42, 0x56, 0x5a, 0x37, 0x67, 0x69, 0x74, 0x68, 0x75, - 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6e, 0x73, 0x70, 0x63, 0x63, 0x2d, 0x64, 0x65, 0x76, 0x2f, - 0x6e, 0x65, 0x6f, 0x66, 0x73, 0x2d, 0x61, 0x70, 0x69, 0x2d, 0x67, 0x6f, 0x2f, 0x76, 0x32, 0x2f, - 0x6e, 0x65, 0x74, 0x6d, 0x61, 0x70, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x3b, 0x6e, 0x65, 0x74, 0x6d, - 0x61, 0x70, 0xaa, 0x02, 0x1a, 0x4e, 0x65, 0x6f, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x53, 0x74, 0x6f, - 0x72, 0x61, 0x67, 0x65, 0x2e, 0x41, 0x50, 0x49, 0x2e, 0x4e, 0x65, 0x74, 0x6d, 0x61, 0x70, 0x62, - 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x12, 0x0b, 0x0a, 0x07, 0x4f, 0x46, 0x46, 0x4c, 0x49, 0x4e, 0x45, 0x10, 0x02, 0x22, 0x8f, 0x01, + 0x0a, 0x0d, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, + 0x49, 0x0a, 0x0a, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x6e, 0x65, 0x6f, 0x2e, 0x66, 0x73, 0x2e, 0x76, 0x32, 0x2e, + 0x6e, 0x65, 0x74, 0x6d, 0x61, 0x70, 0x2e, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x43, 0x6f, + 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x52, 0x0a, + 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x73, 0x1a, 0x33, 0x0a, 0x09, 0x50, 0x61, + 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, + 0xbf, 0x01, 0x0a, 0x0b, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x49, 0x6e, 0x66, 0x6f, 0x12, + 0x23, 0x0a, 0x0d, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x65, 0x70, 0x6f, 0x63, 0x68, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0c, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x45, + 0x70, 0x6f, 0x63, 0x68, 0x12, 0x21, 0x0a, 0x0c, 0x6d, 0x61, 0x67, 0x69, 0x63, 0x5f, 0x6e, 0x75, + 0x6d, 0x62, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x6d, 0x61, 0x67, 0x69, + 0x63, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x20, 0x0a, 0x0c, 0x6d, 0x73, 0x5f, 0x70, 0x65, + 0x72, 0x5f, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x6d, + 0x73, 0x50, 0x65, 0x72, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x12, 0x46, 0x0a, 0x0e, 0x6e, 0x65, 0x74, + 0x77, 0x6f, 0x72, 0x6b, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x18, 0x04, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x1f, 0x2e, 0x6e, 0x65, 0x6f, 0x2e, 0x66, 0x73, 0x2e, 0x76, 0x32, 0x2e, 0x6e, 0x65, + 0x74, 0x6d, 0x61, 0x70, 0x2e, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x43, 0x6f, 0x6e, 0x66, + 0x69, 0x67, 0x52, 0x0d, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x43, 0x6f, 0x6e, 0x66, 0x69, + 0x67, 0x2a, 0x67, 0x0a, 0x09, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x19, + 0x0a, 0x15, 0x4f, 0x50, 0x45, 0x52, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x55, 0x4e, 0x53, 0x50, + 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x06, 0x0a, 0x02, 0x45, 0x51, 0x10, + 0x01, 0x12, 0x06, 0x0a, 0x02, 0x4e, 0x45, 0x10, 0x02, 0x12, 0x06, 0x0a, 0x02, 0x47, 0x54, 0x10, + 0x03, 0x12, 0x06, 0x0a, 0x02, 0x47, 0x45, 0x10, 0x04, 0x12, 0x06, 0x0a, 0x02, 0x4c, 0x54, 0x10, + 0x05, 0x12, 0x06, 0x0a, 0x02, 0x4c, 0x45, 0x10, 0x06, 0x12, 0x06, 0x0a, 0x02, 0x4f, 0x52, 0x10, + 0x07, 0x12, 0x07, 0x0a, 0x03, 0x41, 0x4e, 0x44, 0x10, 0x08, 0x2a, 0x38, 0x0a, 0x06, 0x43, 0x6c, + 0x61, 0x75, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x12, 0x43, 0x4c, 0x41, 0x55, 0x53, 0x45, 0x5f, 0x55, + 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, + 0x53, 0x41, 0x4d, 0x45, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x44, 0x49, 0x53, 0x54, 0x49, 0x4e, + 0x43, 0x54, 0x10, 0x02, 0x42, 0x56, 0x5a, 0x37, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, + 0x6f, 0x6d, 0x2f, 0x6e, 0x73, 0x70, 0x63, 0x63, 0x2d, 0x64, 0x65, 0x76, 0x2f, 0x6e, 0x65, 0x6f, + 0x66, 0x73, 0x2d, 0x61, 0x70, 0x69, 0x2d, 0x67, 0x6f, 0x2f, 0x76, 0x32, 0x2f, 0x6e, 0x65, 0x74, + 0x6d, 0x61, 0x70, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x3b, 0x6e, 0x65, 0x74, 0x6d, 0x61, 0x70, 0xaa, + 0x02, 0x1a, 0x4e, 0x65, 0x6f, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, + 0x65, 0x2e, 0x41, 0x50, 0x49, 0x2e, 0x4e, 0x65, 0x74, 0x6d, 0x61, 0x70, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -899,33 +1040,37 @@ func file_v2_netmap_grpc_types_proto_rawDescGZIP() []byte { } var file_v2_netmap_grpc_types_proto_enumTypes = make([]protoimpl.EnumInfo, 3) -var file_v2_netmap_grpc_types_proto_msgTypes = make([]protoimpl.MessageInfo, 7) +var file_v2_netmap_grpc_types_proto_msgTypes = make([]protoimpl.MessageInfo, 9) var file_v2_netmap_grpc_types_proto_goTypes = []interface{}{ - (Operation)(0), // 0: neo.fs.v2.netmap.Operation - (Clause)(0), // 1: neo.fs.v2.netmap.Clause - (NodeInfo_State)(0), // 2: neo.fs.v2.netmap.NodeInfo.State - (*Filter)(nil), // 3: neo.fs.v2.netmap.Filter - (*Selector)(nil), // 4: neo.fs.v2.netmap.Selector - (*Replica)(nil), // 5: neo.fs.v2.netmap.Replica - (*PlacementPolicy)(nil), // 6: neo.fs.v2.netmap.PlacementPolicy - (*NodeInfo)(nil), // 7: neo.fs.v2.netmap.NodeInfo - (*NetworkInfo)(nil), // 8: neo.fs.v2.netmap.NetworkInfo - (*NodeInfo_Attribute)(nil), // 9: neo.fs.v2.netmap.NodeInfo.Attribute + (Operation)(0), // 0: neo.fs.v2.netmap.Operation + (Clause)(0), // 1: neo.fs.v2.netmap.Clause + (NodeInfo_State)(0), // 2: neo.fs.v2.netmap.NodeInfo.State + (*Filter)(nil), // 3: neo.fs.v2.netmap.Filter + (*Selector)(nil), // 4: neo.fs.v2.netmap.Selector + (*Replica)(nil), // 5: neo.fs.v2.netmap.Replica + (*PlacementPolicy)(nil), // 6: neo.fs.v2.netmap.PlacementPolicy + (*NodeInfo)(nil), // 7: neo.fs.v2.netmap.NodeInfo + (*NetworkConfig)(nil), // 8: neo.fs.v2.netmap.NetworkConfig + (*NetworkInfo)(nil), // 9: neo.fs.v2.netmap.NetworkInfo + (*NodeInfo_Attribute)(nil), // 10: neo.fs.v2.netmap.NodeInfo.Attribute + (*NetworkConfig_Parameter)(nil), // 11: neo.fs.v2.netmap.NetworkConfig.Parameter } var file_v2_netmap_grpc_types_proto_depIdxs = []int32{ - 0, // 0: neo.fs.v2.netmap.Filter.op:type_name -> neo.fs.v2.netmap.Operation - 3, // 1: neo.fs.v2.netmap.Filter.filters:type_name -> neo.fs.v2.netmap.Filter - 1, // 2: neo.fs.v2.netmap.Selector.clause:type_name -> neo.fs.v2.netmap.Clause - 5, // 3: neo.fs.v2.netmap.PlacementPolicy.replicas:type_name -> neo.fs.v2.netmap.Replica - 4, // 4: neo.fs.v2.netmap.PlacementPolicy.selectors:type_name -> neo.fs.v2.netmap.Selector - 3, // 5: neo.fs.v2.netmap.PlacementPolicy.filters:type_name -> neo.fs.v2.netmap.Filter - 9, // 6: neo.fs.v2.netmap.NodeInfo.attributes:type_name -> neo.fs.v2.netmap.NodeInfo.Attribute - 2, // 7: neo.fs.v2.netmap.NodeInfo.state:type_name -> neo.fs.v2.netmap.NodeInfo.State - 8, // [8:8] is the sub-list for method output_type - 8, // [8:8] is the sub-list for method input_type - 8, // [8:8] is the sub-list for extension type_name - 8, // [8:8] is the sub-list for extension extendee - 0, // [0:8] is the sub-list for field type_name + 0, // 0: neo.fs.v2.netmap.Filter.op:type_name -> neo.fs.v2.netmap.Operation + 3, // 1: neo.fs.v2.netmap.Filter.filters:type_name -> neo.fs.v2.netmap.Filter + 1, // 2: neo.fs.v2.netmap.Selector.clause:type_name -> neo.fs.v2.netmap.Clause + 5, // 3: neo.fs.v2.netmap.PlacementPolicy.replicas:type_name -> neo.fs.v2.netmap.Replica + 4, // 4: neo.fs.v2.netmap.PlacementPolicy.selectors:type_name -> neo.fs.v2.netmap.Selector + 3, // 5: neo.fs.v2.netmap.PlacementPolicy.filters:type_name -> neo.fs.v2.netmap.Filter + 10, // 6: neo.fs.v2.netmap.NodeInfo.attributes:type_name -> neo.fs.v2.netmap.NodeInfo.Attribute + 2, // 7: neo.fs.v2.netmap.NodeInfo.state:type_name -> neo.fs.v2.netmap.NodeInfo.State + 11, // 8: neo.fs.v2.netmap.NetworkConfig.parameters:type_name -> neo.fs.v2.netmap.NetworkConfig.Parameter + 8, // 9: neo.fs.v2.netmap.NetworkInfo.network_config:type_name -> neo.fs.v2.netmap.NetworkConfig + 10, // [10:10] is the sub-list for method output_type + 10, // [10:10] is the sub-list for method input_type + 10, // [10:10] is the sub-list for extension type_name + 10, // [10:10] is the sub-list for extension extendee + 0, // [0:10] is the sub-list for field type_name } func init() { file_v2_netmap_grpc_types_proto_init() } @@ -995,7 +1140,7 @@ func file_v2_netmap_grpc_types_proto_init() { } } file_v2_netmap_grpc_types_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*NetworkInfo); i { + switch v := v.(*NetworkConfig); i { case 0: return &v.state case 1: @@ -1007,6 +1152,18 @@ func file_v2_netmap_grpc_types_proto_init() { } } file_v2_netmap_grpc_types_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*NetworkInfo); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_v2_netmap_grpc_types_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*NodeInfo_Attribute); i { case 0: return &v.state @@ -1018,6 +1175,18 @@ func file_v2_netmap_grpc_types_proto_init() { return nil } } + file_v2_netmap_grpc_types_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*NetworkConfig_Parameter); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -1025,7 +1194,7 @@ func file_v2_netmap_grpc_types_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_v2_netmap_grpc_types_proto_rawDesc, NumEnums: 3, - NumMessages: 7, + NumMessages: 9, NumExtensions: 0, NumServices: 0, }, diff --git a/v2/netmap/marshal.go b/v2/netmap/marshal.go index abdc7dff..4f818e54 100644 --- a/v2/netmap/marshal.go +++ b/v2/netmap/marshal.go @@ -468,10 +468,101 @@ func (l *LocalNodeInfoResponseBody) Unmarshal(data []byte) error { return message.Unmarshal(l, data, new(netmap.LocalNodeInfoResponse_Body)) } +const ( + _ = iota + netPrmKeyFNum + netPrmValFNum +) + +func (x *NetworkParameter) StableMarshal(buf []byte) ([]byte, error) { + if x == nil { + return []byte{}, nil + } + + if buf == nil { + buf = make([]byte, x.StableSize()) + } + + var ( + offset, n int + err error + ) + + n, err = protoutil.BytesMarshal(netPrmKeyFNum, buf[offset:], x.k) + if err != nil { + return nil, err + } + + offset += n + + _, err = protoutil.BytesMarshal(netPrmValFNum, buf[offset:], x.v) + if err != nil { + return nil, err + } + + return buf, nil +} + +func (x *NetworkParameter) StableSize() (size int) { + if x == nil { + return 0 + } + + size += protoutil.BytesSize(netPrmKeyFNum, x.k) + size += protoutil.BytesSize(netPrmValFNum, x.v) + + return size +} + +const ( + _ = iota + netCfgPrmsFNum +) + +func (x *NetworkConfig) StableMarshal(buf []byte) ([]byte, error) { + if x == nil { + return []byte{}, nil + } + + if buf == nil { + buf = make([]byte, x.StableSize()) + } + + var ( + offset, n int + err error + ) + + for i := range x.ps { + n, err = protoutil.NestedStructureMarshal(netCfgPrmsFNum, buf[offset:], x.ps[i]) + if err != nil { + return nil, err + } + + offset += n + } + + return buf, nil +} + +func (x *NetworkConfig) StableSize() (size int) { + if x == nil { + return 0 + } + + for i := range x.ps { + size += protoutil.NestedStructureSize(netCfgPrmsFNum, x.ps[i]) + } + + return size +} + const ( _ = iota netInfoCurEpochFNum netInfoMagicNumFNum + netInfoMSPerBlockFNum + netInfoCfgFNum ) func (i *NetworkInfo) StableMarshal(buf []byte) ([]byte, error) { @@ -495,7 +586,21 @@ func (i *NetworkInfo) StableMarshal(buf []byte) ([]byte, error) { offset += n - _, err = protoutil.UInt64Marshal(netInfoMagicNumFNum, buf[offset:], i.magicNum) + n, err = protoutil.UInt64Marshal(netInfoMagicNumFNum, buf[offset:], i.magicNum) + if err != nil { + return nil, err + } + + offset += n + + n, err = protoutil.Int64Marshal(netInfoMSPerBlockFNum, buf[offset:], i.msPerBlock) + if err != nil { + return nil, err + } + + offset += n + + _, err = protoutil.NestedStructureMarshal(netInfoCfgFNum, buf[offset:], i.netCfg) if err != nil { return nil, err } @@ -510,6 +615,8 @@ func (i *NetworkInfo) StableSize() (size int) { size += protoutil.UInt64Size(netInfoCurEpochFNum, i.curEpoch) size += protoutil.UInt64Size(netInfoMagicNumFNum, i.magicNum) + size += protoutil.Int64Size(netInfoMSPerBlockFNum, i.msPerBlock) + size += protoutil.NestedStructureSize(netInfoCfgFNum, i.netCfg) return size } diff --git a/v2/netmap/message_test.go b/v2/netmap/message_test.go index 4a653bf5..1c921e08 100644 --- a/v2/netmap/message_test.go +++ b/v2/netmap/message_test.go @@ -18,6 +18,8 @@ func TestMessageConvert(t *testing.T) { func(empty bool) message.Message { return netmaptest.GenerateNodeInfo(empty) }, func(empty bool) message.Message { return netmaptest.GenerateLocalNodeInfoRequest(empty) }, func(empty bool) message.Message { return netmaptest.GenerateLocalNodeInfoResponseBody(empty) }, + func(empty bool) message.Message { return netmaptest.GenerateNetworkParameter(empty) }, + func(empty bool) message.Message { return netmaptest.GenerateNetworkConfig(empty) }, func(empty bool) message.Message { return netmaptest.GenerateNetworkInfo(empty) }, func(empty bool) message.Message { return netmaptest.GenerateNetworkInfoRequest(empty) }, func(empty bool) message.Message { return netmaptest.GenerateNetworkInfoResponseBody(empty) }, diff --git a/v2/netmap/test/generate.go b/v2/netmap/test/generate.go index f9f316fa..be07f128 100644 --- a/v2/netmap/test/generate.go +++ b/v2/netmap/test/generate.go @@ -188,12 +188,38 @@ func GenerateLocalNodeInfoResponse(empty bool) *netmap.LocalNodeInfoResponse { return m } +func GenerateNetworkParameter(empty bool) *netmap.NetworkParameter { + m := new(netmap.NetworkParameter) + + if !empty { + m.SetKey([]byte("key")) + m.SetValue([]byte("value")) + } + + return m +} + +func GenerateNetworkConfig(empty bool) *netmap.NetworkConfig { + m := new(netmap.NetworkConfig) + + if !empty { + m.SetParameters( + GenerateNetworkParameter(empty), + GenerateNetworkParameter(empty), + ) + } + + return m +} + func GenerateNetworkInfo(empty bool) *netmap.NetworkInfo { m := new(netmap.NetworkInfo) if !empty { m.SetMagicNumber(228) m.SetCurrentEpoch(666) + m.SetMsPerBlock(5678) + m.SetNetworkConfig(GenerateNetworkConfig(empty)) } return m diff --git a/v2/netmap/types.go b/v2/netmap/types.go index 858d8448..af8fb6ff 100644 --- a/v2/netmap/types.go +++ b/v2/netmap/types.go @@ -517,10 +517,86 @@ func (l *LocalNodeInfoResponse) SetBody(body *LocalNodeInfoResponseBody) { } } +// NetworkParameter represents NeoFS network parameter. +type NetworkParameter struct { + k, v []byte +} + +// GetKey returns parameter key. +func (x *NetworkParameter) GetKey() []byte { + if x != nil { + return x.k + } + + return nil +} + +// SetKey sets parameter key. +func (x *NetworkParameter) SetKey(k []byte) { + if x != nil { + x.k = k + } +} + +// GetValue returns parameter value. +func (x *NetworkParameter) GetValue() []byte { + if x != nil { + return x.v + } + + return nil +} + +// SetValue sets parameter value. +func (x *NetworkParameter) SetValue(v []byte) { + if x != nil { + x.v = v + } +} + +// NetworkConfig represents NeoFS network configuration. +type NetworkConfig struct { + ps []*NetworkParameter +} + +// NumberOfParameters returns number of network parameters. +func (x *NetworkConfig) NumberOfParameters() int { + if x != nil { + return len(x.ps) + } + + return 0 +} + +// IterateParameters iterates over network parameters. +// Breaks iteration on f's true return. +// +// Handler must not be nil. +func (x *NetworkConfig) IterateParameters(f func(*NetworkParameter) bool) { + if x != nil { + for i := range x.ps { + if f(x.ps[i]) { + break + } + } + } +} + +// SetParameters sets list of network parameters. +func (x *NetworkConfig) SetParameters(v ...*NetworkParameter) { + if x != nil { + x.ps = v + } +} + // NetworkInfo groups information about // NeoFS network. type NetworkInfo struct { curEpoch, magicNum uint64 + + msPerBlock int64 + + netCfg *NetworkConfig } // GetCurrentEpoch returns number of the current epoch. @@ -555,6 +631,38 @@ func (i *NetworkInfo) SetMagicNumber(magic uint64) { } } +// GetMsPerBlock returns MillisecondsPerBlock network parameter. +func (i *NetworkInfo) GetMsPerBlock() int64 { + if i != nil { + return i.msPerBlock + } + + return 0 +} + +// SetMsPerBlock sets MillisecondsPerBlock network parameter. +func (i *NetworkInfo) SetMsPerBlock(v int64) { + if i != nil { + i.msPerBlock = v + } +} + +// GetNetworkConfig returns NeoFS network configuration. +func (i *NetworkInfo) GetNetworkConfig() *NetworkConfig { + if i != nil { + return i.netCfg + } + + return nil +} + +// SetNetworkConfig sets NeoFS network configuration. +func (i *NetworkInfo) SetNetworkConfig(v *NetworkConfig) { + if i != nil { + i.netCfg = v + } +} + // NetworkInfoRequestBody is a structure of NetworkInfo request body. type NetworkInfoRequestBody struct{}