From 886baf3136f63535a73e41a44cc5f0a269160c8b Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 24 May 2022 14:27:09 +0300 Subject: [PATCH] [#1426] services/tree: Do not replicate to a local node Signed-off-by: Evgenii Stratonikov --- pkg/services/tree/replicator.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/services/tree/replicator.go b/pkg/services/tree/replicator.go index 7dd9adbac..53a3e9ae8 100644 --- a/pkg/services/tree/replicator.go +++ b/pkg/services/tree/replicator.go @@ -1,12 +1,14 @@ package tree import ( + "bytes" "context" "crypto/sha256" "encoding/base64" "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" @@ -29,6 +31,7 @@ const ( ) func (s *Service) replicateLoop(ctx context.Context) { + rawKey := (*keys.PublicKey)(&s.key.PublicKey).Bytes() for { select { case <-s.closeCh: @@ -36,7 +39,7 @@ func (s *Service) replicateLoop(ctx context.Context) { return case op := <-s.replicateCh: ctx, cancel := context.WithTimeout(ctx, defaultReplicatorTimeout) - err := s.replicate(ctx, op) + err := s.replicate(ctx, rawKey, op) cancel() if err != nil { @@ -49,7 +52,7 @@ func (s *Service) replicateLoop(ctx context.Context) { } } -func (s *Service) replicate(ctx context.Context, op movePair) error { +func (s *Service) replicate(ctx context.Context, rawKey []byte, op movePair) error { req := newApplyRequest(&op) err := signMessage(req, s.key) if err != nil { @@ -63,6 +66,10 @@ func (s *Service) replicate(ctx context.Context, op movePair) error { var node clientcore.NodeInfo for _, n := range nodes { + if bytes.Equal(n.PublicKey(), rawKey) { + continue + } + var lastErr error n.IterateNetworkEndpoints(func(addr string) bool {