From d0d2f8d5db126aef1478b71d4838b3579dd28352 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 17 Feb 2021 19:36:03 +0300 Subject: [PATCH] [#259] netmap: Define NetworkInfo RPC and all related messages Signed-off-by: Leonard Lyubich --- v2/netmap/service.go | 19 ++++++ v2/netmap/types.go | 140 +++++++++++++++++++++++++++++++++++++++++++ v2/session/util.go | 81 +++++++++++++++++++++++++ 3 files changed, 240 insertions(+) create mode 100644 v2/session/util.go diff --git a/v2/netmap/service.go b/v2/netmap/service.go index 98e5101e..a57819b2 100644 --- a/v2/netmap/service.go +++ b/v2/netmap/service.go @@ -8,6 +8,7 @@ import ( type Service interface { LocalNodeInfo(ctx context.Context, request *LocalNodeInfoRequest) (*LocalNodeInfoResponse, error) + NetworkInfo(ctx context.Context, request *NetworkInfoRequest) (*NetworkInfoResponse, error) } type LocalNodeInfoRequest struct { @@ -25,3 +26,21 @@ type LocalNodeInfoResponse struct { verifyHeader *session.ResponseVerificationHeader } + +// NetworkInfoRequest is a structure of NetworkInfo request. +type NetworkInfoRequest struct { + body *NetworkInfoRequestBody + + metaHeader *session.RequestMetaHeader + + verifyHeader *session.RequestVerificationHeader +} + +// NetworkInfoResponse is a structure of NetworkInfo response. +type NetworkInfoResponse struct { + body *NetworkInfoResponseBody + + metaHeader *session.ResponseMetaHeader + + verifyHeader *session.ResponseVerificationHeader +} diff --git a/v2/netmap/types.go b/v2/netmap/types.go index a65bd314..320384eb 100644 --- a/v2/netmap/types.go +++ b/v2/netmap/types.go @@ -507,3 +507,143 @@ func (l *LocalNodeInfoResponse) SetVerificationHeader(verifyHeader *session.Resp l.verifyHeader = verifyHeader } } + +// NetworkInfo groups information about +// NeoFS network. +type NetworkInfo struct { + curEpoch, magicNum uint64 +} + +// GetCurrentEpoch returns number of the current epoch. +func (i *NetworkInfo) GetCurrentEpoch() uint64 { + if i != nil { + return i.curEpoch + } + + return 0 +} + +// SetCurrentEpoch sets number of the current epoch. +func (i *NetworkInfo) SetCurrentEpoch(epoch uint64) { + if i != nil { + i.curEpoch = epoch + } +} + +// GetMagicNumber returns magic number of the sidechain. +func (i *NetworkInfo) GetMagicNumber() uint64 { + if i != nil { + return i.magicNum + } + + return 0 +} + +// SetMagicNumber sets magic number of the sidechain. +func (i *NetworkInfo) SetMagicNumber(magic uint64) { + if i != nil { + i.magicNum = magic + } +} + +// NetworkInfoRequestBody is a structure of NetworkInfo request body. +type NetworkInfoRequestBody struct{} + +// NetworkInfoResponseBody is a structure of NetworkInfo response body. +type NetworkInfoResponseBody struct { + netInfo *NetworkInfo +} + +// GetNetworkInfo returns information about the NeoFS network. +func (i *NetworkInfoResponseBody) GetNetworkInfo() *NetworkInfo { + if i != nil { + return i.netInfo + } + + return nil +} + +// SetNetworkInfo sets information about the NeoFS network. +func (i *NetworkInfoResponseBody) SetNetworkInfo(netInfo *NetworkInfo) { + if i != nil { + i.netInfo = netInfo + } +} + +func (l *NetworkInfoRequest) GetBody() *NetworkInfoRequestBody { + if l != nil { + return l.body + } + return nil +} + +func (l *NetworkInfoRequest) SetBody(body *NetworkInfoRequestBody) { + if l != nil { + l.body = body + } +} + +func (l *NetworkInfoRequest) GetMetaHeader() *session.RequestMetaHeader { + if l != nil { + return l.metaHeader + } + return nil +} + +func (l *NetworkInfoRequest) SetMetaHeader(metaHeader *session.RequestMetaHeader) { + if l != nil { + l.metaHeader = metaHeader + } +} + +func (l *NetworkInfoRequest) GetVerificationHeader() *session.RequestVerificationHeader { + if l != nil { + return l.verifyHeader + } + return nil +} + +func (l *NetworkInfoRequest) SetVerificationHeader(verifyHeader *session.RequestVerificationHeader) { + if l != nil { + l.verifyHeader = verifyHeader + } +} + +func (l *NetworkInfoResponse) GetBody() *NetworkInfoResponseBody { + if l != nil { + return l.body + } + return nil +} + +func (l *NetworkInfoResponse) SetBody(body *NetworkInfoResponseBody) { + if l != nil { + l.body = body + } +} + +func (l *NetworkInfoResponse) GetMetaHeader() *session.ResponseMetaHeader { + if l != nil { + return l.metaHeader + } + return nil +} + +func (l *NetworkInfoResponse) SetMetaHeader(metaHeader *session.ResponseMetaHeader) { + if l != nil { + l.metaHeader = metaHeader + } +} + +func (l *NetworkInfoResponse) GetVerificationHeader() *session.ResponseVerificationHeader { + if l != nil { + return l.verifyHeader + } + return nil +} + +func (l *NetworkInfoResponse) SetVerificationHeader(verifyHeader *session.ResponseVerificationHeader) { + if l != nil { + l.verifyHeader = verifyHeader + } +} diff --git a/v2/session/util.go b/v2/session/util.go new file mode 100644 index 00000000..02354294 --- /dev/null +++ b/v2/session/util.go @@ -0,0 +1,81 @@ +package session + +// RequestHeaders represents common part of +// all NeoFS requests including headers. +type RequestHeaders struct { + metaHeader *RequestMetaHeader + + verifyHeader *RequestVerificationHeader +} + +// GetMetaHeader returns meta header of the request. +func (c *RequestHeaders) GetMetaHeader() *RequestMetaHeader { + if c != nil { + return c.metaHeader + } + + return nil +} + +// SetMetaHeader sets meta header of the request. +func (c *RequestHeaders) SetMetaHeader(v *RequestMetaHeader) { + if c != nil { + c.metaHeader = v + } +} + +// GetVerificationHeader returns verification header of the request. +func (c *RequestHeaders) GetVerificationHeader() *RequestVerificationHeader { + if c != nil { + return c.verifyHeader + } + + return nil +} + +// SetVerificationHeader sets verification header of the request. +func (c *RequestHeaders) SetVerificationHeader(v *RequestVerificationHeader) { + if c != nil { + c.verifyHeader = v + } +} + +// ResponseHeaders represents common part of +// all NeoFS responses including headers. +type ResponseHeaders struct { + metaHeader *ResponseMetaHeader + + verifyHeader *ResponseVerificationHeader +} + +// GetMetaHeader returns meta header of the response. +func (c *ResponseHeaders) GetMetaHeader() *ResponseMetaHeader { + if c != nil { + return c.metaHeader + } + + return nil +} + +// SetMetaHeader sets meta header of the response. +func (c *ResponseHeaders) SetMetaHeader(v *ResponseMetaHeader) { + if c != nil { + c.metaHeader = v + } +} + +// GetVerificationHeader returns verification header of the response. +func (c *ResponseHeaders) GetVerificationHeader() *ResponseVerificationHeader { + if c != nil { + return c.verifyHeader + } + + return nil +} + +// SetVerificationHeader sets verification header of the response. +func (c *ResponseHeaders) SetVerificationHeader(v *ResponseVerificationHeader) { + if c != nil { + c.verifyHeader = v + } +}