[#137] Use callback response to update epoch
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
parent
a3713f0d74
commit
6c53da4cde
3 changed files with 14 additions and 2 deletions
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue