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,11 +1,23 @@
|
|||
package intermediate
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust"
|
||||
eigencalc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/calculator"
|
||||
eigentrustctrl "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/controller"
|
||||
)
|
||||
|
||||
// InitialTrustSource is implementation of the
|
||||
// reputation/eigentrust/calculator's InitialTrustSource interface.
|
||||
type InitialTrustSource struct {
|
||||
Trust reputation.TrustValue
|
||||
}
|
||||
|
||||
// InitialTrust returns `initialTrust` as initial trust value.
|
||||
func (i InitialTrustSource) InitialTrust(reputation.PeerID) (reputation.TrustValue, error) {
|
||||
return i.Trust, nil
|
||||
}
|
||||
|
||||
// DaughtersTrustCalculator wraps EigenTrust calculator and implements
|
||||
// eigentrust/calculator's DaughtersTrustCalculator interface.
|
||||
type DaughtersTrustCalculator struct {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package intermediate
|
|||
|
||||
import (
|
||||
"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/storage/daughters"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||
|
@ -21,10 +20,11 @@ type DaughterStorageWriterProvider struct {
|
|||
type DaughterTrustWriter struct {
|
||||
log *logger.Logger
|
||||
storage *daughters.Storage
|
||||
ctx reputationcommon.Context
|
||||
}
|
||||
|
||||
func (w *DaughterTrustWriter) Write(ctx common.Context, t reputation.Trust) error {
|
||||
w.storage.Put(ctx.Epoch(), t)
|
||||
func (w *DaughterTrustWriter) Write(t reputation.Trust) error {
|
||||
w.storage.Put(w.ctx.Epoch(), t)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -32,9 +32,10 @@ func (w *DaughterTrustWriter) Close() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *DaughterStorageWriterProvider) InitWriter(_ reputationcommon.Context) (reputationcommon.Writer, error) {
|
||||
func (s *DaughterStorageWriterProvider) InitWriter(ctx reputationcommon.Context) (reputationcommon.Writer, error) {
|
||||
return &DaughterTrustWriter{
|
||||
log: s.Log,
|
||||
storage: s.Storage,
|
||||
ctx: ctx,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -55,15 +55,20 @@ type TrustWriterProvider struct {
|
|||
}
|
||||
|
||||
func (twp *TrustWriterProvider) InitWriter(ctx reputationcommon.Context) (reputationcommon.Writer, error) {
|
||||
eiContext, ok := ctx.(eigentrustcalc.Context)
|
||||
if !ok {
|
||||
panic(ErrIncorrectContextPanicMsg)
|
||||
}
|
||||
|
||||
return &RemoteTrustWriter{
|
||||
ctx: ctx,
|
||||
eiCtx: eiContext,
|
||||
client: twp.client,
|
||||
key: twp.key,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type RemoteTrustWriter struct {
|
||||
ctx reputationcommon.Context
|
||||
eiCtx eigentrustcalc.Context
|
||||
client apiClient.Client
|
||||
key *ecdsa.PrivateKey
|
||||
|
||||
|
@ -73,12 +78,7 @@ type RemoteTrustWriter struct {
|
|||
// Write check if passed context contains required
|
||||
// data(returns ErrIncorrectContext if not) and
|
||||
// caches passed trusts(as SendIntermediateTrustPrm structs).
|
||||
func (rtp *RemoteTrustWriter) Write(ctx reputationcommon.Context, t reputation.Trust) error {
|
||||
eiContext, ok := ctx.(eigentrustcalc.Context)
|
||||
if !ok {
|
||||
return ErrIncorrectContext
|
||||
}
|
||||
|
||||
func (rtp *RemoteTrustWriter) Write(t reputation.Trust) error {
|
||||
apiTrustingPeer := reputationapi.NewPeerID()
|
||||
apiTrustingPeer.SetPublicKey(t.TrustingPeer())
|
||||
|
||||
|
@ -94,8 +94,8 @@ func (rtp *RemoteTrustWriter) Write(ctx reputationcommon.Context, t reputation.T
|
|||
apiPeerToPeerTrust.SetTrust(apiTrust)
|
||||
|
||||
p := &apiClient.SendIntermediateTrustPrm{}
|
||||
p.SetEpoch(eiContext.Epoch())
|
||||
p.SetIteration(eiContext.I())
|
||||
p.SetEpoch(rtp.eiCtx.Epoch())
|
||||
p.SetIteration(rtp.eiCtx.I())
|
||||
p.SetTrust(apiPeerToPeerTrust)
|
||||
|
||||
rtp.buf = append(rtp.buf, p)
|
||||
|
@ -108,7 +108,7 @@ func (rtp *RemoteTrustWriter) Write(ctx reputationcommon.Context, t reputation.T
|
|||
func (rtp *RemoteTrustWriter) Close() (err error) {
|
||||
for _, prm := range rtp.buf {
|
||||
_, err = rtp.client.SendIntermediateTrust(
|
||||
rtp.ctx,
|
||||
rtp.eiCtx,
|
||||
*prm,
|
||||
apiClient.WithKey(rtp.key),
|
||||
)
|
||||
|
|
|
@ -9,15 +9,6 @@ import (
|
|||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/storage/daughters"
|
||||
)
|
||||
|
||||
// InitialTrustSource is implementation of the
|
||||
// reputation/eigentrust/calculator's InitialTrustSource interface.
|
||||
type InitialTrustSource struct{}
|
||||
|
||||
// InitialTrust returns `1` as initial trust value.
|
||||
func (i InitialTrustSource) InitialTrust(reputation.PeerID) (reputation.TrustValue, error) {
|
||||
return reputation.TrustOne, nil
|
||||
}
|
||||
|
||||
// DaughterTrustIteratorProvider is implementation of the
|
||||
// reputation/eigentrust/calculator's DaughterTrustIteratorProvider interface.
|
||||
type DaughterTrustIteratorProvider struct {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue