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
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
Stefane Fermigier
neo
Commits
4732ff17
Commit
4732ff17
authored
Apr 27, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
49f0c8b9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
21 deletions
+37
-21
go/neo/connection.go
go/neo/connection.go
+24
-6
go/neo/connection_test.go
go/neo/connection_test.go
+13
-15
No files found.
go/neo/connection.go
View file @
4732ff17
...
@@ -180,7 +180,7 @@ func (nl *NodeLink) Close() error {
...
@@ -180,7 +180,7 @@ func (nl *NodeLink) Close() error {
// sendPkt sends raw packet to peer
// sendPkt sends raw packet to peer
// tx error, if any, is returned as is and is analyzed in serveSend
// tx error, if any, is returned as is and is analyzed in serveSend
func
(
nl
*
NodeLink
)
sendPkt
(
pkt
*
PktBuf
)
error
{
func
(
nl
*
NodeLink
)
sendPkt
(
pkt
*
PktBuf
)
error
{
if
tru
e
{
if
fals
e
{
// XXX -> log
// XXX -> log
fmt
.
Printf
(
"%v > %v: %v
\n
"
,
nl
.
peerLink
.
LocalAddr
(),
nl
.
peerLink
.
RemoteAddr
(),
pkt
)
fmt
.
Printf
(
"%v > %v: %v
\n
"
,
nl
.
peerLink
.
LocalAddr
(),
nl
.
peerLink
.
RemoteAddr
(),
pkt
)
//defer fmt.Printf("\t-> sendPkt err: %v\n", err)
//defer fmt.Printf("\t-> sendPkt err: %v\n", err)
...
@@ -237,7 +237,7 @@ func (nl *NodeLink) recvPkt() (*PktBuf, error) {
...
@@ -237,7 +237,7 @@ func (nl *NodeLink) recvPkt() (*PktBuf, error) {
}
}
}
}
if
tru
e
{
if
fals
e
{
// XXX -> log
// XXX -> log
fmt
.
Printf
(
"%v < %v: %v
\n
"
,
nl
.
peerLink
.
LocalAddr
(),
nl
.
peerLink
.
RemoteAddr
(),
pkt
)
fmt
.
Printf
(
"%v < %v: %v
\n
"
,
nl
.
peerLink
.
LocalAddr
(),
nl
.
peerLink
.
RemoteAddr
(),
pkt
)
}
}
...
@@ -376,6 +376,7 @@ func (nl *NodeLink) serveSend() {
...
@@ -376,6 +376,7 @@ func (nl *NodeLink) serveSend() {
case
txreq
:=
<-
nl
.
txq
:
case
txreq
:=
<-
nl
.
txq
:
err
=
nl
.
sendPkt
(
txreq
.
pkt
)
err
=
nl
.
sendPkt
(
txreq
.
pkt
)
fmt
.
Printf
(
"sendPkt -> %v
\n
"
,
err
)
if
err
!=
nil
{
if
err
!=
nil
{
// on IO error framing over peerLink becomes broken
// on IO error framing over peerLink becomes broken
...
@@ -391,6 +392,15 @@ func (nl *NodeLink) serveSend() {
...
@@ -391,6 +392,15 @@ func (nl *NodeLink) serveSend() {
txreq
.
errch
<-
err
// XXX recheck wakeup logic for err case
txreq
.
errch
<-
err
// XXX recheck wakeup logic for err case
// XXX we need to first wait till _both_ serveRecv & serveSend complete
// and only then close all Conns. Reason: e.g. when remote shutdowns
// both sendPkt and recvPkt get error. If recvPkt was
// first serveRecv will be first to mark connections as
// closed and even though sendPkt will return proper IO
// error it won't be delivered as Conn.Send waiting for
// it already waked up on c.closed without seeing
// txreq.errch being ready.
if
err
!=
nil
{
if
err
!=
nil
{
// XXX use errMu to lock vvv if needed
// XXX use errMu to lock vvv if needed
// nl.sendErr = err
// nl.sendErr = err
...
@@ -440,9 +450,17 @@ func (c *Conn) Send(pkt *PktBuf) error {
...
@@ -440,9 +450,17 @@ func (c *Conn) Send(pkt *PktBuf) error {
// NOTE after we return straight here serveSend won't be later
// NOTE after we return straight here serveSend won't be later
// blocked on c.txerr<- because that backchannel is a non-blocking one.
// blocked on c.txerr<- because that backchannel is a non-blocking one.
case
<-
c
.
closed
:
case
<-
c
.
closed
:
// XXX also poll c.txerr
return
ErrClosedConn
// also poll c.txerr here because: when there is TX error,
// return errClosedConn(c.nodeLink.sendErr) // XXX locking ?
// serveSend sends to c.txerr _and_ closes c.closed .
// We still want to return actual transmission error to caller.
select
{
case
err
=
<-
c
.
txerr
:
return
err
default
:
return
ErrClosedConn
// return errClosedConn(c.nodeLink.sendErr) // XXX locking ?
}
case
err
=
<-
c
.
txerr
:
case
err
=
<-
c
.
txerr
:
//fmt.Printf("%v <- c.txerr\n", err)
//fmt.Printf("%v <- c.txerr\n", err)
...
@@ -450,7 +468,7 @@ func (c *Conn) Send(pkt *PktBuf) error {
...
@@ -450,7 +468,7 @@ func (c *Conn) Send(pkt *PktBuf) error {
}
}
}
}
return
err
//
return err
}
}
// Receive packet from connection
// Receive packet from connection
...
...
go/neo/connection_test.go
View file @
4732ff17
...
@@ -158,7 +158,7 @@ func nodeLinkPipe() (nl1, nl2 *NodeLink) {
...
@@ -158,7 +158,7 @@ func nodeLinkPipe() (nl1, nl2 *NodeLink) {
func
TestNodeLink
(
t
*
testing
.
T
)
{
func
TestNodeLink
(
t
*
testing
.
T
)
{
// TODO catch exception -> add proper location from it -> t.Fatal (see git-backup)
// TODO catch exception -> add proper location from it -> t.Fatal (see git-backup)
/
//
*
/*
// Close vs recvPkt
// Close vs recvPkt
nl1, nl2 := _nodeLinkPipe(linkNoRecvSend, linkNoRecvSend)
nl1, nl2 := _nodeLinkPipe(linkNoRecvSend, linkNoRecvSend)
wg := WorkGroup()
wg := WorkGroup()
...
@@ -323,13 +323,13 @@ func TestNodeLink(t *testing.T) {
...
@@ -323,13 +323,13 @@ func TestNodeLink(t *testing.T) {
xclose(c11)
xclose(c11)
xclose(c12)
xclose(c12)
xclose(nl2)
xclose(nl2)
//
*/
*/
// NodeLink.Close vs Conn.Send/Recv on another side TODO
// NodeLink.Close vs Conn.Send/Recv on another side TODO
nl1
,
nl2
=
_nodeLinkPipe
(
0
,
linkNoRecvSend
)
nl1
,
nl2
:
=
_nodeLinkPipe
(
0
,
linkNoRecvSend
)
c11
=
nl1
.
NewConn
()
c11
:
=
nl1
.
NewConn
()
c12
=
nl1
.
NewConn
()
c12
:
=
nl1
.
NewConn
()
wg
=
WorkGroup
()
wg
:
=
WorkGroup
()
wg
.
Gox
(
func
()
{
wg
.
Gox
(
func
()
{
println
(
">>> RECV START"
)
println
(
">>> RECV START"
)
pkt
,
err
:=
c11
.
Recv
()
pkt
,
err
:=
c11
.
Recv
()
...
@@ -344,25 +344,23 @@ func TestNodeLink(t *testing.T) {
...
@@ -344,25 +344,23 @@ func TestNodeLink(t *testing.T) {
println
(
">>> SEND START"
)
println
(
">>> SEND START"
)
err
:=
c12
.
Send
(
pkt
)
err
:=
c12
.
Send
(
pkt
)
println
(
">>> send wakeup"
)
println
(
">>> send wakeup"
)
if
err
!=
io
.
ErrClosedPipe
{
// XXX we are here but what the error should be?
if
want
:=
io
.
ErrClosedPipe
;
err
!=
want
{
// XXX we are here but what the error should be?
exc
.
Raisef
(
"Conn.Send() after peer NodeLink shutdown:
err = %v"
,
err
)
exc
.
Raisef
(
"Conn.Send() after peer NodeLink shutdown:
unexpected err
\n
have: %v
\n
want: %v"
,
err
,
want
)
}
}
println
(
">>> SEND OK"
)
println
(
">>> SEND OK"
)
})
})
tdelay
()
tdelay
()
println
(
"NL2.Close"
)
xclose
(
nl2
)
xclose
(
nl2
)
println
(
"111"
)
xwait
(
wg
)
xwait
(
wg
)
println
(
"222"
)
// TODO check Recv/Send error on second call
xclose
(
c11
)
xclose
(
c11
)
println
(
"aaa"
)
xclose
(
c12
)
xclose
(
c12
)
println
(
"bbb"
)
// TODO check Recv/Send error after Close
xclose
(
nl1
)
xclose
(
nl1
)
println
(
"333"
)
/
//
*
/*
// Conn accept + exchange
// Conn accept + exchange
nl1, nl2 = nodeLinkPipe()
nl1, nl2 = nodeLinkPipe()
wg = WorkGroup()
wg = WorkGroup()
...
@@ -448,5 +446,5 @@ func TestNodeLink(t *testing.T) {
...
@@ -448,5 +446,5 @@ func TestNodeLink(t *testing.T) {
xclose(c2)
xclose(c2)
xclose(nl1)
xclose(nl1)
xclose(nl2)
xclose(nl2)
//
*/
*/
}
}
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