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"
|
|
|
|
)
|
|
|
|
|
|
|
|
// AnnounceLocalTrustPrm groups parameters of AnnounceLocalTrust operation.
|
|
|
|
type AnnounceLocalTrustPrm struct {
|
|
|
|
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.
|
2021-11-09 08:07:49 +00:00
|
|
|
func (x *AnnounceLocalTrustPrm) SetEpoch(epoch uint64) {
|
|
|
|
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.
|
|
|
|
func (x *AnnounceLocalTrustPrm) SetValues(trusts []reputation.Trust) {
|
2021-11-09 08:07:49 +00:00
|
|
|
x.trusts = trusts
|
|
|
|
}
|
|
|
|
|
|
|
|
// AnnounceLocalTrustRes groups results of AnnounceLocalTrust operation.
|
2021-11-16 18:17:25 +00:00
|
|
|
type AnnounceLocalTrustRes struct {
|
|
|
|
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-11 12:44:22 +00:00
|
|
|
// Any client's internal or transport errors are returned as `error`.
|
|
|
|
// If WithNeoFSErrorParsing option has been provided, unsuccessful
|
|
|
|
// NeoFS status codes are returned as `error`, otherwise, are included
|
|
|
|
// in the returned result structure.
|
2021-12-02 12:21:54 +00:00
|
|
|
//
|
|
|
|
// Immediately panics if parameters are set incorrectly (see AnnounceLocalTrustPrm docs).
|
|
|
|
// Context is required and must not be nil. It is used for network communication.
|
|
|
|
//
|
|
|
|
// Exactly one return value is non-nil. Server status return is returned in AnnounceLocalTrustRes.
|
|
|
|
// Reflects all internal errors in second return value (transport problems, response processing, etc.).
|
|
|
|
func (c *Client) AnnounceLocalTrust(ctx context.Context, prm AnnounceLocalTrustPrm) (*AnnounceLocalTrustRes, error) {
|
|
|
|
// 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
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
trusts := make([]*reputation.Trust, 0, len(prm.trusts))
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
for i := range prm.trusts {
|
|
|
|
trusts = append(trusts, &prm.trusts[i])
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
reqBody.SetTrusts(reputation.TrustsToV2(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
|
|
|
|
res AnnounceLocalTrustRes
|
|
|
|
)
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
c.initCallContext(&cc)
|
|
|
|
cc.req = &req
|
|
|
|
cc.statusRes = &res
|
|
|
|
cc.call = func() (responseV2, error) {
|
|
|
|
return rpcapi.AnnounceLocalTrust(c.Raw(), &req, client.WithContext(ctx))
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// AnnounceIntermediateTrustPrm groups parameters of AnnounceIntermediateTrust operation.
|
|
|
|
type AnnounceIntermediateTrustPrm struct {
|
|
|
|
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.
|
2021-11-09 08:07:49 +00:00
|
|
|
func (x *AnnounceIntermediateTrustPrm) SetEpoch(epoch uint64) {
|
|
|
|
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.
|
2021-11-09 08:07:49 +00:00
|
|
|
func (x *AnnounceIntermediateTrustPrm) SetIteration(iter uint32) {
|
|
|
|
x.iter = iter
|
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// SetCurrentValue sets current global trust value computed at the specified iteration
|
|
|
|
//of the client's calculation algorithm. Required parameter.
|
|
|
|
func (x *AnnounceIntermediateTrustPrm) 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
|
|
|
}
|
|
|
|
|
|
|
|
// AnnounceIntermediateTrustRes groups results of AnnounceIntermediateTrust operation.
|
2021-11-16 18:17:25 +00:00
|
|
|
type AnnounceIntermediateTrustRes struct {
|
|
|
|
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-11 12:44:22 +00:00
|
|
|
// Any client's internal or transport errors are returned as `error`.
|
|
|
|
// If WithNeoFSErrorParsing option has been provided, unsuccessful
|
|
|
|
// NeoFS status codes are returned as `error`, otherwise, are included
|
|
|
|
// in the returned result structure.
|
2021-12-02 12:21:54 +00:00
|
|
|
//
|
|
|
|
// Immediately panics if parameters are set incorrectly (see AnnounceIntermediateTrustPrm docs).
|
|
|
|
// Context is required and must not be nil. It is used for network communication.
|
|
|
|
//
|
|
|
|
// Exactly one return value is non-nil. Server status return is returned in AnnounceIntermediateTrustRes.
|
|
|
|
// Reflects all internal errors in second return value (transport problems, response processing, etc.).
|
|
|
|
func (c *Client) AnnounceIntermediateTrust(ctx context.Context, prm AnnounceIntermediateTrustPrm) (*AnnounceIntermediateTrustRes, error) {
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
reqBody.SetTrust(prm.trust.ToV2())
|
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
|
|
|
|
res AnnounceIntermediateTrustRes
|
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)
|
|
|
|
cc.req = &req
|
|
|
|
cc.statusRes = &res
|
|
|
|
cc.call = func() (responseV2, error) {
|
|
|
|
return rpcapi.AnnounceIntermediateResult(c.Raw(), &req, client.WithContext(ctx))
|
|
|
|
}
|
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
|
|
|
}
|