2021-11-09 08:07:49 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
v2reputation "github.com/nspcc-dev/neofs-api-go/v2/reputation"
|
|
|
|
rpcapi "github.com/nspcc-dev/neofs-api-go/v2/rpc"
|
2021-11-16 18:15:56 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
|
2021-11-09 08:07:49 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/reputation"
|
|
|
|
)
|
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// PrmAnnounceLocalTrust groups parameters of AnnounceLocalTrust operation.
|
|
|
|
type PrmAnnounceLocalTrust struct {
|
2022-03-03 11:04:53 +00:00
|
|
|
prmCommonMeta
|
|
|
|
|
2021-11-09 08:07:49 +00:00
|
|
|
epoch uint64
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
trusts []reputation.Trust
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// SetEpoch sets number of NeoFS epoch in which the trust was assessed.
|
|
|
|
// Required parameter, must not be zero.
|
2022-02-17 16:10:49 +00:00
|
|
|
func (x *PrmAnnounceLocalTrust) SetEpoch(epoch uint64) {
|
2021-11-09 08:07:49 +00:00
|
|
|
x.epoch = epoch
|
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// SetValues sets values describing trust of the client to the NeoFS network participants.
|
|
|
|
// Required parameter. Must not be empty.
|
|
|
|
//
|
|
|
|
// Must not be mutated before the end of the operation.
|
2022-02-17 16:10:49 +00:00
|
|
|
func (x *PrmAnnounceLocalTrust) SetValues(trusts []reputation.Trust) {
|
2021-11-09 08:07:49 +00:00
|
|
|
x.trusts = trusts
|
|
|
|
}
|
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// ResAnnounceLocalTrust groups results of AnnounceLocalTrust operation.
|
|
|
|
type ResAnnounceLocalTrust struct {
|
2021-11-16 18:17:25 +00:00
|
|
|
statusRes
|
|
|
|
}
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// AnnounceLocalTrust sends client's trust values to the NeoFS network participants.
|
2021-12-29 13:55:29 +00:00
|
|
|
//
|
2022-01-24 10:33:43 +00:00
|
|
|
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
2022-01-11 12:44:22 +00:00
|
|
|
// Any client's internal or transport errors are returned as `error`.
|
2022-07-04 15:33:33 +00:00
|
|
|
// If PrmInit.ResolveNeoFSFailures has been called, unsuccessful
|
2022-01-11 12:44:22 +00:00
|
|
|
// NeoFS status codes are returned as `error`, otherwise, are included
|
|
|
|
// in the returned result structure.
|
2021-12-02 12:21:54 +00:00
|
|
|
//
|
2022-02-17 16:10:49 +00:00
|
|
|
// Immediately panics if parameters are set incorrectly (see PrmAnnounceLocalTrust docs).
|
2021-12-02 12:21:54 +00:00
|
|
|
// Context is required and must not be nil. It is used for network communication.
|
|
|
|
//
|
2022-01-24 10:33:43 +00:00
|
|
|
// Return statuses:
|
|
|
|
// - global (see Client docs).
|
2022-02-17 16:10:49 +00:00
|
|
|
func (c *Client) AnnounceLocalTrust(ctx context.Context, prm PrmAnnounceLocalTrust) (*ResAnnounceLocalTrust, error) {
|
2021-12-02 12:21:54 +00:00
|
|
|
// check parameters
|
|
|
|
switch {
|
|
|
|
case ctx == nil:
|
|
|
|
panic(panicMsgMissingContext)
|
|
|
|
case prm.epoch == 0:
|
|
|
|
panic("zero epoch")
|
|
|
|
case len(prm.trusts) == 0:
|
|
|
|
panic("missing trusts")
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// form request body
|
2021-11-09 08:07:49 +00:00
|
|
|
reqBody := new(v2reputation.AnnounceLocalTrustRequestBody)
|
2021-12-02 12:21:54 +00:00
|
|
|
reqBody.SetEpoch(prm.epoch)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
trusts := make([]v2reputation.Trust, len(prm.trusts))
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
for i := range prm.trusts {
|
|
|
|
prm.trusts[i].WriteToV2(&trusts[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
reqBody.SetTrusts(trusts)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// form request
|
|
|
|
var req v2reputation.AnnounceLocalTrustRequest
|
|
|
|
|
|
|
|
req.SetBody(reqBody)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// init call context
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
var (
|
|
|
|
cc contextCall
|
2022-02-17 16:10:49 +00:00
|
|
|
res ResAnnounceLocalTrust
|
2021-12-02 12:21:54 +00:00
|
|
|
)
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
c.initCallContext(&cc)
|
2022-03-03 11:04:53 +00:00
|
|
|
cc.meta = prm.prmCommonMeta
|
2021-12-02 12:21:54 +00:00
|
|
|
cc.req = &req
|
|
|
|
cc.statusRes = &res
|
|
|
|
cc.call = func() (responseV2, error) {
|
2022-03-07 11:39:49 +00:00
|
|
|
return rpcapi.AnnounceLocalTrust(&c.c, &req, client.WithContext(ctx))
|
2021-12-02 12:21:54 +00:00
|
|
|
}
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// process call
|
|
|
|
if !cc.processCall() {
|
|
|
|
return nil, cc.err
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
return &res, nil
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// PrmAnnounceIntermediateTrust groups parameters of AnnounceIntermediateTrust operation.
|
|
|
|
type PrmAnnounceIntermediateTrust struct {
|
2022-03-03 11:04:53 +00:00
|
|
|
prmCommonMeta
|
|
|
|
|
2021-11-09 08:07:49 +00:00
|
|
|
epoch uint64
|
|
|
|
|
|
|
|
iter uint32
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
trustSet bool
|
|
|
|
trust reputation.PeerToPeerTrust
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// SetEpoch sets number of NeoFS epoch with which client's calculation algorithm is initialized.
|
|
|
|
// Required parameter, must not be zero.
|
2022-02-17 16:10:49 +00:00
|
|
|
func (x *PrmAnnounceIntermediateTrust) SetEpoch(epoch uint64) {
|
2021-11-09 08:07:49 +00:00
|
|
|
x.epoch = epoch
|
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// SetIteration sets current sequence number of the client's calculation algorithm.
|
|
|
|
// By default, corresponds to initial (zero) iteration.
|
2022-02-17 16:10:49 +00:00
|
|
|
func (x *PrmAnnounceIntermediateTrust) SetIteration(iter uint32) {
|
2021-11-09 08:07:49 +00:00
|
|
|
x.iter = iter
|
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// SetCurrentValue sets current global trust value computed at the specified iteration
|
2022-02-17 16:10:49 +00:00
|
|
|
// of the client's calculation algorithm. Required parameter.
|
|
|
|
func (x *PrmAnnounceIntermediateTrust) SetCurrentValue(trust reputation.PeerToPeerTrust) {
|
2021-11-09 08:07:49 +00:00
|
|
|
x.trust = trust
|
2021-12-02 12:21:54 +00:00
|
|
|
x.trustSet = true
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// ResAnnounceIntermediateTrust groups results of AnnounceIntermediateTrust operation.
|
|
|
|
type ResAnnounceIntermediateTrust struct {
|
2021-11-16 18:17:25 +00:00
|
|
|
statusRes
|
|
|
|
}
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// AnnounceIntermediateTrust sends global trust values calculated for the specified NeoFS network participants
|
|
|
|
// at some stage of client's calculation algorithm.
|
2021-12-29 13:55:29 +00:00
|
|
|
//
|
2022-01-24 10:33:43 +00:00
|
|
|
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
2022-01-11 12:44:22 +00:00
|
|
|
// Any client's internal or transport errors are returned as `error`.
|
2022-07-04 15:33:33 +00:00
|
|
|
// If PrmInit.ResolveNeoFSFailures has been called, unsuccessful
|
2022-01-11 12:44:22 +00:00
|
|
|
// NeoFS status codes are returned as `error`, otherwise, are included
|
|
|
|
// in the returned result structure.
|
2021-12-02 12:21:54 +00:00
|
|
|
//
|
2022-02-17 16:10:49 +00:00
|
|
|
// Immediately panics if parameters are set incorrectly (see PrmAnnounceIntermediateTrust docs).
|
2021-12-02 12:21:54 +00:00
|
|
|
// Context is required and must not be nil. It is used for network communication.
|
|
|
|
//
|
2022-01-24 10:33:43 +00:00
|
|
|
// Return statuses:
|
|
|
|
// - global (see Client docs).
|
2022-02-17 16:10:49 +00:00
|
|
|
func (c *Client) AnnounceIntermediateTrust(ctx context.Context, prm PrmAnnounceIntermediateTrust) (*ResAnnounceIntermediateTrust, error) {
|
2021-12-02 12:21:54 +00:00
|
|
|
// check parameters
|
|
|
|
switch {
|
|
|
|
case ctx == nil:
|
|
|
|
panic(panicMsgMissingContext)
|
|
|
|
case prm.epoch == 0:
|
|
|
|
panic("zero epoch")
|
|
|
|
case !prm.trustSet:
|
|
|
|
panic("current trust value not set")
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
var trust v2reputation.PeerToPeerTrust
|
|
|
|
prm.trust.WriteToV2(&trust)
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// form request body
|
2021-11-09 08:07:49 +00:00
|
|
|
reqBody := new(v2reputation.AnnounceIntermediateResultRequestBody)
|
2021-12-02 12:21:54 +00:00
|
|
|
reqBody.SetEpoch(prm.epoch)
|
|
|
|
reqBody.SetIteration(prm.iter)
|
2022-06-30 16:08:34 +00:00
|
|
|
reqBody.SetTrust(&trust)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// form request
|
|
|
|
var req v2reputation.AnnounceIntermediateResultRequest
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
req.SetBody(reqBody)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// init call context
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
var (
|
2021-12-02 12:21:54 +00:00
|
|
|
cc contextCall
|
2022-02-17 16:10:49 +00:00
|
|
|
res ResAnnounceIntermediateTrust
|
2021-11-16 18:17:25 +00:00
|
|
|
)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
c.initCallContext(&cc)
|
2022-03-03 11:04:53 +00:00
|
|
|
cc.meta = prm.prmCommonMeta
|
2021-12-02 12:21:54 +00:00
|
|
|
cc.req = &req
|
|
|
|
cc.statusRes = &res
|
|
|
|
cc.call = func() (responseV2, error) {
|
2022-03-07 11:39:49 +00:00
|
|
|
return rpcapi.AnnounceIntermediateResult(&c.c, &req, client.WithContext(ctx))
|
2021-12-02 12:21:54 +00:00
|
|
|
}
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// process call
|
|
|
|
if !cc.processCall() {
|
|
|
|
return nil, cc.err
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
return &res, nil
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|