forked from TrueCloudLab/frostfs-node
Drop duplicate entities. Format entities. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com> Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
51 lines
1.6 KiB
Go
51 lines
1.6 KiB
Go
package intermediate
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
|
"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/storage/daughters"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// DaughterStorageWriterProvider is an implementation of the reputation.WriterProvider
|
|
// interface that provides DaughterTrustWriter writer.
|
|
type DaughterStorageWriterProvider struct {
|
|
Log *logger.Logger
|
|
Storage *daughters.Storage
|
|
}
|
|
|
|
// DaughterTrustWriter is an implementation of the reputation.Writer interface
|
|
// that writes passed daughter's Trust values to Daughter storage. After writing
|
|
// that, values can be used in eigenTrust algorithm's iterations.
|
|
type DaughterTrustWriter struct {
|
|
log *logger.Logger
|
|
storage *daughters.Storage
|
|
ep reputationcommon.EpochProvider
|
|
}
|
|
|
|
func (w *DaughterTrustWriter) Write(_ context.Context, t reputation.Trust) error {
|
|
w.log.Debug(logs.IntermediateWritingReceivedDaughtersTrusts,
|
|
zap.Uint64("epoch", w.ep.Epoch()),
|
|
zap.Stringer("trusting_peer", t.TrustingPeer()),
|
|
zap.Stringer("trusted_peer", t.Peer()),
|
|
)
|
|
|
|
w.storage.Put(w.ep.Epoch(), t)
|
|
return nil
|
|
}
|
|
|
|
func (w *DaughterTrustWriter) Close(context.Context) error {
|
|
return nil
|
|
}
|
|
|
|
func (s *DaughterStorageWriterProvider) InitWriter(ep reputationcommon.EpochProvider) (reputationcommon.Writer, error) {
|
|
return &DaughterTrustWriter{
|
|
log: s.Log,
|
|
storage: s.Storage,
|
|
ep: ep,
|
|
}, nil
|
|
}
|