From 44a2c81f8efb2e85c9d9ad3a113a2e9f588a5724 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 22 Jun 2021 18:40:39 +0300 Subject: [PATCH] [#607] reputation/router: Use public keys as keys to server cache In future server info will contain multiple endpoints whose string representation will be worse suited to the cache key. Signed-off-by: Leonard Lyubich --- pkg/services/reputation/common/router/calls.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/services/reputation/common/router/calls.go b/pkg/services/reputation/common/router/calls.go index 76df4e7c..2794107d 100644 --- a/pkg/services/reputation/common/router/calls.go +++ b/pkg/services/reputation/common/router/calls.go @@ -1,6 +1,7 @@ package router import ( + "encoding/hex" "sync" "github.com/nspcc-dev/neofs-node/pkg/services/reputation" @@ -80,13 +81,13 @@ func (w *trustWriter) Write(t reputation.Trust) error { } for _, remoteInfo := range route { - var endpoint string + var key string if remoteInfo != nil { - endpoint = remoteInfo.Address() + key = hex.EncodeToString(remoteInfo.PublicKey()) } - remoteWriter, ok := w.mServers[endpoint] + remoteWriter, ok := w.mServers[key] if !ok { provider, err := w.router.remoteProvider.InitRemote(remoteInfo) if err != nil { @@ -107,7 +108,7 @@ func (w *trustWriter) Write(t reputation.Trust) error { continue } - w.mServers[endpoint] = remoteWriter + w.mServers[key] = remoteWriter } err := remoteWriter.Write(t) @@ -122,11 +123,11 @@ func (w *trustWriter) Write(t reputation.Trust) error { } func (w *trustWriter) Close() error { - for endpoint, wRemote := range w.mServers { + for key, wRemote := range w.mServers { err := wRemote.Close() if err != nil { w.router.log.Debug("could not close remote server writer", - zap.String("endpoint", endpoint), + zap.String("key", key), zap.String("error", err.Error()), ) }