[#971] morph/container: Add optional parameters

Add optional parameters to the client call
signature.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-11-12 18:14:55 +03:00 committed by Alex Vanin
parent 822d73fb02
commit af33dd65b2
8 changed files with 214 additions and 30 deletions

View file

@ -14,6 +14,8 @@ type DeleteArgs struct {
sig []byte // container identifier signature sig []byte // container identifier signature
token []byte // binary session token token []byte // binary session token
client.InvokePrmOptional
} }
// SetCID sets the container identifier // SetCID sets the container identifier
@ -42,6 +44,7 @@ func (c *Client) Delete(args DeleteArgs) error {
prm.SetMethod(c.deleteMethod) prm.SetMethod(c.deleteMethod)
prm.SetArgs(args.cid, args.sig, args.token) prm.SetArgs(args.cid, args.sig, args.token)
prm.InvokePrmOptional = args.InvokePrmOptional
err := c.client.Invoke(prm) err := c.client.Invoke(prm)

View file

@ -16,6 +16,8 @@ type SetEACLArgs struct {
pubkey []byte // binary public key pubkey []byte // binary public key
token []byte // binary session token token []byte // binary session token
client.InvokePrmOptional
} }
// SetEACL sets the extended ACL table // SetEACL sets the extended ACL table
@ -50,6 +52,7 @@ func (c *Client) SetEACL(args SetEACLArgs) error {
prm.SetMethod(c.setEACLMethod) prm.SetMethod(c.setEACLMethod)
prm.SetArgs(args.eacl, args.sig, args.pubkey, args.token) prm.SetArgs(args.eacl, args.sig, args.pubkey, args.token)
prm.InvokePrmOptional = args.InvokePrmOptional
err := c.client.Invoke(prm) err := c.client.Invoke(prm)

View file

@ -6,8 +6,11 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/client"
) )
// StartEstimation groups parameters of StartEstimation operation.
type StartEstimation struct { type StartEstimation struct {
epoch int64 epoch int64
client.InvokePrmOptional
} }
func (e *StartEstimation) SetEpoch(v int64) { func (e *StartEstimation) SetEpoch(v int64) {
@ -16,6 +19,8 @@ func (e *StartEstimation) SetEpoch(v int64) {
type StopEstimation struct { type StopEstimation struct {
epoch int64 epoch int64
client.InvokePrmOptional
} }
func (e *StopEstimation) SetEpoch(v int64) { func (e *StopEstimation) SetEpoch(v int64) {
@ -27,6 +32,7 @@ func (c *Client) StartEstimation(args StartEstimation) error {
prm.SetMethod(c.startEstimation) prm.SetMethod(c.startEstimation)
prm.SetArgs(args.epoch) prm.SetArgs(args.epoch)
prm.InvokePrmOptional = args.InvokePrmOptional
if err := c.client.Invoke(prm); err != nil { if err := c.client.Invoke(prm); err != nil {
return fmt.Errorf("could not invoke method (%s): %w", c.startEstimation, err) return fmt.Errorf("could not invoke method (%s): %w", c.startEstimation, err)
@ -39,6 +45,7 @@ func (c *Client) StopEstimation(args StopEstimation) error {
prm.SetMethod(c.stopEstimation) prm.SetMethod(c.stopEstimation)
prm.SetArgs(args.epoch) prm.SetArgs(args.epoch)
prm.InvokePrmOptional = args.InvokePrmOptional
if err := c.client.Invoke(prm); err != nil { if err := c.client.Invoke(prm); err != nil {
return fmt.Errorf("could not invoke method (%s): %w", c.stopEstimation, err) return fmt.Errorf("could not invoke method (%s): %w", c.stopEstimation, err)

View file

@ -16,6 +16,8 @@ type PutSizeArgs struct {
cid []byte cid []byte
reporterKey []byte reporterKey []byte
client.InvokePrmOptional
} }
// SetEpoch sets the number of the epoch when // SetEpoch sets the number of the epoch when
@ -48,6 +50,7 @@ func (c *Client) PutSize(args PutSizeArgs) error {
prm.SetMethod(c.putSizeMethod) prm.SetMethod(c.putSizeMethod)
prm.SetArgs(args.epoch, args.cid, args.size, args.reporterKey) prm.SetArgs(args.epoch, args.cid, args.size, args.reporterKey)
prm.InvokePrmOptional = args.InvokePrmOptional
err := c.client.Invoke(prm) err := c.client.Invoke(prm)

View file

@ -18,6 +18,8 @@ type PutArgs struct {
token []byte // binary session token token []byte // binary session token
name, zone string // native name and zone name, zone string // native name and zone
client.InvokePrmOptional
} }
// SetPublicKey sets the public key of container owner // SetPublicKey sets the public key of container owner
@ -69,6 +71,7 @@ func (c *Client) Put(args PutArgs) error {
} }
prm.SetMethod(method) prm.SetMethod(method)
prm.InvokePrmOptional = args.InvokePrmOptional
err := c.client.Invoke(prm) err := c.client.Invoke(prm)
if err != nil { if err != nil {

View file

@ -7,6 +7,7 @@ import (
v2refs "github.com/nspcc-dev/neofs-api-go/v2/refs" v2refs "github.com/nspcc-dev/neofs-api-go/v2/refs"
core "github.com/nspcc-dev/neofs-node/pkg/core/container" core "github.com/nspcc-dev/neofs-node/pkg/core/container"
staticli "github.com/nspcc-dev/neofs-node/pkg/morph/client"
client "github.com/nspcc-dev/neofs-node/pkg/morph/client/container" client "github.com/nspcc-dev/neofs-node/pkg/morph/client/container"
"github.com/nspcc-dev/neofs-sdk-go/container" "github.com/nspcc-dev/neofs-sdk-go/container"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id" cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
@ -43,7 +44,14 @@ func Put(w *Wrapper, cnr *container.Container) (*cid.ID, error) {
name, zone := container.GetNativeNameWithZone(cnr) name, zone := container.GetNativeNameWithZone(cnr)
err = w.Put(data, sig.Key(), sig.Sign(), binToken, name, zone) err = w.Put(PutPrm{
cnr: data,
key: sig.Key(),
sig: sig.Sign(),
token: binToken,
name: name,
zone: zone,
})
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -54,6 +62,48 @@ func Put(w *Wrapper, cnr *container.Container) (*cid.ID, error) {
return id, nil return id, nil
} }
// PutPrm groups parameters of Put operation.
type PutPrm struct {
cnr []byte
key []byte
sig []byte
token []byte
name string
zone string
staticli.InvokePrmOptional
}
// SetContainer sets container data.
func (p *PutPrm) SetContainer(cnr []byte) {
p.cnr = cnr
}
// SetKey sets public key.
func (p *PutPrm) SetKey(key []byte) {
p.key = key
}
// SetSignature sets signature.
func (p *PutPrm) SetSignature(sig []byte) {
p.sig = sig
}
// SetToken sets session token.
func (p *PutPrm) SetToken(token []byte) {
p.token = token
}
// SetName sets native name.
func (p *PutPrm) SetName(name string) {
p.name = name
}
// SetZone sets zone.
func (p *PutPrm) SetZone(zone string) {
p.zone = zone
}
// Put saves binary container with its session token, key and signature // Put saves binary container with its session token, key and signature
// in NeoFS system through Container contract call. // in NeoFS system through Container contract call.
// //
@ -61,18 +111,19 @@ func Put(w *Wrapper, cnr *container.Container) (*cid.ID, error) {
// encountered that caused the saving to interrupt. // encountered that caused the saving to interrupt.
// //
// If TryNotary is provided, calls notary contract. // If TryNotary is provided, calls notary contract.
func (w *Wrapper) Put(cnr, key, sig, token []byte, name, zone string) error { func (w *Wrapper) Put(prm PutPrm) error {
if len(sig) == 0 || len(key) == 0 { if len(prm.sig) == 0 || len(prm.key) == 0 {
return errNilArgument return errNilArgument
} }
var args client.PutArgs var args client.PutArgs
args.SetContainer(cnr) args.SetContainer(prm.cnr)
args.SetSignature(sig) args.SetSignature(prm.sig)
args.SetPublicKey(key) args.SetPublicKey(prm.key)
args.SetSessionToken(token) args.SetSessionToken(prm.token)
args.SetNativeNameWithZone(name, zone) args.SetNativeNameWithZone(prm.name, prm.zone)
args.InvokePrmOptional = prm.InvokePrmOptional
err := w.client.Put(args) err := w.client.Put(args)
if err != nil { if err != nil {
@ -167,7 +218,36 @@ func Delete(w *Wrapper, witness core.RemovalWitness) error {
return fmt.Errorf("could not marshal session token: %w", err) return fmt.Errorf("could not marshal session token: %w", err)
} }
return w.Delete(id.ToV2().GetValue(), witness.Signature(), binToken) return w.Delete(
DeletePrm{
cid: id.ToV2().GetValue(),
signature: witness.Signature(),
token: binToken,
})
}
// DeletePrm groups parameters of Delete client operation.
type DeletePrm struct {
cid []byte
signature []byte
token []byte
staticli.InvokePrmOptional
}
// SetCID sets container ID.
func (d *DeletePrm) SetCID(cid []byte) {
d.cid = cid
}
// SetSignature sets signature.
func (d *DeletePrm) SetSignature(signature []byte) {
d.signature = signature
}
// SetToken sets session token.
func (d *DeletePrm) SetToken(token []byte) {
d.token = token
} }
// Delete removes the container from NeoFS system // Delete removes the container from NeoFS system
@ -177,16 +257,17 @@ func Delete(w *Wrapper, witness core.RemovalWitness) error {
// the removal to interrupt. // the removal to interrupt.
// //
// If TryNotary is provided, calls notary contract. // If TryNotary is provided, calls notary contract.
func (w *Wrapper) Delete(cid, signature, token []byte) error { func (w *Wrapper) Delete(prm DeletePrm) error {
if len(signature) == 0 { if len(prm.signature) == 0 {
return errNilArgument return errNilArgument
} }
var args client.DeleteArgs var args client.DeleteArgs
args.SetSignature(signature) args.SetSignature(prm.signature)
args.SetCID(cid) args.SetCID(prm.cid)
args.SetSessionToken(token) args.SetSessionToken(prm.token)
args.InvokePrmOptional = prm.InvokePrmOptional
return w.client.Delete(args) return w.client.Delete(args)
} }
@ -229,21 +310,40 @@ func (w *Wrapper) List(ownerID *owner.ID) ([]*cid.ID, error) {
return result, nil return result, nil
} }
// AnnounceLoadPrm groups parameters of AnnounceLoad operation.
type AnnounceLoadPrm struct {
a container.UsedSpaceAnnouncement
key []byte
staticli.InvokePrmOptional
}
// SetAnnouncement sets announcement.
func (a2 *AnnounceLoadPrm) SetAnnouncement(a container.UsedSpaceAnnouncement) {
a2.a = a
}
// SetReporter sets public key of the reporter.
func (a2 *AnnounceLoadPrm) SetReporter(key []byte) {
a2.key = key
}
// AnnounceLoad saves container size estimation calculated by storage node // AnnounceLoad saves container size estimation calculated by storage node
// with key in NeoFS system through Container contract call. // with key in NeoFS system through Container contract call.
// //
// Returns any error encountered that caused the saving to interrupt. // Returns any error encountered that caused the saving to interrupt.
func (w *Wrapper) AnnounceLoad(a container.UsedSpaceAnnouncement, key []byte) error { func (w *Wrapper) AnnounceLoad(prm AnnounceLoadPrm) error {
v2 := a.ContainerID().ToV2() v2 := prm.a.ContainerID().ToV2()
if v2 == nil { if v2 == nil {
return errUnsupported // use other major version if there any return errUnsupported // use other major version if there any
} }
args := client.PutSizeArgs{} args := client.PutSizeArgs{}
args.SetContainerID(v2.GetValue()) args.SetContainerID(v2.GetValue())
args.SetEpoch(a.Epoch()) args.SetEpoch(prm.a.Epoch())
args.SetSize(a.UsedSpace()) args.SetSize(prm.a.UsedSpace())
args.SetReporterKey(key) args.SetReporterKey(prm.key)
args.InvokePrmOptional = prm.InvokePrmOptional
return w.client.PutSize(args) return w.client.PutSize(args)
} }

View file

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"github.com/nspcc-dev/neofs-node/pkg/core/container" "github.com/nspcc-dev/neofs-node/pkg/core/container"
staticli "github.com/nspcc-dev/neofs-node/pkg/morph/client"
client "github.com/nspcc-dev/neofs-node/pkg/morph/client/container" client "github.com/nspcc-dev/neofs-node/pkg/morph/client/container"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id" cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
"github.com/nspcc-dev/neofs-sdk-go/eacl" "github.com/nspcc-dev/neofs-sdk-go/eacl"
@ -90,23 +91,60 @@ func PutEACL(w *Wrapper, table *eacl.Table) error {
sig := table.Signature() sig := table.Signature()
return w.PutEACL(data, sig.Key(), sig.Sign(), binToken) return w.PutEACL(
PutEACLPrm{
table: data,
key: sig.Key(),
sig: sig.Sign(),
token: binToken,
})
}
// PutEACLPrm groups parameters of PutEACL operation.
type PutEACLPrm struct {
table []byte
key []byte
sig []byte
token []byte
staticli.InvokePrmOptional
}
// SetTable sets table.
func (p *PutEACLPrm) SetTable(table []byte) {
p.table = table
}
// SetKey sets key.
func (p *PutEACLPrm) SetKey(key []byte) {
p.key = key
}
// SetSignature sets signature.
func (p *PutEACLPrm) SetSignature(sig []byte) {
p.sig = sig
}
// SetToken sets session token.
func (p *PutEACLPrm) SetToken(token []byte) {
p.token = token
} }
// PutEACL saves binary eACL table with its session token, key and signature // PutEACL saves binary eACL table with its session token, key and signature
// in NeoFS system through Container contract call. // in NeoFS system through Container contract call.
// //
// Returns any error encountered that caused the saving to interrupt. // Returns any error encountered that caused the saving to interrupt.
func (w *Wrapper) PutEACL(table, key, sig, token []byte) error { func (w *Wrapper) PutEACL(prm PutEACLPrm) error {
if len(sig) == 0 || len(key) == 0 { if len(prm.sig) == 0 || len(prm.key) == 0 {
return errNilArgument return errNilArgument
} }
args := client.SetEACLArgs{} args := client.SetEACLArgs{}
args.SetSignature(sig) args.SetSignature(prm.sig)
args.SetPublicKey(key) args.SetPublicKey(prm.key)
args.SetEACL(table) args.SetEACL(prm.table)
args.SetSessionToken(token) args.SetSessionToken(prm.token)
args.InvokePrmOptional = prm.InvokePrmOptional
return w.client.SetEACL(args) return w.client.SetEACL(args)
} }

View file

@ -1,21 +1,48 @@
package wrapper package wrapper
import ( import (
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/container" "github.com/nspcc-dev/neofs-node/pkg/morph/client/container"
) )
// StartEstimationPrm groups parameters of StartEstimation operation.
type StartEstimationPrm struct {
epoch uint64
client.InvokePrmOptional
}
// SetEpoch sets epoch.
func (s *StartEstimationPrm) SetEpoch(epoch uint64) {
s.epoch = epoch
}
// StartEstimation votes to produce start estimation notification. // StartEstimation votes to produce start estimation notification.
func (w *Wrapper) StartEstimation(epoch uint64) error { func (w *Wrapper) StartEstimation(prm StartEstimationPrm) error {
args := container.StartEstimation{} args := container.StartEstimation{}
args.SetEpoch(int64(epoch)) args.SetEpoch(int64(prm.epoch))
args.InvokePrmOptional = prm.InvokePrmOptional
return w.client.StartEstimation(args) return w.client.StartEstimation(args)
} }
// StopEstimationPrm groups parameters of StopEstimation operation.
type StopEstimationPrm struct {
epoch uint64
client.InvokePrmOptional
}
// SetEpoch sets epoch.
func (s *StopEstimationPrm) SetEpoch(epoch uint64) {
s.epoch = epoch
}
// StopEstimation votes to produce stop estimation notification. // StopEstimation votes to produce stop estimation notification.
func (w *Wrapper) StopEstimation(epoch uint64) error { func (w *Wrapper) StopEstimation(prm StopEstimationPrm) error {
args := container.StopEstimation{} args := container.StopEstimation{}
args.SetEpoch(int64(epoch)) args.SetEpoch(int64(prm.epoch))
args.InvokePrmOptional = prm.InvokePrmOptional
return w.client.StopEstimation(args) return w.client.StopEstimation(args)
} }