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
41c3ed99
Commit
41c3ed99
authored
Sep 06, 2021
by
suyanlong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add local
parent
96ef8012
Pipeline
#7943
failed with stages
Changes
5
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
4 deletions
+33
-4
local.go
internal/peermgr/local.go
+14
-0
port.go
internal/peermgr/port.go
+4
-1
swarm.go
internal/peermgr/swarm.go
+3
-2
port.go
internal/port/port.go
+6
-1
message.go
model/pb/message.go
+6
-0
No files found.
internal/peermgr/local.go
View file @
41c3ed99
...
...
@@ -3,6 +3,7 @@ package peermgr
import
(
"github.com/libp2p/go-libp2p-core/peer"
"github.com/link33/sidecar/internal/port"
"github.com/link33/sidecar/internal/router"
"github.com/link33/sidecar/model/pb"
"github.com/meshplus/bitxhub-kit/crypto"
)
...
...
@@ -12,6 +13,7 @@ type local struct {
privKey
crypto
.
PrivateKey
tag
string
rev
chan
*
pb
.
IBTPX
rout
router
.
Router
}
func
(
l
*
local
)
ID
()
string
{
...
...
@@ -31,6 +33,18 @@ func (l *local) Tag() string {
}
func
(
l
*
local
)
Send
(
msg
port
.
Message
)
(
*
pb
.
Message
,
error
)
{
// 目标to == id 本机,获取信息
// 转发给路由器的。
// 判断数据类型
var
to
=
""
if
to
==
l
.
id
.
String
()
{
//获取本机信息,以及本机做的工作。
}
else
{
//转发给路由模块
//l.rout.Route()
}
panic
(
"implement me"
)
}
...
...
internal/peermgr/port.go
View file @
41c3ed99
...
...
@@ -28,16 +28,19 @@ func (s *sidecar) Tag() string {
return
s
.
tag
}
//TODO 如何区别IBTPX与Message
// Send TODO 如何区别IBTPX与Message
// Send 同步发送给绑定的对应的port dev
func
(
s
*
sidecar
)
Send
(
msg
port
.
Message
)
(
*
pb
.
Message
,
error
)
{
return
s
.
swarm
.
Send
(
s
.
ID
(),
msg
)
}
// AsyncSend 异步发送给绑定的对应的port dev
func
(
s
*
sidecar
)
AsyncSend
(
msg
port
.
Message
)
error
{
return
s
.
swarm
.
AsyncSend
(
s
.
ID
(),
msg
)
}
// ListenIBTPX 从绑定的对应的port dev接收数据
func
(
s
*
sidecar
)
ListenIBTPX
()
<-
chan
*
pb
.
IBTPX
{
return
s
.
rev
}
internal/peermgr/swarm.go
View file @
41c3ed99
...
...
@@ -97,6 +97,7 @@ func (swarm *Swarm) Start() error {
privKey
:
swarm
.
privKey
,
tag
:
""
,
rev
:
make
(
chan
*
pb
.
IBTPX
),
rout
:
swarm
.
router
,
}
swarm
.
router
.
Add
(
l
)
...
...
@@ -183,7 +184,7 @@ func (swarm *Swarm) handleMessage(s network.Stream, data []byte) {
pack
:=
m
.
Payload
.
Data
t
:=
m
.
Type
switch
{
// 接收其它sidecar节点发过来的交易、请求等
// 接收其它sidecar节点发过来的交易、请求等
。主要是IBTP结构相关数据。
case
t
==
pb
.
Message_IBTP_SEND
||
t
==
pb
.
Message_IBTP_GET
||
t
==
pb
.
Message_IBTP_RECEIPT_SEND
||
t
==
pb
.
Message_IBTP_RECEIPT_GET
:
ibtpx
:=
&
pb
.
IBTPX
{}
if
err
:=
m
.
Unmarshal
(
pack
);
err
!=
nil
{
...
...
@@ -208,7 +209,7 @@ func (swarm *Swarm) handleMessage(s network.Stream, data []byte) {
}
swarm
.
router
.
Add
(
newPort
)
rec
<-
ibtpx
default
:
default
:
//非IBTP结构相关数据
//TODO
}
...
...
internal/port/port.go
View file @
41c3ed99
...
...
@@ -38,8 +38,13 @@ type Port interface {
Name
()
string
Tag
()
string
Send
(
msg
Message
)
(
*
pb
.
Message
,
error
)
// Send 同步发送给绑定的对应的port dev
Send
(
msg
Message
)
(
*
pb
.
Message
,
error
)
//TODO 如何区别IBTPX与Message
// AsyncSend 异步发送给绑定的对应的port dev
AsyncSend
(
msg
Message
)
error
// ListenIBTPX 从绑定的对应的port dev接收数据
ListenIBTPX
()
<-
chan
*
pb
.
IBTPX
}
...
...
model/pb/message.go
View file @
41c3ed99
...
...
@@ -3,3 +3,9 @@ package pb
const
(
V1
=
"1.0"
)
//type Message interface {
// Marshal() ([]byte, error)
// Unmarshal([]byte) error
// IsMsg()bool
//}
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