[#418] netmap: Support NetmapService.NetmapSnapshot
RPC
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
f3e1f8ae7a
commit
cf868188ef
36 changed files with 469 additions and 0 deletions
BIN
accounting/grpc/service.pb.go
generated
BIN
accounting/grpc/service.pb.go
generated
Binary file not shown.
BIN
accounting/grpc/service_grpc.pb.go
generated
BIN
accounting/grpc/service_grpc.pb.go
generated
Binary file not shown.
BIN
accounting/grpc/types.pb.go
generated
BIN
accounting/grpc/types.pb.go
generated
Binary file not shown.
BIN
acl/grpc/types.pb.go
generated
BIN
acl/grpc/types.pb.go
generated
Binary file not shown.
BIN
audit/grpc/types.pb.go
generated
BIN
audit/grpc/types.pb.go
generated
Binary file not shown.
BIN
container/grpc/service.pb.go
generated
BIN
container/grpc/service.pb.go
generated
Binary file not shown.
BIN
container/grpc/service_grpc.pb.go
generated
BIN
container/grpc/service_grpc.pb.go
generated
Binary file not shown.
BIN
container/grpc/types.pb.go
generated
BIN
container/grpc/types.pb.go
generated
Binary file not shown.
BIN
lock/grpc/types.pb.go
generated
BIN
lock/grpc/types.pb.go
generated
Binary file not shown.
|
@ -754,3 +754,181 @@ func (l *NetworkInfoResponse) FromGRPCMessage(m grpc.Message) error {
|
|||
|
||||
return l.ResponseHeaders.FromMessage(v)
|
||||
}
|
||||
|
||||
func (x *NetMap) ToGRPCMessage() grpc.Message {
|
||||
var m *netmap.Netmap
|
||||
|
||||
if x != nil {
|
||||
m = new(netmap.Netmap)
|
||||
|
||||
m.SetEpoch(x.epoch)
|
||||
|
||||
if x.nodes != nil {
|
||||
nodes := make([]*netmap.NodeInfo, len(x.nodes))
|
||||
|
||||
for i := range x.nodes {
|
||||
nodes[i] = x.nodes[i].ToGRPCMessage().(*netmap.NodeInfo)
|
||||
}
|
||||
|
||||
m.SetNodes(nodes)
|
||||
}
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func (x *NetMap) FromGRPCMessage(m grpc.Message) error {
|
||||
v, ok := m.(*netmap.Netmap)
|
||||
if !ok {
|
||||
return message.NewUnexpectedMessageType(m, v)
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
nodes := v.GetNodes()
|
||||
if nodes == nil {
|
||||
x.nodes = nil
|
||||
} else {
|
||||
x.nodes = make([]NodeInfo, len(nodes))
|
||||
|
||||
for i := range nodes {
|
||||
err = x.nodes[i].FromGRPCMessage(nodes[i])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
x.epoch = v.GetEpoch()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *SnapshotRequestBody) ToGRPCMessage() grpc.Message {
|
||||
var m *netmap.NetmapSnapshotRequest_Body
|
||||
|
||||
if x != nil {
|
||||
m = new(netmap.NetmapSnapshotRequest_Body)
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func (x *SnapshotRequestBody) FromGRPCMessage(m grpc.Message) error {
|
||||
v, ok := m.(*netmap.NetmapSnapshotRequest_Body)
|
||||
if !ok {
|
||||
return message.NewUnexpectedMessageType(m, v)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *SnapshotRequest) ToGRPCMessage() grpc.Message {
|
||||
var m *netmap.NetmapSnapshotRequest
|
||||
|
||||
if x != nil {
|
||||
m = new(netmap.NetmapSnapshotRequest)
|
||||
|
||||
m.SetBody(x.body.ToGRPCMessage().(*netmap.NetmapSnapshotRequest_Body))
|
||||
x.RequestHeaders.ToMessage(m)
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func (x *SnapshotRequest) FromGRPCMessage(m grpc.Message) error {
|
||||
v, ok := m.(*netmap.NetmapSnapshotRequest)
|
||||
if !ok {
|
||||
return message.NewUnexpectedMessageType(m, v)
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
body := v.GetBody()
|
||||
if body == nil {
|
||||
x.body = nil
|
||||
} else {
|
||||
if x.body == nil {
|
||||
x.body = new(SnapshotRequestBody)
|
||||
}
|
||||
|
||||
err = x.body.FromGRPCMessage(body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return x.RequestHeaders.FromMessage(v)
|
||||
}
|
||||
|
||||
func (x *SnapshotResponseBody) ToGRPCMessage() grpc.Message {
|
||||
var m *netmap.NetmapSnapshotResponse_Body
|
||||
|
||||
if x != nil {
|
||||
m = new(netmap.NetmapSnapshotResponse_Body)
|
||||
|
||||
m.SetNetmap(x.netMap.ToGRPCMessage().(*netmap.Netmap))
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func (x *SnapshotResponseBody) FromGRPCMessage(m grpc.Message) error {
|
||||
v, ok := m.(*netmap.NetmapSnapshotResponse_Body)
|
||||
if !ok {
|
||||
return message.NewUnexpectedMessageType(m, v)
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
netMap := v.GetNetmap()
|
||||
if netMap == nil {
|
||||
x.netMap = nil
|
||||
} else {
|
||||
if x.netMap == nil {
|
||||
x.netMap = new(NetMap)
|
||||
}
|
||||
|
||||
err = x.netMap.FromGRPCMessage(netMap)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (x *SnapshotResponse) ToGRPCMessage() grpc.Message {
|
||||
var m *netmap.NetmapSnapshotResponse
|
||||
|
||||
if x != nil {
|
||||
m = new(netmap.NetmapSnapshotResponse)
|
||||
|
||||
m.SetBody(x.body.ToGRPCMessage().(*netmap.NetmapSnapshotResponse_Body))
|
||||
x.ResponseHeaders.ToMessage(m)
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func (x *SnapshotResponse) FromGRPCMessage(m grpc.Message) error {
|
||||
v, ok := m.(*netmap.NetmapSnapshotResponse)
|
||||
if !ok {
|
||||
return message.NewUnexpectedMessageType(m, v)
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
body := v.GetBody()
|
||||
if body == nil {
|
||||
x.body = nil
|
||||
} else {
|
||||
if x.body == nil {
|
||||
x.body = new(SnapshotResponseBody)
|
||||
}
|
||||
|
||||
err = x.body.FromGRPCMessage(body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return x.ResponseHeaders.FromMessage(v)
|
||||
}
|
||||
|
|
|
@ -79,3 +79,38 @@ func (x *NetworkInfoResponse) SetMetaHeader(v *session.ResponseMetaHeader) {
|
|||
func (x *NetworkInfoResponse) SetVerifyHeader(v *session.ResponseVerificationHeader) {
|
||||
x.VerifyHeader = v
|
||||
}
|
||||
|
||||
// SetBody sets body of the request.
|
||||
func (x *NetmapSnapshotRequest) SetBody(v *NetmapSnapshotRequest_Body) {
|
||||
x.Body = v
|
||||
}
|
||||
|
||||
// SetMetaHeader sets meta header of the request.
|
||||
func (x *NetmapSnapshotRequest) SetMetaHeader(v *session.RequestMetaHeader) {
|
||||
x.MetaHeader = v
|
||||
}
|
||||
|
||||
// SetVerifyHeader sets verification header of the request.
|
||||
func (x *NetmapSnapshotRequest) SetVerifyHeader(v *session.RequestVerificationHeader) {
|
||||
x.VerifyHeader = v
|
||||
}
|
||||
|
||||
// SetNetmap sets current Netmap.
|
||||
func (x *NetmapSnapshotResponse_Body) SetNetmap(v *Netmap) {
|
||||
x.Netmap = v
|
||||
}
|
||||
|
||||
// SetBody sets body of the response.
|
||||
func (x *NetmapSnapshotResponse) SetBody(v *NetmapSnapshotResponse_Body) {
|
||||
x.Body = v
|
||||
}
|
||||
|
||||
// SetMetaHeader sets meta header of the response.
|
||||
func (x *NetmapSnapshotResponse) SetMetaHeader(v *session.ResponseMetaHeader) {
|
||||
x.MetaHeader = v
|
||||
}
|
||||
|
||||
// SetVerifyHeader sets verification header of the response.
|
||||
func (x *NetmapSnapshotResponse) SetVerifyHeader(v *session.ResponseVerificationHeader) {
|
||||
x.VerifyHeader = v
|
||||
}
|
||||
|
|
BIN
netmap/grpc/service.pb.go
generated
BIN
netmap/grpc/service.pb.go
generated
Binary file not shown.
BIN
netmap/grpc/service_grpc.pb.go
generated
BIN
netmap/grpc/service_grpc.pb.go
generated
Binary file not shown.
|
@ -202,3 +202,13 @@ func (x *NetworkConfig_Parameter) SetValue(v []byte) {
|
|||
func (x *NetworkConfig) SetParameters(v []*NetworkConfig_Parameter) {
|
||||
x.Parameters = v
|
||||
}
|
||||
|
||||
// SetEpoch sets revision number of the Netmap.
|
||||
func (x *Netmap) SetEpoch(v uint64) {
|
||||
x.Epoch = v
|
||||
}
|
||||
|
||||
// SetNodes sets nodes presented in the Netmap.
|
||||
func (x *Netmap) SetNodes(v []*NodeInfo) {
|
||||
x.Nodes = v
|
||||
}
|
||||
|
|
BIN
netmap/grpc/types.pb.go
generated
BIN
netmap/grpc/types.pb.go
generated
Binary file not shown.
|
@ -481,3 +481,74 @@ func (i *NetworkInfoResponseBody) StableSize() (size int) {
|
|||
func (i *NetworkInfoResponseBody) Unmarshal(data []byte) error {
|
||||
return message.Unmarshal(i, data, new(netmap.NetworkInfoResponse_Body))
|
||||
}
|
||||
|
||||
const (
|
||||
_ = iota
|
||||
fNumNetMapEpoch
|
||||
fNumNetMapNodes
|
||||
)
|
||||
|
||||
func (x *NetMap) StableMarshal(buf []byte) []byte {
|
||||
if x == nil {
|
||||
return []byte{}
|
||||
}
|
||||
|
||||
if buf == nil {
|
||||
buf = make([]byte, x.StableSize())
|
||||
}
|
||||
|
||||
offset := protoutil.UInt64Marshal(fNumNetMapEpoch, buf, x.epoch)
|
||||
|
||||
for i := range x.nodes {
|
||||
offset += protoutil.NestedStructureMarshal(fNumNetMapNodes, buf[offset:], &x.nodes[i])
|
||||
}
|
||||
|
||||
return buf
|
||||
}
|
||||
|
||||
func (x *NetMap) StableSize() (size int) {
|
||||
if x != nil {
|
||||
size = protoutil.UInt64Size(fNumNetMapEpoch, x.epoch)
|
||||
|
||||
for i := range x.nodes {
|
||||
size += protoutil.NestedStructureSize(fNumNetMapNodes, &x.nodes[i])
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (x *SnapshotRequestBody) StableMarshal([]byte) []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *SnapshotRequestBody) StableSize() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
const (
|
||||
_ = iota
|
||||
fNumSnapshotResponseBodyNetMap
|
||||
)
|
||||
|
||||
func (x *SnapshotResponseBody) StableMarshal(buf []byte) []byte {
|
||||
if x == nil {
|
||||
return []byte{}
|
||||
}
|
||||
|
||||
if buf == nil {
|
||||
buf = make([]byte, x.StableSize())
|
||||
}
|
||||
|
||||
protoutil.NestedStructureMarshal(fNumSnapshotResponseBodyNetMap, buf, x.netMap)
|
||||
|
||||
return buf
|
||||
}
|
||||
|
||||
func (x *SnapshotResponseBody) StableSize() (size int) {
|
||||
if x != nil {
|
||||
size = protoutil.NestedStructureSize(fNumSnapshotResponseBodyNetMap, x.netMap)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -23,5 +23,10 @@ func TestMessageConvert(t *testing.T) {
|
|||
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) },
|
||||
func(empty bool) message.Message { return netmaptest.GenerateNetMap(empty) },
|
||||
func(empty bool) message.Message { return netmaptest.GenerateSnapshotRequestBody(empty) },
|
||||
func(empty bool) message.Message { return netmaptest.GenerateSnapshotRequest(empty) },
|
||||
func(empty bool) message.Message { return netmaptest.GenerateSnapshotResponseBody(empty) },
|
||||
func(empty bool) message.Message { return netmaptest.GenerateSnapshotResponse(empty) },
|
||||
)
|
||||
}
|
||||
|
|
|
@ -267,3 +267,57 @@ func GenerateNetworkInfoResponse(empty bool) *netmap.NetworkInfoResponse {
|
|||
|
||||
return m
|
||||
}
|
||||
|
||||
func GenerateNetMap(empty bool) *netmap.NetMap {
|
||||
m := new(netmap.NetMap)
|
||||
|
||||
if !empty {
|
||||
m.SetEpoch(987)
|
||||
m.SetNodes([]netmap.NodeInfo{
|
||||
*GenerateNodeInfo(false),
|
||||
*GenerateNodeInfo(false),
|
||||
})
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func GenerateSnapshotRequestBody(_ bool) *netmap.SnapshotRequestBody {
|
||||
return new(netmap.SnapshotRequestBody)
|
||||
}
|
||||
|
||||
func GenerateSnapshotRequest(empty bool) *netmap.SnapshotRequest {
|
||||
m := new(netmap.SnapshotRequest)
|
||||
|
||||
if !empty {
|
||||
m.SetBody(GenerateSnapshotRequestBody(false))
|
||||
}
|
||||
|
||||
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
|
||||
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func GenerateSnapshotResponseBody(empty bool) *netmap.SnapshotResponseBody {
|
||||
m := new(netmap.SnapshotResponseBody)
|
||||
|
||||
if !empty {
|
||||
m.SetNetMap(GenerateNetMap(false))
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func GenerateSnapshotResponse(empty bool) *netmap.SnapshotResponse {
|
||||
m := new(netmap.SnapshotResponse)
|
||||
|
||||
if !empty {
|
||||
m.SetBody(GenerateSnapshotResponseBody(false))
|
||||
}
|
||||
|
||||
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
|
||||
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
|
||||
|
||||
return m
|
||||
}
|
||||
|
|
|
@ -650,3 +650,98 @@ func (l *NetworkInfoResponse) GetBody() *NetworkInfoResponseBody {
|
|||
func (l *NetworkInfoResponse) SetBody(body *NetworkInfoResponseBody) {
|
||||
l.body = body
|
||||
}
|
||||
|
||||
// NetMap represents structure of NeoFS network map.
|
||||
type NetMap struct {
|
||||
epoch uint64
|
||||
|
||||
nodes []NodeInfo
|
||||
}
|
||||
|
||||
// Epoch returns revision number of the NetMap.
|
||||
func (x *NetMap) Epoch() uint64 {
|
||||
if x != nil {
|
||||
return x.epoch
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
// SetEpoch sets revision number of the NetMap.
|
||||
func (x *NetMap) SetEpoch(v uint64) {
|
||||
x.epoch = v
|
||||
}
|
||||
|
||||
// Nodes returns nodes presented in the NetMap.
|
||||
func (x *NetMap) Nodes() []NodeInfo {
|
||||
if x != nil {
|
||||
return x.nodes
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetNodes sets nodes presented in the NetMap.
|
||||
func (x *NetMap) SetNodes(v []NodeInfo) {
|
||||
x.nodes = v
|
||||
}
|
||||
|
||||
// SnapshotRequestBody represents structure of Snapshot request body.
|
||||
type SnapshotRequestBody struct{}
|
||||
|
||||
// SnapshotRequest represents structure of Snapshot request.
|
||||
type SnapshotRequest struct {
|
||||
body *SnapshotRequestBody
|
||||
|
||||
session.RequestHeaders
|
||||
}
|
||||
|
||||
func (x *SnapshotRequest) GetBody() *SnapshotRequestBody {
|
||||
if x != nil {
|
||||
return x.body
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *SnapshotRequest) SetBody(body *SnapshotRequestBody) {
|
||||
x.body = body
|
||||
}
|
||||
|
||||
// SnapshotResponseBody represents structure of Snapshot response body.
|
||||
type SnapshotResponseBody struct {
|
||||
netMap *NetMap
|
||||
}
|
||||
|
||||
// NetMap returns current NetMap.
|
||||
func (x *SnapshotResponseBody) NetMap() *NetMap {
|
||||
if x != nil {
|
||||
return x.netMap
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetNetMap sets current NetMap.
|
||||
func (x *SnapshotResponseBody) SetNetMap(netMap *NetMap) {
|
||||
x.netMap = netMap
|
||||
}
|
||||
|
||||
// SnapshotResponse represents structure of Snapshot response.
|
||||
type SnapshotResponse struct {
|
||||
body *SnapshotResponseBody
|
||||
|
||||
session.ResponseHeaders
|
||||
}
|
||||
|
||||
func (x *SnapshotResponse) GetBody() *SnapshotResponseBody {
|
||||
if x != nil {
|
||||
return x.body
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *SnapshotResponse) SetBody(body *SnapshotResponseBody) {
|
||||
x.body = body
|
||||
}
|
||||
|
|
BIN
object/grpc/service.pb.go
generated
BIN
object/grpc/service.pb.go
generated
Binary file not shown.
BIN
object/grpc/service_grpc.pb.go
generated
BIN
object/grpc/service_grpc.pb.go
generated
Binary file not shown.
BIN
object/grpc/types.pb.go
generated
BIN
object/grpc/types.pb.go
generated
Binary file not shown.
BIN
refs/grpc/types.pb.go
generated
BIN
refs/grpc/types.pb.go
generated
Binary file not shown.
BIN
reputation/grpc/service.pb.go
generated
BIN
reputation/grpc/service.pb.go
generated
Binary file not shown.
BIN
reputation/grpc/service_grpc.pb.go
generated
BIN
reputation/grpc/service_grpc.pb.go
generated
Binary file not shown.
BIN
reputation/grpc/types.pb.go
generated
BIN
reputation/grpc/types.pb.go
generated
Binary file not shown.
|
@ -11,6 +11,7 @@ const serviceNetmap = serviceNamePrefix + "netmap.NetmapService"
|
|||
const (
|
||||
rpcNetmapNodeInfo = "LocalNodeInfo"
|
||||
rpcNetmapNetInfo = "NetworkInfo"
|
||||
rpcNetmapSnapshot = "NetmapSnapshot"
|
||||
)
|
||||
|
||||
// LocalNodeInfo executes NetmapService.LocalNodeInfo RPC.
|
||||
|
@ -44,3 +45,19 @@ func NetworkInfo(
|
|||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// NetMapSnapshot executes NetmapService.NetmapSnapshot RPC.
|
||||
func NetMapSnapshot(
|
||||
cli *client.Client,
|
||||
req *netmap.SnapshotRequest,
|
||||
opts ...client.CallOption,
|
||||
) (*netmap.SnapshotResponse, error) {
|
||||
resp := new(netmap.SnapshotResponse)
|
||||
|
||||
err := client.SendUnary(cli, common.CallMethodInfoUnary(serviceNetmap, rpcNetmapSnapshot), req, resp, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
|
BIN
session/grpc/service.pb.go
generated
BIN
session/grpc/service.pb.go
generated
Binary file not shown.
BIN
session/grpc/service_grpc.pb.go
generated
BIN
session/grpc/service_grpc.pb.go
generated
Binary file not shown.
BIN
session/grpc/types.pb.go
generated
BIN
session/grpc/types.pb.go
generated
Binary file not shown.
|
@ -375,6 +375,10 @@ func serviceMessageBody(req interface{}) stableMarshaler {
|
|||
return v.GetBody()
|
||||
case *netmap.NetworkInfoResponse:
|
||||
return v.GetBody()
|
||||
case *netmap.SnapshotRequest:
|
||||
return v.GetBody()
|
||||
case *netmap.SnapshotResponse:
|
||||
return v.GetBody()
|
||||
|
||||
/* Reputation */
|
||||
case *reputation.AnnounceLocalTrustRequest:
|
||||
|
|
BIN
status/grpc/types.pb.go
generated
BIN
status/grpc/types.pb.go
generated
Binary file not shown.
BIN
storagegroup/grpc/types.pb.go
generated
BIN
storagegroup/grpc/types.pb.go
generated
Binary file not shown.
BIN
subnet/grpc/types.pb.go
generated
BIN
subnet/grpc/types.pb.go
generated
Binary file not shown.
BIN
tombstone/grpc/types.pb.go
generated
BIN
tombstone/grpc/types.pb.go
generated
Binary file not shown.
BIN
util/proto/test/test.pb.go
generated
BIN
util/proto/test/test.pb.go
generated
Binary file not shown.
Loading…
Reference in a new issue