Commit 8fe096b0 authored by suyanlong's avatar suyanlong

feat馃彿 Add route method for config file

parent 041e1292
......@@ -50,6 +50,12 @@ rule = "info"
#plugin = "appchain_plugin"
#config = "chain33"
[router]
enable = false
RouteMethod = "single"
RouteMethodArg = []
[[appchains]]
enable = true
type = "appchain"
......
......@@ -53,7 +53,7 @@ func NewSidecar(repoRoot string, config *repo.Config) (internal.Launcher, error)
nodePrivKey, err := repo.LoadNodePrivateKey(repoRoot)
tool.Asset(err)
ck := &checker.MockChecker{} //TODO
r := router.NewRouter(privateKey, loggers.Logger(loggers.Router), ck)
r := router.NewRouter(config, privateKey, loggers.Logger(loggers.Router), ck)
pm, err := peermgr.New(config, r, nodePrivKey, privateKey, 1, loggers.Logger(loggers.PeerMgr))
tool.Asset(err)
persister := manager.NewPersister(addr.String(), store, loggers.Logger(loggers.Manager))
......
......@@ -23,10 +23,17 @@ type Config struct {
Port Port `toml:"port" json:"port"`
Log Log `toml:"log" json:"log"`
Appchains []Appchain `toml:"appchains" json:"appchains"`
Router Router `toml:"router" json:"router"`
Security Security `toml:"security" json:"security"`
Peer Peer `toml:"peer" json:"peer"`
}
type Router struct {
Enable bool `toml:"enable" json:"enable,omitempty"`
RouteMethod string `toml:"routeMethod" json:"routeMethod,omitempty"`
RouteMethodArg []string `toml:"routeMethodArg" json:"routeMethodArg,omitempty"`
}
type Peer struct {
Peers []string `toml:"peers" json:"peers"`
Connectors []string `toml:"connectors" json:"connectors"`
......@@ -124,6 +131,11 @@ func DefaultConfig() *Config {
Config: "chain33",
},
},
Router: Router{
Enable: false,
RouteMethod: "single",
RouteMethodArg: []string{},
},
}
}
......
......@@ -17,6 +17,7 @@ import (
)
type router struct {
config *repo.Config
logger logrus.FieldLogger
ctx context.Context
cancel context.CancelFunc
......@@ -29,9 +30,10 @@ type router struct {
type routeMethod func([]string) []port.Port
func NewRouter(privateKey crypto.PrivateKey, logger logrus.FieldLogger, checker checker.Checker) Router {
func NewRouter(config *repo.Config, privateKey crypto.PrivateKey, logger logrus.FieldLogger, checker checker.Checker) Router {
ctx, cancel := context.WithCancel(context.Background())
return &router{
config: config,
logger: logger,
ctx: ctx,
cancel: cancel,
......@@ -204,8 +206,13 @@ func (r *router) Route(msg *pb.Message) error {
} else {
// 瑙勫垯鍒ゆ柇 杞彂缁欏叾瀹冪殑sidecar鑺傜偣
method := strings.ToLower(ibtpx.RouteMethod)
args := ibtpx.RouteMethodArg
if r.config.Router.Enable {
method = r.config.Router.RouteMethod
args = r.config.Router.RouteMethodArg
}
if md, is := r.methodMap[method]; is {
ports := md(ibtpx.RouteMethodArg)
ports := md(args)
if len(ports) == 0 {
r.firstRoute(msg)
}
......
......@@ -20,6 +20,11 @@ func (m *IBTPX) Hash() *types.Hash {
return m.digest(data, m.RouteSign)
}
func (m *IBTPX) SetMethod(method string, args []string) {
m.RouteMethod = method
m.RouteMethodArg = args
}
func (m *IBTPX) FrontPart() []byte {
var data []byte
hash := m.Ibtp.Hash()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment