2021-11-09 08:07:49 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-03-07 11:20:03 +00:00
|
|
|
v2reputation "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/reputation"
|
|
|
|
rpcapi "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/reputation"
|
2021-11-09 08:07:49 +00:00
|
|
|
)
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// SetEpoch sets number of FrostFS epoch in which the trust was assessed.
|
2021-12-02 12:21:54 +00:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// SetValues sets values describing trust of the client to the FrostFS network participants.
|
2021-12-02 12:21:54 +00:00
|
|
|
// 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
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// AnnounceLocalTrust sends client's trust values to the FrostFS 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-12-29 10:46:18 +00:00
|
|
|
// If PrmInit.ResolveFrostFSFailures has been called, unsuccessful
|
|
|
|
// FrostFS status codes are returned as `error`, otherwise, are included
|
2022-01-11 12:44:22 +00:00
|
|
|
// in the returned result structure.
|
2021-12-02 12:21:54 +00:00
|
|
|
//
|
2023-02-27 07:53:27 +00:00
|
|
|
// Returns an error 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:
|
2022-08-24 14:17:40 +00:00
|
|
|
// - 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 prm.epoch == 0:
|
2023-02-27 07:53:27 +00:00
|
|
|
return nil, errorZeroEpoch
|
2021-12-02 12:21:54 +00:00
|
|
|
case len(prm.trusts) == 0:
|
2023-02-27 07:53:27 +00:00
|
|
|
return nil, errorMissingTrusts
|
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
|
|
|
}
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// SetEpoch sets number of FrostFS epoch with which client's calculation algorithm is initialized.
|
2021-12-02 12:21:54 +00:00
|
|
|
// 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
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// AnnounceIntermediateTrust sends global trust values calculated for the specified FrostFS network participants
|
2021-12-02 12:21:54 +00:00
|
|
|
// 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-12-29 10:46:18 +00:00
|
|
|
// If PrmInit.ResolveFrostFSFailures has been called, unsuccessful
|
|
|
|
// FrostFS status codes are returned as `error`, otherwise, are included
|
2022-01-11 12:44:22 +00:00
|
|
|
// in the returned result structure.
|
2021-12-02 12:21:54 +00:00
|
|
|
//
|
2023-02-27 07:53:27 +00:00
|
|
|
// Returns an error 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:
|
2022-08-24 14:17:40 +00:00
|
|
|
// - 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 prm.epoch == 0:
|
2023-02-27 07:53:27 +00:00
|
|
|
return nil, errorZeroEpoch
|
2021-12-02 12:21:54 +00:00
|
|
|
case !prm.trustSet:
|
2023-02-27 07:53:27 +00:00
|
|
|
return nil, errorTrustNotSet
|
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
|
|
|
}
|