From e2a1b0e0eec9204ef850e3bf8656ffe08330c110 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Wed, 21 Apr 2021 13:37:20 +0300 Subject: [PATCH] [#488] reputation/eigentrust/storages: Fix args Change anonymous func arg for `Iterate` methods of Storages to `PeerTrustsHandler` type for implementing corresponding interface. Implement missing `Iterate` method for daughter Storage. Signed-off-by: Pavel Karpy --- .../eigentrust/storage/consumers/calls.go | 3 +- .../eigentrust/storage/daughters/calls.go | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/pkg/services/reputation/eigentrust/storage/consumers/calls.go b/pkg/services/reputation/eigentrust/storage/consumers/calls.go index ee147820..9e363a69 100644 --- a/pkg/services/reputation/eigentrust/storage/consumers/calls.go +++ b/pkg/services/reputation/eigentrust/storage/consumers/calls.go @@ -5,6 +5,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/services/reputation" "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust" + eigentrustcalc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/calculator" ) // Put saves intermediate trust of the consumer to daughter peer. @@ -135,7 +136,7 @@ func (x *ConsumersStorage) put(trust eigentrust.IterationTrust) { // Iterate passes IDs of the daughter peers with the trusts of their consumers to h. // // Returns errors from h directly. -func (x *ConsumersStorage) Iterate(h func(trusted reputation.PeerID, consumerTrusts *ConsumersTrusts) error) (err error) { +func (x *ConsumersStorage) Iterate(h eigentrustcalc.PeerTrustsHandler) (err error) { x.mtx.RLock() { diff --git a/pkg/services/reputation/eigentrust/storage/daughters/calls.go b/pkg/services/reputation/eigentrust/storage/daughters/calls.go index d291bcf8..b61af14c 100644 --- a/pkg/services/reputation/eigentrust/storage/daughters/calls.go +++ b/pkg/services/reputation/eigentrust/storage/daughters/calls.go @@ -4,6 +4,7 @@ import ( "sync" "github.com/nspcc-dev/neofs-node/pkg/services/reputation" + eigentrustcalc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/calculator" ) // Put saves daughter peer's trust to its provider for the epoch. @@ -52,6 +53,18 @@ func (x *Storage) DaughterTrusts(epoch uint64, daughter reputation.PeerID) (*Dau return s.daughterTrusts(daughter) } +// AllDaughterTrusts returns daughter iterator for the epoch. +// +// Returns false if there is no data for the epoch and daughter. +func (x *Storage) AllDaughterTrusts(epoch uint64) (*daughterStorage, bool) { + x.mtx.RLock() + defer x.mtx.RUnlock() + + s, ok := x.mItems[epoch] + + return s, ok +} + // maps IDs of daughter peers to repositories of the local trusts to their providers. type daughterStorage struct { mtx sync.RWMutex @@ -59,6 +72,25 @@ type daughterStorage struct { mItems map[reputation.PeerID]*DaughterTrusts } +// Iterate passes IDs of the daughter peers with their trusts to h. +// +// Returns errors from h directly. +func (x *daughterStorage) Iterate(h eigentrustcalc.PeerTrustsHandler) (err error) { + x.mtx.RLock() + + { + for daughter, daughterTrusts := range x.mItems { + if err = h(daughter, daughterTrusts); err != nil { + break + } + } + } + + x.mtx.RUnlock() + + return +} + func (x *daughterStorage) put(trust reputation.Trust) { var dt *DaughterTrusts