[#488] reputation/common: Move ServerInfo to common pkg

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-04-23 17:54:55 +03:00 committed by Alex Vanin
parent f7aa79f0b6
commit e69917b27a
8 changed files with 32 additions and 32 deletions

View file

@ -11,11 +11,11 @@ import (
type routeContext struct {
common.Context
passedRoute []ServerInfo
passedRoute []common.ServerInfo
}
// NewRouteContext wraps the main context of value passing with its traversal route and epoch.
func NewRouteContext(ctx common.Context, passed []ServerInfo) common.Context {
func NewRouteContext(ctx common.Context, passed []common.ServerInfo) common.Context {
return &routeContext{
Context: ctx,
passedRoute: passed,
@ -54,7 +54,7 @@ func (r *Router) InitWriter(ctx common.Context) (common.Writer, error) {
if routeCtx, ok = ctx.(*routeContext); !ok {
routeCtx = &routeContext{
Context: ctx,
passedRoute: []ServerInfo{r.localSrvInfo},
passedRoute: []common.ServerInfo{r.localSrvInfo},
}
}
@ -73,7 +73,7 @@ func (w *trustWriter) Write(ctx common.Context, t reputation.Trust) error {
if err != nil {
return err
} else if len(route) == 0 {
route = []ServerInfo{nil}
route = []common.ServerInfo{nil}
}
for _, remoteInfo := range route {

View file

@ -5,20 +5,6 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
)
// ServerInfo describes a set of
// characteristics of a point in a route.
type ServerInfo interface {
// PublicKey returns public key of the node
// from the route in a binary representation.
PublicKey() []byte
// Returns network address of the node
// in the route.
//
// Can be empty.
Address() string
}
// Builder groups methods to route values in the network.
type Builder interface {
// NextStage must return next group of route points
@ -28,7 +14,7 @@ type Builder interface {
// Empty passed list means being at the starting point of the route.
//
// Must return empty list and no error if the endpoint of the route is reached.
NextStage(epoch uint64, t reputation.Trust, passed []ServerInfo) ([]ServerInfo, error)
NextStage(epoch uint64, t reputation.Trust, passed []common.ServerInfo) ([]common.ServerInfo, error)
}
// RemoteWriterProvider describes the component
@ -38,5 +24,5 @@ type RemoteWriterProvider interface {
// corresponding to info.
//
// Nil info matches the end of the route.
InitRemote(info ServerInfo) (common.WriterProvider, error)
InitRemote(info common.ServerInfo) (common.WriterProvider, error)
}

View file

@ -3,6 +3,7 @@ package router
import (
"fmt"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
)
@ -15,7 +16,7 @@ type Prm struct {
// Characteristics of the local node's server.
//
// Must not be nil.
LocalServerInfo ServerInfo
LocalServerInfo common.ServerInfo
// Component for sending values to a fixed route point.
//
@ -46,7 +47,7 @@ type Router struct {
routeBuilder Builder
localSrvInfo ServerInfo
localSrvInfo common.ServerInfo
}
const invalidPrmValFmt = "invalid parameter %s (%T):%v"

View file

@ -5,6 +5,7 @@ import (
"errors"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
)
var errWrongRoute = errors.New("wrong route")
@ -12,7 +13,7 @@ var errWrongRoute = errors.New("wrong route")
// CheckRoute checks if the route is a route correctly constructed by the builder for value a.
//
// Returns nil if route is correct, otherwise an error clarifying the inconsistency.
func CheckRoute(builder Builder, epoch uint64, t reputation.Trust, route []ServerInfo) error {
func CheckRoute(builder Builder, epoch uint64, t reputation.Trust, route []common.ServerInfo) error {
for i := 1; i < len(route); i++ {
servers, err := builder.NextStage(epoch, t, route[:i])
if err != nil {