[#1570] Upgrade NeoFS SDK Go with changed reputation API

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-07-04 16:24:51 +03:00 committed by LeL
parent 9a6da336db
commit 9a11a75b77
28 changed files with 146 additions and 158 deletions

View file

@ -1,11 +1,13 @@
package consumerstorage
import (
"fmt"
"sync"
"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"
apireputation "github.com/nspcc-dev/neofs-sdk-go/reputation"
)
// Put saves intermediate trust of the consumer to daughter peer.
@ -76,7 +78,7 @@ func (x *iterationConsumersStorage) put(trust eigentrust.IterationTrust) {
s = x.mItems[iter]
if s == nil {
s = &ConsumersStorage{
mItems: make(map[reputation.PeerID]*ConsumersTrusts, 1),
mItems: make(map[string]*ConsumersTrusts, 1),
}
x.mItems[iter] = s
@ -107,7 +109,7 @@ func (x *iterationConsumersStorage) consumers(iter uint32) (s *ConsumersStorage,
type ConsumersStorage struct {
mtx sync.RWMutex
mItems map[reputation.PeerID]*ConsumersTrusts
mItems map[string]*ConsumersTrusts
}
func (x *ConsumersStorage) put(trust eigentrust.IterationTrust) {
@ -116,12 +118,12 @@ func (x *ConsumersStorage) put(trust eigentrust.IterationTrust) {
x.mtx.Lock()
{
daughter := trust.Peer()
daughter := trust.Peer().EncodeToString()
s = x.mItems[daughter]
if s == nil {
s = &ConsumersTrusts{
mItems: make(map[reputation.PeerID]reputation.Trust, 1),
mItems: make(map[string]reputation.Trust, 1),
}
x.mItems[daughter] = s
@ -140,7 +142,16 @@ func (x *ConsumersStorage) Iterate(h eigentrustcalc.PeerTrustsHandler) (err erro
x.mtx.RLock()
{
for trusted, trusts := range x.mItems {
for strTrusted, trusts := range x.mItems {
var trusted apireputation.PeerID
if strTrusted != "" {
err = trusted.DecodeString(strTrusted)
if err != nil {
panic(fmt.Sprintf("decode peer ID string %s: %v", strTrusted, err))
}
}
if err = h(trusted, trusts); err != nil {
break
}
@ -157,14 +168,14 @@ func (x *ConsumersStorage) Iterate(h eigentrustcalc.PeerTrustsHandler) (err erro
type ConsumersTrusts struct {
mtx sync.RWMutex
mItems map[reputation.PeerID]reputation.Trust
mItems map[string]reputation.Trust
}
func (x *ConsumersTrusts) put(trust eigentrust.IterationTrust) {
x.mtx.Lock()
{
x.mItems[trust.TrustingPeer()] = trust.Trust
x.mItems[trust.TrustingPeer().EncodeToString()] = trust.Trust
}
x.mtx.Unlock()