[#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

@ -8,7 +8,6 @@ import (
netmapcore "github.com/nspcc-dev/neofs-node/pkg/core/netmap" netmapcore "github.com/nspcc-dev/neofs-node/pkg/core/netmap"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation" "github.com/nspcc-dev/neofs-node/pkg/services/reputation"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/common" "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
reputationrouter "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common/router"
"github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-node/pkg/util/logger"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -56,7 +55,7 @@ func NewManagerBuilder(prm ManagersPrm, opts ...MngOption) common.ManagerBuilder
// BuildManagers sorts nodes in NetMap with HRW algorithms and // BuildManagers sorts nodes in NetMap with HRW algorithms and
// takes the next node after the current one as the only manager. // takes the next node after the current one as the only manager.
func (mb *managerBuilder) BuildManagers(epoch uint64, p reputation.PeerID) ([]reputationrouter.ServerInfo, error) { func (mb *managerBuilder) BuildManagers(epoch uint64, p reputation.PeerID) ([]common.ServerInfo, error) {
nm, err := mb.nmSrc.GetNetMapByEpoch(epoch) nm, err := mb.nmSrc.GetNetMapByEpoch(epoch)
if err != nil { if err != nil {
return nil, err return nil, err
@ -77,7 +76,7 @@ func (mb *managerBuilder) BuildManagers(epoch uint64, p reputation.PeerID) ([]re
managerIndex = 0 managerIndex = 0
} }
return []reputationrouter.ServerInfo{nodes[managerIndex]}, nil return []common.ServerInfo{nodes[managerIndex]}, nil
} }
} }

View file

@ -5,7 +5,6 @@ import (
"io" "io"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation" "github.com/nspcc-dev/neofs-node/pkg/services/reputation"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/common/router"
) )
// Context wraps stdlib context // Context wraps stdlib context
@ -60,5 +59,19 @@ type WriterProvider interface {
type ManagerBuilder interface { type ManagerBuilder interface {
// BuildManagers must compose list of managers. It depends on // BuildManagers must compose list of managers. It depends on
// particular epoch and PeerID of the current route point. // particular epoch and PeerID of the current route point.
BuildManagers(epoch uint64, p reputation.PeerID) ([]router.ServerInfo, error) BuildManagers(epoch uint64, p reputation.PeerID) ([]ServerInfo, error)
}
// 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
} }

View file

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

View file

@ -5,20 +5,6 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/common" "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. // Builder groups methods to route values in the network.
type Builder interface { type Builder interface {
// NextStage must return next group of route points // 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. // 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. // 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 // RemoteWriterProvider describes the component
@ -38,5 +24,5 @@ type RemoteWriterProvider interface {
// corresponding to info. // corresponding to info.
// //
// Nil info matches the end of the route. // 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 ( import (
"fmt" "fmt"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
"github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-node/pkg/util/logger"
) )
@ -15,7 +16,7 @@ type Prm struct {
// Characteristics of the local node's server. // Characteristics of the local node's server.
// //
// Must not be nil. // Must not be nil.
LocalServerInfo ServerInfo LocalServerInfo common.ServerInfo
// Component for sending values to a fixed route point. // Component for sending values to a fixed route point.
// //
@ -46,7 +47,7 @@ type Router struct {
routeBuilder Builder routeBuilder Builder
localSrvInfo ServerInfo localSrvInfo common.ServerInfo
} }
const invalidPrmValFmt = "invalid parameter %s (%T):%v" const invalidPrmValFmt = "invalid parameter %s (%T):%v"

View file

@ -5,6 +5,7 @@ import (
"errors" "errors"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation" "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") 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. // 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. // 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++ { for i := 1; i < len(route); i++ {
servers, err := builder.NextStage(epoch, t, route[:i]) servers, err := builder.NextStage(epoch, t, route[:i])
if err != nil { if err != nil {

View file

@ -2,14 +2,14 @@ package routes
import ( import (
"github.com/nspcc-dev/neofs-node/pkg/services/reputation" "github.com/nspcc-dev/neofs-node/pkg/services/reputation"
reputationroute "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common/router" "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
// NextStage builds Manager list for trusted node and returns it directly. // NextStage builds Manager list for trusted node and returns it directly.
// //
// If passed route has more than one point, then endpoint of the route is reached. // If passed route has more than one point, then endpoint of the route is reached.
func (b *Builder) NextStage(epoch uint64, t reputation.Trust, passed []reputationroute.ServerInfo) ([]reputationroute.ServerInfo, error) { func (b *Builder) NextStage(epoch uint64, t reputation.Trust, passed []common.ServerInfo) ([]common.ServerInfo, error) {
if len(passed) > 1 { if len(passed) > 1 {
return nil, nil return nil, nil
} }

View file

@ -2,14 +2,14 @@ package routes
import ( import (
"github.com/nspcc-dev/neofs-node/pkg/services/reputation" "github.com/nspcc-dev/neofs-node/pkg/services/reputation"
reputationroute "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common/router" "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
// NextStage builds Manager list for trusting node and returns it directly. // NextStage builds Manager list for trusting node and returns it directly.
// //
// If passed route has more than one point, then endpoint of the route is reached. // If passed route has more than one point, then endpoint of the route is reached.
func (b *Builder) NextStage(epoch uint64, t reputation.Trust, passed []reputationroute.ServerInfo) ([]reputationroute.ServerInfo, error) { func (b *Builder) NextStage(epoch uint64, t reputation.Trust, passed []common.ServerInfo) ([]common.ServerInfo, error) {
if len(passed) > 1 { if len(passed) > 1 {
return nil, nil return nil, nil
} }