[#83] services/response: Set epoch number from network state

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-10-22 14:22:23 +03:00 committed by Alex Vanin
parent 19f9c7eacb
commit 7fdb14cf8a

View file

@ -4,6 +4,7 @@ import (
"github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg"
"github.com/nspcc-dev/neofs-api-go/v2/refs" "github.com/nspcc-dev/neofs-api-go/v2/refs"
"github.com/nspcc-dev/neofs-api-go/v2/session" "github.com/nspcc-dev/neofs-api-go/v2/session"
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
"github.com/nspcc-dev/neofs-node/pkg/services/util" "github.com/nspcc-dev/neofs-node/pkg/services/util"
) )
@ -19,7 +20,7 @@ type Option func(*cfg)
type cfg struct { type cfg struct {
version *refs.Version version *refs.Version
// TODO: neofs-node#83 add network state state netmap.State
} }
func defaultCfg() *cfg { func defaultCfg() *cfg {
@ -45,9 +46,7 @@ func setMeta(resp util.ResponseMessage, cfg *cfg) {
meta := new(session.ResponseMetaHeader) meta := new(session.ResponseMetaHeader)
meta.SetVersion(cfg.version) meta.SetVersion(cfg.version)
meta.SetTTL(1) // FIXME: TTL must be calculated meta.SetTTL(1) // FIXME: TTL must be calculated
meta.SetEpoch(cfg.state.CurrentEpoch())
// TODO: neofs-node#83
// meta.SetEpoch()
if origin := resp.GetMetaHeader(); origin != nil { if origin := resp.GetMetaHeader(); origin != nil {
// FIXME: what if origin is set by local server? // FIXME: what if origin is set by local server?
@ -56,3 +55,10 @@ func setMeta(resp util.ResponseMessage, cfg *cfg) {
resp.SetMetaHeader(meta) resp.SetMetaHeader(meta)
} }
// WithNetworkState returns option to set network state of Service.
func WithNetworkState(v netmap.State) Option {
return func(c *cfg) {
c.state = v
}
}