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
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
neoppod
Commits
94001fa9
Commit
94001fa9
authored
Dec 21, 2016
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
de551085
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
35 deletions
+50
-35
t/neo/connection.go
t/neo/connection.go
+4
-8
t/neo/connection_test.go
t/neo/connection_test.go
+46
-27
No files found.
t/neo/connection.go
View file @
94001fa9
...
@@ -21,10 +21,8 @@ import (
...
@@ -21,10 +21,8 @@ import (
"sync"
"sync"
"unsafe"
"unsafe"
"fmt"
//
"fmt"
)
)
// XXX temp
var
_
=
fmt
.
Println
// NodeLink is a node-node link in NEO
// NodeLink is a node-node link in NEO
//
//
...
@@ -54,8 +52,8 @@ type NodeLink struct {
...
@@ -54,8 +52,8 @@ type NodeLink struct {
connTab
map
[
uint32
]
*
Conn
// connId -> Conn associated with connId
connTab
map
[
uint32
]
*
Conn
// connId -> Conn associated with connId
nextConnId
uint32
// next connId to use for Conn initiated by us
nextConnId
uint32
// next connId to use for Conn initiated by us
serveWg
sync
.
WaitGroup
serveWg
sync
.
WaitGroup
// for serve{Send,Recv}
//handleWg sync.WaitGroup // for spawned handlers XXX do we need this + .Wait() ?
handleNewConn
func
(
conn
*
Conn
)
// handler for new connections
handleNewConn
func
(
conn
*
Conn
)
// handler for new connections
txreq
chan
txReq
// tx requests from Conns go via here
txreq
chan
txReq
// tx requests from Conns go via here
...
@@ -280,8 +278,6 @@ func (nl *NodeLink) serveRecv() {
...
@@ -280,8 +278,6 @@ func (nl *NodeLink) serveRecv() {
if
handleNewConn
!=
nil
{
if
handleNewConn
!=
nil
{
conn
=
nl
.
newConn
(
connId
)
conn
=
nl
.
newConn
(
connId
)
}
}
// FIXME update connTab with born conn
}
}
nl
.
connMu
.
Unlock
()
nl
.
connMu
.
Unlock
()
...
@@ -422,7 +418,7 @@ func (c *Conn) close() {
...
@@ -422,7 +418,7 @@ func (c *Conn) close() {
// Close connection
// Close connection
// Any blocked Send() or Recv() will be unblocked and return error
// Any blocked Send() or Recv() will be unblocked and return error
// XXX Send() - if started - will first complete (not to break framing) XXX <- in background
// XXX Send() - if started - will first complete (not to break framing) XXX <- in background
func
(
c
*
Conn
)
Close
()
error
{
// XXX do we need error here?
func
(
c
*
Conn
)
Close
()
error
{
// adjust nodeLink.connTab
// adjust nodeLink.connTab
c
.
nodeLink
.
connMu
.
Lock
()
c
.
nodeLink
.
connMu
.
Lock
()
delete
(
c
.
nodeLink
.
connTab
,
c
.
connId
)
delete
(
c
.
nodeLink
.
connTab
,
c
.
connId
)
...
...
t/neo/connection_test.go
View file @
94001fa9
...
@@ -260,10 +260,11 @@ func TestNodeLink(t *testing.T) {
...
@@ -260,10 +260,11 @@ func TestNodeLink(t *testing.T) {
xwait
(
wg
)
xwait
(
wg
)
xclose
(
c11
)
xclose
(
c11
)
xclose
(
c12
)
xclose
(
c12
)
xclose
(
nl2
)
// for completeness
xclose
(
nl2
)
// Conn accept + exchange
// Conn accept + exchange
nl1
,
nl2
=
nodeLinkPipe
()
nl1
,
nl2
=
nodeLinkPipe
()
hdone
:=
make
(
chan
struct
{})
nl2
.
HandleNewConn
(
func
(
c
*
Conn
)
{
nl2
.
HandleNewConn
(
func
(
c
*
Conn
)
{
// TODO raised err -> errch
// TODO raised err -> errch
pkt
:=
xrecv
(
c
)
pkt
:=
xrecv
(
c
)
...
@@ -271,56 +272,74 @@ func TestNodeLink(t *testing.T) {
...
@@ -271,56 +272,74 @@ func TestNodeLink(t *testing.T) {
// change pkt a bit and send it back
// change pkt a bit and send it back
xsend
(
c
,
mkpkt
(
34
,
[]
byte
(
"pong"
)))
xsend
(
c
,
mkpkt
(
34
,
[]
byte
(
"pong"
)))
// one more time
pkt
=
xrecv
(
c
)
xverifyPkt
(
pkt
,
c
.
connId
,
35
,
[]
byte
(
"ping2"
))
xsend
(
c
,
mkpkt
(
36
,
[]
byte
(
"pong2"
)))
xclose
(
c
)
xclose
(
c
)
close
(
hdone
)
})
})
c1
:=
nl1
.
NewConn
()
c
=
nl1
.
NewConn
()
pkt
=
mkpkt
(
33
,
[]
byte
(
"ping"
))
xsend
(
c
,
mkpkt
(
33
,
[]
byte
(
"ping"
)))
xsend
(
c1
,
pkt
)
pkt
=
xrecv
(
c
)
pkt2
:=
xrecv
(
c1
)
xverifyPkt
(
pkt
,
c
.
connId
,
34
,
[]
byte
(
"pong"
))
xverifyPkt
(
pkt2
,
c1
.
connId
,
34
,
[]
byte
(
"pong"
))
xsend
(
c
,
mkpkt
(
35
,
[]
byte
(
"ping2"
)))
pkt
=
xrecv
(
c
)
xverifyPkt
(
pkt
,
c
.
connId
,
36
,
[]
byte
(
"pong2"
))
<-
hdone
xclose
(
c
)
xclose
(
nl1
)
xclose
(
nl2
)
// test 2 channels with replies comming in reversed time order
// test 2 channels with replies comming in reversed time order
nl1
,
nl2
=
nodeLinkPipe
()
nl1
,
nl2
=
nodeLinkPipe
()
o
rder
:=
map
[
uint16
]
struct
{
// "order" in which to process requests
replyO
rder
:=
map
[
uint16
]
struct
{
// "order" in which to process requests
start
chan
int
// processing starts when start chan is ready
start
chan
struct
{}
// processing starts when start chan is ready
next
uint16
// after processing this switch to next
next
uint16
// after processing this switch to next
}{
}{
2
:
{
make
(
chan
int
),
1
},
2
:
{
make
(
chan
struct
{}
),
1
},
1
:
{
make
(
chan
int
),
0
},
1
:
{
make
(
chan
struct
{}
),
0
},
}
}
go
func
()
{
close
(
replyOrder
[
2
]
.
start
)
order
[
2
]
.
start
<-
0
}()
c1
=
nl1
.
NewConn
()
// XXX temp?
c2
:=
nl1
.
NewConn
()
nl2
.
HandleNewConn
(
func
(
c
*
Conn
)
{
nl2
.
HandleNewConn
(
func
(
c
*
Conn
)
{
pkt
:=
xrecv
(
c
)
pkt
:=
xrecv
(
c
)
n
:=
ntoh16
(
pkt
.
Header
()
.
MsgCode
)
n
:=
ntoh16
(
pkt
.
Header
()
.
MsgCode
)
x
:=
o
rder
[
n
]
x
:=
replyO
rder
[
n
]
// wait before it is our turn & echo pkt back
// wait before it is our turn & echo pkt back
<-
x
.
start
<-
x
.
start
xsend
(
c
,
pkt
)
xsend
(
c
,
pkt
)
xclose
(
c
)
// tell next it can start
// tell next it can start
if
x
.
next
!=
0
{
if
x
.
next
!=
0
{
order
[
x
.
next
]
.
start
<-
0
close
(
replyOrder
[
x
.
next
]
.
start
)
}
}
})
})
c1
:=
nl1
.
NewConn
()
c2
:=
nl1
.
NewConn
()
println
(
"111"
)
xsend
(
c1
,
mkpkt
(
1
,
[]
byte
(
""
)))
xsend
(
c1
,
mkpkt
(
1
,
[]
byte
(
""
)))
println
(
"222"
)
xsend
(
c2
,
mkpkt
(
2
,
[]
byte
(
""
)))
xsend
(
c2
,
mkpkt
(
2
,
[]
byte
(
""
)))
println
(
"333"
)
wg
=
WorkGroup
()
// replies must be coming in reverse order
echoWait
:=
func
(
c
*
Conn
,
msgCode
uint16
)
func
()
{
xechoWait
:=
func
(
c
*
Conn
,
msgCode
uint16
)
{
return
func
()
{
pkt
:=
xrecv
(
c
)
pkt
:=
xrecv
(
c
)
xverifyPkt
(
pkt
,
c
.
connId
,
msgCode
,
[]
byte
(
""
))
xverifyPkt
(
pkt
,
c
.
connId
,
msgCode
,
[]
byte
(
""
))
}
}
}
wg
.
Gox
(
echoWait
(
c1
,
1
))
println
(
"aaa"
)
wg
.
Gox
(
echoWait
(
c2
,
2
))
xechoWait
(
c2
,
2
)
xwait
(
wg
)
println
(
"bbb"
)
xechoWait
(
c1
,
1
)
println
(
"ccc"
)
xclose
(
c1
)
xclose
(
c1
)
xclose
(
c2
)
xclose
(
c2
)
...
...
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