[#613] pkg/reputation: Move manager building to pkg
Move `managers` package to `pkg` since it can be reused in other packages. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
a4587dbcd4
commit
6b176e8769
2 changed files with 8 additions and 8 deletions
|
@ -68,11 +68,11 @@ func initReputationService(c *cfg) {
|
||||||
LocalKey: localKey,
|
LocalKey: localKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
managerBuilder := common.NewManagerBuilder(
|
managerBuilder := reputationcommon.NewManagerBuilder(
|
||||||
common.ManagersPrm{
|
reputationcommon.ManagersPrm{
|
||||||
NetMapSource: nmSrc,
|
NetMapSource: nmSrc,
|
||||||
},
|
},
|
||||||
common.WithLogger(c.log),
|
reputationcommon.WithLogger(c.log),
|
||||||
)
|
)
|
||||||
|
|
||||||
localRouteBuilder := localroutes.New(
|
localRouteBuilder := localroutes.New(
|
||||||
|
|
|
@ -2,12 +2,12 @@ package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/nspcc-dev/hrw"
|
"github.com/nspcc-dev/hrw"
|
||||||
apiNetmap "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
apiNetmap "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
||||||
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/util/logger"
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
@ -36,10 +36,10 @@ type ManagersPrm struct {
|
||||||
//
|
//
|
||||||
// The created managerBuilder does not require additional
|
// The created managerBuilder does not require additional
|
||||||
// initialization and is completely ready for work.
|
// initialization and is completely ready for work.
|
||||||
func NewManagerBuilder(prm ManagersPrm, opts ...MngOption) common.ManagerBuilder {
|
func NewManagerBuilder(prm ManagersPrm, opts ...MngOption) ManagerBuilder {
|
||||||
switch {
|
switch {
|
||||||
case prm.NetMapSource == nil:
|
case prm.NetMapSource == nil:
|
||||||
PanicOnPrmValue("NetMapSource", prm.NetMapSource)
|
panic(fmt.Sprintf("invalid NetMapSource (%T):%v", prm.NetMapSource, prm.NetMapSource))
|
||||||
}
|
}
|
||||||
|
|
||||||
o := defaultMngOpts()
|
o := defaultMngOpts()
|
||||||
|
@ -57,7 +57,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) ([]common.ServerInfo, error) {
|
func (mb *managerBuilder) BuildManagers(epoch uint64, p reputation.PeerID) ([]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
|
||||||
|
@ -78,7 +78,7 @@ func (mb *managerBuilder) BuildManagers(epoch uint64, p reputation.PeerID) ([]co
|
||||||
managerIndex = 0
|
managerIndex = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
return []common.ServerInfo{nodes[managerIndex]}, nil
|
return []ServerInfo{nodes[managerIndex]}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue