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
8caeaceb
Commit
8caeaceb
authored
Dec 15, 2016
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
63a70d44
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
20 deletions
+46
-20
t/neo/connection.go
t/neo/connection.go
+14
-18
t/neo/connection_test.go
t/neo/connection_test.go
+32
-2
No files found.
t/neo/connection.go
View file @
8caeaceb
...
@@ -15,9 +15,6 @@
...
@@ -15,9 +15,6 @@
package
neo
package
neo
import
(
import
(
//"fmt"
//"encoding/binary"
"io"
"io"
"net"
"net"
"unsafe"
"unsafe"
...
@@ -67,13 +64,12 @@ type Conn struct {
...
@@ -67,13 +64,12 @@ type Conn struct {
// Buffer with packet data
// Buffer with packet data
type
PktBuf
struct
{
type
PktBuf
struct
{
//PktHead
Data
[]
byte
// whole packet data including all headers XXX -> Buf ?
Data
[]
byte
// whole packet data including all headers XXX -> Buf ?
}
}
// Get pointer to packet header
// Get pointer to packet header
func
(
pkt
*
PktBuf
)
Header
()
*
PktHead
{
func
(
pkt
*
PktBuf
)
Header
()
*
PktHead
{
// XXX check len(Data) < PktHead ?
// XXX check len(Data) < PktHead ?
-> no, Data has to be allocated with cap >= PktHeadLen
return
(
*
PktHead
)(
unsafe
.
Pointer
(
&
pkt
.
Data
[
0
]))
return
(
*
PktHead
)(
unsafe
.
Pointer
(
&
pkt
.
Data
[
0
]))
}
}
...
@@ -108,6 +104,8 @@ func (nl *NodeLink) sendPkt(pkt *PktBuf) error {
...
@@ -108,6 +104,8 @@ func (nl *NodeLink) sendPkt(pkt *PktBuf) error {
func
(
nl
*
NodeLink
)
recvPkt
()
(
*
PktBuf
,
error
)
{
func
(
nl
*
NodeLink
)
recvPkt
()
(
*
PktBuf
,
error
)
{
// TODO organize rx buffers management (freelist etc)
// TODO organize rx buffers management (freelist etc)
// TODO cleanup lots of ntoh32(...)
// TODO cleanup lots of ntoh32(...)
// XXX do we need to retry if err is temporary?
// TODO on error framing is broken -> close connection / whole NodeLink ?
// first read to read pkt header and hopefully up to page of data in 1 syscall
// first read to read pkt header and hopefully up to page of data in 1 syscall
pkt
:=
&
PktBuf
{
make
([]
byte
,
4096
)}
pkt
:=
&
PktBuf
{
make
([]
byte
,
4096
)}
...
@@ -117,10 +115,8 @@ func (nl *NodeLink) recvPkt() (*PktBuf, error) {
...
@@ -117,10 +115,8 @@ func (nl *NodeLink) recvPkt() (*PktBuf, error) {
}
}
pkth
:=
pkt
.
Header
()
pkth
:=
pkt
.
Header
()
//pkt.Id = binary.BigEndian.Uint32(rxbuf[0:]) // XXX -> PktHeader.Decode() ?
//pkt.Code = binary.BigEndian.Uint16(rxbuf[4:])
//pkt.Len = binary.BigEndian.Uint32(rxbuf[6:])
// XXX -> better PktHeader.Decode() ?
if
ntoh32
(
pkth
.
Len
)
<
PktHeadLen
{
if
ntoh32
(
pkth
.
Len
)
<
PktHeadLen
{
panic
(
"TODO pkt.Len < PktHeadLen"
)
// XXX err (length is a whole packet len with header)
panic
(
"TODO pkt.Len < PktHeadLen"
)
// XXX err (length is a whole packet len with header)
}
}
...
@@ -141,13 +137,21 @@ func (nl *NodeLink) recvPkt() (*PktBuf, error) {
...
@@ -141,13 +137,21 @@ func (nl *NodeLink) recvPkt() (*PktBuf, error) {
if
n
<
len
(
pkt
.
Data
)
{
if
n
<
len
(
pkt
.
Data
)
{
_
,
err
=
io
.
ReadFull
(
nl
.
peerLink
,
pkt
.
Data
[
n
:
])
_
,
err
=
io
.
ReadFull
(
nl
.
peerLink
,
pkt
.
Data
[
n
:
])
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
// XXX err
return
nil
,
err
// XXX err adjust ?
}
}
}
}
return
pkt
,
nil
return
pkt
,
nil
}
}
// 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
return
nl
.
peerLink
.
Close
()
}
// Make a connection on top of node-node link
// Make a connection on top of node-node link
func
(
nl
*
NodeLink
)
NewConn
()
*
Conn
{
func
(
nl
*
NodeLink
)
NewConn
()
*
Conn
{
...
@@ -197,14 +201,6 @@ func (nl *NodeLink) HandleNewConn(h func(*Conn)) {
...
@@ -197,14 +201,6 @@ func (nl *NodeLink) HandleNewConn(h func(*Conn)) {
nl
.
handleNewConn
=
h
// NOTE can change handler at runtime XXX do we need this?
nl
.
handleNewConn
=
h
// NOTE can change handler at runtime XXX do we need this?
}
}
// 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
return
nl
.
peerLink
.
Close
()
}
// Send packet via connection
// Send packet via connection
// XXX vs cancel
// XXX vs cancel
...
@@ -215,8 +211,8 @@ func (c *Conn) Send(pkt *PktBuf) error {
...
@@ -215,8 +211,8 @@ func (c *Conn) Send(pkt *PktBuf) error {
}
}
// Receive packet from connection
// Receive packet from connection
// XXX vs cancel
func
(
c
*
Conn
)
Recv
()
(
*
PktBuf
,
error
)
{
func
(
c
*
Conn
)
Recv
()
(
*
PktBuf
,
error
)
{
// TODO also select on closech
pkt
,
ok
:=
<-
c
.
rxq
pkt
,
ok
:=
<-
c
.
rxq
if
!
ok
{
if
!
ok
{
return
nil
,
io
.
EOF
// XXX check erroring & other errors?
return
nil
,
io
.
EOF
// XXX check erroring & other errors?
...
...
t/neo/connection_test.go
View file @
8caeaceb
...
@@ -196,10 +196,39 @@ func TestNodeLink(t *testing.T) {
...
@@ -196,10 +196,39 @@ func TestNodeLink(t *testing.T) {
xwait
(
wgclose
)
xwait
(
wgclose
)
// test
1
channels on top of nodelink
// test channels on top of nodelink
nl1
,
nl2
=
nodeLinkPipe
()
nl1
,
nl2
=
nodeLinkPipe
()
c1
:=
nl1
.
NewConn
()
// Close vs Recv
c
:=
nl1
.
NewConn
()
wg
=
WorkGroup
()
wg
.
Gox
(
func
()
{
tdelay
()
xclose
(
c
)
})
pkt
,
err
=
c
.
Recv
()
if
!
(
pkt
==
nil
&&
err
==
io
.
ErrClosedPipe
)
{
t
.
Fatalf
(
"Conn.Recv() after close: pkt = %v err = %v"
,
pkt
,
err
)
}
xwait
(
wg
)
// Close vs Send
c
=
nl1
.
NewConn
()
wg
=
WorkGroup
()
wg
.
Gox
(
func
()
{
tdelay
()
xclose
(
c
)
})
pkt
=
&
PktBuf
{[]
byte
(
"data"
)}
err
=
c
.
Send
(
pkt
)
if
err
!=
io
.
ErrClosedPipe
{
t
.
Fatalf
(
"Conn.Send() after close: err = %v"
,
err
)
}
xwait
(
wg
)
/*
nl2.HandleNewConn(func(c *Conn) {
nl2.HandleNewConn(func(c *Conn) {
pkt := xrecv(c) // XXX t.Fatal() must be called from main goroutine -> context.Cancel ?
pkt := xrecv(c) // XXX t.Fatal() must be called from main goroutine -> context.Cancel ?
// change pkt a bit (TODO) and send it back
// change pkt a bit (TODO) and send it back
...
@@ -211,4 +240,5 @@ func TestNodeLink(t *testing.T) {
...
@@ -211,4 +240,5 @@ func TestNodeLink(t *testing.T) {
// TODO check pkt2 is pkt1 + small modification
// TODO check pkt2 is pkt1 + small modification
// test 2 channels with replies comming in reversed time order
// 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