forked from TrueCloudLab/frostfs-node
Add Inner Ring code
This commit is contained in:
parent
dadfd90dcd
commit
b7b5079934
400 changed files with 11420 additions and 8690 deletions
37
pkg/morph/client/netmap/wrapper/add_peer.go
Normal file
37
pkg/morph/client/netmap/wrapper/add_peer.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
package wrapper
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
||||
contract "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// AddPeer registers peer in NeoFS network through
|
||||
// Netmap contract call.
|
||||
func (w *Wrapper) AddPeer(nodeInfo netmap.Info) error {
|
||||
// prepare invocation arguments
|
||||
args := contract.AddPeerArgs{}
|
||||
|
||||
info := contract.PeerInfo{}
|
||||
info.SetPublicKey(nodeInfo.PublicKey())
|
||||
info.SetAddress([]byte(nodeInfo.Address()))
|
||||
|
||||
opts := nodeInfo.Options()
|
||||
binOpts := make([][]byte, 0, len(opts))
|
||||
|
||||
for i := range opts {
|
||||
binOpts = append(binOpts, []byte(opts[i]))
|
||||
}
|
||||
|
||||
info.SetOptions(binOpts)
|
||||
|
||||
args.SetInfo(info)
|
||||
|
||||
// invoke smart contract call
|
||||
//
|
||||
// Note: errors.Wrap returns nil on nil error arg.
|
||||
return errors.Wrap(
|
||||
w.client.AddPeer(args),
|
||||
"could not invoke smart contract",
|
||||
)
|
||||
}
|
21
pkg/morph/client/netmap/wrapper/irlist.go
Normal file
21
pkg/morph/client/netmap/wrapper/irlist.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package wrapper
|
||||
|
||||
import (
|
||||
contract "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// InnerRingKeys receives public key list of inner
|
||||
// ring nodes through Netmap contract call and returns it.
|
||||
func (w *Wrapper) InnerRingKeys() ([][]byte, error) {
|
||||
// prepare invocation arguments
|
||||
args := contract.InnerRingListArgs{}
|
||||
|
||||
// invoke smart contract call
|
||||
values, err := w.client.InnerRingList(args)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not invoke smart contract")
|
||||
}
|
||||
|
||||
return values.KeyList(), nil
|
||||
}
|
60
pkg/morph/client/netmap/wrapper/netmap.go
Normal file
60
pkg/morph/client/netmap/wrapper/netmap.go
Normal file
|
@ -0,0 +1,60 @@
|
|||
package wrapper
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
||||
contract "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// NetMap represents the NeoFS network map.
|
||||
//
|
||||
// It is a type alias of
|
||||
// github.com/nspcc-dev/neofs-node/pkg/core/NetMap.
|
||||
type NetMap = netmap.NetMap
|
||||
|
||||
// Info represents node information.
|
||||
//
|
||||
// It is a type alias of
|
||||
// github.com/nspcc-dev/neofs-node/pkg/core/netmap.Info.
|
||||
type Info = netmap.Info
|
||||
|
||||
// GetNetMap receives information list about storage nodes
|
||||
// through the Netmap contract call, composes network map
|
||||
// from them and returns it.
|
||||
func (w *Wrapper) GetNetMap() (*NetMap, error) {
|
||||
// prepare invocation arguments
|
||||
args := contract.GetNetMapArgs{}
|
||||
|
||||
// invoke smart contract call
|
||||
values, err := w.client.NetMap(args)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not invoke smart contract")
|
||||
}
|
||||
|
||||
// parse response and fill the network map
|
||||
nm := netmap.New()
|
||||
|
||||
peerList := values.Peers()
|
||||
|
||||
for i := range peerList {
|
||||
info := Info{}
|
||||
|
||||
info.SetPublicKey(peerList[i].PublicKey())
|
||||
info.SetAddress(string(peerList[i].Address()))
|
||||
|
||||
binOpts := peerList[i].Options()
|
||||
opts := make([]string, 0, len(binOpts))
|
||||
|
||||
for j := range binOpts {
|
||||
opts = append(opts, string(binOpts[j]))
|
||||
}
|
||||
|
||||
info.SetOptions(opts)
|
||||
|
||||
if err := nm.AddNode(info); err != nil {
|
||||
return nil, errors.Wrapf(err, "could not add node #%d to network map", i)
|
||||
}
|
||||
}
|
||||
|
||||
return nm, nil
|
||||
}
|
23
pkg/morph/client/netmap/wrapper/new_epoch.go
Normal file
23
pkg/morph/client/netmap/wrapper/new_epoch.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
package wrapper
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neofs-node/pkg/core/netmap/epoch"
|
||||
contract "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// NewEpoch updates NeoFS epoch number through
|
||||
// Netmap contract call.
|
||||
func (w *Wrapper) NewEpoch(e epoch.Epoch) error {
|
||||
// prepare invocation arguments
|
||||
args := contract.NewEpochArgs{}
|
||||
args.SetEpochNumber(int64(epoch.ToUint64(e)))
|
||||
|
||||
// invoke smart contract call
|
||||
//
|
||||
// Note: errors.Wrap returns nil on nil error arg.
|
||||
return errors.Wrap(
|
||||
w.client.NewEpoch(args),
|
||||
"could not invoke smart contract",
|
||||
)
|
||||
}
|
32
pkg/morph/client/netmap/wrapper/update_state.go
Normal file
32
pkg/morph/client/netmap/wrapper/update_state.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
package wrapper
|
||||
|
||||
import (
|
||||
contract "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// NodeState is a type of node states enumeration.
|
||||
type NodeState int64
|
||||
|
||||
const (
|
||||
_ NodeState = iota
|
||||
|
||||
// StateOffline is an offline node state value.
|
||||
StateOffline
|
||||
)
|
||||
|
||||
// UpdatePeerState changes peer status through Netmap contract
|
||||
// call.
|
||||
func (w *Wrapper) UpdatePeerState(key []byte, state NodeState) error {
|
||||
args := contract.UpdateStateArgs{}
|
||||
args.SetPublicKey(key)
|
||||
args.SetState(int64(state))
|
||||
|
||||
// invoke smart contract call
|
||||
//
|
||||
// Note: errors.Wrap returns nil on nil error arg.
|
||||
return errors.Wrap(
|
||||
w.client.UpdateState(args),
|
||||
"could not invoke smart contract",
|
||||
)
|
||||
}
|
43
pkg/morph/client/netmap/wrapper/wrapper.go
Normal file
43
pkg/morph/client/netmap/wrapper/wrapper.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package wrapper
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
||||
)
|
||||
|
||||
// Client represents the Netmap contract client.
|
||||
//
|
||||
// It is a type alias of
|
||||
// github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap.Client.
|
||||
type Client = netmap.Client
|
||||
|
||||
// Wrapper is a wrapper over netmap contract
|
||||
// client which implements:
|
||||
// * network map storage;
|
||||
// * tool for peer state updating.
|
||||
//
|
||||
// Working wrapper must be created via constructor New.
|
||||
// Using the Wrapper that has been created with new(Wrapper)
|
||||
// expression (or just declaring a Wrapper variable) is unsafe
|
||||
// and can lead to panic.
|
||||
type Wrapper struct {
|
||||
client *Client
|
||||
}
|
||||
|
||||
// ErrNilWrapper is returned by functions that expect
|
||||
// a non-nil Wrapper pointer, but received nil.
|
||||
var ErrNilWrapper = errors.New("netmap contract client wrapper is nil")
|
||||
|
||||
// New creates, initializes and returns the Wrapper instance.
|
||||
//
|
||||
// If Client is nil, netmap.ErrNilClient is returned.
|
||||
func New(c *Client) (*Wrapper, error) {
|
||||
if c == nil {
|
||||
return nil, netmap.ErrNilClient
|
||||
}
|
||||
|
||||
return &Wrapper{
|
||||
client: c,
|
||||
}, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue