forked from TrueCloudLab/frostfs-node
[#1570] Upgrade NeoFS SDK Go with changed reputation API
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
9a6da336db
commit
9a11a75b77
28 changed files with 146 additions and 158 deletions
|
@ -35,7 +35,6 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement"
|
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/policer"
|
"github.com/nspcc-dev/neofs-node/pkg/services/policer"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/replicator"
|
"github.com/nspcc-dev/neofs-node/pkg/services/replicator"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
|
||||||
truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage"
|
truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/client"
|
"github.com/nspcc-dev/neofs-sdk-go/client"
|
||||||
|
@ -44,6 +43,7 @@ import (
|
||||||
eaclSDK "github.com/nspcc-dev/neofs-sdk-go/eacl"
|
eaclSDK "github.com/nspcc-dev/neofs-sdk-go/eacl"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
|
apireputation "github.com/nspcc-dev/neofs-sdk-go/reputation"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/user"
|
"github.com/nspcc-dev/neofs-sdk-go/user"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
@ -526,11 +526,14 @@ func (c *reputationClientConstructor) Get(info coreclient.NodeInfo) (coreclient.
|
||||||
key := info.PublicKey()
|
key := info.PublicKey()
|
||||||
|
|
||||||
nmNodes := nm.Nodes()
|
nmNodes := nm.Nodes()
|
||||||
|
var peer apireputation.PeerID
|
||||||
|
|
||||||
for i := range nmNodes {
|
for i := range nmNodes {
|
||||||
if bytes.Equal(nmNodes[i].PublicKey(), key) {
|
if bytes.Equal(nmNodes[i].PublicKey(), key) {
|
||||||
|
peer.SetPublicKey(nmNodes[i].PublicKey())
|
||||||
|
|
||||||
prm := truststorage.UpdatePrm{}
|
prm := truststorage.UpdatePrm{}
|
||||||
prm.SetPeer(reputation.PeerIDFromBytes(nmNodes[i].PublicKey()))
|
prm.SetPeer(peer)
|
||||||
|
|
||||||
return &reputationClient{
|
return &reputationClient{
|
||||||
MultiAddressClient: cl.(coreclient.MultiAddressClient),
|
MultiAddressClient: cl.(coreclient.MultiAddressClient),
|
||||||
|
|
|
@ -29,6 +29,7 @@ import (
|
||||||
truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage"
|
truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage"
|
||||||
reputationrpc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/rpc"
|
reputationrpc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/rpc"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||||
|
apireputation "github.com/nspcc-dev/neofs-sdk-go/reputation"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -330,11 +331,15 @@ func (s *reputationServer) processLocalTrust(epoch uint64, t reputation.Trust,
|
||||||
|
|
||||||
// apiToLocalTrust converts v2 Trust to local reputation.Trust, adding trustingPeer.
|
// apiToLocalTrust converts v2 Trust to local reputation.Trust, adding trustingPeer.
|
||||||
func apiToLocalTrust(t *v2reputation.Trust, trustingPeer []byte) reputation.Trust {
|
func apiToLocalTrust(t *v2reputation.Trust, trustingPeer []byte) reputation.Trust {
|
||||||
|
var trusted, trusting apireputation.PeerID
|
||||||
|
trusted.SetPublicKey(t.GetPeer().GetPublicKey())
|
||||||
|
trusting.SetPublicKey(trustingPeer)
|
||||||
|
|
||||||
localTrust := reputation.Trust{}
|
localTrust := reputation.Trust{}
|
||||||
|
|
||||||
localTrust.SetValue(reputation.TrustValueFromFloat64(t.GetValue()))
|
localTrust.SetValue(reputation.TrustValueFromFloat64(t.GetValue()))
|
||||||
localTrust.SetPeer(reputation.PeerIDFromBytes(t.GetPeer().GetPublicKey()))
|
localTrust.SetPeer(trusted)
|
||||||
localTrust.SetTrustingPeer(reputation.PeerIDFromBytes(trustingPeer))
|
localTrust.SetTrustingPeer(trusting)
|
||||||
|
|
||||||
return localTrust
|
return localTrust
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust"
|
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust"
|
||||||
eigencalc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/calculator"
|
eigencalc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/calculator"
|
||||||
eigentrustctrl "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/controller"
|
eigentrustctrl "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/controller"
|
||||||
|
apireputation "github.com/nspcc-dev/neofs-sdk-go/reputation"
|
||||||
)
|
)
|
||||||
|
|
||||||
// InitialTrustSource is an implementation of the
|
// InitialTrustSource is an implementation of the
|
||||||
|
@ -20,7 +21,7 @@ type InitialTrustSource struct {
|
||||||
var ErrEmptyNetMap = errors.New("empty NepMap")
|
var ErrEmptyNetMap = errors.New("empty NepMap")
|
||||||
|
|
||||||
// InitialTrust returns `initialTrust` as an initial trust value.
|
// InitialTrust returns `initialTrust` as an initial trust value.
|
||||||
func (i InitialTrustSource) InitialTrust(reputation.PeerID) (reputation.TrustValue, error) {
|
func (i InitialTrustSource) InitialTrust(apireputation.PeerID) (reputation.TrustValue, error) {
|
||||||
nm, err := i.NetMap.GetNetMap(1)
|
nm, err := i.NetMap.GetNetMap(1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return reputation.TrustZero, fmt.Errorf("failed to get NetMap: %w", err)
|
return reputation.TrustZero, fmt.Errorf("failed to get NetMap: %w", err)
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package intermediate
|
package intermediate
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
||||||
reputationcommon "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"
|
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust"
|
||||||
|
@ -34,8 +32,8 @@ func (w *ConsumerTrustWriter) Write(t reputation.Trust) error {
|
||||||
w.log.Debug("writing received consumer's trusts",
|
w.log.Debug("writing received consumer's trusts",
|
||||||
zap.Uint64("epoch", w.eiCtx.Epoch()),
|
zap.Uint64("epoch", w.eiCtx.Epoch()),
|
||||||
zap.Uint32("iteration", w.eiCtx.I()),
|
zap.Uint32("iteration", w.eiCtx.I()),
|
||||||
zap.String("trusting_peer", hex.EncodeToString(t.TrustingPeer().Bytes())),
|
zap.Stringer("trusting_peer", t.TrustingPeer()),
|
||||||
zap.String("trusted_peer", hex.EncodeToString(t.Peer().Bytes())),
|
zap.Stringer("trusted_peer", t.Peer()),
|
||||||
)
|
)
|
||||||
|
|
||||||
trust := eigentrust.IterationTrust{Trust: t}
|
trust := eigentrust.IterationTrust{Trust: t}
|
||||||
|
|
|
@ -2,13 +2,13 @@ package intermediate
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"encoding/hex"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
repClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation"
|
repClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/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"
|
eigentrustcalc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/calculator"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||||
|
neofsecdsa "github.com/nspcc-dev/neofs-sdk-go/crypto/ecdsa"
|
||||||
apireputation "github.com/nspcc-dev/neofs-sdk-go/reputation"
|
apireputation "github.com/nspcc-dev/neofs-sdk-go/reputation"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
@ -75,27 +75,23 @@ func (fw FinalWriter) WriteIntermediateTrust(t eigentrust.IterationTrust) error
|
||||||
|
|
||||||
args := repClient.PutPrm{}
|
args := repClient.PutPrm{}
|
||||||
|
|
||||||
var trustedPublicKey [33]byte
|
apiTrustedPeerID := t.Peer()
|
||||||
copy(trustedPublicKey[:], t.Peer().Bytes())
|
|
||||||
|
|
||||||
apiTrustedPeerID := apireputation.NewPeerID()
|
var apiTrust apireputation.Trust
|
||||||
apiTrustedPeerID.SetPublicKey(trustedPublicKey)
|
|
||||||
|
|
||||||
apiTrust := apireputation.NewTrust()
|
|
||||||
apiTrust.SetValue(t.Value().Float64())
|
apiTrust.SetValue(t.Value().Float64())
|
||||||
apiTrust.SetPeer(apiTrustedPeerID)
|
apiTrust.SetPeer(t.Peer())
|
||||||
|
|
||||||
var managerPublicKey [33]byte
|
var managerPublicKey [33]byte
|
||||||
copy(managerPublicKey[:], fw.pubKey)
|
copy(managerPublicKey[:], fw.pubKey)
|
||||||
|
|
||||||
apiMangerPeerID := apireputation.NewPeerID()
|
var apiMangerPeerID apireputation.PeerID
|
||||||
apiMangerPeerID.SetPublicKey(managerPublicKey)
|
apiMangerPeerID.SetPublicKey(managerPublicKey[:])
|
||||||
|
|
||||||
gTrust := apireputation.NewGlobalTrust()
|
var gTrust apireputation.GlobalTrust
|
||||||
gTrust.SetTrust(apiTrust)
|
gTrust.SetTrust(apiTrust)
|
||||||
gTrust.SetManager(apiMangerPeerID)
|
gTrust.SetManager(apiMangerPeerID)
|
||||||
|
|
||||||
err := gTrust.Sign(fw.privatKey)
|
err := gTrust.Sign(neofsecdsa.Signer(*fw.privatKey))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fw.l.Debug(
|
fw.l.Debug(
|
||||||
"failed to sign global trust",
|
"failed to sign global trust",
|
||||||
|
@ -105,8 +101,8 @@ func (fw FinalWriter) WriteIntermediateTrust(t eigentrust.IterationTrust) error
|
||||||
}
|
}
|
||||||
|
|
||||||
args.SetEpoch(t.Epoch())
|
args.SetEpoch(t.Epoch())
|
||||||
args.SetValue(*gTrust)
|
args.SetValue(gTrust)
|
||||||
args.SetPeerID(*apiTrustedPeerID)
|
args.SetPeerID(apiTrustedPeerID)
|
||||||
|
|
||||||
err = fw.client.Put(
|
err = fw.client.Put(
|
||||||
args,
|
args,
|
||||||
|
@ -123,7 +119,7 @@ func (fw FinalWriter) WriteIntermediateTrust(t eigentrust.IterationTrust) error
|
||||||
"sent global trust to contract",
|
"sent global trust to contract",
|
||||||
zap.Uint64("epoch", t.Epoch()),
|
zap.Uint64("epoch", t.Epoch()),
|
||||||
zap.Float64("value", t.Value().Float64()),
|
zap.Float64("value", t.Value().Float64()),
|
||||||
zap.String("peer", hex.EncodeToString(t.Peer().Bytes())),
|
zap.Stringer("peer", t.Peer()),
|
||||||
)
|
)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package intermediate
|
package intermediate
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
||||||
reputationcommon "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/services/reputation/eigentrust/storage/daughters"
|
||||||
|
@ -29,8 +27,8 @@ type DaughterTrustWriter struct {
|
||||||
func (w *DaughterTrustWriter) Write(t reputation.Trust) error {
|
func (w *DaughterTrustWriter) Write(t reputation.Trust) error {
|
||||||
w.log.Debug("writing received daughter's trusts",
|
w.log.Debug("writing received daughter's trusts",
|
||||||
zap.Uint64("epoch", w.ctx.Epoch()),
|
zap.Uint64("epoch", w.ctx.Epoch()),
|
||||||
zap.String("trusting_peer", hex.EncodeToString(t.TrustingPeer().Bytes())),
|
zap.Stringer("trusting_peer", t.TrustingPeer()),
|
||||||
zap.String("trusted_peer", hex.EncodeToString(t.Peer().Bytes())),
|
zap.Stringer("trusted_peer", t.Peer()),
|
||||||
)
|
)
|
||||||
|
|
||||||
w.storage.Put(w.ctx.Epoch(), t)
|
w.storage.Put(w.ctx.Epoch(), t)
|
||||||
|
|
|
@ -2,7 +2,6 @@ package intermediate
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"encoding/hex"
|
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/common"
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/common"
|
||||||
internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/internal/client"
|
internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/internal/client"
|
||||||
|
@ -95,22 +94,16 @@ func (rtp *RemoteTrustWriter) Write(t reputation.Trust) error {
|
||||||
rtp.log.Debug("announcing trust",
|
rtp.log.Debug("announcing trust",
|
||||||
zap.Uint64("epoch", epoch),
|
zap.Uint64("epoch", epoch),
|
||||||
zap.Uint32("iteration", i),
|
zap.Uint32("iteration", i),
|
||||||
zap.String("trusting_peer", hex.EncodeToString(t.TrustingPeer().Bytes())),
|
zap.Stringer("trusting_peer", t.TrustingPeer()),
|
||||||
zap.String("trusted_peer", hex.EncodeToString(t.Peer().Bytes())),
|
zap.Stringer("trusted_peer", t.Peer()),
|
||||||
)
|
)
|
||||||
|
|
||||||
apiTrustingPeer := reputationapi.NewPeerID()
|
var apiTrust reputationapi.Trust
|
||||||
apiTrustingPeer.SetPublicKey(t.TrustingPeer())
|
|
||||||
|
|
||||||
apiTrustedPeer := reputationapi.NewPeerID()
|
|
||||||
apiTrustedPeer.SetPublicKey(t.Peer())
|
|
||||||
|
|
||||||
apiTrust := reputationapi.NewTrust()
|
|
||||||
apiTrust.SetValue(t.Value().Float64())
|
apiTrust.SetValue(t.Value().Float64())
|
||||||
apiTrust.SetPeer(apiTrustedPeer)
|
apiTrust.SetPeer(t.Peer())
|
||||||
|
|
||||||
apiPeerToPeerTrust := reputationapi.NewPeerToPeerTrust()
|
var apiPeerToPeerTrust reputationapi.PeerToPeerTrust
|
||||||
apiPeerToPeerTrust.SetTrustingPeer(apiTrustingPeer)
|
apiPeerToPeerTrust.SetTrustingPeer(t.TrustingPeer())
|
||||||
apiPeerToPeerTrust.SetTrust(apiTrust)
|
apiPeerToPeerTrust.SetTrust(apiTrust)
|
||||||
|
|
||||||
var p internalclient.AnnounceIntermediatePrm
|
var p internalclient.AnnounceIntermediatePrm
|
||||||
|
@ -119,7 +112,7 @@ func (rtp *RemoteTrustWriter) Write(t reputation.Trust) error {
|
||||||
p.SetClient(rtp.client)
|
p.SetClient(rtp.client)
|
||||||
p.SetEpoch(epoch)
|
p.SetEpoch(epoch)
|
||||||
p.SetIteration(i)
|
p.SetIteration(i)
|
||||||
p.SetTrust(*apiPeerToPeerTrust)
|
p.SetTrust(apiPeerToPeerTrust)
|
||||||
|
|
||||||
_, err := internalclient.AnnounceIntermediate(p)
|
_, err := internalclient.AnnounceIntermediate(p)
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
package intermediate
|
package intermediate
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
|
||||||
eigentrustcalc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/calculator"
|
eigentrustcalc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/calculator"
|
||||||
consumerstorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/storage/consumers"
|
consumerstorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/storage/consumers"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/storage/daughters"
|
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/storage/daughters"
|
||||||
|
apireputation "github.com/nspcc-dev/neofs-sdk-go/reputation"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DaughterTrustIteratorProvider is an implementation of the
|
// DaughterTrustIteratorProvider is an implementation of the
|
||||||
|
@ -20,15 +19,12 @@ type DaughterTrustIteratorProvider struct {
|
||||||
// InitDaughterIterator returns an iterator over the received
|
// InitDaughterIterator returns an iterator over the received
|
||||||
// local trusts for ctx.Epoch() epoch from daughter p.
|
// local trusts for ctx.Epoch() epoch from daughter p.
|
||||||
func (ip *DaughterTrustIteratorProvider) InitDaughterIterator(ctx eigentrustcalc.Context,
|
func (ip *DaughterTrustIteratorProvider) InitDaughterIterator(ctx eigentrustcalc.Context,
|
||||||
p reputation.PeerID) (eigentrustcalc.TrustIterator, error) {
|
p apireputation.PeerID) (eigentrustcalc.TrustIterator, error) {
|
||||||
epoch := ctx.Epoch()
|
epoch := ctx.Epoch()
|
||||||
|
|
||||||
daughterIterator, ok := ip.DaughterStorage.DaughterTrusts(epoch, p)
|
daughterIterator, ok := ip.DaughterStorage.DaughterTrusts(epoch, p)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("no data in %d epoch for daughter: %s",
|
return nil, fmt.Errorf("no data in %d epoch for daughter: %s", epoch, p)
|
||||||
epoch,
|
|
||||||
hex.EncodeToString(p.Bytes()),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return daughterIterator, nil
|
return daughterIterator, nil
|
||||||
|
|
|
@ -82,15 +82,12 @@ type RemoteTrustWriter struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rtp *RemoteTrustWriter) Write(t reputation.Trust) error {
|
func (rtp *RemoteTrustWriter) Write(t reputation.Trust) error {
|
||||||
apiTrust := reputationapi.NewTrust()
|
var apiTrust reputationapi.Trust
|
||||||
|
|
||||||
apiPeer := reputationapi.NewPeerID()
|
|
||||||
apiPeer.SetPublicKey(t.Peer())
|
|
||||||
|
|
||||||
apiTrust.SetValue(t.Value().Float64())
|
apiTrust.SetValue(t.Value().Float64())
|
||||||
apiTrust.SetPeer(apiPeer)
|
apiTrust.SetPeer(t.Peer())
|
||||||
|
|
||||||
rtp.buf = append(rtp.buf, *apiTrust)
|
rtp.buf = append(rtp.buf, apiTrust)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
trustcontroller "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/controller"
|
trustcontroller "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/controller"
|
||||||
truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage"
|
truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||||
|
apireputation "github.com/nspcc-dev/neofs-sdk-go/reputation"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -87,10 +88,15 @@ func (it *TrustIterator) Iterate(h reputation.TrustHandler) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var trusted, trusting apireputation.PeerID
|
||||||
|
|
||||||
|
trusted.SetPublicKey(nmNodes[i].PublicKey())
|
||||||
|
trusting.SetPublicKey(it.storage.LocalKey)
|
||||||
|
|
||||||
trust := reputation.Trust{}
|
trust := reputation.Trust{}
|
||||||
trust.SetPeer(reputation.PeerIDFromBytes(nmNodes[i].PublicKey()))
|
trust.SetPeer(trusted)
|
||||||
trust.SetValue(p)
|
trust.SetValue(p)
|
||||||
trust.SetTrustingPeer(reputation.PeerIDFromBytes(it.storage.LocalKey))
|
trust.SetTrustingPeer(trusting)
|
||||||
|
|
||||||
if err := h(trust); err != nil {
|
if err := h(trust); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
4
go.mod
4
go.mod
|
@ -17,9 +17,9 @@ require (
|
||||||
github.com/nspcc-dev/hrw v1.0.9
|
github.com/nspcc-dev/hrw v1.0.9
|
||||||
github.com/nspcc-dev/neo-go v0.99.1-pre.0.20220609082921-2c9fb2044242
|
github.com/nspcc-dev/neo-go v0.99.1-pre.0.20220609082921-2c9fb2044242
|
||||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5 // indirect
|
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5 // indirect
|
||||||
github.com/nspcc-dev/neofs-api-go/v2 v2.12.3-0.20220630100506-c6f7ab3ef1bf
|
github.com/nspcc-dev/neofs-api-go/v2 v2.13.0
|
||||||
github.com/nspcc-dev/neofs-contract v0.15.1
|
github.com/nspcc-dev/neofs-contract v0.15.1
|
||||||
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.4.0.20220704082116-2ad89085a341
|
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.4.0.20220705084258-cec2373b50ae
|
||||||
github.com/nspcc-dev/tzhash v1.5.2
|
github.com/nspcc-dev/tzhash v1.5.2
|
||||||
github.com/panjf2000/ants/v2 v2.4.0
|
github.com/panjf2000/ants/v2 v2.4.0
|
||||||
github.com/paulmach/orb v0.2.2
|
github.com/paulmach/orb v0.2.2
|
||||||
|
|
8
go.sum
8
go.sum
|
@ -399,8 +399,8 @@ github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5 h1:bW
|
||||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
|
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
|
||||||
github.com/nspcc-dev/neofs-api-go/v2 v2.11.0-pre.0.20211201134523-3604d96f3fe1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs=
|
github.com/nspcc-dev/neofs-api-go/v2 v2.11.0-pre.0.20211201134523-3604d96f3fe1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs=
|
||||||
github.com/nspcc-dev/neofs-api-go/v2 v2.11.1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs=
|
github.com/nspcc-dev/neofs-api-go/v2 v2.11.1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs=
|
||||||
github.com/nspcc-dev/neofs-api-go/v2 v2.12.3-0.20220630100506-c6f7ab3ef1bf h1:QRPx+DdyN2KmJ5/oDYH4c86Bl81d1ZacQL5Q9IC9wZA=
|
github.com/nspcc-dev/neofs-api-go/v2 v2.13.0 h1:7BcBiSjmWqJx0SPFlGRYt9ZFbMjucRIz9+Mv8UBLeq8=
|
||||||
github.com/nspcc-dev/neofs-api-go/v2 v2.12.3-0.20220630100506-c6f7ab3ef1bf/go.mod h1:73j09Xa7I2zQbM3HCvAHnDHPYiiWnEHa1d6Z6RDMBLU=
|
github.com/nspcc-dev/neofs-api-go/v2 v2.13.0/go.mod h1:73j09Xa7I2zQbM3HCvAHnDHPYiiWnEHa1d6Z6RDMBLU=
|
||||||
github.com/nspcc-dev/neofs-contract v0.15.1 h1:1r27t4SGKF7W1PRPOIfircEXHvALThNYNagT+SIabcA=
|
github.com/nspcc-dev/neofs-contract v0.15.1 h1:1r27t4SGKF7W1PRPOIfircEXHvALThNYNagT+SIabcA=
|
||||||
github.com/nspcc-dev/neofs-contract v0.15.1/go.mod h1:kxO5ZTqdzFnRM5RMvM+Fhd+3GGrJo6AmG2ZyA9OCqqQ=
|
github.com/nspcc-dev/neofs-contract v0.15.1/go.mod h1:kxO5ZTqdzFnRM5RMvM+Fhd+3GGrJo6AmG2ZyA9OCqqQ=
|
||||||
github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA=
|
github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA=
|
||||||
|
@ -409,8 +409,8 @@ github.com/nspcc-dev/neofs-crypto v0.3.0 h1:zlr3pgoxuzrmGCxc5W8dGVfA9Rro8diFvVnB
|
||||||
github.com/nspcc-dev/neofs-crypto v0.3.0/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw=
|
github.com/nspcc-dev/neofs-crypto v0.3.0/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw=
|
||||||
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20211201182451-a5b61c4f6477/go.mod h1:dfMtQWmBHYpl9Dez23TGtIUKiFvCIxUZq/CkSIhEpz4=
|
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20211201182451-a5b61c4f6477/go.mod h1:dfMtQWmBHYpl9Dez23TGtIUKiFvCIxUZq/CkSIhEpz4=
|
||||||
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220113123743-7f3162110659/go.mod h1:/jay1lr3w7NQd/VDBkEhkJmDmyPNsu4W+QV2obsUV40=
|
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220113123743-7f3162110659/go.mod h1:/jay1lr3w7NQd/VDBkEhkJmDmyPNsu4W+QV2obsUV40=
|
||||||
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.4.0.20220704082116-2ad89085a341 h1:poXrrTjCClTMUpEZ7xlQ3Pk4+vtLH+EqaTduBmn+Z9Y=
|
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.4.0.20220705084258-cec2373b50ae h1:cTUlqMMmuMzX3pujenjYlhkpJaTCx9Nj3w4acUFiRlY=
|
||||||
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.4.0.20220704082116-2ad89085a341/go.mod h1:ck/wjPGFZ7mqcz6vZLMuQFEfL1Qu5zVrBrBJrH0VjOo=
|
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.4.0.20220705084258-cec2373b50ae/go.mod h1:hP3HrbK8omERJZvwjsGZgvzsUDxsPDPemrHzgqfpADM=
|
||||||
github.com/nspcc-dev/rfc6979 v0.1.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso=
|
github.com/nspcc-dev/rfc6979 v0.1.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso=
|
||||||
github.com/nspcc-dev/rfc6979 v0.2.0 h1:3e1WNxrN60/6N0DW7+UYisLeZJyfqZTNOjeV/toYvOE=
|
github.com/nspcc-dev/rfc6979 v0.2.0 h1:3e1WNxrN60/6N0DW7+UYisLeZJyfqZTNOjeV/toYvOE=
|
||||||
github.com/nspcc-dev/rfc6979 v0.2.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso=
|
github.com/nspcc-dev/rfc6979 v0.2.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso=
|
||||||
|
|
|
@ -15,7 +15,7 @@ func (rp *Processor) handlePutReputation(ev event.Event) {
|
||||||
// FIXME: #1147 do not use `ToV2` method outside neofs-api-go library
|
// FIXME: #1147 do not use `ToV2` method outside neofs-api-go library
|
||||||
rp.log.Info("notification",
|
rp.log.Info("notification",
|
||||||
zap.String("type", "reputation put"),
|
zap.String("type", "reputation put"),
|
||||||
zap.String("peer_id", hex.EncodeToString(peerID.ToV2().GetPublicKey())))
|
zap.String("peer_id", hex.EncodeToString(peerID.PublicKey())))
|
||||||
|
|
||||||
// send event to the worker pool
|
// send event to the worker pool
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
|
|
||||||
repClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation"
|
repClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation"
|
||||||
reputationEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/reputation"
|
reputationEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/reputation"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
|
||||||
apireputation "github.com/nspcc-dev/neofs-sdk-go/reputation"
|
apireputation "github.com/nspcc-dev/neofs-sdk-go/reputation"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
@ -37,16 +36,16 @@ func (rp *Processor) processPut(e *reputationEvent.Put) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check signature
|
// check signature
|
||||||
if err := value.VerifySignature(); err != nil {
|
if !value.VerifySignature() {
|
||||||
rp.log.Info("ignore reputation value",
|
rp.log.Info("ignore reputation value",
|
||||||
zap.String("reason", "invalid signature"),
|
zap.String("reason", "invalid signature"),
|
||||||
zap.String("error", err.Error()))
|
)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if manager is correct
|
// check if manager is correct
|
||||||
if err := rp.checkManagers(epoch, *value.Manager(), id); err != nil {
|
if err := rp.checkManagers(epoch, value.Manager(), id); err != nil {
|
||||||
rp.log.Info("ignore reputation value",
|
rp.log.Info("ignore reputation value",
|
||||||
zap.String("reason", "wrong manager"),
|
zap.String("reason", "wrong manager"),
|
||||||
zap.String("error", err.Error()))
|
zap.String("error", err.Error()))
|
||||||
|
@ -58,14 +57,14 @@ func (rp *Processor) processPut(e *reputationEvent.Put) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rp *Processor) checkManagers(e uint64, mng apireputation.PeerID, peer apireputation.PeerID) error {
|
func (rp *Processor) checkManagers(e uint64, mng apireputation.PeerID, peer apireputation.PeerID) error {
|
||||||
mm, err := rp.mngBuilder.BuildManagers(e, reputation.PeerIDFromBytes(peer.ToV2().GetPublicKey()))
|
mm, err := rp.mngBuilder.BuildManagers(e, peer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not build managers: %w", err)
|
return fmt.Errorf("could not build managers: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, m := range mm {
|
for _, m := range mm {
|
||||||
// FIXME: #1147 do not use `ToV2` method outside neofs-api-go library
|
// FIXME: #1147 do not use `ToV2` method outside neofs-api-go library
|
||||||
if bytes.Equal(mng.ToV2().GetPublicKey(), m.PublicKey()) {
|
if bytes.Equal(mng.PublicKey(), m.PublicKey()) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,7 +92,7 @@ func (rp *Processor) approvePutReputation(e *reputationEvent.Put) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// FIXME: #1147 do not use `ToV2` method outside neofs-api-go library
|
// FIXME: #1147 do not use `ToV2` method outside neofs-api-go library
|
||||||
rp.log.Warn("can't send approval tx for reputation value",
|
rp.log.Warn("can't send approval tx for reputation value",
|
||||||
zap.String("peer_id", hex.EncodeToString(id.ToV2().GetPublicKey())),
|
zap.String("peer_id", hex.EncodeToString(id.PublicKey())),
|
||||||
zap.String("error", err.Error()))
|
zap.String("error", err.Error()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ func (g *GetByIDPrm) SetID(v ID) {
|
||||||
func (c *Client) Get(p GetPrm) ([]reputation.GlobalTrust, error) {
|
func (c *Client) Get(p GetPrm) ([]reputation.GlobalTrust, error) {
|
||||||
invokePrm := client.TestInvokePrm{}
|
invokePrm := client.TestInvokePrm{}
|
||||||
invokePrm.SetMethod(getMethod)
|
invokePrm.SetMethod(getMethod)
|
||||||
invokePrm.SetArgs(p.epoch, p.peerID.ToV2().GetPublicKey())
|
invokePrm.SetArgs(p.epoch, p.peerID.PublicKey())
|
||||||
|
|
||||||
res, err := c.client.TestInvoke(invokePrm)
|
res, err := c.client.TestInvoke(invokePrm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -35,16 +35,11 @@ func (p *PutPrm) SetValue(v reputation.GlobalTrust) {
|
||||||
//
|
//
|
||||||
// If TryNotary is provided, calls notary contract.
|
// If TryNotary is provided, calls notary contract.
|
||||||
func (c *Client) Put(p PutPrm) error {
|
func (c *Client) Put(p PutPrm) error {
|
||||||
data, err := p.value.Marshal()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't marshal global trust value: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
prm := client.InvokePrm{}
|
prm := client.InvokePrm{}
|
||||||
prm.SetMethod(putMethod)
|
prm.SetMethod(putMethod)
|
||||||
prm.SetArgs(p.epoch, p.peerID.ToV2().GetPublicKey(), data)
|
prm.SetArgs(p.epoch, p.peerID.PublicKey(), p.value.Marshal())
|
||||||
|
|
||||||
err = c.client.Invoke(prm)
|
err := c.client.Invoke(prm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not invoke method (%s): %w", putMethod, err)
|
return fmt.Errorf("could not invoke method (%s): %w", putMethod, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,9 +82,7 @@ func ParsePut(e *subscriptions.NotificationEvent) (event.Event, error) {
|
||||||
return nil, fmt.Errorf("peer ID is %d byte long, expected %d", ln, peerIDLength)
|
return nil, fmt.Errorf("peer ID is %d byte long, expected %d", ln, peerIDLength)
|
||||||
}
|
}
|
||||||
|
|
||||||
var publicKey [33]byte
|
ev.peerID.SetPublicKey(peerID)
|
||||||
copy(publicKey[:], peerID)
|
|
||||||
ev.peerID.SetPublicKey(publicKey)
|
|
||||||
|
|
||||||
// parse global trust value
|
// parse global trust value
|
||||||
rawValue, err := client.BytesFromStackItem(params[2])
|
rawValue, err := client.BytesFromStackItem(params[2])
|
||||||
|
|
|
@ -15,9 +15,7 @@ func (p *Put) setPeerID(v []byte) error {
|
||||||
return fmt.Errorf("peer ID is %d byte long, expected %d", ln, peerIDLength)
|
return fmt.Errorf("peer ID is %d byte long, expected %d", ln, peerIDLength)
|
||||||
}
|
}
|
||||||
|
|
||||||
var publicKey [33]byte
|
p.peerID.SetPublicKey(v)
|
||||||
copy(publicKey[:], v)
|
|
||||||
p.peerID.SetPublicKey(publicKey)
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,31 +9,27 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/reputation"
|
"github.com/nspcc-dev/neofs-sdk-go/reputation"
|
||||||
|
reputationtest "github.com/nspcc-dev/neofs-sdk-go/reputation/test"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestParsePut(t *testing.T) {
|
func TestParsePut(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
peerID reputation.PeerID
|
peerID = reputationtest.PeerID()
|
||||||
|
|
||||||
value reputation.GlobalTrust
|
value reputation.GlobalTrust
|
||||||
trust reputation.Trust
|
trust reputation.Trust
|
||||||
trustValue float64 = 64
|
trustValue float64 = 0.64
|
||||||
|
|
||||||
epoch uint64 = 42
|
epoch uint64 = 42
|
||||||
|
|
||||||
rawPeerID = [33]byte{1, 2, 3, 4, 5, 6}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
peerID.SetPublicKey(rawPeerID)
|
|
||||||
|
|
||||||
trust.SetValue(trustValue)
|
trust.SetValue(trustValue)
|
||||||
trust.SetPeer(&peerID)
|
trust.SetPeer(peerID)
|
||||||
|
|
||||||
value.SetTrust(&trust)
|
value.SetTrust(trust)
|
||||||
|
|
||||||
rawValue, err := value.Marshal()
|
rawValue := value.Marshal()
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
t.Run("wrong number of parameters", func(t *testing.T) {
|
t.Run("wrong number of parameters", func(t *testing.T) {
|
||||||
prms := []stackitem.Item{
|
prms := []stackitem.Item{
|
||||||
|
@ -65,7 +61,7 @@ func TestParsePut(t *testing.T) {
|
||||||
t.Run("wrong value parameter", func(t *testing.T) {
|
t.Run("wrong value parameter", func(t *testing.T) {
|
||||||
_, err := ParsePut(createNotifyEventFromItems([]stackitem.Item{
|
_, err := ParsePut(createNotifyEventFromItems([]stackitem.Item{
|
||||||
stackitem.NewBigInteger(new(big.Int).SetUint64(epoch)),
|
stackitem.NewBigInteger(new(big.Int).SetUint64(epoch)),
|
||||||
stackitem.NewByteArray(rawPeerID[:]),
|
stackitem.NewByteArray(peerID.PublicKey()),
|
||||||
stackitem.NewMap(),
|
stackitem.NewMap(),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
@ -75,7 +71,7 @@ func TestParsePut(t *testing.T) {
|
||||||
t.Run("correct behavior", func(t *testing.T) {
|
t.Run("correct behavior", func(t *testing.T) {
|
||||||
ev, err := ParsePut(createNotifyEventFromItems([]stackitem.Item{
|
ev, err := ParsePut(createNotifyEventFromItems([]stackitem.Item{
|
||||||
stackitem.NewBigInteger(new(big.Int).SetUint64(epoch)),
|
stackitem.NewBigInteger(new(big.Int).SetUint64(epoch)),
|
||||||
stackitem.NewByteArray(rawPeerID[:]),
|
stackitem.NewByteArray(peerID.PublicKey()),
|
||||||
stackitem.NewByteArray(rawValue),
|
stackitem.NewByteArray(rawValue),
|
||||||
}))
|
}))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
||||||
|
apireputation "github.com/nspcc-dev/neofs-sdk-go/reputation"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Context wraps stdlib context
|
// Context wraps stdlib context
|
||||||
|
@ -59,7 +60,7 @@ type WriterProvider interface {
|
||||||
type ManagerBuilder interface {
|
type ManagerBuilder interface {
|
||||||
// BuildManagers must compose list of managers. It depends on
|
// BuildManagers must compose list of managers. It depends on
|
||||||
// particular epoch and PeerID of the current route point.
|
// particular epoch and PeerID of the current route point.
|
||||||
BuildManagers(epoch uint64, p reputation.PeerID) ([]ServerInfo, error)
|
BuildManagers(epoch uint64, p apireputation.PeerID) ([]ServerInfo, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServerInfo describes a set of
|
// ServerInfo describes a set of
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/hex"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/nspcc-dev/hrw"
|
"github.com/nspcc-dev/hrw"
|
||||||
netmapcore "github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
netmapcore "github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||||
apiNetmap "github.com/nspcc-dev/neofs-sdk-go/netmap"
|
apiNetmap "github.com/nspcc-dev/neofs-sdk-go/netmap"
|
||||||
|
apireputation "github.com/nspcc-dev/neofs-sdk-go/reputation"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -73,10 +71,10 @@ func (x nodeServer) NumberOfAddresses() int {
|
||||||
|
|
||||||
// BuildManagers sorts nodes in NetMap with HRW algorithms and
|
// BuildManagers sorts nodes in NetMap with HRW algorithms and
|
||||||
// takes the next node after the current one as the only manager.
|
// takes the next node after the current one as the only manager.
|
||||||
func (mb *managerBuilder) BuildManagers(epoch uint64, p reputation.PeerID) ([]ServerInfo, error) {
|
func (mb *managerBuilder) BuildManagers(epoch uint64, p apireputation.PeerID) ([]ServerInfo, error) {
|
||||||
mb.log.Debug("start building managers",
|
mb.log.Debug("start building managers",
|
||||||
zap.Uint64("epoch", epoch),
|
zap.Uint64("epoch", epoch),
|
||||||
zap.String("peer", hex.EncodeToString(p.Bytes())),
|
zap.Stringer("peer", p),
|
||||||
)
|
)
|
||||||
|
|
||||||
nm, err := mb.nmSrc.GetNetMapByEpoch(epoch)
|
nm, err := mb.nmSrc.GetNetMapByEpoch(epoch)
|
||||||
|
@ -94,7 +92,7 @@ func (mb *managerBuilder) BuildManagers(epoch uint64, p reputation.PeerID) ([]Se
|
||||||
hrw.SortSliceByValue(nodes, epoch)
|
hrw.SortSliceByValue(nodes, epoch)
|
||||||
|
|
||||||
for i := range nodes {
|
for i := range nodes {
|
||||||
if bytes.Equal(nodes[i].PublicKey(), p.Bytes()) {
|
if apireputation.ComparePeerKey(p, nodes[i].PublicKey()) {
|
||||||
managerIndex := i + 1
|
managerIndex := i + 1
|
||||||
|
|
||||||
if managerIndex == len(nodes) {
|
if managerIndex == len(nodes) {
|
||||||
|
|
|
@ -2,10 +2,10 @@ package eigentrustcalc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/hex"
|
|
||||||
|
|
||||||
"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"
|
||||||
|
apireputation "github.com/nspcc-dev/neofs-sdk-go/reputation"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ func (c *Calculator) Calculate(prm CalculatePrm) {
|
||||||
// continue with initial iteration number
|
// continue with initial iteration number
|
||||||
ctx.SetI(iter)
|
ctx.SetI(iter)
|
||||||
|
|
||||||
err = consumersIter.Iterate(func(daughter reputation.PeerID, iter TrustIterator) error {
|
err = consumersIter.Iterate(func(daughter apireputation.PeerID, iter TrustIterator) error {
|
||||||
err := c.prm.WorkerPool.Submit(func() {
|
err := c.prm.WorkerPool.Submit(func() {
|
||||||
c.iterateDaughter(iterDaughterPrm{
|
c.iterateDaughter(iterDaughterPrm{
|
||||||
lastIter: prm.last,
|
lastIter: prm.last,
|
||||||
|
@ -99,7 +99,7 @@ type iterDaughterPrm struct {
|
||||||
|
|
||||||
ctx Context
|
ctx Context
|
||||||
|
|
||||||
id reputation.PeerID
|
id apireputation.PeerID
|
||||||
|
|
||||||
consumersIter TrustIterator
|
consumersIter TrustIterator
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ func (c *Calculator) iterateDaughter(p iterDaughterPrm) {
|
||||||
initTrust, err := c.prm.InitialTrustSource.InitialTrust(p.id)
|
initTrust, err := c.prm.InitialTrustSource.InitialTrust(p.id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.opts.log.Debug("get initial trust failure",
|
c.opts.log.Debug("get initial trust failure",
|
||||||
zap.String("daughter", hex.EncodeToString(p.id.Bytes())),
|
zap.Stringer("daughter", p.id),
|
||||||
zap.String("error", err.Error()),
|
zap.String("error", err.Error()),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -244,14 +244,14 @@ func (c *Calculator) sendInitialValues(ctx Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = daughterIter.Iterate(func(daughter reputation.PeerID, iterator TrustIterator) error {
|
err = daughterIter.Iterate(func(daughter apireputation.PeerID, iterator TrustIterator) error {
|
||||||
return iterator.Iterate(func(trust reputation.Trust) error {
|
return iterator.Iterate(func(trust reputation.Trust) error {
|
||||||
trusted := trust.Peer()
|
trusted := trust.Peer()
|
||||||
|
|
||||||
initTrust, err := c.prm.InitialTrustSource.InitialTrust(trusted)
|
initTrust, err := c.prm.InitialTrustSource.InitialTrust(trusted)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.opts.log.Debug("get initial trust failure",
|
c.opts.log.Debug("get initial trust failure",
|
||||||
zap.String("peer", hex.EncodeToString(trusted.Bytes())),
|
zap.Stringer("peer", trusted),
|
||||||
zap.String("error", err.Error()),
|
zap.String("error", err.Error()),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -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"
|
||||||
|
apireputation "github.com/nspcc-dev/neofs-sdk-go/reputation"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Context interface {
|
type Context interface {
|
||||||
|
@ -22,7 +23,7 @@ type Context interface {
|
||||||
// trusts to current node's daughter. Realization may depends
|
// trusts to current node's daughter. Realization may depends
|
||||||
// on daughter.
|
// on daughter.
|
||||||
type InitialTrustSource interface {
|
type InitialTrustSource interface {
|
||||||
InitialTrust(reputation.PeerID) (reputation.TrustValue, error)
|
InitialTrust(apireputation.PeerID) (reputation.TrustValue, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TrustIterator must iterate over all retrieved(or calculated) trusts
|
// TrustIterator must iterate over all retrieved(or calculated) trusts
|
||||||
|
@ -31,7 +32,7 @@ type TrustIterator interface {
|
||||||
Iterate(reputation.TrustHandler) error
|
Iterate(reputation.TrustHandler) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type PeerTrustsHandler func(reputation.PeerID, TrustIterator) error
|
type PeerTrustsHandler func(apireputation.PeerID, TrustIterator) error
|
||||||
|
|
||||||
// PeerTrustsIterator must iterate over all nodes(PeerIDs) and provide
|
// PeerTrustsIterator must iterate over all nodes(PeerIDs) and provide
|
||||||
// TrustIterator for iteration over node's Trusts to others peers.
|
// TrustIterator for iteration over node's Trusts to others peers.
|
||||||
|
@ -43,7 +44,7 @@ type DaughterTrustIteratorProvider interface {
|
||||||
// InitDaughterIterator must init TrustIterator
|
// InitDaughterIterator must init TrustIterator
|
||||||
// that iterates over received local trusts from
|
// that iterates over received local trusts from
|
||||||
// daughter p for ctx.Epoch() epoch.
|
// daughter p for ctx.Epoch() epoch.
|
||||||
InitDaughterIterator(ctx Context, p reputation.PeerID) (TrustIterator, error)
|
InitDaughterIterator(ctx Context, p apireputation.PeerID) (TrustIterator, error)
|
||||||
// InitAllDaughtersIterator must init PeerTrustsIterator
|
// InitAllDaughtersIterator must init PeerTrustsIterator
|
||||||
// that must iterate over all daughters of the current
|
// that must iterate over all daughters of the current
|
||||||
// node(manager) and all trusts received from them for
|
// node(manager) and all trusts received from them for
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
package consumerstorage
|
package consumerstorage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"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"
|
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.
|
// 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]
|
s = x.mItems[iter]
|
||||||
if s == nil {
|
if s == nil {
|
||||||
s = &ConsumersStorage{
|
s = &ConsumersStorage{
|
||||||
mItems: make(map[reputation.PeerID]*ConsumersTrusts, 1),
|
mItems: make(map[string]*ConsumersTrusts, 1),
|
||||||
}
|
}
|
||||||
|
|
||||||
x.mItems[iter] = s
|
x.mItems[iter] = s
|
||||||
|
@ -107,7 +109,7 @@ func (x *iterationConsumersStorage) consumers(iter uint32) (s *ConsumersStorage,
|
||||||
type ConsumersStorage struct {
|
type ConsumersStorage struct {
|
||||||
mtx sync.RWMutex
|
mtx sync.RWMutex
|
||||||
|
|
||||||
mItems map[reputation.PeerID]*ConsumersTrusts
|
mItems map[string]*ConsumersTrusts
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *ConsumersStorage) put(trust eigentrust.IterationTrust) {
|
func (x *ConsumersStorage) put(trust eigentrust.IterationTrust) {
|
||||||
|
@ -116,12 +118,12 @@ func (x *ConsumersStorage) put(trust eigentrust.IterationTrust) {
|
||||||
x.mtx.Lock()
|
x.mtx.Lock()
|
||||||
|
|
||||||
{
|
{
|
||||||
daughter := trust.Peer()
|
daughter := trust.Peer().EncodeToString()
|
||||||
|
|
||||||
s = x.mItems[daughter]
|
s = x.mItems[daughter]
|
||||||
if s == nil {
|
if s == nil {
|
||||||
s = &ConsumersTrusts{
|
s = &ConsumersTrusts{
|
||||||
mItems: make(map[reputation.PeerID]reputation.Trust, 1),
|
mItems: make(map[string]reputation.Trust, 1),
|
||||||
}
|
}
|
||||||
|
|
||||||
x.mItems[daughter] = s
|
x.mItems[daughter] = s
|
||||||
|
@ -140,7 +142,16 @@ func (x *ConsumersStorage) Iterate(h eigentrustcalc.PeerTrustsHandler) (err erro
|
||||||
x.mtx.RLock()
|
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 {
|
if err = h(trusted, trusts); err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -157,14 +168,14 @@ func (x *ConsumersStorage) Iterate(h eigentrustcalc.PeerTrustsHandler) (err erro
|
||||||
type ConsumersTrusts struct {
|
type ConsumersTrusts struct {
|
||||||
mtx sync.RWMutex
|
mtx sync.RWMutex
|
||||||
|
|
||||||
mItems map[reputation.PeerID]reputation.Trust
|
mItems map[string]reputation.Trust
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *ConsumersTrusts) put(trust eigentrust.IterationTrust) {
|
func (x *ConsumersTrusts) put(trust eigentrust.IterationTrust) {
|
||||||
x.mtx.Lock()
|
x.mtx.Lock()
|
||||||
|
|
||||||
{
|
{
|
||||||
x.mItems[trust.TrustingPeer()] = trust.Trust
|
x.mItems[trust.TrustingPeer().EncodeToString()] = trust.Trust
|
||||||
}
|
}
|
||||||
|
|
||||||
x.mtx.Unlock()
|
x.mtx.Unlock()
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package daughters
|
package daughters
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"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"
|
eigentrustcalc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/calculator"
|
||||||
|
apireputation "github.com/nspcc-dev/neofs-sdk-go/reputation"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Put saves daughter peer's trust to its provider for the epoch.
|
// Put saves daughter peer's trust to its provider for the epoch.
|
||||||
|
@ -17,7 +19,7 @@ func (x *Storage) Put(epoch uint64, trust reputation.Trust) {
|
||||||
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[string]*DaughterTrusts, 1),
|
||||||
}
|
}
|
||||||
|
|
||||||
x.mItems[epoch] = s
|
x.mItems[epoch] = s
|
||||||
|
@ -32,7 +34,7 @@ func (x *Storage) Put(epoch uint64, trust reputation.Trust) {
|
||||||
// DaughterTrusts returns daughter trusts for the epoch.
|
// DaughterTrusts returns daughter trusts 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) DaughterTrusts(epoch uint64, daughter reputation.PeerID) (*DaughterTrusts, bool) {
|
func (x *Storage) DaughterTrusts(epoch uint64, daughter apireputation.PeerID) (*DaughterTrusts, bool) {
|
||||||
var (
|
var (
|
||||||
s *DaughterStorage
|
s *DaughterStorage
|
||||||
ok bool
|
ok bool
|
||||||
|
@ -69,7 +71,7 @@ func (x *Storage) AllDaughterTrusts(epoch uint64) (*DaughterStorage, bool) {
|
||||||
type DaughterStorage struct {
|
type DaughterStorage struct {
|
||||||
mtx sync.RWMutex
|
mtx sync.RWMutex
|
||||||
|
|
||||||
mItems map[reputation.PeerID]*DaughterTrusts
|
mItems map[string]*DaughterTrusts
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate passes IDs of the daughter peers with their trusts to h.
|
// Iterate passes IDs of the daughter peers with their trusts to h.
|
||||||
|
@ -79,7 +81,16 @@ func (x *DaughterStorage) Iterate(h eigentrustcalc.PeerTrustsHandler) (err error
|
||||||
x.mtx.RLock()
|
x.mtx.RLock()
|
||||||
|
|
||||||
{
|
{
|
||||||
for daughter, daughterTrusts := range x.mItems {
|
for strDaughter, daughterTrusts := range x.mItems {
|
||||||
|
var daughter apireputation.PeerID
|
||||||
|
|
||||||
|
if strDaughter != "" {
|
||||||
|
err = daughter.DecodeString(strDaughter)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("decode peer ID string %s: %v", strDaughter, err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err = h(daughter, daughterTrusts); err != nil {
|
if err = h(daughter, daughterTrusts); err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -97,12 +108,12 @@ func (x *DaughterStorage) put(trust reputation.Trust) {
|
||||||
x.mtx.Lock()
|
x.mtx.Lock()
|
||||||
|
|
||||||
{
|
{
|
||||||
trusting := trust.TrustingPeer()
|
trusting := trust.TrustingPeer().EncodeToString()
|
||||||
|
|
||||||
dt = x.mItems[trusting]
|
dt = x.mItems[trusting]
|
||||||
if dt == nil {
|
if dt == nil {
|
||||||
dt = &DaughterTrusts{
|
dt = &DaughterTrusts{
|
||||||
mItems: make(map[reputation.PeerID]reputation.Trust, 1),
|
mItems: make(map[string]reputation.Trust, 1),
|
||||||
}
|
}
|
||||||
|
|
||||||
x.mItems[trusting] = dt
|
x.mItems[trusting] = dt
|
||||||
|
@ -114,11 +125,11 @@ 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 apireputation.PeerID) (dt *DaughterTrusts, ok bool) {
|
||||||
x.mtx.RLock()
|
x.mtx.RLock()
|
||||||
|
|
||||||
{
|
{
|
||||||
dt, ok = x.mItems[id]
|
dt, ok = x.mItems[id.EncodeToString()]
|
||||||
}
|
}
|
||||||
|
|
||||||
x.mtx.RUnlock()
|
x.mtx.RUnlock()
|
||||||
|
@ -133,14 +144,14 @@ func (x *DaughterStorage) daughterTrusts(id reputation.PeerID) (dt *DaughterTrus
|
||||||
type DaughterTrusts struct {
|
type DaughterTrusts struct {
|
||||||
mtx sync.RWMutex
|
mtx sync.RWMutex
|
||||||
|
|
||||||
mItems map[reputation.PeerID]reputation.Trust
|
mItems map[string]reputation.Trust
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *DaughterTrusts) put(trust reputation.Trust) {
|
func (x *DaughterTrusts) put(trust reputation.Trust) {
|
||||||
x.mtx.Lock()
|
x.mtx.Lock()
|
||||||
|
|
||||||
{
|
{
|
||||||
x.mItems[trust.Peer()] = trust
|
x.mItems[trust.Peer().EncodeToString()] = trust
|
||||||
}
|
}
|
||||||
|
|
||||||
x.mtx.Unlock()
|
x.mtx.Unlock()
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
||||||
|
apireputation "github.com/nspcc-dev/neofs-sdk-go/reputation"
|
||||||
)
|
)
|
||||||
|
|
||||||
// UpdatePrm groups the parameters of Storage's Update operation.
|
// UpdatePrm groups the parameters of Storage's Update operation.
|
||||||
|
@ -13,7 +14,7 @@ type UpdatePrm struct {
|
||||||
|
|
||||||
epoch uint64
|
epoch uint64
|
||||||
|
|
||||||
peer reputation.PeerID
|
peer apireputation.PeerID
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetEpoch sets number of the epoch
|
// SetEpoch sets number of the epoch
|
||||||
|
@ -24,7 +25,7 @@ func (p *UpdatePrm) SetEpoch(e uint64) {
|
||||||
|
|
||||||
// SetPeer sets identifier of the peer
|
// SetPeer sets identifier of the peer
|
||||||
// with which the local node interacted.
|
// with which the local node interacted.
|
||||||
func (p *UpdatePrm) SetPeer(id reputation.PeerID) {
|
func (p *UpdatePrm) SetPeer(id apireputation.PeerID) {
|
||||||
p.peer = id
|
p.peer = id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,12 +52,13 @@ func newTrustValueStorage() *EpochTrustValueStorage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func stringifyPeerID(id reputation.PeerID) string {
|
func stringifyPeerID(id apireputation.PeerID) string {
|
||||||
return string(id.Bytes())
|
return string(id.PublicKey())
|
||||||
}
|
}
|
||||||
|
|
||||||
func peerIDFromString(str string) reputation.PeerID {
|
func peerIDFromString(str string) (res apireputation.PeerID) {
|
||||||
return reputation.PeerIDFromBytes([]byte(str))
|
res.SetPublicKey([]byte(str))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *EpochTrustValueStorage) update(prm UpdatePrm) {
|
func (s *EpochTrustValueStorage) update(prm UpdatePrm) {
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
package reputation
|
|
||||||
|
|
||||||
const peerIDLength = 33
|
|
||||||
|
|
||||||
// PeerID represents identifier of reputation system participant.
|
|
||||||
type PeerID [peerIDLength]byte
|
|
||||||
|
|
||||||
// Bytes converts PeerID to []byte.
|
|
||||||
func (id PeerID) Bytes() []byte {
|
|
||||||
return id[:]
|
|
||||||
}
|
|
||||||
|
|
||||||
// PeerIDFromBytes restores PeerID from []byte.
|
|
||||||
func PeerIDFromBytes(data []byte) (id PeerID) {
|
|
||||||
copy(id[:], data)
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -2,6 +2,8 @@ package reputation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-sdk-go/reputation"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TrustValue represents the numeric value of the node's trust.
|
// TrustValue represents the numeric value of the node's trust.
|
||||||
|
@ -56,7 +58,7 @@ func (v TrustValue) IsZero() bool {
|
||||||
|
|
||||||
// Trust represents peer's trust (reputation).
|
// Trust represents peer's trust (reputation).
|
||||||
type Trust struct {
|
type Trust struct {
|
||||||
trusting, peer PeerID
|
trusting, peer reputation.PeerID
|
||||||
|
|
||||||
val TrustValue
|
val TrustValue
|
||||||
}
|
}
|
||||||
|
@ -80,21 +82,21 @@ func (t *Trust) SetValue(val TrustValue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Peer returns trusted peer ID.
|
// Peer returns trusted peer ID.
|
||||||
func (t Trust) Peer() PeerID {
|
func (t Trust) Peer() reputation.PeerID {
|
||||||
return t.peer
|
return t.peer
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetPeer sets trusted peer ID.
|
// SetPeer sets trusted peer ID.
|
||||||
func (t *Trust) SetPeer(id PeerID) {
|
func (t *Trust) SetPeer(id reputation.PeerID) {
|
||||||
t.peer = id
|
t.peer = id
|
||||||
}
|
}
|
||||||
|
|
||||||
// TrustingPeer returns trusting peer ID.
|
// TrustingPeer returns trusting peer ID.
|
||||||
func (t Trust) TrustingPeer() PeerID {
|
func (t Trust) TrustingPeer() reputation.PeerID {
|
||||||
return t.trusting
|
return t.trusting
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetTrustingPeer sets trusting peer ID.
|
// SetTrustingPeer sets trusting peer ID.
|
||||||
func (t *Trust) SetTrustingPeer(id PeerID) {
|
func (t *Trust) SetTrustingPeer(id reputation.PeerID) {
|
||||||
t.trusting = id
|
t.trusting = id
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue