2021-11-02 13:26:39 +00:00
|
|
|
package internal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-01-13 15:01:50 +00:00
|
|
|
coreclient "github.com/nspcc-dev/neofs-node/pkg/core/client"
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/client"
|
2021-11-06 11:13:04 +00:00
|
|
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/reputation"
|
2021-11-02 13:26:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type commonPrm struct {
|
2022-01-13 15:01:50 +00:00
|
|
|
cli coreclient.Client
|
2021-11-02 13:26:39 +00:00
|
|
|
|
|
|
|
ctx context.Context
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetClient sets base client for NeoFS API communication.
|
|
|
|
//
|
|
|
|
// Required parameter.
|
2022-01-13 15:01:50 +00:00
|
|
|
func (x *commonPrm) SetClient(cli coreclient.Client) {
|
2021-11-02 13:26:39 +00:00
|
|
|
x.cli = cli
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetContext sets context.Context for network communication.
|
|
|
|
//
|
|
|
|
// Required parameter.
|
|
|
|
func (x *commonPrm) SetContext(ctx context.Context) {
|
|
|
|
x.ctx = ctx
|
|
|
|
}
|
|
|
|
|
|
|
|
// AnnounceLocalPrm groups parameters of AnnounceLocal operation.
|
|
|
|
type AnnounceLocalPrm struct {
|
|
|
|
commonPrm
|
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
cliPrm client.PrmAnnounceLocalTrust
|
2021-11-02 13:26:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetEpoch sets epoch in which the trust was assessed.
|
|
|
|
func (x *AnnounceLocalPrm) SetEpoch(epoch uint64) {
|
|
|
|
x.cliPrm.SetEpoch(epoch)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetTrusts sets list of local trust values.
|
2022-01-21 16:53:06 +00:00
|
|
|
func (x *AnnounceLocalPrm) SetTrusts(ts []reputation.Trust) {
|
|
|
|
x.cliPrm.SetValues(ts)
|
2021-11-02 13:26:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AnnounceLocalRes groups resulting values of AnnounceLocal operation.
|
|
|
|
type AnnounceLocalRes struct{}
|
|
|
|
|
|
|
|
// AnnounceLocal sends estimations of local trust to the remote node.
|
|
|
|
//
|
|
|
|
// Client, context and key must be set.
|
2021-11-03 17:13:16 +00:00
|
|
|
//
|
|
|
|
// Returns any error prevented the operation from completing correctly in error return.
|
2021-11-02 13:26:39 +00:00
|
|
|
func AnnounceLocal(prm AnnounceLocalPrm) (res AnnounceLocalRes, err error) {
|
2022-02-25 09:20:49 +00:00
|
|
|
var cliRes *client.ResAnnounceLocalTrust
|
2021-11-06 11:13:04 +00:00
|
|
|
|
2022-01-21 16:53:06 +00:00
|
|
|
cliRes, err = prm.cli.AnnounceLocalTrust(prm.ctx, prm.cliPrm)
|
2021-11-06 11:13:04 +00:00
|
|
|
if err == nil {
|
|
|
|
// pull out an error from status
|
|
|
|
err = apistatus.ErrFromStatus(cliRes.Status())
|
|
|
|
}
|
2021-11-02 13:26:39 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// AnnounceIntermediatePrm groups parameters of AnnounceIntermediate operation.
|
|
|
|
type AnnounceIntermediatePrm struct {
|
|
|
|
commonPrm
|
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
cliPrm client.PrmAnnounceIntermediateTrust
|
2021-11-02 13:26:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetEpoch sets number of the epoch when the trust calculation's iteration was executed.
|
|
|
|
func (x *AnnounceIntermediatePrm) SetEpoch(epoch uint64) {
|
|
|
|
x.cliPrm.SetEpoch(epoch)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetIteration sets number of the iteration of the trust calculation algorithm.
|
|
|
|
func (x *AnnounceIntermediatePrm) SetIteration(iter uint32) {
|
|
|
|
x.cliPrm.SetIteration(iter)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetTrust sets current global trust value computed at the iteration.
|
2022-01-21 16:53:06 +00:00
|
|
|
func (x *AnnounceIntermediatePrm) SetTrust(t reputation.PeerToPeerTrust) {
|
|
|
|
x.cliPrm.SetCurrentValue(t)
|
2021-11-02 13:26:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AnnounceIntermediateRes groups resulting values of AnnounceIntermediate operation.
|
|
|
|
type AnnounceIntermediateRes struct{}
|
|
|
|
|
|
|
|
// AnnounceIntermediate sends global trust value calculated at the specified iteration
|
|
|
|
// and epoch to to the remote node.
|
|
|
|
//
|
|
|
|
// Client, context and key must be set.
|
2021-11-03 17:13:16 +00:00
|
|
|
//
|
|
|
|
// Returns any error prevented the operation from completing correctly in error return.
|
2021-11-02 13:26:39 +00:00
|
|
|
func AnnounceIntermediate(prm AnnounceIntermediatePrm) (res AnnounceIntermediateRes, err error) {
|
2022-02-25 09:20:49 +00:00
|
|
|
var cliRes *client.ResAnnounceIntermediateTrust
|
2021-11-06 11:13:04 +00:00
|
|
|
|
2022-01-21 16:53:06 +00:00
|
|
|
cliRes, err = prm.cli.AnnounceIntermediateTrust(prm.ctx, prm.cliPrm)
|
2021-11-06 11:13:04 +00:00
|
|
|
if err == nil {
|
|
|
|
// pull out an error from status
|
|
|
|
err = apistatus.ErrFromStatus(cliRes.Status())
|
|
|
|
}
|
2021-11-02 13:26:39 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|