From 2b171e161721b1dbc2776c076df7a25b5fea8747 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 3 Nov 2020 18:59:57 +0300 Subject: [PATCH] [#188] sdk: Implement Epoch method Implement Epoch method on Client that receives epoch number through Netmap .LocalNodeInfo call. Signed-off-by: Leonard Lyubich --- pkg/client/netmap.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/pkg/client/netmap.go b/pkg/client/netmap.go index 515d130..d8a66d2 100644 --- a/pkg/client/netmap.go +++ b/pkg/client/netmap.go @@ -15,13 +15,33 @@ import ( func (c Client) EndpointInfo(ctx context.Context, opts ...CallOption) (*netmap.NodeInfo, error) { switch c.remoteNode.Version.GetMajor() { case 2: - return c.endpointInfoV2(ctx, opts...) + resp, err := c.endpointInfoV2(ctx, opts...) + if err != nil { + return nil, err + } + + return resp.GetBody().GetNodeInfo(), nil default: return nil, unsupportedProtocolErr } } -func (c Client) endpointInfoV2(ctx context.Context, opts ...CallOption) (*netmap.NodeInfo, error) { +// Epoch returns the epoch number from the local state of the remote host. +func (c Client) Epoch(ctx context.Context, opts ...CallOption) (uint64, error) { + switch c.remoteNode.Version.GetMajor() { + case 2: + resp, err := c.endpointInfoV2(ctx, opts...) + if err != nil { + return 0, err + } + + return resp.GetMetaHeader().GetEpoch(), nil + default: + return 0, unsupportedProtocolErr + } +} + +func (c Client) endpointInfoV2(ctx context.Context, opts ...CallOption) (*netmap.LocalNodeInfoResponse, error) { // apply all available options callOptions := c.defaultCallOptions() for i := range opts { @@ -56,7 +76,7 @@ func (c Client) endpointInfoV2(ctx context.Context, opts ...CallOption) (*netmap return nil, errors.Wrap(err, "can't verify response message") } - return resp.GetBody().GetNodeInfo(), nil + return resp, nil default: return nil, unsupportedProtocolErr }