[#1426] services/tree: Do not replicate to a local node

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-05-24 14:27:09 +03:00 committed by fyrchik
parent 7703dd5d7f
commit 886baf3136

View file

@ -1,12 +1,14 @@
package tree package tree
import ( import (
"bytes"
"context" "context"
"crypto/sha256" "crypto/sha256"
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"time" "time"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
clientcore "github.com/nspcc-dev/neofs-node/pkg/core/client" 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/local_object_storage/pilorama"
"github.com/nspcc-dev/neofs-node/pkg/network" "github.com/nspcc-dev/neofs-node/pkg/network"
@ -29,6 +31,7 @@ const (
) )
func (s *Service) replicateLoop(ctx context.Context) { func (s *Service) replicateLoop(ctx context.Context) {
rawKey := (*keys.PublicKey)(&s.key.PublicKey).Bytes()
for { for {
select { select {
case <-s.closeCh: case <-s.closeCh:
@ -36,7 +39,7 @@ func (s *Service) replicateLoop(ctx context.Context) {
return return
case op := <-s.replicateCh: case op := <-s.replicateCh:
ctx, cancel := context.WithTimeout(ctx, defaultReplicatorTimeout) ctx, cancel := context.WithTimeout(ctx, defaultReplicatorTimeout)
err := s.replicate(ctx, op) err := s.replicate(ctx, rawKey, op)
cancel() cancel()
if err != nil { 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) req := newApplyRequest(&op)
err := signMessage(req, s.key) err := signMessage(req, s.key)
if err != nil { if err != nil {
@ -63,6 +66,10 @@ func (s *Service) replicate(ctx context.Context, op movePair) error {
var node clientcore.NodeInfo var node clientcore.NodeInfo
for _, n := range nodes { for _, n := range nodes {
if bytes.Equal(n.PublicKey(), rawKey) {
continue
}
var lastErr error var lastErr error
n.IterateNetworkEndpoints(func(addr string) bool { n.IterateNetworkEndpoints(func(addr string) bool {