forked from TrueCloudLab/frostfs-node
[#971] morph/netmap: Add optional parameters
Add optional parameters to the client call signature. Group parameters of a client call into struct to improve future codebase support. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
3114be39d0
commit
c25f5a86ae
11 changed files with 224 additions and 90 deletions
|
@ -7,50 +7,12 @@ import (
|
|||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||
)
|
||||
|
||||
// GetNetMapArgs groups the arguments
|
||||
// of get network map test invoke call.
|
||||
type GetNetMapArgs struct {
|
||||
}
|
||||
|
||||
// GetSnapshotArgs groups the arguments
|
||||
// of get netmap snapshot test invoke call.
|
||||
type GetSnapshotArgs struct {
|
||||
diff uint64
|
||||
}
|
||||
|
||||
// GetNetMapValues groups the stack parameters
|
||||
// returned by get network map test invoke.
|
||||
type GetNetMapValues struct {
|
||||
peers [][]byte
|
||||
}
|
||||
|
||||
// EpochSnapshotArgs groups the arguments
|
||||
// of snapshot by epoch test invoke call.
|
||||
type EpochSnapshotArgs struct {
|
||||
epoch uint64
|
||||
}
|
||||
|
||||
// EpochSnapshotValues groups the stack parameters
|
||||
// returned by snapshot by epoch test invoke.
|
||||
type EpochSnapshotValues struct {
|
||||
*GetNetMapValues
|
||||
}
|
||||
|
||||
// GetNetMapCandidatesArgs groups the arguments
|
||||
// of get network map candidates test invoke call.
|
||||
type GetNetMapCandidatesArgs struct {
|
||||
}
|
||||
|
||||
// GetNetMapCandidatesValues groups the stack parameters
|
||||
// returned by get network map candidates test invoke.
|
||||
type GetNetMapCandidatesValues struct {
|
||||
netmapNodes []*PeerWithState
|
||||
}
|
||||
|
||||
func (g GetNetMapCandidatesValues) NetmapNodes() []*PeerWithState {
|
||||
return g.netmapNodes
|
||||
}
|
||||
|
||||
// State is an enumeration of various states of the NeoFS node.
|
||||
type State int64
|
||||
|
||||
|
@ -86,23 +48,16 @@ const (
|
|||
peerWithStateFixedPrmNumber = 2
|
||||
)
|
||||
|
||||
// SetDiff sets argument for snapshot method of
|
||||
// netmap contract.
|
||||
func (g *GetSnapshotArgs) SetDiff(d uint64) {
|
||||
g.diff = d
|
||||
}
|
||||
|
||||
// SetEpoch sets epoch number to get snapshot.
|
||||
func (a *EpochSnapshotArgs) SetEpoch(d uint64) {
|
||||
a.epoch = d
|
||||
}
|
||||
|
||||
// Peers return the list of peers from
|
||||
// network map in a binary format.
|
||||
func (g GetNetMapValues) Peers() [][]byte {
|
||||
return g.peers
|
||||
}
|
||||
|
||||
// GetNetMapArgs groups the arguments
|
||||
// of get network map test invoke call.
|
||||
type GetNetMapArgs struct{}
|
||||
|
||||
// NetMap performs the test invoke of get network map
|
||||
// method of NeoFS Netmap contract.
|
||||
func (c *Client) NetMap(_ GetNetMapArgs) (*GetNetMapValues, error) {
|
||||
|
@ -118,6 +73,18 @@ func (c *Client) NetMap(_ GetNetMapArgs) (*GetNetMapValues, error) {
|
|||
return peersFromStackItems(prms, c.netMapMethod)
|
||||
}
|
||||
|
||||
// GetSnapshotArgs groups the arguments
|
||||
// of get netmap snapshot test invoke call.
|
||||
type GetSnapshotArgs struct {
|
||||
diff uint64
|
||||
}
|
||||
|
||||
// SetDiff sets argument for snapshot method of
|
||||
// netmap contract.
|
||||
func (g *GetSnapshotArgs) SetDiff(d uint64) {
|
||||
g.diff = d
|
||||
}
|
||||
|
||||
// Snapshot performs the test invoke of get snapshot of network map
|
||||
// from NeoFS Netmap contract. Contract saves only one previous epoch,
|
||||
// so all invokes with diff > 1 return error.
|
||||
|
@ -136,6 +103,23 @@ func (c *Client) Snapshot(a GetSnapshotArgs) (*GetNetMapValues, error) {
|
|||
return peersFromStackItems(prms, c.snapshotMethod)
|
||||
}
|
||||
|
||||
// EpochSnapshotArgs groups the arguments
|
||||
// of snapshot by epoch test invoke call.
|
||||
type EpochSnapshotArgs struct {
|
||||
epoch uint64
|
||||
}
|
||||
|
||||
// SetEpoch sets epoch number to get snapshot.
|
||||
func (a *EpochSnapshotArgs) SetEpoch(d uint64) {
|
||||
a.epoch = d
|
||||
}
|
||||
|
||||
// EpochSnapshotValues groups the stack parameters
|
||||
// returned by snapshot by epoch test invoke.
|
||||
type EpochSnapshotValues struct {
|
||||
*GetNetMapValues
|
||||
}
|
||||
|
||||
// EpochSnapshot performs the test invoke of get snapshot of network map by epoch
|
||||
// from NeoFS Netmap contract.
|
||||
func (c *Client) EpochSnapshot(args EpochSnapshotArgs) (*EpochSnapshotValues, error) {
|
||||
|
@ -160,6 +144,20 @@ func (c *Client) EpochSnapshot(args EpochSnapshotArgs) (*EpochSnapshotValues, er
|
|||
}, nil
|
||||
}
|
||||
|
||||
// GetNetMapCandidatesArgs groups the arguments
|
||||
// of get network map candidates test invoke call.
|
||||
type GetNetMapCandidatesArgs struct{}
|
||||
|
||||
// GetNetMapCandidatesValues groups the stack parameters
|
||||
// returned by get network map candidates test invoke.
|
||||
type GetNetMapCandidatesValues struct {
|
||||
netmapNodes []*PeerWithState
|
||||
}
|
||||
|
||||
func (g GetNetMapCandidatesValues) NetmapNodes() []*PeerWithState {
|
||||
return g.netmapNodes
|
||||
}
|
||||
|
||||
func (c *Client) Candidates(_ GetNetMapCandidatesArgs) (*GetNetMapCandidatesValues, error) {
|
||||
invokePrm := client.TestInvokePrm{}
|
||||
invokePrm.SetMethod(c.netMapCandidatesMethod)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue