Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
bebc5e77
Commit
bebc5e77
authored
Jan 12, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
35d32ba6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
16 deletions
+30
-16
go/neo/neonet/connection.go
go/neo/neonet/connection.go
+26
-12
go/neo/neonet/connection_test.go
go/neo/neonet/connection_test.go
+3
-3
go/neo/neonet/pkt.go
go/neo/neonet/pkt.go
+1
-1
No files found.
go/neo/neonet/connection.go
View file @
bebc5e77
...
...
@@ -821,10 +821,17 @@ func (nl *NodeLink) serveRecv() {
// NOTE if nl.peerLink was just closed by tx->shutdown we'll get ErrNetClosing
pkt
,
err
:=
nl
.
recvPkt
()
//fmt.Printf("\n%p recvPkt -> %v, %v\n", nl, pkt, err)
if
err
!=
nil
{
// on IO error framing over peerLink becomes broken
// so we shut down node link and all connections over it.
// pkt.ConnId -> Conn
var
connId
uint32
if
err
==
nil
{
connId
,
_
,
_
,
err
=
pktDecodeHead
(
nl
.
enc
,
pkt
)
}
// on IO error framing over peerLink becomes broken
// so we shut down node link and all connections over it.
// Same if we cannot decode packet header.
if
err
!=
nil
{
nl
.
errMu
.
Lock
()
nl
.
errRecv
=
err
nl
.
errMu
.
Unlock
()
...
...
@@ -833,8 +840,7 @@ func (nl *NodeLink) serveRecv() {
return
}
// pkt.ConnId -> Conn
connId
:=
packed
.
Ntoh32
(
pkt
.
Header
()
.
ConnId
)
accept
:=
false
nl
.
connMu
.
Lock
()
...
...
@@ -1155,11 +1161,17 @@ func (nl *NodeLink) serveSend() {
// sendPktDirect sends raw packet with appropriate connection ID directly via link.
func
(
c
*
Conn
)
sendPktDirect
(
pkt
*
pktBuf
)
error
{
// set pkt connId associated with this connection
pkt
.
Header
()
.
ConnId
=
packed
.
Hton32
(
c
.
connId
)
// connId must be set to one associated with this connection
connID
,
_
,
_
,
err
:=
pktDecodeHead
(
c
.
link
.
enc
,
pkt
)
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"Conn.sendPkt: bad packet: %s"
,
err
))
}
if
connID
!=
c
.
connId
{
panic
(
"Conn.sendPkt: connId wrong"
)
}
// NOTE if n.peerLink was just closed by rx->shutdown we'll get ErrNetClosing
err
:
=
c
.
link
.
sendPkt
(
pkt
)
err
=
c
.
link
.
sendPkt
(
pkt
)
//fmt.Printf("sendPkt -> %v\n", err)
// on IO error framing over peerLink becomes broken
...
...
@@ -1555,13 +1567,15 @@ func (c *Conn) Expect(msgv ...proto.Msg) (which int, err error) {
}
defer
pkt
.
Free
()
// XXX encN-specific
pkth
:=
pkt
.
Header
()
msgCode
:=
packed
.
Ntoh16
(
pkth
.
MsgCode
)
// decode packet
_
,
msgCode
,
payload
,
err
:=
pktDecodeHead
(
c
.
link
.
enc
,
pkt
)
if
err
!=
nil
{
return
-
1
,
err
}
for
i
,
msg
:=
range
msgv
{
if
proto
.
MsgCode
(
msg
)
==
msgCode
{
_
,
err
:=
c
.
link
.
enc
.
NEOMsgDecode
(
msg
,
p
kt
.
Payload
()
)
_
,
err
:=
c
.
link
.
enc
.
NEOMsgDecode
(
msg
,
p
ayload
)
if
err
!=
nil
{
return
-
1
,
c
.
err
(
"decode"
,
err
)
}
...
...
go/neo/neonet/connection_test.go
View file @
bebc5e77
...
...
@@ -640,9 +640,9 @@ func _TestNodeLink(t *T) {
gox
(
wg
,
func
(
_
context
.
Context
)
{
pkt
:=
xrecvPkt
(
c
)
// XXX encN-specific
n
:=
packed
.
Ntoh16
(
pkt
.
Header
()
.
MsgCode
)
x
:=
replyOrder
[
n
]
_
,
msgCode
,
_
,
err
:=
pktDecodeHead
(
t
.
enc
,
pkt
)
exc
.
Raiseif
(
err
)
x
:=
replyOrder
[
msgCode
]
// wait before it is our turn & echo pkt back
<-
x
.
start
...
...
go/neo/neonet/pkt.go
View file @
bebc5e77
...
...
@@ -39,7 +39,7 @@ type pktBuf struct {
}
// HeaderN returns pointer to packet header in 'N'-encoding.
func
(
pkt
*
pktBuf
)
Header
()
*
proto
.
PktHeader
{
return
pkt
.
HeaderN
()
}
// XXX kill
//
func (pkt *pktBuf) Header() *proto.PktHeader { return pkt.HeaderN() } // XXX kill
func
(
pkt
*
pktBuf
)
HeaderN
()
*
proto
.
PktHeader
{
// NOTE no need to check len(.data) < PktHeader:
// .data is always allocated with cap >= PktHeaderLen.
...
...
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