From 01d2e06a9bf315106f3e1e1e9f28a36254cd6ece Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 26 May 2022 15:40:44 +0300 Subject: [PATCH] [#1401] services/tree: Marshal public key once Signed-off-by: Evgenii Stratonikov --- pkg/services/tree/options.go | 3 +++ pkg/services/tree/redirect.go | 4 +--- pkg/services/tree/replicator.go | 8 +++----- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/pkg/services/tree/options.go b/pkg/services/tree/options.go index 2cf2bdf45..59917ec93 100644 --- a/pkg/services/tree/options.go +++ b/pkg/services/tree/options.go @@ -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() } } diff --git a/pkg/services/tree/redirect.go b/pkg/services/tree/redirect.go index 34fefd908..95cbccff9 100644 --- a/pkg/services/tree/redirect.go +++ b/pkg/services/tree/redirect.go @@ -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 } } diff --git a/pkg/services/tree/replicator.go b/pkg/services/tree/replicator.go index 53a3e9ae8..4fdaa53f2 100644 --- a/pkg/services/tree/replicator.go +++ b/pkg/services/tree/replicator.go @@ -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 }