Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
fbe26454
Commit
fbe26454
authored
Dec 16, 2016
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
3af68694
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
7 deletions
+31
-7
t/neo/connection.go
t/neo/connection.go
+10
-6
t/neo/connection_test.go
t/neo/connection_test.go
+21
-1
No files found.
t/neo/connection.go
View file @
fbe26454
...
...
@@ -101,9 +101,12 @@ func NewNodeLink(c net.Conn) *NodeLink {
// Close node-node link.
// IO on connections established over it is automatically interrupted with an error.
func
(
nl
*
NodeLink
)
Close
()
error
{
// TODO adjust connTab & friends
close
(
nl
.
closed
)
return
nl
.
peerLink
.
Close
()
err
:=
nl
.
peerLink
.
Close
()
// TODO close active Conns
// XXX wait for serve{Send,Recv} to complete
nl
.
wg
.
Wait
()
}
// send raw packet to peer
...
...
@@ -190,11 +193,12 @@ func (nl *NodeLink) serveRecv() {
panic
(
err
)
// XXX err
}
// if we don't yet have connection established for pkt.MsgId spawn connection-serving goroutine
// if we don't yet have connection established for pkt.MsgId -
// spawn connection-serving goroutine
// XXX connTab locking
conn
:=
nl
.
connTab
[
ntoh32
(
pkt
.
Header
()
.
MsgId
)]
if
conn
==
nil
{
if
nl
.
handleNewConn
==
nil
{
// TODO check != nil in ctor, not here
if
nl
.
handleNewConn
==
nil
{
// we are not accepting incoming connections - ignore packet
// XXX also log?
continue
...
...
@@ -224,9 +228,10 @@ func (nl *NodeLink) serveSend() {
for
{
select
{
case
<-
nl
.
closed
:
return
break
case
txreq
:=
<-
nl
.
txreq
:
pkt
.
Header
()
.
MsgId
=
hton32
(
0
)
// TODO next msgid, or using same msgid as received
err
:=
nl
.
sendPkt
(
txreq
.
pkt
)
if
err
!=
nil
{
// XXX also close whole nodeLink since tx framing now can be broken?
...
...
@@ -249,7 +254,6 @@ var ErrClosedConn = errors.New("read/write on closed connection")
// Send packet via connection
func
(
c
*
Conn
)
Send
(
pkt
*
PktBuf
)
error
{
pkt
.
Header
()
.
MsgId
=
hton32
(
0
)
// TODO next msgid, or using same msgid as received
select
{
case
<-
c
.
closed
:
return
ErrClosedConn
...
...
t/neo/connection_test.go
View file @
fbe26454
...
...
@@ -226,7 +226,27 @@ func TestNodeLink(t *testing.T) {
}
xwait
(
wg
)
// TODO check NodeLink.Close -> aborts Conn.Send/Recv
// NodeLink.Close vs Conn.Send/Recv
c11
:=
nl1
.
NewConn
()
c12
:=
nl1
.
NewConn
()
wg
=
WorkGroup
()
wg
.
Gox
(
func
()
{
pkt
,
err
:=
c11
.
Recv
()
if
!
(
pkt
==
nil
&&
err
==
ErrClosedConn
)
{
exc
.
Raisef
(
"Conn.Recv() after NodeLink.close: pkt = %v err = %v"
,
pkt
,
err
)
}
})
wg
.
Gox
(
func
()
{
pkt
:=
&
PktBuf
{[]
byte
(
"data"
)}
err
:=
c12
.
Send
(
pkt
)
if
err
!=
ErrClosedConn
{
exc
.
Raisef
(
"Conn.Send() after close: err = %v"
,
err
)
}
})
tdelay
()
xclose
(
nl1
)
xwait
(
wg
)
xclose
(
nl2
)
// for completeness
/*
...
...
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