[#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:
parent
16a5107ef1
commit
a8481223d6
3 changed files with 29 additions and 0 deletions
|
@ -163,6 +163,8 @@ type cfgNetmap struct {
|
||||||
parsers map[event.Type]event.Parser
|
parsers map[event.Type]event.Parser
|
||||||
|
|
||||||
subscribers map[event.Type][]event.Handler
|
subscribers map[event.Type][]event.Handler
|
||||||
|
|
||||||
|
state *networkState
|
||||||
}
|
}
|
||||||
|
|
||||||
type BootstrapType uint32
|
type BootstrapType uint32
|
||||||
|
|
|
@ -5,11 +5,32 @@ import (
|
||||||
netmapGRPC "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc"
|
netmapGRPC "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc"
|
||||||
crypto "github.com/nspcc-dev/neofs-crypto"
|
crypto "github.com/nspcc-dev/neofs-crypto"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
"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"
|
netmapTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/netmap/grpc"
|
||||||
netmapService "github.com/nspcc-dev/neofs-node/pkg/services/netmap"
|
netmapService "github.com/nspcc-dev/neofs-node/pkg/services/netmap"
|
||||||
"github.com/pkg/errors"
|
"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) {
|
func initNetmapService(c *cfg) {
|
||||||
peerInfo := new(netmap.NodeInfo)
|
peerInfo := new(netmap.NodeInfo)
|
||||||
peerInfo.SetAddress(c.localAddr.String())
|
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) {
|
func bootstrapNode(c *cfg) {
|
||||||
|
|
|
@ -233,6 +233,7 @@ func initObjectService(c *cfg) {
|
||||||
putsvc.WithFormatValidatorOpts(
|
putsvc.WithFormatValidatorOpts(
|
||||||
objectCore.WithDeleteHandler(objGC),
|
objectCore.WithDeleteHandler(objGC),
|
||||||
),
|
),
|
||||||
|
putsvc.WithNetworkState(c.cfgNetmap.state),
|
||||||
)
|
)
|
||||||
|
|
||||||
sPutV2 := putsvcV2.NewService(
|
sPutV2 := putsvcV2.NewService(
|
||||||
|
|
Loading…
Reference in a new issue