Resolved containedctx linters. Renamed context structs and interfaces to more understandble names. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
65 lines
2.1 KiB
Go
65 lines
2.1 KiB
Go
package intermediate
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/reputation"
|
|
reputationcommon "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/reputation/common"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/reputation/eigentrust"
|
|
eigencalc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/reputation/eigentrust/calculator"
|
|
consumerstorage "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/reputation/eigentrust/storage/consumers"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
var ErrIncorrectContextPanicMsg = "could not write intermediate trust: passed context incorrect"
|
|
|
|
// ConsumerStorageWriterProvider is an implementation of the reputation.WriterProvider
|
|
// interface that provides ConsumerTrustWriter writer.
|
|
type ConsumerStorageWriterProvider struct {
|
|
Log *logger.Logger
|
|
Storage *consumerstorage.Storage
|
|
}
|
|
|
|
// ConsumerTrustWriter is an implementation of the reputation.Writer interface
|
|
// that writes passed consumer's Trust values to the Consumer storage. After writing
|
|
// that, values can be used in eigenTrust algorithm's iterations.
|
|
type ConsumerTrustWriter struct {
|
|
log *logger.Logger
|
|
storage *consumerstorage.Storage
|
|
iterInfo eigencalc.EpochIterationInfo
|
|
}
|
|
|
|
func (w *ConsumerTrustWriter) Write(_ context.Context, t reputation.Trust) error {
|
|
w.log.Debug("writing received consumer's trusts",
|
|
zap.Uint64("epoch", w.iterInfo.Epoch()),
|
|
zap.Uint32("iteration", w.iterInfo.I()),
|
|
zap.Stringer("trusting_peer", t.TrustingPeer()),
|
|
zap.Stringer("trusted_peer", t.Peer()),
|
|
)
|
|
|
|
trust := eigentrust.IterationTrust{Trust: t}
|
|
|
|
trust.SetEpoch(w.iterInfo.Epoch())
|
|
trust.SetI(w.iterInfo.I())
|
|
|
|
w.storage.Put(trust)
|
|
return nil
|
|
}
|
|
|
|
func (w *ConsumerTrustWriter) Close(context.Context) error {
|
|
return nil
|
|
}
|
|
|
|
func (s *ConsumerStorageWriterProvider) InitWriter(ep reputationcommon.EpochProvider) (reputationcommon.Writer, error) {
|
|
iterInfo, ok := ep.(eigencalc.EpochIterationInfo)
|
|
if !ok {
|
|
panic(ErrIncorrectContextPanicMsg)
|
|
}
|
|
|
|
return &ConsumerTrustWriter{
|
|
log: s.Log,
|
|
storage: s.Storage,
|
|
iterInfo: iterInfo,
|
|
}, nil
|
|
}
|