From 477682adb743cd0fd06f5ac09a2dbeaeff7da202 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Sat, 17 Apr 2021 22:17:30 +0300 Subject: [PATCH] [#482] reputation/router: Move router to `./common` Signed-off-by: Pavel Karpy --- cmd/neofs-node/reputation.go | 24 +++++++++---------- .../{local/route => common/router}/calls.go | 2 +- .../{local/route => common/router}/deps.go | 2 +- .../{local/route => common/router}/opts.go | 2 +- .../{local/route => common/router}/router.go | 2 +- .../{local/route => common/router}/util.go | 2 +- .../reputation/local/controller/controller.go | 4 ++-- .../local/{route => }/managers/builder.go | 0 .../local/{route => }/managers/calls.go | 2 +- .../local/{route => }/managers/deps.go | 4 ++-- 10 files changed, 22 insertions(+), 22 deletions(-) rename pkg/services/reputation/{local/route => common/router}/calls.go (99%) rename pkg/services/reputation/{local/route => common/router}/deps.go (98%) rename pkg/services/reputation/{local/route => common/router}/opts.go (94%) rename pkg/services/reputation/{local/route => common/router}/router.go (98%) rename pkg/services/reputation/{local/route => common/router}/util.go (97%) rename pkg/services/reputation/local/{route => }/managers/builder.go (100%) rename pkg/services/reputation/local/{route => }/managers/calls.go (96%) rename pkg/services/reputation/local/{route => }/managers/deps.go (79%) diff --git a/cmd/neofs-node/reputation.go b/cmd/neofs-node/reputation.go index 128a584a9..78192ae21 100644 --- a/cmd/neofs-node/reputation.go +++ b/cmd/neofs-node/reputation.go @@ -21,9 +21,9 @@ import ( grpcreputation "github.com/nspcc-dev/neofs-node/pkg/network/transport/reputation/grpc" "github.com/nspcc-dev/neofs-node/pkg/services/reputation" reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common" + reputationrouter "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common/router" trustcontroller "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/controller" - reputationroute "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/route" - "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/route/managers" + "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/managers" truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage" reputationrpc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/rpc" "github.com/nspcc-dev/neofs-node/pkg/util/logger" @@ -144,7 +144,7 @@ func (rtwp *remoteLocalTrustWriterProvider) InitWriter(ctx reputationcommon.Cont }, nil } -func (rtp *remoteLocalTrustProvider) InitRemote(srv reputationroute.ServerInfo) (reputationcommon.WriterProvider, error) { +func (rtp *remoteLocalTrustProvider) InitRemote(srv reputationrouter.ServerInfo) (reputationcommon.WriterProvider, error) { if srv == nil { return rtp.deadEndProvider, nil } @@ -174,7 +174,7 @@ func (rtp *remoteLocalTrustProvider) InitRemote(srv reputationroute.ServerInfo) // 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) ([]reputationroute.ServerInfo, error) { +func (mb *managerBuilder) BuildManagers(epoch uint64, p reputation.PeerID) ([]reputationrouter.ServerInfo, error) { nm, err := mb.nmSrc.GetNetMapByEpoch(epoch) if err != nil { return nil, err @@ -195,7 +195,7 @@ func (mb *managerBuilder) BuildManagers(epoch uint64, p reputation.PeerID) ([]re managerIndex = 0 } - return []reputationroute.ServerInfo{nodes[managerIndex]}, nil + return []reputationrouter.ServerInfo{nodes[managerIndex]}, nil } } @@ -298,8 +298,8 @@ func initReputationService(c *cfg) { key: c.key, } - router := reputationroute.New( - reputationroute.Prm{ + router := reputationrouter.New( + reputationrouter.Prm{ LocalServerInfo: c, RemoteWriterProvider: remoteLocalTrustProvider, Builder: routeBuilder, @@ -364,7 +364,7 @@ type reputationServer struct { *cfg log *logger.Logger router reputationcommon.WriterProvider - routeBuilder reputationroute.Builder + routeBuilder reputationrouter.Builder } type epochContext struct { @@ -389,7 +389,7 @@ func (*reputationOnlyKeyRemoteServerInfo) Address() string { } func (s *reputationServer) SendLocalTrust(ctx context.Context, req *v2reputation.SendLocalTrustRequest) (*v2reputation.SendLocalTrustResponse, error) { - var passedRoute []reputationroute.ServerInfo + var passedRoute []reputationrouter.ServerInfo for hdr := req.GetVerificationHeader(); hdr != nil; hdr = hdr.GetOrigin() { passedRoute = append(passedRoute, &reputationOnlyKeyRemoteServerInfo{ @@ -410,7 +410,7 @@ func (s *reputationServer) SendLocalTrust(ctx context.Context, req *v2reputation epoch: body.GetEpoch(), } - w, err := s.router.InitWriter(reputationroute.NewRouteContext(eCtx, passedRoute)) + w, err := s.router.InitWriter(reputationrouter.NewRouteContext(eCtx, passedRoute)) if err != nil { return nil, errors.Wrap(err, "could not initialize local trust writer") } @@ -448,8 +448,8 @@ func apiToLocalTrust(t *v2reputation.Trust, trustingPeer []byte) reputation.Trus } func (s *reputationServer) processTrust(epoch uint64, t reputation.Trust, - passedRoute []reputationroute.ServerInfo, w reputationcommon.Writer) error { - err := reputationroute.CheckRoute(s.routeBuilder, epoch, t, passedRoute) + passedRoute []reputationrouter.ServerInfo, w reputationcommon.Writer) error { + err := reputationrouter.CheckRoute(s.routeBuilder, epoch, t, passedRoute) if err != nil { return errors.Wrap(err, "wrong route of reputation trust value") } diff --git a/pkg/services/reputation/local/route/calls.go b/pkg/services/reputation/common/router/calls.go similarity index 99% rename from pkg/services/reputation/local/route/calls.go rename to pkg/services/reputation/common/router/calls.go index 702d0e7f8..8d7be1931 100644 --- a/pkg/services/reputation/local/route/calls.go +++ b/pkg/services/reputation/common/router/calls.go @@ -1,4 +1,4 @@ -package reputationroute +package router import ( "sync" diff --git a/pkg/services/reputation/local/route/deps.go b/pkg/services/reputation/common/router/deps.go similarity index 98% rename from pkg/services/reputation/local/route/deps.go rename to pkg/services/reputation/common/router/deps.go index a6e2cd1e1..8c2bc36d4 100644 --- a/pkg/services/reputation/local/route/deps.go +++ b/pkg/services/reputation/common/router/deps.go @@ -1,4 +1,4 @@ -package reputationroute +package router import ( "github.com/nspcc-dev/neofs-node/pkg/services/reputation" diff --git a/pkg/services/reputation/local/route/opts.go b/pkg/services/reputation/common/router/opts.go similarity index 94% rename from pkg/services/reputation/local/route/opts.go rename to pkg/services/reputation/common/router/opts.go index 1cf3f61f4..20a3e2eea 100644 --- a/pkg/services/reputation/local/route/opts.go +++ b/pkg/services/reputation/common/router/opts.go @@ -1,4 +1,4 @@ -package reputationroute +package router import ( "github.com/nspcc-dev/neofs-node/pkg/util/logger" diff --git a/pkg/services/reputation/local/route/router.go b/pkg/services/reputation/common/router/router.go similarity index 98% rename from pkg/services/reputation/local/route/router.go rename to pkg/services/reputation/common/router/router.go index 895f77593..b5fe634c9 100644 --- a/pkg/services/reputation/local/route/router.go +++ b/pkg/services/reputation/common/router/router.go @@ -1,4 +1,4 @@ -package reputationroute +package router import ( "fmt" diff --git a/pkg/services/reputation/local/route/util.go b/pkg/services/reputation/common/router/util.go similarity index 97% rename from pkg/services/reputation/local/route/util.go rename to pkg/services/reputation/common/router/util.go index e3de88c85..77c92b7f3 100644 --- a/pkg/services/reputation/local/route/util.go +++ b/pkg/services/reputation/common/router/util.go @@ -1,4 +1,4 @@ -package reputationroute +package router import ( "bytes" diff --git a/pkg/services/reputation/local/controller/controller.go b/pkg/services/reputation/local/controller/controller.go index c6e799d47..0ce60aa90 100644 --- a/pkg/services/reputation/local/controller/controller.go +++ b/pkg/services/reputation/local/controller/controller.go @@ -5,7 +5,7 @@ import ( "fmt" "sync" - "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common" + reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common" ) // Prm groups the required parameters of the Controller's constructor. @@ -24,7 +24,7 @@ type Prm struct { // trust to other nodes. // // Must not be nil. - LocalTrustTarget common.WriterProvider + LocalTrustTarget reputationcommon.WriterProvider } // Controller represents main handler for starting diff --git a/pkg/services/reputation/local/route/managers/builder.go b/pkg/services/reputation/local/managers/builder.go similarity index 100% rename from pkg/services/reputation/local/route/managers/builder.go rename to pkg/services/reputation/local/managers/builder.go diff --git a/pkg/services/reputation/local/route/managers/calls.go b/pkg/services/reputation/local/managers/calls.go similarity index 96% rename from pkg/services/reputation/local/route/managers/calls.go rename to pkg/services/reputation/local/managers/calls.go index 0e5e8e132..b18288a58 100644 --- a/pkg/services/reputation/local/route/managers/calls.go +++ b/pkg/services/reputation/local/managers/calls.go @@ -2,7 +2,7 @@ package managers import ( "github.com/nspcc-dev/neofs-node/pkg/services/reputation" - reputationroute "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/route" + reputationroute "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common/router" "github.com/pkg/errors" ) diff --git a/pkg/services/reputation/local/route/managers/deps.go b/pkg/services/reputation/local/managers/deps.go similarity index 79% rename from pkg/services/reputation/local/route/managers/deps.go rename to pkg/services/reputation/local/managers/deps.go index 135924da6..48c9d08bc 100644 --- a/pkg/services/reputation/local/route/managers/deps.go +++ b/pkg/services/reputation/local/managers/deps.go @@ -2,7 +2,7 @@ package managers import ( "github.com/nspcc-dev/neofs-node/pkg/services/reputation" - reputationroute "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/route" + reputationrouter "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common/router" ) // ManagerBuilder defines an interface for providing a list @@ -10,5 +10,5 @@ import ( 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) ([]reputationroute.ServerInfo, error) + BuildManagers(epoch uint64, p reputation.PeerID) ([]reputationrouter.ServerInfo, error) }