forked from TrueCloudLab/frostfs-node
[#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 <carpawell@nspcc.ru>
This commit is contained in:
parent
35ec694b04
commit
e2a1b0e0ee
2 changed files with 34 additions and 1 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust"
|
"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.
|
// 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.
|
// Iterate passes IDs of the daughter peers with the trusts of their consumers to h.
|
||||||
//
|
//
|
||||||
// Returns errors from h directly.
|
// 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()
|
x.mtx.RLock()
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
"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.
|
// 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)
|
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.
|
// 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
|
||||||
|
@ -59,6 +72,25 @@ type daughterStorage struct {
|
||||||
mItems map[reputation.PeerID]*DaughterTrusts
|
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) {
|
func (x *daughterStorage) put(trust reputation.Trust) {
|
||||||
var dt *DaughterTrusts
|
var dt *DaughterTrusts
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue