forked from TrueCloudLab/frostfs-node
[#488] reputation: Add commentaries
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
2c8c9f69c8
commit
eb74a9cafc
8 changed files with 38 additions and 13 deletions
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// EpochContext is a std context extended with epoch data.
|
||||||
type EpochContext struct {
|
type EpochContext struct {
|
||||||
context.Context
|
context.Context
|
||||||
E uint64
|
E uint64
|
||||||
|
@ -27,6 +28,8 @@ func (NopReputationWriter) Close() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OnlyKeyRemoteServerInfo if implementation of reputation.ServerInfo
|
||||||
|
// interface but with only public key data.
|
||||||
type OnlyKeyRemoteServerInfo struct {
|
type OnlyKeyRemoteServerInfo struct {
|
||||||
Key []byte
|
Key []byte
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,11 +14,16 @@ import (
|
||||||
|
|
||||||
var ErrIncorrectContext = errors.New("could not write intermediate trust: passed context incorrect")
|
var ErrIncorrectContext = errors.New("could not write intermediate trust: passed context incorrect")
|
||||||
|
|
||||||
|
// ConsumerStorageWriterProvider is implementation of reputation.WriterProvider
|
||||||
|
// interface that provides ConsumerTrustWriter writer.
|
||||||
type ConsumerStorageWriterProvider struct {
|
type ConsumerStorageWriterProvider struct {
|
||||||
Log *logger.Logger
|
Log *logger.Logger
|
||||||
Storage *consumerstorage.Storage
|
Storage *consumerstorage.Storage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ConsumerTrustWriter is implementation of reputation.Writer interface
|
||||||
|
// that writes passed consumer's Trust values to Consumer storage. After writing
|
||||||
|
// that values can be used in eigenTrust algorithm's iterations.
|
||||||
type ConsumerTrustWriter struct {
|
type ConsumerTrustWriter struct {
|
||||||
log *logger.Logger
|
log *logger.Logger
|
||||||
storage *consumerstorage.Storage
|
storage *consumerstorage.Storage
|
||||||
|
|
|
@ -42,6 +42,8 @@ func NewFinalWriterProvider(prm FinalWriterProviderPrm, opts ...FinalWriterOptio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FinalWriterProvider is implementation of reputation.eigentrust.calculator
|
||||||
|
// IntermediateWriterProvider interface. It inits FinalWriter.
|
||||||
type FinalWriterProvider struct {
|
type FinalWriterProvider struct {
|
||||||
prm FinalWriterProviderPrm
|
prm FinalWriterProviderPrm
|
||||||
opts *finalWriterOptions
|
opts *finalWriterOptions
|
||||||
|
@ -55,9 +57,10 @@ func (fwp FinalWriterProvider) InitIntermediateWriter(
|
||||||
client: fwp.prm.Client,
|
client: fwp.prm.Client,
|
||||||
l: fwp.opts.log,
|
l: fwp.opts.log,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FinalWriter is implementation of reputation.eigentrust.calculator IntermediateWriter
|
||||||
|
// interface that writes GlobalTrust to contract directly.
|
||||||
type FinalWriter struct {
|
type FinalWriter struct {
|
||||||
privatKey *ecdsa.PrivateKey
|
privatKey *ecdsa.PrivateKey
|
||||||
pubKey []byte
|
pubKey []byte
|
||||||
|
|
|
@ -8,11 +8,16 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// DaughterStorageWriterProvider is implementation of reputation.WriterProvider
|
||||||
|
// interface that provides DaughterTrustWriter writer.
|
||||||
type DaughterStorageWriterProvider struct {
|
type DaughterStorageWriterProvider struct {
|
||||||
Log *logger.Logger
|
Log *logger.Logger
|
||||||
Storage *daughters.Storage
|
Storage *daughters.Storage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DaughterTrustWriter is implementation of 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 {
|
type DaughterTrustWriter struct {
|
||||||
log *logger.Logger
|
log *logger.Logger
|
||||||
storage *daughters.Storage
|
storage *daughters.Storage
|
||||||
|
|
|
@ -33,7 +33,7 @@ type ErrNoData struct {
|
||||||
|
|
||||||
func (e *ErrNoData) Error() string {
|
func (e *ErrNoData) Error() string {
|
||||||
if e.hasDaughter {
|
if e.hasDaughter {
|
||||||
return fmt.Sprintf("no data in %d epoch for peer: %s", e.epoch, e.daughter)
|
return fmt.Sprintf("no data in %d epoch for peer: %s", e.epoch, string(e.daughter.Bytes()))
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("no daughter data in %d epoch", e.epoch)
|
return fmt.Sprintf("no daughter data in %d epoch", e.epoch)
|
||||||
|
@ -72,7 +72,6 @@ func (ip *DaughterTrustIteratorProvider) InitAllDaughtersIterator(
|
||||||
}
|
}
|
||||||
|
|
||||||
return iter, nil
|
return iter, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitConsumersIterator returns iterator over all daughters
|
// InitConsumersIterator returns iterator over all daughters
|
||||||
|
|
|
@ -18,10 +18,15 @@ type Context interface {
|
||||||
I() uint32
|
I() uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InitialTrustSource must provide initial(non-calculated)
|
||||||
|
// trusts to current node's daughter. Realization may depends
|
||||||
|
// on daughter.
|
||||||
type InitialTrustSource interface {
|
type InitialTrustSource interface {
|
||||||
InitialTrust(reputation.PeerID) (reputation.TrustValue, error)
|
InitialTrust(reputation.PeerID) (reputation.TrustValue, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TrustIterator must iterate over all retrieved(or calculated) trusts
|
||||||
|
// and call passed TrustHandler on them.
|
||||||
type TrustIterator interface {
|
type TrustIterator interface {
|
||||||
Iterate(reputation.TrustHandler) error
|
Iterate(reputation.TrustHandler) error
|
||||||
}
|
}
|
||||||
|
@ -52,10 +57,15 @@ type DaughterTrustIteratorProvider interface {
|
||||||
InitConsumersIterator(Context) (PeerTrustsIterator, error)
|
InitConsumersIterator(Context) (PeerTrustsIterator, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IntermediateWriter must write intermediate result to contract.
|
||||||
|
// It may depends on realization either trust is sent directly to contract
|
||||||
|
// or via redirecting to other node.
|
||||||
type IntermediateWriter interface {
|
type IntermediateWriter interface {
|
||||||
WriteIntermediateTrust(eigentrust.IterationTrust) error
|
WriteIntermediateTrust(eigentrust.IterationTrust) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IntermediateWriterProvider must provide ready-to-work
|
||||||
|
// IntermediateWriter.
|
||||||
type IntermediateWriterProvider interface {
|
type IntermediateWriterProvider interface {
|
||||||
InitIntermediateWriter(Context) (IntermediateWriter, error)
|
InitIntermediateWriter(Context) (IntermediateWriter, error)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,14 +9,14 @@ import (
|
||||||
|
|
||||||
// Put saves daughter peer's trust to its provider for the epoch.
|
// Put saves daughter peer's trust to its provider for the epoch.
|
||||||
func (x *Storage) Put(epoch uint64, trust reputation.Trust) {
|
func (x *Storage) Put(epoch uint64, trust reputation.Trust) {
|
||||||
var s *daughterStorage
|
var s *DaughterStorage
|
||||||
|
|
||||||
x.mtx.Lock()
|
x.mtx.Lock()
|
||||||
|
|
||||||
{
|
{
|
||||||
s = x.mItems[epoch]
|
s = x.mItems[epoch]
|
||||||
if s == nil {
|
if s == nil {
|
||||||
s = &daughterStorage{
|
s = &DaughterStorage{
|
||||||
mItems: make(map[reputation.PeerID]*DaughterTrusts, 1),
|
mItems: make(map[reputation.PeerID]*DaughterTrusts, 1),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ func (x *Storage) Put(epoch uint64, trust reputation.Trust) {
|
||||||
// Returns false if there is no data for the epoch and daughter.
|
// Returns false if there is no data for the epoch and daughter.
|
||||||
func (x *Storage) DaughterTrusts(epoch uint64, daughter reputation.PeerID) (*DaughterTrusts, bool) {
|
func (x *Storage) DaughterTrusts(epoch uint64, daughter reputation.PeerID) (*DaughterTrusts, bool) {
|
||||||
var (
|
var (
|
||||||
s *daughterStorage
|
s *DaughterStorage
|
||||||
ok bool
|
ok bool
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ func (x *Storage) DaughterTrusts(epoch uint64, daughter reputation.PeerID) (*Dau
|
||||||
// AllDaughterTrusts returns daughter iterator for the epoch.
|
// AllDaughterTrusts returns daughter iterator for the epoch.
|
||||||
//
|
//
|
||||||
// Returns false if there is no data for the epoch and daughter.
|
// Returns false if there is no data for the epoch and daughter.
|
||||||
func (x *Storage) AllDaughterTrusts(epoch uint64) (*daughterStorage, bool) {
|
func (x *Storage) AllDaughterTrusts(epoch uint64) (*DaughterStorage, bool) {
|
||||||
x.mtx.RLock()
|
x.mtx.RLock()
|
||||||
defer x.mtx.RUnlock()
|
defer x.mtx.RUnlock()
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ func (x *Storage) AllDaughterTrusts(epoch uint64) (*daughterStorage, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// maps IDs of daughter peers to repositories of the local trusts to their providers.
|
// maps IDs of daughter peers to repositories of the local trusts to their providers.
|
||||||
type daughterStorage struct {
|
type DaughterStorage struct {
|
||||||
mtx sync.RWMutex
|
mtx sync.RWMutex
|
||||||
|
|
||||||
mItems map[reputation.PeerID]*DaughterTrusts
|
mItems map[reputation.PeerID]*DaughterTrusts
|
||||||
|
@ -75,7 +75,7 @@ type daughterStorage struct {
|
||||||
// Iterate passes IDs of the daughter peers with their trusts to h.
|
// Iterate passes IDs of the daughter peers with their trusts to h.
|
||||||
//
|
//
|
||||||
// Returns errors from h directly.
|
// Returns errors from h directly.
|
||||||
func (x *daughterStorage) Iterate(h eigentrustcalc.PeerTrustsHandler) (err error) {
|
func (x *DaughterStorage) Iterate(h eigentrustcalc.PeerTrustsHandler) (err error) {
|
||||||
x.mtx.RLock()
|
x.mtx.RLock()
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -91,7 +91,7 @@ func (x *daughterStorage) Iterate(h eigentrustcalc.PeerTrustsHandler) (err error
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *daughterStorage) put(trust reputation.Trust) {
|
func (x *DaughterStorage) put(trust reputation.Trust) {
|
||||||
var dt *DaughterTrusts
|
var dt *DaughterTrusts
|
||||||
|
|
||||||
x.mtx.Lock()
|
x.mtx.Lock()
|
||||||
|
@ -114,7 +114,7 @@ func (x *daughterStorage) put(trust reputation.Trust) {
|
||||||
dt.put(trust)
|
dt.put(trust)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *daughterStorage) daughterTrusts(id reputation.PeerID) (dt *DaughterTrusts, ok bool) {
|
func (x *DaughterStorage) daughterTrusts(id reputation.PeerID) (dt *DaughterTrusts, ok bool) {
|
||||||
x.mtx.RLock()
|
x.mtx.RLock()
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,7 +24,7 @@ type Prm struct{}
|
||||||
type Storage struct {
|
type Storage struct {
|
||||||
mtx sync.RWMutex
|
mtx sync.RWMutex
|
||||||
|
|
||||||
mItems map[uint64]*daughterStorage
|
mItems map[uint64]*DaughterStorage
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new instance of the Storage.
|
// New creates a new instance of the Storage.
|
||||||
|
@ -33,6 +33,6 @@ type Storage struct {
|
||||||
// initialization and is completely ready for work.
|
// initialization and is completely ready for work.
|
||||||
func New(_ Prm) *Storage {
|
func New(_ Prm) *Storage {
|
||||||
return &Storage{
|
return &Storage{
|
||||||
mItems: make(map[uint64]*daughterStorage),
|
mItems: make(map[uint64]*DaughterStorage),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue