2021-04-21 04:56:38 +00:00
|
|
|
package intermediate
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
|
|
|
reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/storage/daughters"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
2021-03-01 19:01:45 +00:00
|
|
|
"go.uber.org/zap"
|
2021-04-21 04:56:38 +00:00
|
|
|
)
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// DaughterStorageWriterProvider is an implementation of the reputation.WriterProvider
|
2021-04-29 06:33:09 +00:00
|
|
|
// interface that provides DaughterTrustWriter writer.
|
2021-04-23 14:51:51 +00:00
|
|
|
type DaughterStorageWriterProvider struct {
|
2021-04-21 04:56:38 +00:00
|
|
|
Log *logger.Logger
|
|
|
|
Storage *daughters.Storage
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// DaughterTrustWriter is an implementation of the reputation.Writer interface
|
2021-04-29 06:33:09 +00:00
|
|
|
// that writes passed daughter's Trust values to Daughter storage. After writing
|
2022-04-21 11:28:05 +00:00
|
|
|
// that, values can be used in eigenTrust algorithm's iterations.
|
2021-04-21 04:56:38 +00:00
|
|
|
type DaughterTrustWriter struct {
|
|
|
|
log *logger.Logger
|
|
|
|
storage *daughters.Storage
|
2021-05-04 06:16:51 +00:00
|
|
|
ctx reputationcommon.Context
|
2021-04-21 04:56:38 +00:00
|
|
|
}
|
|
|
|
|
2021-05-04 06:16:51 +00:00
|
|
|
func (w *DaughterTrustWriter) Write(t reputation.Trust) error {
|
2021-03-01 19:01:45 +00:00
|
|
|
w.log.Debug("writing received daughter's trusts",
|
|
|
|
zap.Uint64("epoch", w.ctx.Epoch()),
|
2022-07-04 13:24:51 +00:00
|
|
|
zap.Stringer("trusting_peer", t.TrustingPeer()),
|
|
|
|
zap.Stringer("trusted_peer", t.Peer()),
|
2021-03-01 19:01:45 +00:00
|
|
|
)
|
|
|
|
|
2021-05-04 06:16:51 +00:00
|
|
|
w.storage.Put(w.ctx.Epoch(), t)
|
2021-04-21 04:56:38 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *DaughterTrustWriter) Close() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-05-04 06:16:51 +00:00
|
|
|
func (s *DaughterStorageWriterProvider) InitWriter(ctx reputationcommon.Context) (reputationcommon.Writer, error) {
|
2021-04-21 04:56:38 +00:00
|
|
|
return &DaughterTrustWriter{
|
|
|
|
log: s.Log,
|
|
|
|
storage: s.Storage,
|
2021-05-04 06:16:51 +00:00
|
|
|
ctx: ctx,
|
2021-04-21 04:56:38 +00:00
|
|
|
}, nil
|
|
|
|
}
|