[#60] cmd/neofs-node: Implement primary network State instance

Define networkState structure and implement netmap.State interface on it.
Set epoch number on NewEpoch notification from chain. Provide
WithNetworkState option to Put service constructor.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-10-21 18:12:31 +03:00 committed by Alex Vanin
parent 16a5107ef1
commit a8481223d6
3 changed files with 29 additions and 0 deletions

View file

@ -163,6 +163,8 @@ type cfgNetmap struct {
parsers map[event.Type]event.Parser
subscribers map[event.Type][]event.Handler
state *networkState
}
type BootstrapType uint32

View file

@ -5,11 +5,32 @@ import (
netmapGRPC "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc"
crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
netmapEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
netmapTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/netmap/grpc"
netmapService "github.com/nspcc-dev/neofs-node/pkg/services/netmap"
"github.com/pkg/errors"
"go.uber.org/atomic"
)
// primary solution of local network state dump.
type networkState struct {
epoch *atomic.Uint64
}
func newNetworkState() *networkState {
return &networkState{
epoch: atomic.NewUint64(0),
}
}
func (s *networkState) CurrentEpoch() uint64 {
return s.epoch.Load()
}
func (s *networkState) setCurrentEpoch(v uint64) {
s.epoch.Store(v)
}
func initNetmapService(c *cfg) {
peerInfo := new(netmap.NodeInfo)
peerInfo.SetAddress(c.localAddr.String())
@ -29,6 +50,11 @@ func initNetmapService(c *cfg) {
),
),
)
c.cfgNetmap.state = newNetworkState()
addNewEpochNotificationHandler(c, func(ev event.Event) {
c.cfgNetmap.state.setCurrentEpoch(ev.(netmapEvent.NewEpoch).EpochNumber())
})
}
func bootstrapNode(c *cfg) {

View file

@ -233,6 +233,7 @@ func initObjectService(c *cfg) {
putsvc.WithFormatValidatorOpts(
objectCore.WithDeleteHandler(objGC),
),
putsvc.WithNetworkState(c.cfgNetmap.state),
)
sPutV2 := putsvcV2.NewService(