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
88993240
Commit
88993240
authored
Nov 24, 2021
by
suyanlong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.Add Router interface function.
2.Fixed bug for Manger
parent
7277a275
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
41 additions
and
37 deletions
+41
-37
server.go
api/server.go
+23
-28
sidecar.go
internal/app/sidecar.go
+3
-4
manager.go
internal/manger/manager.go
+8
-2
interface.go
internal/router/interface.go
+4
-0
json.go
pkg/json/json.go
+1
-3
tool.go
tool/tool.go
+2
-0
No files found.
api/server.go
View file @
88993240
...
@@ -2,7 +2,6 @@ package api
...
@@ -2,7 +2,6 @@ package api
import
(
import
(
"context"
"context"
"encoding/json"
"fmt"
"fmt"
"net/http"
"net/http"
"path/filepath"
"path/filepath"
...
@@ -13,44 +12,43 @@ import (
...
@@ -13,44 +12,43 @@ import (
"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus"
"gitlab.33.cn/link33/sidecar/cmd/sidecar/client"
"gitlab.33.cn/link33/sidecar/cmd/sidecar/client"
"gitlab.33.cn/link33/sidecar/internal/peermgr"
"gitlab.33.cn/link33/sidecar/internal/repo"
"gitlab.33.cn/link33/sidecar/internal/repo"
"gitlab.33.cn/link33/sidecar/internal/r
ulemg
r"
"gitlab.33.cn/link33/sidecar/internal/r
oute
r"
"gitlab.33.cn/link33/sidecar/model/pb"
"gitlab.33.cn/link33/sidecar/model/pb"
"gitlab.33.cn/link33/sidecar/pkg/json"
"gitlab.33.cn/link33/sidecar/tool"
)
)
type
Server
struct
{
type
Server
struct
{
router
*
gin
.
Engine
engine
*
gin
.
Engine
config
*
repo
.
Config
config
*
repo
.
Config
logger
logrus
.
FieldLogger
logger
logrus
.
FieldLogger
ctx
context
.
Context
ctx
context
.
Context
cancel
context
.
CancelFunc
cancel
context
.
CancelFunc
peerMgr
peermgr
.
PeerManager
router
router
.
Router
rule
*
rulemgr
.
RuleMgr
}
}
type
response
struct
{
type
response
struct
{
Data
[]
byte
`json:"data"`
Data
[]
byte
`json:"data"`
}
}
func
NewServer
(
config
*
repo
.
Config
,
peerMgr
peermgr
.
PeerManager
,
rule
*
rulemgr
.
RuleMg
r
,
logger
logrus
.
FieldLogger
)
*
Server
{
func
NewServer
(
config
*
repo
.
Config
,
router
router
.
Route
r
,
logger
logrus
.
FieldLogger
)
*
Server
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
gin
.
SetMode
(
gin
.
ReleaseMode
)
gin
.
SetMode
(
gin
.
ReleaseMode
)
r
outer
:=
gin
.
New
()
r
:=
gin
.
New
()
return
&
Server
{
return
&
Server
{
router
:
router
,
engine
:
r
,
config
:
config
,
config
:
config
,
logger
:
logger
,
logger
:
logger
,
ctx
:
ctx
,
ctx
:
ctx
,
cancel
:
cancel
,
cancel
:
cancel
,
peerMgr
:
peerMgr
,
router
:
router
,
rule
:
rule
,
}
}
}
}
func
(
g
*
Server
)
Start
()
error
{
func
(
g
*
Server
)
Start
()
error
{
g
.
router
.
Use
(
gin
.
Recovery
())
g
.
engine
.
Use
(
gin
.
Recovery
())
v1
:=
g
.
router
.
Group
(
"/v1"
)
v1
:=
g
.
engine
.
Group
(
"/v1"
)
{
{
v1
.
POST
(
client
.
RegisterAppchainUrl
,
g
.
registerAppchain
)
v1
.
POST
(
client
.
RegisterAppchainUrl
,
g
.
registerAppchain
)
v1
.
POST
(
client
.
UpdateAppchainUrl
,
g
.
updateAppchain
)
v1
.
POST
(
client
.
UpdateAppchainUrl
,
g
.
updateAppchain
)
...
@@ -59,14 +57,11 @@ func (g *Server) Start() error {
...
@@ -59,14 +57,11 @@ func (g *Server) Start() error {
go
func
()
{
go
func
()
{
go
func
()
{
go
func
()
{
err
:=
g
.
router
.
Run
(
fmt
.
Sprintf
(
":%d"
,
g
.
config
.
Port
.
Http
))
tool
.
Asset
(
g
.
engine
.
Run
(
fmt
.
Sprintf
(
":%d"
,
g
.
config
.
Port
.
Http
)))
if
err
!=
nil
{
panic
(
err
)
}
}()
}()
<-
g
.
ctx
.
Done
()
<-
g
.
ctx
.
Done
()
}()
}()
return
g
.
peerMgr
.
RegisterMsgHandler
(
pb
.
Message_RULE_DEPLOY
,
g
.
rule
.
HandleRule
)
return
nil
}
}
func
(
g
*
Server
)
Stop
()
error
{
func
(
g
*
Server
)
Stop
()
error
{
...
@@ -99,7 +94,7 @@ func (g *Server) sendAppchain(c *gin.Context, appchainType pb.Message_Type) {
...
@@ -99,7 +94,7 @@ func (g *Server) sendAppchain(c *gin.Context, appchainType pb.Message_Type) {
}
}
msg
:=
pb
.
Msg
(
appchainType
,
true
,
data
)
msg
:=
pb
.
Msg
(
appchainType
,
true
,
data
)
ackMsg
,
err
:=
g
.
peerMgr
.
SendByID
(
sidecarID
,
msg
)
ackMsg
,
err
:=
g
.
router
.
Send
(
sidecarID
,
msg
)
if
err
!=
nil
{
if
err
!=
nil
{
res
.
Data
=
[]
byte
(
err
.
Error
())
res
.
Data
=
[]
byte
(
err
.
Error
())
c
.
JSON
(
http
.
StatusInternalServerError
,
res
)
c
.
JSON
(
http
.
StatusInternalServerError
,
res
)
...
@@ -150,7 +145,7 @@ func (g *Server) getAppchain(c *gin.Context) {
...
@@ -150,7 +145,7 @@ func (g *Server) getAppchain(c *gin.Context) {
}
}
msg
:=
pb
.
Msg
(
pb
.
Message_APPCHAIN_GET
,
true
,
data
)
msg
:=
pb
.
Msg
(
pb
.
Message_APPCHAIN_GET
,
true
,
data
)
ackMsg
,
err
:=
g
.
peerMgr
.
SendByID
(
targetSidecarID
,
msg
)
ackMsg
,
err
:=
g
.
router
.
Send
(
targetSidecarID
,
msg
)
if
err
!=
nil
{
if
err
!=
nil
{
res
.
Data
=
[]
byte
(
err
.
Error
())
res
.
Data
=
[]
byte
(
err
.
Error
())
c
.
JSON
(
http
.
StatusInternalServerError
,
res
)
c
.
JSON
(
http
.
StatusInternalServerError
,
res
)
...
...
internal/app/sidecar.go
View file @
88993240
...
@@ -66,12 +66,11 @@ func NewSidecar(repoRoot string, config *repo.Config) (internal.Launcher, error)
...
@@ -66,12 +66,11 @@ func NewSidecar(repoRoot string, config *repo.Config) (internal.Launcher, error)
cryptor
:=
txcrypto
.
NewCryptor
(
nil
,
appchainMgr
,
privateKey
)
cryptor
:=
txcrypto
.
NewCryptor
(
nil
,
appchainMgr
,
privateKey
)
clientPort
:=
appchain
.
NewPorts
(
clients
,
cryptor
,
logger
)
clientPort
:=
appchain
.
NewPorts
(
clients
,
cryptor
,
logger
)
r
.
Adds
(
clientPort
)
r
.
Adds
(
clientPort
)
mg
,
err
:=
manger
.
NewManager
(
addr
.
String
(),
pm
,
appchainMgr
,
loggers
.
Logger
(
loggers
.
Manger
))
tool
.
Asset
(
err
)
rule
,
err
:=
rulemgr
.
New
(
store
,
loggers
.
Logger
(
loggers
.
Rule
))
rule
,
err
:=
rulemgr
.
New
(
store
,
loggers
.
Logger
(
loggers
.
Rule
))
tool
.
Asset
(
err
)
tool
.
Asset
(
err
)
apiServer
:=
api
.
NewServer
(
config
,
pm
,
rule
,
loggers
.
Logger
(
loggers
.
ApiServer
))
mg
,
err
:=
manger
.
NewManager
(
addr
.
String
(),
pm
,
appchainMgr
,
rule
,
loggers
.
Logger
(
loggers
.
Manger
))
tool
.
Asset
(
err
)
apiServer
:=
api
.
NewServer
(
config
,
r
,
loggers
.
Logger
(
loggers
.
ApiServer
))
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
return
&
App
{
return
&
App
{
storage
:
store
,
storage
:
store
,
...
...
internal/manger/manager.go
View file @
88993240
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"gitlab.33.cn/link33/sidecar/internal/peermgr"
"gitlab.33.cn/link33/sidecar/internal/peermgr"
"gitlab.33.cn/link33/sidecar/internal/port"
"gitlab.33.cn/link33/sidecar/internal/port"
"gitlab.33.cn/link33/sidecar/internal/rulemgr"
"gitlab.33.cn/link33/sidecar/model/pb"
"gitlab.33.cn/link33/sidecar/model/pb"
"gitlab.33.cn/link33/sidecar/pkg/json"
"gitlab.33.cn/link33/sidecar/pkg/json"
)
)
...
@@ -14,6 +15,7 @@ type Manager struct {
...
@@ -14,6 +15,7 @@ type Manager struct {
logger
logrus
.
FieldLogger
logger
logrus
.
FieldLogger
appchainMgr
appchainmgr
.
AppchainMgr
appchainMgr
appchainmgr
.
AppchainMgr
pm
peermgr
.
PeerManager
pm
peermgr
.
PeerManager
rule
*
rulemgr
.
RuleMgr
// router router.Router
// router router.Router
}
}
...
@@ -25,11 +27,12 @@ func (mgr *Manager) Stop() error {
...
@@ -25,11 +27,12 @@ func (mgr *Manager) Stop() error {
return
mgr
.
pm
.
Stop
()
return
mgr
.
pm
.
Stop
()
}
}
func
NewManager
(
addr
string
,
pm
peermgr
.
PeerManager
,
Mgr
appchainmgr
.
AppchainMgr
,
logger
logrus
.
FieldLogger
)
(
*
Manager
,
error
)
{
func
NewManager
(
addr
string
,
pm
peermgr
.
PeerManager
,
Mgr
appchainmgr
.
AppchainMgr
,
rule
*
rulemgr
.
RuleMgr
,
logger
logrus
.
FieldLogger
)
(
*
Manager
,
error
)
{
am
:=
&
Manager
{
am
:=
&
Manager
{
appchainMgr
:
Mgr
,
appchainMgr
:
Mgr
,
logger
:
logger
,
logger
:
logger
,
pm
:
pm
,
pm
:
pm
,
rule
:
rule
,
}
}
err
:=
pm
.
RegisterMultiMsgHandler
([]
pb
.
Message_Type
{
err
:=
pm
.
RegisterMultiMsgHandler
([]
pb
.
Message_Type
{
...
@@ -40,7 +43,10 @@ func NewManager(addr string, pm peermgr.PeerManager, Mgr appchainmgr.AppchainMgr
...
@@ -40,7 +43,10 @@ func NewManager(addr string, pm peermgr.PeerManager, Mgr appchainmgr.AppchainMgr
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
err
=
pm
.
RegisterMsgHandler
(
pb
.
Message_RULE_DEPLOY
,
rule
.
HandleRule
)
if
err
!=
nil
{
return
nil
,
err
}
return
am
,
nil
return
am
,
nil
}
}
...
...
internal/router/interface.go
View file @
88993240
...
@@ -18,6 +18,10 @@ type Router interface {
...
@@ -18,6 +18,10 @@ type Router interface {
Load
(
key
string
)
(
value
port
.
Port
,
ok
bool
)
Load
(
key
string
)
(
value
port
.
Port
,
ok
bool
)
Send
(
id
string
,
msg
*
pb
.
Message
)
(
*
pb
.
Message
,
error
)
AsyncSend
(
id
string
,
msg
*
pb
.
Message
)
error
// InPut(ibtp *pb.IBTP) chan *pb.IBTP
// InPut(ibtp *pb.IBTP) chan *pb.IBTP
// OutPut(ibtp *pb.IBTP) chan *pb.IBTP
// OutPut(ibtp *pb.IBTP) chan *pb.IBTP
// 代替上面两个方法
// 代替上面两个方法
...
...
pkg/json/json.go
View file @
88993240
...
@@ -3,8 +3,6 @@ package json
...
@@ -3,8 +3,6 @@ package json
import
json
"github.com/goccy/go-json"
import
json
"github.com/goccy/go-json"
var
(
var
(
Marshal
=
json
.
Marshal
Marshal
=
json
.
Marshal
Unmarshal
=
json
.
Unmarshal
Unmarshal
=
json
.
Unmarshal
)
)
tool/tool.go
View file @
88993240
...
@@ -76,3 +76,5 @@ func Exist(path string) bool {
...
@@ -76,3 +76,5 @@ func Exist(path string) bool {
//https://github.com/zricethezav/gitleaks
//https://github.com/zricethezav/gitleaks
//https://github.com/casbin/casbin
//https://github.com/casbin/casbin
//https://github.com/casbin/casbin
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