[#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 <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-06-22 18:40:39 +03:00 committed by Leonard Lyubich
parent f7b42a1525
commit 44a2c81f8e

View file

@ -1,6 +1,7 @@
package router package router
import ( import (
"encoding/hex"
"sync" "sync"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation" "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 { for _, remoteInfo := range route {
var endpoint string var key string
if remoteInfo != nil { if remoteInfo != nil {
endpoint = remoteInfo.Address() key = hex.EncodeToString(remoteInfo.PublicKey())
} }
remoteWriter, ok := w.mServers[endpoint] remoteWriter, ok := w.mServers[key]
if !ok { if !ok {
provider, err := w.router.remoteProvider.InitRemote(remoteInfo) provider, err := w.router.remoteProvider.InitRemote(remoteInfo)
if err != nil { if err != nil {
@ -107,7 +108,7 @@ func (w *trustWriter) Write(t reputation.Trust) error {
continue continue
} }
w.mServers[endpoint] = remoteWriter w.mServers[key] = remoteWriter
} }
err := remoteWriter.Write(t) err := remoteWriter.Write(t)
@ -122,11 +123,11 @@ func (w *trustWriter) Write(t reputation.Trust) error {
} }
func (w *trustWriter) Close() error { func (w *trustWriter) Close() error {
for endpoint, wRemote := range w.mServers { for key, wRemote := range w.mServers {
err := wRemote.Close() err := wRemote.Close()
if err != nil { if err != nil {
w.router.log.Debug("could not close remote server writer", w.router.log.Debug("could not close remote server writer",
zap.String("endpoint", endpoint), zap.String("key", key),
zap.String("error", err.Error()), zap.String("error", err.Error()),
) )
} }