2021-04-17 19:17:30 +00:00
|
|
|
package router
|
2021-04-02 18:16:09 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/services/reputation/common"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/util/logger"
|
2021-04-02 18:16:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Prm groups the required parameters of the Router's constructor.
|
|
|
|
//
|
|
|
|
// All values must comply with the requirements imposed on them.
|
|
|
|
// Passing incorrect parameter values will result in constructor
|
|
|
|
// failure (error or panic depending on the implementation).
|
|
|
|
type Prm struct {
|
|
|
|
// Characteristics of the local node's server.
|
|
|
|
//
|
|
|
|
// Must not be nil.
|
2021-04-23 14:54:55 +00:00
|
|
|
LocalServerInfo common.ServerInfo
|
2021-04-02 18:16:09 +00:00
|
|
|
|
|
|
|
// Component for sending values to a fixed route point.
|
|
|
|
//
|
|
|
|
// Must not be nil.
|
|
|
|
RemoteWriterProvider RemoteWriterProvider
|
|
|
|
|
|
|
|
// Route planner.
|
|
|
|
//
|
|
|
|
// Must not be nil.
|
|
|
|
Builder Builder
|
|
|
|
}
|
|
|
|
|
|
|
|
// Router represents component responsible for routing
|
|
|
|
// local trust values over the network.
|
|
|
|
//
|
|
|
|
// For each fixed pair (node peer, epoch) there is a
|
|
|
|
// single value route on the network. Router provides the
|
|
|
|
// interface for writing values to the next point of the route.
|
|
|
|
//
|
|
|
|
// For correct operation, Router must be created using
|
|
|
|
// the constructor (New) based on the required parameters
|
|
|
|
// and optional components. After successful creation,
|
|
|
|
// the Router is immediately ready to work through API.
|
|
|
|
type Router struct {
|
|
|
|
log *logger.Logger
|
|
|
|
|
|
|
|
remoteProvider RemoteWriterProvider
|
|
|
|
|
|
|
|
routeBuilder Builder
|
|
|
|
|
2021-04-23 14:54:55 +00:00
|
|
|
localSrvInfo common.ServerInfo
|
2021-04-02 18:16:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const invalidPrmValFmt = "invalid parameter %s (%T):%v"
|
|
|
|
|
2023-02-21 11:42:45 +00:00
|
|
|
func panicOnPrmValue(n string, v any) {
|
2021-04-02 18:16:09 +00:00
|
|
|
panic(fmt.Sprintf(invalidPrmValFmt, n, v, v))
|
|
|
|
}
|
|
|
|
|
|
|
|
func New(prm Prm, opts ...Option) *Router {
|
|
|
|
switch {
|
|
|
|
case prm.RemoteWriterProvider == nil:
|
|
|
|
panicOnPrmValue("RemoteWriterProvider", prm.RemoteWriterProvider)
|
|
|
|
case prm.Builder == nil:
|
|
|
|
panicOnPrmValue("Builder", prm.Builder)
|
|
|
|
case prm.LocalServerInfo == nil:
|
|
|
|
panicOnPrmValue("LocalServerInfo", prm.LocalServerInfo)
|
|
|
|
}
|
|
|
|
|
|
|
|
o := defaultOpts()
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](o)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Router{
|
|
|
|
log: o.log,
|
|
|
|
remoteProvider: prm.RemoteWriterProvider,
|
|
|
|
routeBuilder: prm.Builder,
|
|
|
|
localSrvInfo: prm.LocalServerInfo,
|
|
|
|
}
|
|
|
|
}
|