[#1401] services/tree: Marshal public key once

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-05-26 15:40:44 +03:00 committed by fyrchik
parent 1f5a650b05
commit 01d2e06a9b
3 changed files with 7 additions and 8 deletions

View file

@ -3,6 +3,7 @@ package tree
import (
"crypto/ecdsa"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neofs-node/pkg/core/container"
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/pilorama"
@ -12,6 +13,7 @@ import (
type cfg struct {
log *zap.Logger
key *ecdsa.PrivateKey
rawPub []byte
nmSource netmap.Source
cnrSource container.Source
forest pilorama.Forest
@ -41,6 +43,7 @@ func WithNetmapSource(src netmap.Source) Option {
func WithPrivateKey(key *ecdsa.PrivateKey) Option {
return func(c *cfg) {
c.key = key
c.rawPub = (*keys.PublicKey)(&key.PublicKey).Bytes()
}
}

View file

@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neofs-node/pkg/network"
cidSDK "github.com/nspcc-dev/neofs-sdk-go/container/id"
"go.uber.org/zap"
@ -24,9 +23,8 @@ func (s *Service) forEachNode(ctx context.Context, cid cidSDK.ID, f func(c TreeS
return fmt.Errorf("can't get container nodes for %s: %w", cid, err)
}
rawPub := (*keys.PublicKey)(&s.key.PublicKey).Bytes()
for _, n := range cntNodes {
if bytes.Equal(n.PublicKey(), rawPub) {
if bytes.Equal(n.PublicKey(), s.rawPub) {
return nil
}
}

View file

@ -8,7 +8,6 @@ import (
"fmt"
"time"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
clientcore "github.com/nspcc-dev/neofs-node/pkg/core/client"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/pilorama"
"github.com/nspcc-dev/neofs-node/pkg/network"
@ -31,7 +30,6 @@ const (
)
func (s *Service) replicateLoop(ctx context.Context) {
rawKey := (*keys.PublicKey)(&s.key.PublicKey).Bytes()
for {
select {
case <-s.closeCh:
@ -39,7 +37,7 @@ func (s *Service) replicateLoop(ctx context.Context) {
return
case op := <-s.replicateCh:
ctx, cancel := context.WithTimeout(ctx, defaultReplicatorTimeout)
err := s.replicate(ctx, rawKey, op)
err := s.replicate(ctx, op)
cancel()
if err != nil {
@ -52,7 +50,7 @@ func (s *Service) replicateLoop(ctx context.Context) {
}
}
func (s *Service) replicate(ctx context.Context, rawKey []byte, op movePair) error {
func (s *Service) replicate(ctx context.Context, op movePair) error {
req := newApplyRequest(&op)
err := signMessage(req, s.key)
if err != nil {
@ -66,7 +64,7 @@ func (s *Service) replicate(ctx context.Context, rawKey []byte, op movePair) err
var node clientcore.NodeInfo
for _, n := range nodes {
if bytes.Equal(n.PublicKey(), rawKey) {
if bytes.Equal(n.PublicKey(), s.rawPub) {
continue
}