[#488] reputation/router: Add commentaries and TODO

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-05-04 15:31:20 +03:00 committed by Alex Vanin
parent 25ea5fea90
commit 20b7295087
2 changed files with 9 additions and 4 deletions

View file

@ -57,6 +57,7 @@ type TrustWriterProvider struct {
func (twp *TrustWriterProvider) InitWriter(ctx reputationcommon.Context) (reputationcommon.Writer, error) {
eiContext, ok := ctx.(eigentrustcalc.Context)
if !ok {
// TODO: think if this can be done without such limitation
panic(ErrIncorrectContextPanicMsg)
}

View file

@ -8,6 +8,9 @@ import (
"go.uber.org/zap"
)
// routeContext wraps context with additional passed
// route data. It is only used inside Router and is
// not passed in any external methods.
type routeContext struct {
common.Context
@ -25,7 +28,7 @@ func NewRouteContext(ctx common.Context, passed []common.ServerInfo) common.Cont
type trustWriter struct {
router *Router
ctx *routeContext
routeCtx *routeContext
routeMtx sync.RWMutex
mServers map[string]common.Writer
@ -60,7 +63,7 @@ func (r *Router) InitWriter(ctx common.Context) (common.Writer, error) {
return &trustWriter{
router: r,
ctx: routeCtx,
routeCtx: routeCtx,
mServers: make(map[string]common.Writer),
}, nil
}
@ -69,7 +72,7 @@ func (w *trustWriter) Write(t reputation.Trust) error {
w.routeMtx.Lock()
defer w.routeMtx.Unlock()
route, err := w.router.routeBuilder.NextStage(w.ctx.Epoch(), t, w.ctx.passedRoute)
route, err := w.router.routeBuilder.NextStage(w.routeCtx.Epoch(), t, w.routeCtx.passedRoute)
if err != nil {
return err
} else if len(route) == 0 {
@ -94,7 +97,8 @@ func (w *trustWriter) Write(t reputation.Trust) error {
continue
}
remoteWriter, err = provider.InitWriter(w.ctx.Context)
// init writer with original context wrapped in routeContext
remoteWriter, err = provider.InitWriter(w.routeCtx.Context)
if err != nil {
w.router.log.Debug("could not initialize writer",
zap.String("error", err.Error()),