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
f9293ea7
Commit
f9293ea7
authored
Dec 20, 2016
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
d129e07f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
24 deletions
+32
-24
t/neo/connection.go
t/neo/connection.go
+28
-22
t/neo/connection_test.go
t/neo/connection_test.go
+4
-2
No files found.
t/neo/connection.go
View file @
f9293ea7
...
...
@@ -21,7 +21,7 @@ import (
"sync"
"unsafe"
"fmt"
//
"fmt"
)
// NodeLink is a node-node link in NEO
...
...
@@ -34,7 +34,7 @@ import (
// New connection can be created with .NewConn() . Once connection is
// created and data is sent over it, on peer's side another corresponding
// new connection will be created - accepting first packet "request" - and all
// further communication send/receive exchange will be happen
n
ing in between
// further communication send/receive exchange will be happening in between
// those 2 connections.
//
// For a node to be able to accept new incoming connection it has to register
...
...
@@ -108,7 +108,7 @@ const (
// Make a new NodeLink from already established net.Conn
//
// role specifies how to treat conn - either as server or client one.
// The differ
r
ence in between client and server roles are in connid % 2 XXX text
// The difference in between client and server roles are in connid % 2 XXX text
//
// Usually server role should be used for connections created via
// net.Listen/net.Accept and client role for connections created via net.Dial.
...
...
@@ -141,21 +141,24 @@ func NewNodeLink(conn net.Conn, role ConnRole) *NodeLink {
// Close node-node link.
// IO on connections established over it is automatically interrupted with an error.
func
(
nl
*
NodeLink
)
Close
()
error
{
close
(
nl
.
closed
)
err
:=
nl
.
peerLink
.
Close
()
// wait for serve{Send,Recv} to complete
fmt
.
Printf
(
"%p serveWg.Wait ...
\n
"
,
nl
)
nl
.
serveWg
.
Wait
()
fmt
.
Printf
(
"%p
\t
(wait) -> woken up
\n
"
,
nl
)
// close active Conns
// mark all active Conns as closed
nl
.
connMu
.
Lock
()
defer
nl
.
connMu
.
Unlock
()
for
_
,
conn
:=
range
nl
.
connTab
{
conn
.
close
()
}
nl
.
connTab
=
nil
// clear + mark closed
// close actual link to peer
// this will wakeup serve{Send,Recv}
close
(
nl
.
closed
)
err
:=
nl
.
peerLink
.
Close
()
// wait for serve{Send,Recv} to complete
//fmt.Printf("%p serveWg.Wait ...\n", nl)
nl
.
serveWg
.
Wait
()
//fmt.Printf("%p\t (wait) -> woken up\n", nl)
return
err
}
...
...
@@ -246,9 +249,9 @@ func (nl *NodeLink) serveRecv() {
defer
nl
.
serveWg
.
Done
()
for
{
// receive 1 packet
println
(
nl
,
"serveRecv -> recv..."
)
//
println(nl, "serveRecv -> recv...")
pkt
,
err
:=
nl
.
recvPkt
()
fmt
.
Printf
(
"%p
\t
(recv) -> %v
\n
"
,
nl
,
err
)
//
fmt.Printf("%p\t (recv) -> %v\n", nl, err)
if
err
!=
nil
{
// this might be just error on close - simply stop in such case
select
{
...
...
@@ -305,16 +308,16 @@ func (nl *NodeLink) serveSend() {
defer
nl
.
serveWg
.
Done
()
runloop
:
for
{
fmt
.
Printf
(
"%p serveSend -> select ...
\n
"
,
nl
)
//
fmt.Printf("%p serveSend -> select ...\n", nl)
select
{
case
<-
nl
.
closed
:
fmt
.
Printf
(
"%p
\t
(send) -> closed
\n
"
,
nl
)
//
fmt.Printf("%p\t (send) -> closed\n", nl)
break
runloop
case
txreq
:=
<-
nl
.
txreq
:
fmt
.
Printf
(
"%p
\t
(send) -> txreq
\n
"
,
nl
)
//
fmt.Printf("%p\t (send) -> txreq\n", nl)
err
:=
nl
.
sendPkt
(
txreq
.
pkt
)
fmt
.
Printf
(
"%p
\t
(send) -> err: %v
\n
"
,
nl
,
err
)
//
fmt.Printf("%p\t (send) -> err: %v\n", nl, err)
if
err
!=
nil
{
// XXX also close whole nodeLink since tx framing now can be broken?
}
...
...
@@ -322,7 +325,7 @@ runloop:
}
}
fmt
.
Printf
(
"%p
\t
(send) -> exit
\n
"
,
nl
)
//
fmt.Printf("%p\t (send) -> exit\n", nl)
}
// XXX move to NodeLink ctor ?
...
...
@@ -351,7 +354,7 @@ func (c *Conn) Send(pkt *PktBuf) error {
select
{
// tx request was sent to serveSend and is being transmitted on the wire.
// the transmission may block for indefinitely long though and
// we cannot interrupt it as the only way to interrup is
// we cannot interrupt it as the only way to interrup
t
is
// .nodeLink.Close() which will close all other Conns.
//
// That's why we are also checking for c.closed while waiting
...
...
@@ -366,9 +369,12 @@ func (c *Conn) Send(pkt *PktBuf) error {
}
}
// if we got transmission error
mayb
e it was due to underlying NodeLink
// if we got transmission error
chances ar
e it was due to underlying NodeLink
// being closed. If our Conn was also requested to be closed adjust err
// to ErrClosedConn along the way.
//
// ( reaching here is theoretically possible if both c.closed and
// c.txerr are ready above )
if
err
!=
nil
{
select
{
case
<-
c
.
closed
:
...
...
@@ -398,7 +404,7 @@ func (c *Conn) Recv() (*PktBuf, error) {
// worker for Close() & co
func
(
c
*
Conn
)
close
()
{
c
.
closeOnce
.
Do
(
func
()
{
fmt
.
Printf
(
"%p Conn.close
\n
"
,
c
)
//
fmt.Printf("%p Conn.close\n", c)
close
(
c
.
closed
)
// XXX better just close c.rxq + ??? for tx
})
}
...
...
t/neo/connection_test.go
View file @
f9293ea7
...
...
@@ -238,8 +238,6 @@ func TestNodeLink(t *testing.T) {
}
xwait
(
wg
)
return
// NodeLink.Close vs Conn.Send/Recv
c11
:=
nl1
.
NewConn
()
c12
:=
nl1
.
NewConn
()
...
...
@@ -281,5 +279,9 @@ func TestNodeLink(t *testing.T) {
pkt2
:=
xrecv
(
c1
)
xverifyPkt
(
pkt2
,
c1
.
connId
,
34
,
[]
byte
(
"pong"
))
xclose
(
c1
)
xclose
(
nl1
)
xclose
(
nl2
)
// test 2 channels with replies comming in reversed time order
}
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