forked from TrueCloudLab/frostfs-node
[#613] pkg/innerring: Add sanity check of GlobalTrust
Add sanity checks of GlobalTrust value: check if "got manager" is real manager for peer with building managers for peer. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
6b176e8769
commit
ed9a5e44b6
3 changed files with 44 additions and 5 deletions
|
@ -1,14 +1,20 @@
|
|||
package reputation
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/reputation"
|
||||
apireputation "github.com/nspcc-dev/neofs-api-go/pkg/reputation"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation/wrapper"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func (rp *Processor) processPut(epoch uint64, id reputation.PeerID, value reputation.GlobalTrust) {
|
||||
var errWrongManager = errors.New("got manager that is incorrect for peer")
|
||||
|
||||
func (rp *Processor) processPut(epoch uint64, id apireputation.PeerID, value apireputation.GlobalTrust) {
|
||||
if !rp.alphabetState.IsAlphabet() {
|
||||
rp.log.Info("non alphabet mode, ignore reputation put notification")
|
||||
return
|
||||
|
@ -34,7 +40,14 @@ func (rp *Processor) processPut(epoch uint64, id reputation.PeerID, value reputa
|
|||
return
|
||||
}
|
||||
|
||||
// todo: do sanity checks of value
|
||||
// check if manager is correct
|
||||
if err := rp.checkManagers(epoch, *value.Manager(), id); err != nil {
|
||||
rp.log.Info("ignore reputation value",
|
||||
zap.String("reason", "wrong manager"),
|
||||
zap.String("error", err.Error()))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
args := wrapper.PutArgs{}
|
||||
args.SetEpoch(epoch)
|
||||
|
@ -48,3 +61,18 @@ func (rp *Processor) processPut(epoch uint64, id reputation.PeerID, value reputa
|
|||
zap.String("error", err.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()))
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not build managers: %w", err)
|
||||
}
|
||||
|
||||
for _, m := range mm {
|
||||
if bytes.Equal(mng.ToV2().GetPublicKey(), m.PublicKey()) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return errWrongManager
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue