forked from TrueCloudLab/frostfs-sdk-go
[#137] Use callback response to update epoch
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
parent
9814748958
commit
fcfae4a249
3 changed files with 16 additions and 4 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
10
pool/pool.go
10
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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue