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
4a632a93
Commit
4a632a93
authored
Apr 06, 2022
by
suyanlong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug
parent
58cc8183
Pipeline
#8624
failed with stages
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
57 additions
and
63 deletions
+57
-63
sidecar.go
internal/app/sidecar.go
+13
-21
appchain.go
internal/appchain/appchain.go
+2
-2
swarm.go
internal/peermgr/swarm.go
+33
-32
router.go
internal/router/router.go
+4
-3
ibtp.proto
model/pb/ibtp.proto
+5
-5
No files found.
internal/app/sidecar.go
View file @
4a632a93
...
...
@@ -35,9 +35,9 @@ type App struct {
config
*
repo
.
Config
logger
logrus
.
FieldLogger
manger
internal
.
Launcher
apiServer
*
api
.
Server
m
anagerPort
*
appchain
.
Manager
manger
internal
.
Launcher
apiServer
*
api
.
Server
appM
anagerPort
*
appchain
.
Manager
}
// NewSidecar instantiates sidecar instance.
...
...
@@ -71,14 +71,14 @@ func NewSidecar(repoRoot string, config *repo.Config) (internal.Launcher, error)
apiServer
:=
api
.
NewServer
(
config
,
r
,
managerPort
,
loggers
.
Logger
(
loggers
.
ApiServer
))
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
return
&
App
{
storage
:
store
,
logger
:
logger
,
ctx
:
ctx
,
cancel
:
cancel
,
config
:
config
,
manger
:
mg
,
apiServer
:
apiServer
,
m
anagerPort
:
managerPort
,
storage
:
store
,
logger
:
logger
,
ctx
:
ctx
,
cancel
:
cancel
,
config
:
config
,
manger
:
mg
,
apiServer
:
apiServer
,
appM
anagerPort
:
managerPort
,
},
nil
}
...
...
@@ -88,7 +88,7 @@ func (s *App) Start() error {
return
err
}
if
err
:=
s
.
m
anagerPort
.
Start
();
err
!=
nil
{
if
err
:=
s
.
appM
anagerPort
.
Start
();
err
!=
nil
{
return
err
}
...
...
@@ -97,13 +97,5 @@ func (s *App) Start() error {
// Stop stops three main components of sidecar app
func
(
s
*
App
)
Stop
()
error
{
if
err
:=
s
.
apiServer
.
Stop
();
err
!=
nil
{
return
err
}
if
err
:=
s
.
managerPort
.
Stop
();
err
!=
nil
{
return
err
}
return
s
.
manger
.
Stop
()
return
tool
.
SelectError
(
s
.
apiServer
.
Stop
(),
s
.
appManagerPort
.
Stop
(),
s
.
manger
.
Stop
())
}
internal/appchain/appchain.go
View file @
4a632a93
...
...
@@ -30,7 +30,7 @@ type appChain struct {
logger
logrus
.
FieldLogger
ctx
context
.
Context
cancel
context
.
CancelFunc
cryptor
txcrypto
.
Cryptor
cryptor
txcrypto
.
Cryptor
//TODO FIX BUG
msgCh
chan
*
pb
.
Message
}
...
...
@@ -147,7 +147,7 @@ func (a *appChain) applyReceiptIBTP(ibtp *pb.IBTP) error {
contentByte
:=
pd
.
Content
var
err
error
if
pd
.
Encrypted
{
if
pd
.
Encrypted
{
//TODO
// TODO fix bug about mode value
contentByte
,
err
=
a
.
cryptor
.
Decrypt
(
contentByte
,
ibtp
.
To
,
repo
.
DirectMode
)
if
err
!=
nil
{
...
...
internal/peermgr/swarm.go
View file @
4a632a93
...
...
@@ -3,9 +3,6 @@ package peermgr
import
(
"context"
"fmt"
"sync"
"time"
"github.com/Rican7/retry"
"github.com/Rican7/retry/strategy"
cid
"github.com/ipfs/go-cid"
...
...
@@ -13,6 +10,8 @@ import (
"github.com/meshplus/bitxhub-kit/crypto"
network
"github.com/meshplus/go-lightp2p"
"github.com/sirupsen/logrus"
"sync"
"time"
"gitlab.33.cn/link33/sidecar/internal/port"
"gitlab.33.cn/link33/sidecar/internal/repo"
...
...
@@ -132,40 +131,42 @@ func (swarm *Swarm) Start() error {
for
id
,
addr
:=
range
swarm
.
peers
{
go
func
(
remoteID
string
,
addr
*
peer
.
AddrInfo
)
{
if
err
:=
retry
.
Retry
(
func
(
attempt
uint
)
error
{
if
err
:=
swarm
.
p2p
.
Connect
(
*
addr
);
err
!=
nil
{
if
attempt
!=
0
&&
attempt
%
5
==
0
{
swarm
.
logger
.
WithFields
(
logrus
.
Fields
{
"node"
:
remoteID
,
"error"
:
err
,
})
.
Error
(
"Connect failed"
)
}
err
:=
retry
.
Retry
(
func
(
attempt
uint
)
error
{
err
:=
swarm
.
p2p
.
Connect
(
*
addr
)
if
err
!=
nil
{
swarm
.
logger
.
WithFields
(
logrus
.
Fields
{
"node"
:
remoteID
,
"error"
:
err
,
"attempt"
:
attempt
,
}
)
.
Error
(
"Connect failed"
,
err
)
return
err
}
return
nil
},
strategy
.
Wait
(
1
*
time
.
Second
));
err
!=
nil
{
swarm
.
logger
.
Error
(
err
)
}
address
,
err
:=
swarm
.
getRemoteAddress
(
addr
.
ID
)
},
strategy
.
Limit
(
5
),
strategy
.
Wait
(
time
.
Second
))
if
err
!=
nil
{
swarm
.
logger
.
Error
(
err
)
}
else
{
address
,
err
:=
swarm
.
getRemoteAddress
(
addr
.
ID
)
if
err
!=
nil
{
swarm
.
logger
.
WithFields
(
logrus
.
Fields
{
"node"
:
remoteID
,
"error"
:
err
,
})
.
Error
(
"Get remote address failed"
)
}
swarm
.
addRemotePortByID
(
remoteID
)
swarm
.
logger
.
WithFields
(
logrus
.
Fields
{
"node"
:
remoteID
,
"error"
:
err
,
})
.
Error
(
"Get remote address failed"
)
}
swarm
.
addRemotePortByID
(
remoteID
)
swarm
.
logger
.
WithFields
(
logrus
.
Fields
{
"node"
:
remoteID
,
"address:"
:
address
,
})
.
Info
(
"Connect successfully"
)
{
//swarm.lock.RLock()
//defer swarm.lock.RUnlock()
//for _, handler := range swarm.connectHandlers {
// go func(connectHandler ConnectHandler, address string) {
// connectHandler(address)
// }(handler, address)
//}
"node"
:
remoteID
,
"address:"
:
address
,
})
.
Info
(
"Connect successfully"
)
{
//swarm.lock.RLock()
//defer swarm.lock.RUnlock()
//for _, handler := range swarm.connectHandlers {
// go func(connectHandler ConnectHandler, address string) {
// connectHandler(address)
// }(handler, address)
//}
}
}
wg
.
Done
()
}(
id
,
addr
)
...
...
internal/router/router.go
View file @
4a632a93
...
...
@@ -106,7 +106,8 @@ func (r *router) Remove(p port.Port) error {
// 路由的有那些数据?需要区分!!!
func
(
r
*
router
)
Route
(
msg
*
pb
.
Message
)
error
{
if
msg
==
nil
{
r
.
logger
.
Error
(
"msg = nil"
)
r
.
logger
.
Error
(
"msg == nil"
)
return
errors
.
New
(
"msg == nil"
)
}
ibtpx
:=
&
pb
.
IBTPX
{}
err
:=
ibtpx
.
Unmarshal
(
msg
.
Payload
.
Data
)
...
...
@@ -194,8 +195,8 @@ func (r *router) Route(msg *pb.Message) error {
r
.
logger
.
Error
(
err
)
return
err
}
case
pb
.
Message_IBTP_GET
:
case
pb
.
Message_IBTP_RECEIPT_GET
:
case
pb
.
Message_IBTP_GET
:
//TODO
case
pb
.
Message_IBTP_RECEIPT_GET
:
//TODO
default
:
return
nil
}
...
...
model/pb/ibtp.proto
View file @
4a632a93
...
...
@@ -7,11 +7,11 @@ import "basic.proto";
// Inter-blockchain Transfer Protocol
message
IBTP
{
enum
Type
{
INTERCHAIN
=
0
;
RECEIPT_SUCCESS
=
1
;
RECEIPT_FAILURE
=
2
;
ROLLBACK
=
3
;
RECEIPT_ROLLBACK
=
4
;
INTERCHAIN
=
0
;
// 发送跨链交易。
RECEIPT_SUCCESS
=
1
;
// 接收成功
RECEIPT_FAILURE
=
2
;
// 接收失败
ROLLBACK
=
3
;
// 回滚
RECEIPT_ROLLBACK
=
4
;
// 接收回滚
}
enum
Category
{
...
...
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