Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sidecar
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
sidecar
Commits
8fe096b0
Commit
8fe096b0
authored
Jan 06, 2022
by
suyanlong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat
馃彿
Add route method for config file
parent
041e1292
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
3 deletions
+33
-3
sidecar.toml
config/sidecar.toml
+6
-0
sidecar.go
internal/app/sidecar.go
+1
-1
config.go
internal/repo/config.go
+12
-0
router.go
internal/router/router.go
+9
-2
ibtpx.go
model/pb/ibtpx.go
+5
-0
No files found.
config/sidecar.toml
View file @
8fe096b0
...
@@ -50,6 +50,12 @@ rule = "info"
...
@@ -50,6 +50,12 @@ rule = "info"
#plugin = "appchain_plugin"
#plugin = "appchain_plugin"
#config = "chain33"
#config = "chain33"
[router]
enable
=
false
RouteMethod
=
"single"
RouteMethodArg
=
[]
[[appchains]]
[[appchains]]
enable
=
true
enable
=
true
type
=
"appchain"
type
=
"appchain"
...
...
internal/app/sidecar.go
View file @
8fe096b0
...
@@ -53,7 +53,7 @@ func NewSidecar(repoRoot string, config *repo.Config) (internal.Launcher, error)
...
@@ -53,7 +53,7 @@ func NewSidecar(repoRoot string, config *repo.Config) (internal.Launcher, error)
nodePrivKey
,
err
:=
repo
.
LoadNodePrivateKey
(
repoRoot
)
nodePrivKey
,
err
:=
repo
.
LoadNodePrivateKey
(
repoRoot
)
tool
.
Asset
(
err
)
tool
.
Asset
(
err
)
ck
:=
&
checker
.
MockChecker
{}
//TODO
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
))
pm
,
err
:=
peermgr
.
New
(
config
,
r
,
nodePrivKey
,
privateKey
,
1
,
loggers
.
Logger
(
loggers
.
PeerMgr
))
tool
.
Asset
(
err
)
tool
.
Asset
(
err
)
persister
:=
manager
.
NewPersister
(
addr
.
String
(),
store
,
loggers
.
Logger
(
loggers
.
Manager
))
persister
:=
manager
.
NewPersister
(
addr
.
String
(),
store
,
loggers
.
Logger
(
loggers
.
Manager
))
...
...
internal/repo/config.go
View file @
8fe096b0
...
@@ -23,10 +23,17 @@ type Config struct {
...
@@ -23,10 +23,17 @@ type Config struct {
Port
Port
`toml:"port" json:"port"`
Port
Port
`toml:"port" json:"port"`
Log
Log
`toml:"log" json:"log"`
Log
Log
`toml:"log" json:"log"`
Appchains
[]
Appchain
`toml:"appchains" json:"appchains"`
Appchains
[]
Appchain
`toml:"appchains" json:"appchains"`
Router
Router
`toml:"router" json:"router"`
Security
Security
`toml:"security" json:"security"`
Security
Security
`toml:"security" json:"security"`
Peer
Peer
`toml:"peer" json:"peer"`
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
{
type
Peer
struct
{
Peers
[]
string
`toml:"peers" json:"peers"`
Peers
[]
string
`toml:"peers" json:"peers"`
Connectors
[]
string
`toml:"connectors" json:"connectors"`
Connectors
[]
string
`toml:"connectors" json:"connectors"`
...
@@ -124,6 +131,11 @@ func DefaultConfig() *Config {
...
@@ -124,6 +131,11 @@ func DefaultConfig() *Config {
Config
:
"chain33"
,
Config
:
"chain33"
,
},
},
},
},
Router
:
Router
{
Enable
:
false
,
RouteMethod
:
"single"
,
RouteMethodArg
:
[]
string
{},
},
}
}
}
}
...
...
internal/router/router.go
View file @
8fe096b0
...
@@ -17,6 +17,7 @@ import (
...
@@ -17,6 +17,7 @@ import (
)
)
type
router
struct
{
type
router
struct
{
config
*
repo
.
Config
logger
logrus
.
FieldLogger
logger
logrus
.
FieldLogger
ctx
context
.
Context
ctx
context
.
Context
cancel
context
.
CancelFunc
cancel
context
.
CancelFunc
...
@@ -29,9 +30,10 @@ type router struct {
...
@@ -29,9 +30,10 @@ type router struct {
type
routeMethod
func
([]
string
)
[]
port
.
Port
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
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
return
&
router
{
return
&
router
{
config
:
config
,
logger
:
logger
,
logger
:
logger
,
ctx
:
ctx
,
ctx
:
ctx
,
cancel
:
cancel
,
cancel
:
cancel
,
...
@@ -204,8 +206,13 @@ func (r *router) Route(msg *pb.Message) error {
...
@@ -204,8 +206,13 @@ func (r *router) Route(msg *pb.Message) error {
}
else
{
}
else
{
// 瑙勫垯鍒ゆ柇 杞彂缁欏叾瀹冪殑sidecar鑺傜偣
// 瑙勫垯鍒ゆ柇 杞彂缁欏叾瀹冪殑sidecar鑺傜偣
method
:=
strings
.
ToLower
(
ibtpx
.
RouteMethod
)
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
{
if
md
,
is
:=
r
.
methodMap
[
method
];
is
{
ports
:=
md
(
ibtpx
.
RouteMethodArg
)
ports
:=
md
(
args
)
if
len
(
ports
)
==
0
{
if
len
(
ports
)
==
0
{
r
.
firstRoute
(
msg
)
r
.
firstRoute
(
msg
)
}
}
...
...
model/pb/ibtpx.go
View file @
8fe096b0
...
@@ -20,6 +20,11 @@ func (m *IBTPX) Hash() *types.Hash {
...
@@ -20,6 +20,11 @@ func (m *IBTPX) Hash() *types.Hash {
return
m
.
digest
(
data
,
m
.
RouteSign
)
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
{
func
(
m
*
IBTPX
)
FrontPart
()
[]
byte
{
var
data
[]
byte
var
data
[]
byte
hash
:=
m
.
Ibtp
.
Hash
()
hash
:=
m
.
Ibtp
.
Hash
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment