[#488] reputation/router: Add commentaries and TODO
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
25ea5fea90
commit
20b7295087
2 changed files with 9 additions and 4 deletions
|
@ -57,6 +57,7 @@ type TrustWriterProvider struct {
|
||||||
func (twp *TrustWriterProvider) InitWriter(ctx reputationcommon.Context) (reputationcommon.Writer, error) {
|
func (twp *TrustWriterProvider) InitWriter(ctx reputationcommon.Context) (reputationcommon.Writer, error) {
|
||||||
eiContext, ok := ctx.(eigentrustcalc.Context)
|
eiContext, ok := ctx.(eigentrustcalc.Context)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
// TODO: think if this can be done without such limitation
|
||||||
panic(ErrIncorrectContextPanicMsg)
|
panic(ErrIncorrectContextPanicMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,9 @@ import (
|
||||||
"go.uber.org/zap"
|
"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 {
|
type routeContext struct {
|
||||||
common.Context
|
common.Context
|
||||||
|
|
||||||
|
@ -25,7 +28,7 @@ func NewRouteContext(ctx common.Context, passed []common.ServerInfo) common.Cont
|
||||||
type trustWriter struct {
|
type trustWriter struct {
|
||||||
router *Router
|
router *Router
|
||||||
|
|
||||||
ctx *routeContext
|
routeCtx *routeContext
|
||||||
|
|
||||||
routeMtx sync.RWMutex
|
routeMtx sync.RWMutex
|
||||||
mServers map[string]common.Writer
|
mServers map[string]common.Writer
|
||||||
|
@ -60,7 +63,7 @@ func (r *Router) InitWriter(ctx common.Context) (common.Writer, error) {
|
||||||
|
|
||||||
return &trustWriter{
|
return &trustWriter{
|
||||||
router: r,
|
router: r,
|
||||||
ctx: routeCtx,
|
routeCtx: routeCtx,
|
||||||
mServers: make(map[string]common.Writer),
|
mServers: make(map[string]common.Writer),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -69,7 +72,7 @@ func (w *trustWriter) Write(t reputation.Trust) error {
|
||||||
w.routeMtx.Lock()
|
w.routeMtx.Lock()
|
||||||
defer w.routeMtx.Unlock()
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else if len(route) == 0 {
|
} else if len(route) == 0 {
|
||||||
|
@ -94,7 +97,8 @@ func (w *trustWriter) Write(t reputation.Trust) error {
|
||||||
continue
|
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 {
|
if err != nil {
|
||||||
w.router.log.Debug("could not initialize writer",
|
w.router.log.Debug("could not initialize writer",
|
||||||
zap.String("error", err.Error()),
|
zap.String("error", err.Error()),
|
||||||
|
|
Loading…
Reference in a new issue