2021-03-23 18:48:50 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-03-24 09:57:50 +00:00
|
|
|
"context"
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
2021-03-23 18:48:50 +00:00
|
|
|
|
2021-03-24 09:57:50 +00:00
|
|
|
v2reputation "github.com/nspcc-dev/neofs-api-go/v2/reputation"
|
|
|
|
v2reputationgrpc "github.com/nspcc-dev/neofs-api-go/v2/reputation/grpc"
|
2021-04-29 06:43:15 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
2021-04-23 15:02:55 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/common"
|
|
|
|
intermediatereputation "github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/intermediate"
|
2021-04-18 08:51:49 +00:00
|
|
|
localreputation "github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/local"
|
2022-03-02 16:31:56 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/ticker"
|
2022-01-31 12:19:10 +00:00
|
|
|
repClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation"
|
2021-03-23 18:54:00 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
|
2021-03-24 09:57:50 +00:00
|
|
|
grpcreputation "github.com/nspcc-dev/neofs-node/pkg/network/transport/reputation/grpc"
|
2021-03-23 18:48:50 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
2021-04-17 17:13:29 +00:00
|
|
|
reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
|
2021-04-17 19:17:30 +00:00
|
|
|
reputationrouter "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common/router"
|
2021-04-29 06:43:15 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust"
|
|
|
|
eigentrustcalc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/calculator"
|
|
|
|
eigentrustctrl "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/controller"
|
2021-04-23 15:02:55 +00:00
|
|
|
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"
|
2021-04-21 04:56:38 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/storage/daughters"
|
2021-04-29 06:43:15 +00:00
|
|
|
localtrustcontroller "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/controller"
|
2021-04-23 15:02:55 +00:00
|
|
|
localroutes "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/routes"
|
2021-03-23 18:48:50 +00:00
|
|
|
truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage"
|
2021-03-24 09:57:50 +00:00
|
|
|
reputationrpc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/rpc"
|
2021-03-23 18:48:50 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
2022-07-04 13:24:51 +00:00
|
|
|
apireputation "github.com/nspcc-dev/neofs-sdk-go/reputation"
|
2021-03-23 18:51:31 +00:00
|
|
|
"go.uber.org/zap"
|
2021-03-23 18:48:50 +00:00
|
|
|
)
|
|
|
|
|
2021-03-23 18:54:00 +00:00
|
|
|
func initReputationService(c *cfg) {
|
2022-01-31 12:19:10 +00:00
|
|
|
wrap, err := repClient.NewFromMorph(c.cfgMorph.client, c.cfgReputation.scriptHash, 0, repClient.TryNotary())
|
2021-04-29 06:43:15 +00:00
|
|
|
fatalOnErr(err)
|
|
|
|
|
2021-05-31 08:55:38 +00:00
|
|
|
localKey := c.key.PublicKey().Bytes()
|
2021-04-29 06:43:15 +00:00
|
|
|
|
2022-03-29 13:52:12 +00:00
|
|
|
nmSrc := c.netMapSource
|
2021-03-23 18:54:00 +00:00
|
|
|
|
2021-04-21 04:56:38 +00:00
|
|
|
// storing calculated trusts as a daughter
|
2021-04-29 06:43:15 +00:00
|
|
|
c.cfgReputation.localTrustStorage = truststorage.New(
|
2021-05-04 06:16:51 +00:00
|
|
|
truststorage.Prm{},
|
2021-04-29 06:43:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
daughterStorage := daughters.New(daughters.Prm{})
|
|
|
|
consumerStorage := consumerstorage.New(consumerstorage.Prm{})
|
2021-03-23 18:54:00 +00:00
|
|
|
|
2021-04-23 15:02:55 +00:00
|
|
|
// storing received daughter(of current node) trusts as a manager
|
2021-08-24 10:53:35 +00:00
|
|
|
daughterStorageWriterProvider := &intermediatereputation.DaughterStorageWriterProvider{
|
2021-04-21 04:56:38 +00:00
|
|
|
Log: c.log,
|
2021-04-29 06:43:15 +00:00
|
|
|
Storage: daughterStorage,
|
2021-04-21 04:56:38 +00:00
|
|
|
}
|
|
|
|
|
2021-08-24 10:53:35 +00:00
|
|
|
consumerStorageWriterProvider := &intermediatereputation.ConsumerStorageWriterProvider{
|
2021-04-23 15:02:55 +00:00
|
|
|
Log: c.log,
|
2021-04-29 06:43:15 +00:00
|
|
|
Storage: consumerStorage,
|
2021-04-23 15:02:55 +00:00
|
|
|
}
|
|
|
|
|
2021-03-01 19:01:45 +00:00
|
|
|
localTrustLogger := c.log.With(zap.String("trust_type", "local"))
|
|
|
|
intermediateTrustLogger := c.log.With(zap.String("trust_type", "intermediate"))
|
|
|
|
|
2021-04-29 06:43:15 +00:00
|
|
|
localTrustStorage := &localreputation.TrustStorage{
|
2021-03-01 19:01:45 +00:00
|
|
|
Log: localTrustLogger,
|
2021-04-18 08:51:49 +00:00
|
|
|
Storage: c.cfgReputation.localTrustStorage,
|
|
|
|
NmSrc: nmSrc,
|
2021-04-29 06:43:15 +00:00
|
|
|
LocalKey: localKey,
|
2021-03-23 18:54:00 +00:00
|
|
|
}
|
|
|
|
|
2021-06-11 15:29:49 +00:00
|
|
|
managerBuilder := reputationcommon.NewManagerBuilder(
|
|
|
|
reputationcommon.ManagersPrm{
|
2021-04-18 08:51:49 +00:00
|
|
|
NetMapSource: nmSrc,
|
|
|
|
},
|
2021-06-11 15:29:49 +00:00
|
|
|
reputationcommon.WithLogger(c.log),
|
2021-04-18 08:51:49 +00:00
|
|
|
)
|
2021-04-03 08:07:11 +00:00
|
|
|
|
2021-04-23 15:02:55 +00:00
|
|
|
localRouteBuilder := localroutes.New(
|
|
|
|
localroutes.Prm{
|
|
|
|
ManagerBuilder: managerBuilder,
|
2021-03-01 19:01:45 +00:00
|
|
|
Log: localTrustLogger,
|
2021-04-23 15:02:55 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
intermediateRouteBuilder := intermediateroutes.New(
|
|
|
|
intermediateroutes.Prm{
|
|
|
|
ManagerBuilder: managerBuilder,
|
2021-03-01 19:01:45 +00:00
|
|
|
Log: intermediateTrustLogger,
|
2021-04-23 15:02:55 +00:00
|
|
|
},
|
|
|
|
)
|
2021-04-03 08:07:11 +00:00
|
|
|
|
2021-04-23 15:02:55 +00:00
|
|
|
remoteLocalTrustProvider := common.NewRemoteTrustProvider(
|
|
|
|
common.RemoteProviderPrm{
|
2021-09-06 12:17:14 +00:00
|
|
|
NetmapKeys: c,
|
2021-04-23 15:02:55 +00:00
|
|
|
DeadEndProvider: daughterStorageWriterProvider,
|
2021-07-13 11:12:23 +00:00
|
|
|
ClientCache: c.clientCache,
|
2021-04-23 15:02:55 +00:00
|
|
|
WriterProvider: localreputation.NewRemoteProvider(
|
|
|
|
localreputation.RemoteProviderPrm{
|
2021-05-31 08:55:38 +00:00
|
|
|
Key: &c.key.PrivateKey,
|
2021-03-01 19:01:45 +00:00
|
|
|
Log: localTrustLogger,
|
2021-04-23 15:02:55 +00:00
|
|
|
},
|
|
|
|
),
|
2021-03-01 19:01:45 +00:00
|
|
|
Log: localTrustLogger,
|
2021-04-18 08:51:49 +00:00
|
|
|
},
|
|
|
|
)
|
2021-04-03 08:07:11 +00:00
|
|
|
|
2021-04-23 15:02:55 +00:00
|
|
|
remoteIntermediateTrustProvider := common.NewRemoteTrustProvider(
|
|
|
|
common.RemoteProviderPrm{
|
2021-09-06 12:17:14 +00:00
|
|
|
NetmapKeys: c,
|
2021-04-23 15:02:55 +00:00
|
|
|
DeadEndProvider: consumerStorageWriterProvider,
|
2021-07-13 11:12:23 +00:00
|
|
|
ClientCache: c.clientCache,
|
2021-04-23 15:02:55 +00:00
|
|
|
WriterProvider: intermediatereputation.NewRemoteProvider(
|
|
|
|
intermediatereputation.RemoteProviderPrm{
|
2021-05-31 08:55:38 +00:00
|
|
|
Key: &c.key.PrivateKey,
|
2021-03-01 19:01:45 +00:00
|
|
|
Log: intermediateTrustLogger,
|
2021-04-23 15:02:55 +00:00
|
|
|
},
|
|
|
|
),
|
2021-03-01 19:01:45 +00:00
|
|
|
Log: intermediateTrustLogger,
|
2021-04-23 15:02:55 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
localTrustRouter := reputationrouter.New(
|
2021-04-17 19:17:30 +00:00
|
|
|
reputationrouter.Prm{
|
2021-04-03 08:07:11 +00:00
|
|
|
LocalServerInfo: c,
|
|
|
|
RemoteWriterProvider: remoteLocalTrustProvider,
|
2021-04-23 15:02:55 +00:00
|
|
|
Builder: localRouteBuilder,
|
|
|
|
},
|
2021-03-01 19:01:45 +00:00
|
|
|
reputationrouter.WithLogger(localTrustLogger))
|
2021-04-03 08:07:11 +00:00
|
|
|
|
2021-04-29 06:43:15 +00:00
|
|
|
intermediateTrustRouter := reputationrouter.New(
|
2021-04-23 15:02:55 +00:00
|
|
|
reputationrouter.Prm{
|
|
|
|
LocalServerInfo: c,
|
|
|
|
RemoteWriterProvider: remoteIntermediateTrustProvider,
|
|
|
|
Builder: intermediateRouteBuilder,
|
|
|
|
},
|
2021-03-01 19:01:45 +00:00
|
|
|
reputationrouter.WithLogger(intermediateTrustLogger),
|
2021-04-23 15:02:55 +00:00
|
|
|
)
|
|
|
|
|
2021-04-29 06:43:15 +00:00
|
|
|
eigenTrustCalculator := eigentrustcalc.New(
|
|
|
|
eigentrustcalc.Prm{
|
2021-05-05 21:03:07 +00:00
|
|
|
AlphaProvider: c.cfgNetmap.wrapper,
|
2021-05-04 06:16:51 +00:00
|
|
|
InitialTrustSource: intermediatereputation.InitialTrustSource{
|
2021-05-04 10:10:41 +00:00
|
|
|
NetMap: nmSrc,
|
2021-05-04 06:16:51 +00:00
|
|
|
},
|
2021-04-29 06:43:15 +00:00
|
|
|
IntermediateValueTarget: intermediateTrustRouter,
|
|
|
|
WorkerPool: c.cfgReputation.workerPool,
|
2021-08-24 10:53:35 +00:00
|
|
|
FinalResultTarget: intermediatereputation.NewFinalWriterProvider(
|
|
|
|
intermediatereputation.FinalWriterProviderPrm{
|
2021-05-31 08:55:38 +00:00
|
|
|
PrivatKey: &c.key.PrivateKey,
|
2021-04-29 06:43:15 +00:00
|
|
|
PubKey: localKey,
|
|
|
|
Client: wrap,
|
|
|
|
},
|
2021-08-24 10:53:35 +00:00
|
|
|
intermediatereputation.FinalWriterWithLogger(c.log),
|
2021-04-29 06:43:15 +00:00
|
|
|
),
|
2021-08-24 10:53:35 +00:00
|
|
|
DaughterTrustSource: &intermediatereputation.DaughterTrustIteratorProvider{
|
2021-04-29 06:43:15 +00:00
|
|
|
DaughterStorage: daughterStorage,
|
|
|
|
ConsumerStorage: consumerStorage,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
eigentrustcalc.WithLogger(c.log),
|
|
|
|
)
|
|
|
|
|
|
|
|
eigenTrustController := eigentrustctrl.New(
|
|
|
|
eigentrustctrl.Prm{
|
2021-08-24 10:53:35 +00:00
|
|
|
DaughtersTrustCalculator: &intermediatereputation.DaughtersTrustCalculator{
|
2021-04-29 06:43:15 +00:00
|
|
|
Calculator: eigenTrustCalculator,
|
|
|
|
},
|
|
|
|
IterationsProvider: c.cfgNetmap.wrapper,
|
|
|
|
WorkerPool: c.cfgReputation.workerPool,
|
|
|
|
},
|
2021-03-01 19:01:45 +00:00
|
|
|
eigentrustctrl.WithLogger(c.log),
|
2021-04-29 06:43:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
c.cfgReputation.localTrustCtrl = localtrustcontroller.New(
|
|
|
|
localtrustcontroller.Prm{
|
|
|
|
LocalTrustSource: localTrustStorage,
|
2021-04-23 15:02:55 +00:00
|
|
|
LocalTrustTarget: localTrustRouter,
|
|
|
|
},
|
2021-03-01 19:01:45 +00:00
|
|
|
localtrustcontroller.WithLogger(c.log),
|
2021-04-23 15:02:55 +00:00
|
|
|
)
|
2021-03-23 18:54:00 +00:00
|
|
|
|
2021-04-13 12:53:58 +00:00
|
|
|
addNewEpochAsyncNotificationHandler(
|
|
|
|
c,
|
|
|
|
func(ev event.Event) {
|
2021-03-01 19:01:45 +00:00
|
|
|
c.log.Debug("start reporting reputation on new epoch event")
|
|
|
|
|
2021-04-29 06:43:15 +00:00
|
|
|
var reportPrm localtrustcontroller.ReportPrm
|
2021-03-23 18:54:00 +00:00
|
|
|
|
2021-04-13 12:53:58 +00:00
|
|
|
// report collected values from previous epoch
|
|
|
|
reportPrm.SetEpoch(ev.(netmap.NewEpoch).EpochNumber() - 1)
|
2021-03-23 18:54:00 +00:00
|
|
|
|
2021-04-13 12:53:58 +00:00
|
|
|
c.cfgReputation.localTrustCtrl.Report(reportPrm)
|
|
|
|
},
|
|
|
|
)
|
2021-03-24 09:57:50 +00:00
|
|
|
|
2021-06-22 17:25:18 +00:00
|
|
|
server := grpcreputation.New(
|
|
|
|
reputationrpc.NewSignService(
|
|
|
|
&c.key.PrivateKey,
|
|
|
|
reputationrpc.NewResponseService(
|
|
|
|
&reputationServer{
|
|
|
|
cfg: c,
|
|
|
|
log: c.log,
|
|
|
|
localRouter: localTrustRouter,
|
|
|
|
intermediateRouter: intermediateTrustRouter,
|
|
|
|
routeBuilder: localRouteBuilder,
|
|
|
|
},
|
|
|
|
c.respSvc,
|
2021-03-24 09:57:50 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
2021-04-15 14:57:29 +00:00
|
|
|
|
2021-06-22 17:25:18 +00:00
|
|
|
for _, srv := range c.cfgGRPC.servers {
|
|
|
|
v2reputationgrpc.RegisterReputationServiceServer(srv, server)
|
|
|
|
}
|
|
|
|
|
2021-04-15 14:57:29 +00:00
|
|
|
// initialize eigen trust block timer
|
2022-03-02 16:31:56 +00:00
|
|
|
newEigenTrustIterTimer(c)
|
2021-04-15 14:57:29 +00:00
|
|
|
|
|
|
|
addNewEpochAsyncNotificationHandler(
|
|
|
|
c,
|
|
|
|
func(e event.Event) {
|
2022-03-02 16:31:56 +00:00
|
|
|
epoch := e.(netmap.NewEpoch).EpochNumber()
|
|
|
|
|
|
|
|
log := c.log.With(zap.Uint64("epoch", epoch))
|
|
|
|
|
|
|
|
duration, err := c.cfgNetmap.wrapper.EpochDuration()
|
|
|
|
if err != nil {
|
|
|
|
log.Debug("could not fetch epoch duration", zap.Error(err))
|
|
|
|
return
|
|
|
|
}
|
2021-04-15 14:57:29 +00:00
|
|
|
|
2022-03-02 16:31:56 +00:00
|
|
|
iterations, err := c.cfgNetmap.wrapper.EigenTrustIterations()
|
2021-04-15 14:57:29 +00:00
|
|
|
if err != nil {
|
2022-03-02 16:31:56 +00:00
|
|
|
log.Debug("could not fetch iteration number", zap.Error(err))
|
|
|
|
return
|
2021-04-15 14:57:29 +00:00
|
|
|
}
|
2022-03-02 16:31:56 +00:00
|
|
|
|
|
|
|
epochTimer, err := ticker.NewIterationsTicker(duration, iterations, func() {
|
|
|
|
eigenTrustController.Continue(
|
|
|
|
eigentrustctrl.ContinuePrm{
|
|
|
|
Epoch: epoch - 1,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
log.Debug("could not create fixed epoch timer", zap.Error(err))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
c.cfgMorph.eigenTrustTicker.addEpochTimer(epoch, epochTimer)
|
2021-04-15 14:57:29 +00:00
|
|
|
},
|
|
|
|
)
|
2021-03-24 09:57:50 +00:00
|
|
|
}
|
|
|
|
|
2021-04-06 17:15:09 +00:00
|
|
|
type reputationServer struct {
|
|
|
|
*cfg
|
2021-04-29 06:43:15 +00:00
|
|
|
log *logger.Logger
|
|
|
|
localRouter reputationcommon.WriterProvider
|
|
|
|
intermediateRouter reputationcommon.WriterProvider
|
|
|
|
routeBuilder reputationrouter.Builder
|
2021-04-06 17:15:09 +00:00
|
|
|
}
|
|
|
|
|
2021-05-07 11:13:11 +00:00
|
|
|
func (s *reputationServer) AnnounceLocalTrust(ctx context.Context, req *v2reputation.AnnounceLocalTrustRequest) (*v2reputation.AnnounceLocalTrustResponse, error) {
|
2021-04-29 06:43:15 +00:00
|
|
|
passedRoute := reverseRoute(req.GetVerificationHeader())
|
2021-04-06 17:15:09 +00:00
|
|
|
passedRoute = append(passedRoute, s)
|
|
|
|
|
2021-03-24 09:57:50 +00:00
|
|
|
body := req.GetBody()
|
|
|
|
|
2021-04-23 15:02:55 +00:00
|
|
|
eCtx := &common.EpochContext{
|
2021-04-06 17:15:09 +00:00
|
|
|
Context: ctx,
|
2021-04-18 08:51:49 +00:00
|
|
|
E: body.GetEpoch(),
|
2021-04-06 17:15:09 +00:00
|
|
|
}
|
|
|
|
|
2021-04-29 06:43:15 +00:00
|
|
|
w, err := s.localRouter.InitWriter(reputationrouter.NewRouteContext(eCtx, passedRoute))
|
2021-04-06 17:15:09 +00:00
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not initialize local trust writer: %w", err)
|
2021-04-06 17:15:09 +00:00
|
|
|
}
|
2021-03-24 09:57:50 +00:00
|
|
|
|
2021-04-06 17:15:09 +00:00
|
|
|
for _, trust := range body.GetTrusts() {
|
2022-03-15 12:11:35 +00:00
|
|
|
err = s.processLocalTrust(body.GetEpoch(), apiToLocalTrust(&trust, passedRoute[0].PublicKey()), passedRoute, w)
|
2021-04-17 16:15:38 +00:00
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not write one of local trusts: %w", err)
|
2021-04-06 17:15:09 +00:00
|
|
|
}
|
2021-03-24 09:57:50 +00:00
|
|
|
}
|
|
|
|
|
2021-05-07 11:13:11 +00:00
|
|
|
resp := new(v2reputation.AnnounceLocalTrustResponse)
|
|
|
|
resp.SetBody(new(v2reputation.AnnounceLocalTrustResponseBody))
|
2021-03-24 09:57:50 +00:00
|
|
|
|
|
|
|
return resp, nil
|
2021-03-23 18:54:00 +00:00
|
|
|
}
|
2021-04-05 09:27:58 +00:00
|
|
|
|
2021-05-07 11:13:11 +00:00
|
|
|
func (s *reputationServer) AnnounceIntermediateResult(ctx context.Context, req *v2reputation.AnnounceIntermediateResultRequest) (*v2reputation.AnnounceIntermediateResultResponse, error) {
|
2021-04-29 06:43:15 +00:00
|
|
|
passedRoute := reverseRoute(req.GetVerificationHeader())
|
|
|
|
passedRoute = append(passedRoute, s)
|
|
|
|
|
|
|
|
body := req.GetBody()
|
2021-04-05 09:27:58 +00:00
|
|
|
|
2021-05-04 06:16:51 +00:00
|
|
|
eiCtx := eigentrust.NewIterContext(ctx, body.GetEpoch(), body.GetIteration())
|
2021-04-29 06:43:15 +00:00
|
|
|
|
2021-05-04 06:16:51 +00:00
|
|
|
w, err := s.intermediateRouter.InitWriter(reputationrouter.NewRouteContext(eiCtx, passedRoute))
|
2021-04-29 06:43:15 +00:00
|
|
|
if err != nil {
|
2021-03-01 19:01:45 +00:00
|
|
|
return nil, fmt.Errorf("could not initialize trust writer: %w", err)
|
2021-04-29 06:43:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
v2Trust := body.GetTrust()
|
|
|
|
|
2021-05-07 11:13:11 +00:00
|
|
|
trust := apiToLocalTrust(v2Trust.GetTrust(), v2Trust.GetTrustingPeer().GetPublicKey())
|
2021-04-29 06:43:15 +00:00
|
|
|
|
2021-05-04 06:16:51 +00:00
|
|
|
err = w.Write(trust)
|
2021-04-29 06:43:15 +00:00
|
|
|
if err != nil {
|
2021-03-01 19:01:45 +00:00
|
|
|
return nil, fmt.Errorf("could not write trust: %w", err)
|
2021-04-29 06:43:15 +00:00
|
|
|
}
|
|
|
|
|
2021-05-07 11:13:11 +00:00
|
|
|
resp := new(v2reputation.AnnounceIntermediateResultResponse)
|
|
|
|
resp.SetBody(new(v2reputation.AnnounceIntermediateResultResponseBody))
|
2021-04-05 09:27:58 +00:00
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|
2021-04-06 17:15:09 +00:00
|
|
|
|
2021-04-29 06:43:15 +00:00
|
|
|
func (s *reputationServer) processLocalTrust(epoch uint64, t reputation.Trust,
|
|
|
|
passedRoute []reputationcommon.ServerInfo, w reputationcommon.Writer) error {
|
|
|
|
err := reputationrouter.CheckRoute(s.routeBuilder, epoch, t, passedRoute)
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return fmt.Errorf("wrong route of reputation trust value: %w", err)
|
2021-04-29 06:43:15 +00:00
|
|
|
}
|
|
|
|
|
2021-05-04 06:16:51 +00:00
|
|
|
return w.Write(t)
|
2021-04-29 06:43:15 +00:00
|
|
|
}
|
|
|
|
|
2021-04-17 16:15:38 +00:00
|
|
|
// apiToLocalTrust converts v2 Trust to local reputation.Trust, adding trustingPeer.
|
|
|
|
func apiToLocalTrust(t *v2reputation.Trust, trustingPeer []byte) reputation.Trust {
|
2022-07-04 13:24:51 +00:00
|
|
|
var trusted, trusting apireputation.PeerID
|
|
|
|
trusted.SetPublicKey(t.GetPeer().GetPublicKey())
|
|
|
|
trusting.SetPublicKey(trustingPeer)
|
|
|
|
|
2021-04-06 17:15:09 +00:00
|
|
|
localTrust := reputation.Trust{}
|
|
|
|
|
|
|
|
localTrust.SetValue(reputation.TrustValueFromFloat64(t.GetValue()))
|
2022-07-04 13:24:51 +00:00
|
|
|
localTrust.SetPeer(trusted)
|
|
|
|
localTrust.SetTrustingPeer(trusting)
|
2021-04-06 17:15:09 +00:00
|
|
|
|
|
|
|
return localTrust
|
|
|
|
}
|
|
|
|
|
2021-04-29 06:43:15 +00:00
|
|
|
func reverseRoute(hdr *session.RequestVerificationHeader) (passedRoute []reputationcommon.ServerInfo) {
|
|
|
|
for hdr != nil {
|
|
|
|
passedRoute = append(passedRoute, &common.OnlyKeyRemoteServerInfo{
|
|
|
|
Key: hdr.GetBodySignature().GetKey(),
|
|
|
|
})
|
|
|
|
|
|
|
|
hdr = hdr.GetOrigin()
|
2021-04-06 17:15:09 +00:00
|
|
|
}
|
|
|
|
|
2021-04-29 06:43:15 +00:00
|
|
|
return
|
2021-04-06 17:15:09 +00:00
|
|
|
}
|