[#488] reputation/managers: Implement route builders

Add implementation of Builder interface for
intermediate trusts. Move all code associated
with managers to `common` directory in `cmd`
and `pkg/services/reputation`

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-04-22 17:56:25 +03:00 committed by Alex Vanin
parent 6ffc109a75
commit 49d477f466
9 changed files with 106 additions and 31 deletions

View file

@ -1,4 +1,4 @@
package local
package common
import (
"bytes"
@ -7,8 +7,8 @@ import (
apiNetmap "github.com/nspcc-dev/neofs-api-go/pkg/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/common"
reputationrouter "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common/router"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/managers"
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
"go.uber.org/zap"
)
@ -36,10 +36,10 @@ type ManagersPrm struct {
//
// The created managerBuilder does not require additional
// initialization and is completely ready for work.
func NewManagerBuilder(prm ManagersPrm, opts ...MngOption) managers.ManagerBuilder {
func NewManagerBuilder(prm ManagersPrm, opts ...MngOption) common.ManagerBuilder {
switch {
case prm.NetMapSource == nil:
panicOnPrmValue("NetMapSource", prm.NetMapSource)
PanicOnPrmValue("NetMapSource", prm.NetMapSource)
}
o := defaultMngOpts()

View file

@ -1,4 +1,4 @@
package local
package common
import (
"context"
@ -41,6 +41,6 @@ func (*OnlyKeyRemoteServerInfo) Address() string {
const invalidPrmValFmt = "invalid parameter %s (%T):%v"
func panicOnPrmValue(n string, v interface{}) {
func PanicOnPrmValue(n string, v interface{}) {
panic(fmt.Sprintf(invalidPrmValFmt, n, v, v))
}

View file

@ -5,6 +5,7 @@ import (
apiClient "github.com/nspcc-dev/neofs-api-go/pkg/client"
reputationapi "github.com/nspcc-dev/neofs-api-go/pkg/reputation"
reputationutil "github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/common"
"github.com/nspcc-dev/neofs-node/pkg/network"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common"
@ -41,13 +42,13 @@ type RemoteProviderPrm struct {
func NewRemoteTrustProvider(prm RemoteProviderPrm) reputationrouter.RemoteWriterProvider {
switch {
case prm.LocalAddrSrc == nil:
panicOnPrmValue("LocalAddrSrc", prm.LocalAddrSrc)
reputationutil.PanicOnPrmValue("LocalAddrSrc", prm.LocalAddrSrc)
case prm.DeadEndProvider == nil:
panicOnPrmValue("DeadEndProvider", prm.DeadEndProvider)
reputationutil.PanicOnPrmValue("DeadEndProvider", prm.DeadEndProvider)
case prm.Key == nil:
panicOnPrmValue("Key", prm.Key)
reputationutil.PanicOnPrmValue("Key", prm.Key)
case prm.ClientCache == nil:
panicOnPrmValue("ClientCache", prm.ClientCache)
reputationutil.PanicOnPrmValue("ClientCache", prm.ClientCache)
}
return &remoteTrustProvider{
@ -67,7 +68,7 @@ func (rtp *remoteTrustProvider) InitRemote(srv reputationrouter.ServerInfo) (rep
if rtp.localAddrSrc.LocalAddress().String() == srv.Address() {
// if local => return no-op writer
return trustcontroller.SimpleWriterProvider(new(NopReputationWriter)), nil
return trustcontroller.SimpleWriterProvider(new(reputationutil.NopReputationWriter)), nil
}
ipAddr, err := network.IPAddrFromMultiaddr(addr)