forked from TrueCloudLab/frostfs-node
[#488] reputation/common: Move ServerInfo
to common
pkg
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
f7aa79f0b6
commit
e69917b27a
8 changed files with 32 additions and 32 deletions
|
@ -8,7 +8,6 @@ import (
|
|||
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/common"
|
||||
reputationrouter "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common/router"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||
"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
|
||||
// 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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -77,7 +76,7 @@ func (mb *managerBuilder) BuildManagers(epoch uint64, p reputation.PeerID) ([]re
|
|||
managerIndex = 0
|
||||
}
|
||||
|
||||
return []reputationrouter.ServerInfo{nodes[managerIndex]}, nil
|
||||
return []common.ServerInfo{nodes[managerIndex]}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"io"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/common/router"
|
||||
)
|
||||
|
||||
// Context wraps stdlib context
|
||||
|
@ -60,5 +59,19 @@ type WriterProvider interface {
|
|||
type ManagerBuilder interface {
|
||||
// BuildManagers must compose list of managers. It depends on
|
||||
// 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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -2,14 +2,14 @@ package routes
|
|||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
// 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.
|
||||
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 {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
@ -2,14 +2,14 @@ package routes
|
|||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
// 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.
|
||||
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 {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue