[#137] Use callback response to update epoch

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2022-02-17 15:27:49 +03:00 committed by Alex Vanin
parent 9814748958
commit fcfae4a249
3 changed files with 16 additions and 4 deletions

View file

@ -202,6 +202,7 @@ func (x *contextCall) processResponse() bool {
if x.callbackResp != nil {
x.err = x.callbackResp(ResponseMetaInfo{
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)

View file

@ -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
}

View file

@ -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)