[#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
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue