From c4a1c7008966783f6d2e080b6a65349bcac105c6 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 23 Mar 2021 21:51:31 +0300 Subject: [PATCH] [#428] cmd/node: Implement logging writer provider Implement simple `WriterProvider` building a `Writer` that writes incoming data to the log. In the future, this action will be replaced by sending the value to the manager nodes. Signed-off-by: Leonard Lyubich --- cmd/neofs-node/reputation.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/cmd/neofs-node/reputation.go b/cmd/neofs-node/reputation.go index 147b14f32..821c8517f 100644 --- a/cmd/neofs-node/reputation.go +++ b/cmd/neofs-node/reputation.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "encoding/hex" netmapcore "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/services/reputation" @@ -9,6 +10,7 @@ import ( truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage" "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/pkg/errors" + "go.uber.org/zap" ) type localTrustStorage struct { @@ -88,3 +90,30 @@ func (it *localTrustIterator) Iterate(h reputation.TrustHandler) error { return nil } + +func (s *localTrustStorage) InitWriter(ctx trustcontroller.Context) (trustcontroller.Writer, error) { + return &localTrustLogger{ + ctx: ctx, + log: s.log, + }, nil +} + +type localTrustLogger struct { + ctx trustcontroller.Context + + log *logger.Logger +} + +func (l *localTrustLogger) Write(t reputation.Trust) error { + l.log.Info("new local trust", + zap.Uint64("epoch", l.ctx.Epoch()), + zap.String("peer", hex.EncodeToString(t.Peer().Bytes())), + zap.Stringer("value", t.Value()), + ) + + return nil +} + +func (*localTrustLogger) Close() error { + return nil +}