[#488] reputation/cmd: Add implementation

Change existing implementations and
add new in `main` package after defining
new interfaces.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-04-23 18:02:55 +03:00 committed by Alex Vanin
parent e69917b27a
commit b75074991b

View file

@ -6,7 +6,9 @@ import (
v2reputation "github.com/nspcc-dev/neofs-api-go/v2/reputation" v2reputation "github.com/nspcc-dev/neofs-api-go/v2/reputation"
v2reputationgrpc "github.com/nspcc-dev/neofs-api-go/v2/reputation/grpc" v2reputationgrpc "github.com/nspcc-dev/neofs-api-go/v2/reputation/grpc"
crypto "github.com/nspcc-dev/neofs-crypto" crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/common"
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/intermediate" "github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/intermediate"
intermediatereputation "github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/intermediate"
localreputation "github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/local" localreputation "github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/local"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap" "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
@ -15,9 +17,11 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/services/reputation" "github.com/nspcc-dev/neofs-node/pkg/services/reputation"
reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common" reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
reputationrouter "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common/router" reputationrouter "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common/router"
intermediateroutes "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/routes"
consumerstorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/storage/consumers"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/storage/daughters" "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/storage/daughters"
trustcontroller "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/controller" trustcontroller "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/controller"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/managers" localroutes "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/routes"
truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage" truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage"
reputationrpc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/rpc" reputationrpc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/rpc"
"github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-node/pkg/util/logger"
@ -32,12 +36,17 @@ func initReputationService(c *cfg) {
// storing calculated trusts as a daughter // storing calculated trusts as a daughter
c.cfgReputation.localTrustStorage = truststorage.New(truststorage.Prm{}) c.cfgReputation.localTrustStorage = truststorage.New(truststorage.Prm{})
// storing received trusts as a manager // storing received daughter(of current node) trusts as a manager
daughterStorage := &intermediate.DaughterStorage{ daughterStorageWriterProvider := &intermediate.DaughterStorageWriterProvider{
Log: c.log, Log: c.log,
Storage: daughters.New(daughters.Prm{}), Storage: daughters.New(daughters.Prm{}),
} }
consumerStorageWriterProvider := &intermediate.ConsumerStorageWriterProvider{
Log: c.log,
Storage: consumerstorage.New(consumerstorage.Prm{}),
}
trustStorage := &localreputation.TrustStorage{ trustStorage := &localreputation.TrustStorage{
Log: c.log, Log: c.log,
Storage: c.cfgReputation.localTrustStorage, Storage: c.cfgReputation.localTrustStorage,
@ -45,37 +54,75 @@ func initReputationService(c *cfg) {
LocalKey: crypto.MarshalPublicKey(&c.key.PublicKey), LocalKey: crypto.MarshalPublicKey(&c.key.PublicKey),
} }
managerBuilder := localreputation.NewManagerBuilder( managerBuilder := common.NewManagerBuilder(
localreputation.ManagersPrm{ common.ManagersPrm{
NetMapSource: nmSrc, NetMapSource: nmSrc,
}, },
localreputation.WithLogger(c.log), common.WithLogger(c.log),
) )
routeBuilder := managers.New(managers.Prm{ localRouteBuilder := localroutes.New(
ManagerBuilder: managerBuilder, localroutes.Prm{
}) ManagerBuilder: managerBuilder,
remoteLocalTrustProvider := localreputation.NewRemoteTrustProvider(
localreputation.RemoteProviderPrm{
LocalAddrSrc: c,
DeadEndProvider: daughterStorage,
ClientCache: cache.NewSDKClientCache(),
Key: c.key,
}, },
) )
router := reputationrouter.New( intermediateRouteBuilder := intermediateroutes.New(
intermediateroutes.Prm{
ManagerBuilder: managerBuilder,
},
)
apiClientCache := cache.NewSDKClientCache()
remoteLocalTrustProvider := common.NewRemoteTrustProvider(
common.RemoteProviderPrm{
LocalAddrSrc: c,
DeadEndProvider: daughterStorageWriterProvider,
ClientCache: apiClientCache,
WriterProvider: localreputation.NewRemoteProvider(
localreputation.RemoteProviderPrm{
Key: c.key,
},
),
},
)
remoteIntermediateTrustProvider := common.NewRemoteTrustProvider(
common.RemoteProviderPrm{
LocalAddrSrc: c,
DeadEndProvider: consumerStorageWriterProvider,
ClientCache: apiClientCache,
WriterProvider: intermediatereputation.NewRemoteProvider(
intermediatereputation.RemoteProviderPrm{
Key: c.key,
},
),
},
)
localTrustRouter := reputationrouter.New(
reputationrouter.Prm{ reputationrouter.Prm{
LocalServerInfo: c, LocalServerInfo: c,
RemoteWriterProvider: remoteLocalTrustProvider, RemoteWriterProvider: remoteLocalTrustProvider,
Builder: routeBuilder, Builder: localRouteBuilder,
}) },
)
c.cfgReputation.localTrustCtrl = trustcontroller.New(trustcontroller.Prm{ _ = reputationrouter.New( // intermediateTrustRouter
LocalTrustSource: trustStorage, reputationrouter.Prm{
LocalTrustTarget: router, LocalServerInfo: c,
}) RemoteWriterProvider: remoteIntermediateTrustProvider,
Builder: intermediateRouteBuilder,
},
)
c.cfgReputation.localTrustCtrl = trustcontroller.New(
trustcontroller.Prm{
LocalTrustSource: trustStorage,
LocalTrustTarget: localTrustRouter,
},
)
addNewEpochAsyncNotificationHandler( addNewEpochAsyncNotificationHandler(
c, c,
@ -97,8 +144,8 @@ func initReputationService(c *cfg) {
&reputationServer{ &reputationServer{
cfg: c, cfg: c,
log: c.log, log: c.log,
router: router, router: localTrustRouter,
routeBuilder: routeBuilder, routeBuilder: localRouteBuilder,
}, },
c.respSvc, c.respSvc,
), ),
@ -135,10 +182,10 @@ type reputationServer struct {
} }
func (s *reputationServer) SendLocalTrust(ctx context.Context, req *v2reputation.SendLocalTrustRequest) (*v2reputation.SendLocalTrustResponse, error) { func (s *reputationServer) SendLocalTrust(ctx context.Context, req *v2reputation.SendLocalTrustRequest) (*v2reputation.SendLocalTrustResponse, error) {
var passedRoute []reputationrouter.ServerInfo var passedRoute []reputationcommon.ServerInfo
for hdr := req.GetVerificationHeader(); hdr != nil; hdr = hdr.GetOrigin() { for hdr := req.GetVerificationHeader(); hdr != nil; hdr = hdr.GetOrigin() {
passedRoute = append(passedRoute, &localreputation.OnlyKeyRemoteServerInfo{ passedRoute = append(passedRoute, &common.OnlyKeyRemoteServerInfo{
Key: hdr.GetBodySignature().GetKey(), Key: hdr.GetBodySignature().GetKey(),
}) })
} }
@ -151,7 +198,7 @@ func (s *reputationServer) SendLocalTrust(ctx context.Context, req *v2reputation
body := req.GetBody() body := req.GetBody()
eCtx := &localreputation.EpochContext{ eCtx := &common.EpochContext{
Context: ctx, Context: ctx,
E: body.GetEpoch(), E: body.GetEpoch(),
} }
@ -194,11 +241,11 @@ func apiToLocalTrust(t *v2reputation.Trust, trustingPeer []byte) reputation.Trus
} }
func (s *reputationServer) processTrust(epoch uint64, t reputation.Trust, func (s *reputationServer) processTrust(epoch uint64, t reputation.Trust,
passedRoute []reputationrouter.ServerInfo, w reputationcommon.Writer) error { passedRoute []reputationcommon.ServerInfo, w reputationcommon.Writer) error {
err := reputationrouter.CheckRoute(s.routeBuilder, epoch, t, passedRoute) err := reputationrouter.CheckRoute(s.routeBuilder, epoch, t, passedRoute)
if err != nil { if err != nil {
return errors.Wrap(err, "wrong route of reputation trust value") return errors.Wrap(err, "wrong route of reputation trust value")
} }
return w.Write(&localreputation.EpochContext{E: epoch}, t) return w.Write(&common.EpochContext{E: epoch}, t)
} }