From 6c53da4cde5976d49e5fd74d329d99a556839c80 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Thu, 17 Feb 2022 15:27:49 +0300 Subject: [PATCH] [#137] Use callback response to update epoch Signed-off-by: Denis Kirillov --- client/common.go | 3 ++- client/response.go | 7 +++++++ pool/pool.go | 6 +++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/client/common.go b/client/common.go index f5dbedc..8ff7755 100644 --- a/client/common.go +++ b/client/common.go @@ -164,7 +164,8 @@ func (x *contextCall) processResponse() bool { // call response callback if set if x.callbackResp != nil { x.err = x.callbackResp(ResponseMetaInfo{ - key: x.resp.GetVerificationHeader().GetBodySignature().GetKey(), + key: x.resp.GetVerificationHeader().GetBodySignature().GetKey(), + epoch: x.resp.GetMetaHeader().GetEpoch(), }) if x.err != nil { x.err = fmt.Errorf("response callback error: %w", x.err) diff --git a/client/response.go b/client/response.go index ad1667c..885940a 100644 --- a/client/response.go +++ b/client/response.go @@ -5,6 +5,8 @@ import "github.com/nspcc-dev/neofs-api-go/v2/session" // ResponseMetaInfo groups meta information about any NeoFS API response. type ResponseMetaInfo struct { key []byte + + epoch uint64 } type responseV2 interface { @@ -19,6 +21,11 @@ func (x ResponseMetaInfo) ResponderKey() []byte { return x.key } +// Epoch return current epoch. +func (x ResponseMetaInfo) Epoch() uint64 { + return x.epoch +} + // WithResponseInfoHandler allows specifying handler of response meta information for the all Client operations. // The handler is called right after the response is received. Client returns handler's error immediately. func WithResponseInfoHandler(f func(ResponseMetaInfo) error) Option { diff --git a/pool/pool.go b/pool/pool.go index be6c391..d4fbe9d 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -277,7 +277,11 @@ func newPool(ctx context.Context, options *BuilderOptions) (Pool, error) { c, err := options.clientBuilder(client.WithDefaultPrivateKey(options.Key), client.WithURIAddress(addr, nil), client.WithDialTimeout(options.NodeConnectionTimeout), - client.WithNeoFSErrorParsing()) + client.WithNeoFSErrorParsing(), + client.WithResponseInfoHandler(func(info client.ResponseMetaInfo) error { + cache.UpdateEpoch(info.Epoch()) + return nil + })) if err != nil { return nil, err }