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
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
3ca87f70
Commit
3ca87f70
authored
Dec 11, 2016
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
b4170a64
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
14 deletions
+16
-14
t/neo/connection.go
t/neo/connection.go
+15
-13
t/neo/pkt.go
t/neo/pkt.go
+1
-1
No files found.
t/neo/connection.go
View file @
3ca87f70
...
@@ -15,9 +15,10 @@
...
@@ -15,9 +15,10 @@
package
neo
package
neo
import
(
import
(
"encoding/binary"
//
"encoding/binary"
"io"
"io"
"net"
"net"
"unsafe"
)
)
// NodeLink is a node-node link in NEO
// NodeLink is a node-node link in NEO
...
@@ -69,7 +70,7 @@ type PktBuf struct {
...
@@ -69,7 +70,7 @@ type PktBuf struct {
}
}
// Get pointer to packet header
// Get pointer to packet header
func
(
pkt
*
PktBuf
)
Head
()
*
PktHead
{
func
(
pkt
*
PktBuf
)
Head
er
()
*
PktHead
{
// XXX check len(Data) < PktHead ?
// XXX check len(Data) < PktHead ?
return
(
*
PktHead
)(
unsafe
.
Pointer
(
&
pkt
.
Data
[
0
]))
return
(
*
PktHead
)(
unsafe
.
Pointer
(
&
pkt
.
Data
[
0
]))
}
}
...
@@ -87,7 +88,7 @@ func NewNodeLink(c net.Conn) *NodeLink {
...
@@ -87,7 +88,7 @@ func NewNodeLink(c net.Conn) *NodeLink {
// send raw packet to peer
// send raw packet to peer
func
(
nl
*
NodeLink
)
sendPkt
(
pkt
*
PktBuf
)
error
{
func
(
nl
*
NodeLink
)
sendPkt
(
pkt
*
PktBuf
)
error
{
n
,
err
:=
nl
.
peerLink
.
Write
(
pkt
.
WholeBuffer
())
// XXX WholeBuffer
_
,
err
:=
nl
.
peerLink
.
Write
(
pkt
.
Data
)
if
err
!=
nil
{
if
err
!=
nil
{
// XXX do we need to retry if err is temporary?
// XXX do we need to retry if err is temporary?
// TODO data could be written partially and thus the message stream is now broken
// TODO data could be written partially and thus the message stream is now broken
...
@@ -107,26 +108,27 @@ func (nl *NodeLink) recvPkt() (pkt *PktBuf, err error) {
...
@@ -107,26 +108,27 @@ func (nl *NodeLink) recvPkt() (pkt *PktBuf, err error) {
panic
(
err
)
// XXX err
panic
(
err
)
// XXX err
}
}
pkt
.
Id
=
binary
.
BigEndian
.
Uint32
(
rxbuf
[
0
:
])
// XXX -> PktHeader.Decode() ?
pkth
:=
pkt
.
Header
()
pkt
.
Code
=
binary
.
BigEndian
.
Uint16
(
rxbuf
[
4
:
])
//pkt.Id = binary.BigEndian.Uint32(rxbuf[0:]) // XXX -> PktHeader.Decode() ?
pkt
.
Len
=
binary
.
BigEndian
.
Uint32
(
rxbuf
[
6
:
])
//pkt.Code = binary.BigEndian.Uint16(rxbuf[4:])
//pkt.Len = binary.BigEndian.Uint32(rxbuf[6:])
if
pkt
.
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)
}
}
if
pkt
.
Len
>
MAX_PACKET_SIZE
{
if
ntoh32
(
pkth
.
Len
)
>
MAX_PACKET_SIZE
{
panic
(
"TODO message too big"
)
// XXX err
panic
(
"TODO message too big"
)
// XXX err
}
}
if
pkt
.
Len
>
uint32
(
len
(
rxbuf
))
{
if
ntoh32
(
pkth
.
Len
)
>
uint32
(
len
(
rxbuf
))
{
// grow rxbuf
// grow rxbuf
rxbuf2
:=
make
([]
byte
,
pkt
.
Len
)
rxbuf2
:=
make
([]
byte
,
ntoh32
(
pkth
.
Len
)
)
copy
(
rxbuf2
,
rxbuf
[
:
n
])
copy
(
rxbuf2
,
rxbuf
[
:
n
])
rxbuf
=
rxbuf2
rxbuf
=
rxbuf2
}
}
// read rest of pkt data, if we need to
// read rest of pkt data, if we need to
_
,
err
=
io
.
ReadFull
(
nl
.
peerLink
,
rxbuf
[
n
:
pkt
.
Len
])
_
,
err
=
io
.
ReadFull
(
nl
.
peerLink
,
rxbuf
[
n
:
ntoh32
(
pkth
.
Len
)
])
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
// XXX err
panic
(
err
)
// XXX err
}
}
...
@@ -158,7 +160,7 @@ func (nl *NodeLink) serveRecv() error {
...
@@ -158,7 +160,7 @@ func (nl *NodeLink) serveRecv() error {
// if we don't yet have connection established for pkt.Id spawn connection-serving goroutine
// if we don't yet have connection established for pkt.Id spawn connection-serving goroutine
// XXX connTab locking
// XXX connTab locking
conn
:=
nl
.
connTab
[
pkt
.
Id
]
conn
:=
nl
.
connTab
[
ntoh32
(
pkt
.
Header
()
.
MsgId
)
]
if
conn
==
nil
{
if
conn
==
nil
{
if
nl
.
handleNewConn
==
nil
{
if
nl
.
handleNewConn
==
nil
{
// we are not accepting incoming connections - ignore packet
// we are not accepting incoming connections - ignore packet
...
@@ -196,7 +198,7 @@ func (nl *NodeLink) Close() error {
...
@@ -196,7 +198,7 @@ func (nl *NodeLink) Close() error {
// Send packet via connection
// Send packet via connection
// XXX vs cancel
// XXX vs cancel
func
(
c
*
Conn
)
Send
(
pkt
*
PktBuf
)
error
{
func
(
c
*
Conn
)
Send
(
pkt
*
PktBuf
)
error
{
pkt
.
Id
=
0
// TODO next msgid, or using same msgid as received
pkt
.
Header
()
.
MsgId
=
hton32
(
0
)
// TODO next msgid, or using same msgid as received
err
:=
c
.
nodeLink
.
sendPkt
(
pkt
)
err
:=
c
.
nodeLink
.
sendPkt
(
pkt
)
return
err
// XXX do we need to adjust err ?
return
err
// XXX do we need to adjust err ?
}
}
...
...
t/neo/pkt.go
View file @
3ca87f70
...
@@ -169,7 +169,7 @@ type RequestIdentification struct {
...
@@ -169,7 +169,7 @@ type RequestIdentification struct {
UUID
UUID
UUID
UUID
Address
Address
Name
string
Name
string
IdTimestamp
Float
IdTimestamp
Float
64
}
}
// XXX -> ReplyIdentification? RequestIdentification.Answer somehow ?
// XXX -> ReplyIdentification? RequestIdentification.Answer somehow ?
...
...
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