[#119] client: Configure network magic

In the latest NeoFS protocol update, each request is provided with a
network magic number. We have to provide the ability to set it on
the client.

Add `WithNetworkMagic` option constructor which accepts magic number.
Write the number to meta header of the all requests.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-01-14 13:38:51 +03:00 committed by LeL
parent 7f31621106
commit 49a17a7159
3 changed files with 17 additions and 1 deletions

View file

@ -27,6 +27,9 @@ type (
key *ecdsa.PrivateKey
session *session.Token
bearer *token.BearerToken
// network magic is a client config, but it's convenient to copy it here (see v2MetaHeaderFromOpts)
// the value remains the same between calls
netMagic uint64
}
clientOptions struct {
@ -41,6 +44,8 @@ type (
//
// default is false
parseNeoFSErrors bool
netMagic uint64
}
v2SessionReqInfo struct {
@ -56,6 +61,8 @@ func (c *Client) defaultCallOptions() *callOptions {
version: version.Current(),
ttl: 2,
key: c.opts.key,
// copy client's static value is a bit overhead, but it is the easiest way at the time of feature intro
netMagic: c.opts.netMagic,
}
}
@ -115,6 +122,8 @@ func v2MetaHeaderFromOpts(options *callOptions) *v2session.RequestMetaHeader {
meta.SetSessionToken(options.session.ToV2())
meta.SetNetworkMagic(options.netMagic)
return meta
}
@ -210,3 +219,10 @@ func WithNeoFSErrorParsing() Option {
opts.parseNeoFSErrors = true
}
}
// WithNetworkMagic returns option to specify NeoFS network magic.
func WithNetworkMagic(magic uint64) Option {
return func(opts *clientOptions) {
opts.netMagic = magic
}
}

2
go.mod
View file

@ -10,7 +10,7 @@ require (
github.com/mr-tron/base58 v1.2.0
github.com/nspcc-dev/hrw v1.0.9
github.com/nspcc-dev/neo-go v0.98.0
github.com/nspcc-dev/neofs-api-go/v2 v2.11.1
github.com/nspcc-dev/neofs-api-go/v2 v2.11.2-0.20220114101721-227a871a04ac
github.com/nspcc-dev/neofs-crypto v0.3.0
github.com/stretchr/testify v1.7.0
go.uber.org/zap v1.18.1

BIN
go.sum

Binary file not shown.