forked from TrueCloudLab/frostfs-node
[#488] reputation: Change Writer
interface
Includes: - Delete first `ctx` argument in `Write` method. - Move intermediate Initial trust struct and method to `calculator` file. - Change Alpha to 0.1. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
0d34d7c508
commit
d1db54acf8
14 changed files with 61 additions and 63 deletions
|
@ -1,10 +1,7 @@
|
|||
package intermediate
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
|
||||
reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust"
|
||||
eigencalc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/calculator"
|
||||
|
@ -12,7 +9,7 @@ import (
|
|||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||
)
|
||||
|
||||
var ErrIncorrectContext = errors.New("could not write intermediate trust: passed context incorrect")
|
||||
var ErrIncorrectContextPanicMsg = "could not write intermediate trust: passed context incorrect"
|
||||
|
||||
// ConsumerStorageWriterProvider is implementation of reputation.WriterProvider
|
||||
// interface that provides ConsumerTrustWriter writer.
|
||||
|
@ -27,18 +24,14 @@ type ConsumerStorageWriterProvider struct {
|
|||
type ConsumerTrustWriter struct {
|
||||
log *logger.Logger
|
||||
storage *consumerstorage.Storage
|
||||
eiCtx eigencalc.Context
|
||||
}
|
||||
|
||||
func (w *ConsumerTrustWriter) Write(ctx common.Context, t reputation.Trust) error {
|
||||
eiCtx, ok := ctx.(eigencalc.Context)
|
||||
if !ok {
|
||||
return ErrIncorrectContext
|
||||
}
|
||||
|
||||
func (w *ConsumerTrustWriter) Write(t reputation.Trust) error {
|
||||
trust := eigentrust.IterationTrust{Trust: t}
|
||||
|
||||
trust.SetEpoch(eiCtx.Epoch())
|
||||
trust.SetI(eiCtx.I())
|
||||
trust.SetEpoch(w.eiCtx.Epoch())
|
||||
trust.SetI(w.eiCtx.I())
|
||||
|
||||
w.storage.Put(trust)
|
||||
return nil
|
||||
|
@ -48,9 +41,15 @@ func (w *ConsumerTrustWriter) Close() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *ConsumerStorageWriterProvider) InitWriter(_ reputationcommon.Context) (reputationcommon.Writer, error) {
|
||||
func (s *ConsumerStorageWriterProvider) InitWriter(ctx reputationcommon.Context) (reputationcommon.Writer, error) {
|
||||
eiCtx, ok := ctx.(eigencalc.Context)
|
||||
if !ok {
|
||||
panic(ErrIncorrectContextPanicMsg)
|
||||
}
|
||||
|
||||
return &ConsumerTrustWriter{
|
||||
log: s.Log,
|
||||
storage: s.Storage,
|
||||
eiCtx: eiCtx,
|
||||
}, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue