[#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>
remotes/fyrchik/master
Leonard Lyubich 2022-01-14 13:38:51 +03:00 committed by LeL
parent 7f31621106
commit 49a17a7159
3 changed files with 19 additions and 3 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

4
go.sum
View File

@ -177,8 +177,8 @@ github.com/nspcc-dev/neo-go v0.73.1-pre.0.20200303142215-f5a1b928ce09/go.mod h1:
github.com/nspcc-dev/neo-go v0.98.0 h1:yyW4sgY88/pLf0949qmgfkQXzRKC3CI/WyhqXNnwMd8=
github.com/nspcc-dev/neo-go v0.98.0/go.mod h1:E3cc1x6RXSXrJb2nDWXTXjnXk3rIqVN8YdFyWv+FrqM=
github.com/nspcc-dev/neofs-api-go/v2 v2.11.0-pre.0.20211201134523-3604d96f3fe1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs=
github.com/nspcc-dev/neofs-api-go/v2 v2.11.1 h1:SVqc523pZsSaS9vnPS1mm3VV6b6xY0gvdA0uYJ/GWZQ=
github.com/nspcc-dev/neofs-api-go/v2 v2.11.1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs=
github.com/nspcc-dev/neofs-api-go/v2 v2.11.2-0.20220114101721-227a871a04ac h1:65C4z7pybLT2HjtY96abZj6kbgVp34AbrApn5DD+ZxY=
github.com/nspcc-dev/neofs-api-go/v2 v2.11.2-0.20220114101721-227a871a04ac/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs=
github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA=
github.com/nspcc-dev/neofs-crypto v0.2.3/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw=
github.com/nspcc-dev/neofs-crypto v0.3.0 h1:zlr3pgoxuzrmGCxc5W8dGVfA9Rro8diFvVnBg0L4ifM=