From 49a17a71598633725ee9b4751c111c2a429e51d6 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Fri, 14 Jan 2022 13:38:51 +0300 Subject: [PATCH] [#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 --- client/opts.go | 16 ++++++++++++++++ go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/client/opts.go b/client/opts.go index 60a3894..2afd17f 100644 --- a/client/opts.go +++ b/client/opts.go @@ -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 + } +} diff --git a/go.mod b/go.mod index aa785bb..be65912 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 7fbcae7..166500a 100644 --- a/go.sum +++ b/go.sum @@ -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=