From fcfae4a24984cbf90785dd60fd972553461181dc 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 | 10 +++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/client/common.go b/client/common.go index 759606ee..b1fd7d6f 100644 --- a/client/common.go +++ b/client/common.go @@ -201,7 +201,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 7ec3594c..d7e8448d 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 { @@ -18,3 +20,8 @@ type responseV2 interface { func (x ResponseMetaInfo) ResponderKey() []byte { return x.key } + +// Epoch return current epoch. +func (x ResponseMetaInfo) Epoch() uint64 { + return x.epoch +} diff --git a/pool/pool.go b/pool/pool.go index 372566f5..236019dc 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -495,13 +495,13 @@ func NewPool(options InitParameters) (*Pool, error) { return nil, err } - fillDefaultInitParams(&options) - cache, err := newCache() if err != nil { return nil, fmt.Errorf("couldn't create cache: %w", err) } + fillDefaultInitParams(&options, cache) + pool := &Pool{ key: options.key, owner: owner.NewIDFromPublicKey(&options.key.PublicKey), @@ -575,7 +575,7 @@ func (p *Pool) Dial(ctx context.Context) error { return nil } -func fillDefaultInitParams(params *InitParameters) { +func fillDefaultInitParams(params *InitParameters, cache *sessionCache) { if params.sessionExpirationDuration == 0 { params.sessionExpirationDuration = defaultSessionTokenExpirationDuration } @@ -599,6 +599,10 @@ func fillDefaultInitParams(params *InitParameters) { var prmInit sdkClient.PrmInit prmInit.ResolveNeoFSFailures() prmInit.SetDefaultPrivateKey(*params.key) + prmInit.SetResponseInfoCallback(func(info sdkClient.ResponseMetaInfo) error { + cache.UpdateEpoch(info.Epoch()) + return nil + }) c.Init(prmInit)