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
69d5916b
Commit
69d5916b
authored
Aug 02, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
daff41d2
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
403 additions
and
403 deletions
+403
-403
go/neo/connection.go
go/neo/connection.go
+6
-6
go/neo/proto.go
go/neo/proto.go
+11
-11
go/neo/proto_test.go
go/neo/proto_test.go
+8
-8
go/neo/protogen.go
go/neo/protogen.go
+10
-10
go/neo/zproto-marshal.go
go/neo/zproto-marshal.go
+368
-368
No files found.
go/neo/connection.go
View file @
69d5916b
...
...
@@ -784,7 +784,7 @@ func (c *Conn) Recv() (Msg, error) {
// TODO use free-list for decoded messages + when possible decode in-place
msg
:=
reflect
.
New
(
msgType
)
.
Interface
()
.
(
Msg
)
_
,
err
=
msg
.
NEO
MsgDecode
(
pkt
.
Payload
())
_
,
err
=
msg
.
neo
MsgDecode
(
pkt
.
Payload
())
if
err
!=
nil
{
return
nil
,
&
ConnError
{
Conn
:
c
,
Op
:
"decode"
,
Err
:
err
}
}
...
...
@@ -798,15 +798,15 @@ func (c *Conn) Recv() (Msg, error) {
func
(
c
*
Conn
)
Send
(
msg
Msg
)
error
{
traceConnSendPre
(
c
,
msg
)
l
:=
msg
.
NEO
MsgEncodedLen
()
l
:=
msg
.
neo
MsgEncodedLen
()
buf
:=
PktBuf
{
make
([]
byte
,
PktHeadLen
+
l
)}
// TODO -> freelist
h
:=
buf
.
Header
()
// h.ConnId will be set by conn.Send
h
.
MsgCode
=
hton16
(
msg
.
NEO
MsgCode
())
h
.
MsgCode
=
hton16
(
msg
.
neo
MsgCode
())
h
.
MsgLen
=
hton32
(
uint32
(
l
))
// XXX casting: think again
msg
.
NEO
MsgEncode
(
buf
.
Payload
())
msg
.
neo
MsgEncode
(
buf
.
Payload
())
// XXX why pointer?
// XXX more context in err? (msg type)
...
...
@@ -832,8 +832,8 @@ func (c *Conn) Expect(msgv ...Msg) (which int, err error) {
msgCode
:=
ntoh16
(
pkth
.
MsgCode
)
for
i
,
msg
:=
range
msgv
{
if
msg
.
NEO
MsgCode
()
==
msgCode
{
_
,
err
=
msg
.
NEO
MsgDecode
(
pkt
.
Payload
())
if
msg
.
neo
MsgCode
()
==
msgCode
{
_
,
err
=
msg
.
neo
MsgDecode
(
pkt
.
Payload
())
if
err
!=
nil
{
return
-
1
,
&
ConnError
{
Conn
:
c
,
Op
:
"decode"
,
Err
:
err
}
}
...
...
go/neo/proto.go
View file @
69d5916b
...
...
@@ -138,24 +138,24 @@ type NodeUUID int32
// TODO NodeType -> base NodeUUID
// ErrDecodeOverflow is the error returned by
NEO
MsgDecode when decoding hit buffer overflow
// ErrDecodeOverflow is the error returned by
neo
MsgDecode when decoding hit buffer overflow
var
ErrDecodeOverflow
=
errors
.
New
(
"decode: bufer overflow"
)
// Msg is the interface implemented by NEO messages to marshal/unmarshal them into/from wire format
type
Msg
interface
{
//
NEO
MsgCode returns message code needed to be used for particular message type
//
neo
MsgCode returns message code needed to be used for particular message type
// on the wire
NEO
MsgCode
()
uint16
neo
MsgCode
()
uint16
//
NEO
MsgEncodedLen returns how much space is needed to encode current message payload
NEO
MsgEncodedLen
()
int
//
neo
MsgEncodedLen returns how much space is needed to encode current message payload
neo
MsgEncodedLen
()
int
//
NEO
MsgEncode encodes current message state into buf.
// len(buf) must be >=
NEO
MsgEncodedLen()
NEO
MsgEncode
(
buf
[]
byte
)
//
neo
MsgEncode encodes current message state into buf.
// len(buf) must be >=
neo
MsgEncodedLen()
neo
MsgEncode
(
buf
[]
byte
)
//
NEO
MsgDecode decodes data into message in-place.
NEO
MsgDecode
(
data
[]
byte
)
(
nread
int
,
err
error
)
//
neo
MsgDecode decodes data into message in-place.
neo
MsgDecode
(
data
[]
byte
)
(
nread
int
,
err
error
)
}
...
...
@@ -165,7 +165,7 @@ type Address struct {
}
// NOTE if Host == "" -> Port not added to wire (see py.PAddress):
// func (a *Address)
NEO
MsgEncode(b []byte) int {
// func (a *Address)
neo
MsgEncode(b []byte) int {
// n := string_NEOEncode(a.Host, b[0:])
// if a.Host != "" {
// BigEndian.PutUint16(b[n:], a.Port)
...
...
go/neo/proto_test.go
View file @
69d5916b
...
...
@@ -82,8 +82,8 @@ func testMsgMarshal(t *testing.T, msg Msg, encoded string) {
}()
// msg.encode() == expected
msgCode
:=
msg
.
NEO
MsgCode
()
n
:=
msg
.
NEO
MsgEncodedLen
()
msgCode
:=
msg
.
neo
MsgCode
()
n
:=
msg
.
neo
MsgEncodedLen
()
msgType
:=
msgTypeRegistry
[
msgCode
]
if
msgType
!=
typ
{
t
.
Errorf
(
"%v: msgCode = %v which corresponds to %v"
,
typ
,
msgCode
,
msgType
)
...
...
@@ -93,7 +93,7 @@ func testMsgMarshal(t *testing.T, msg Msg, encoded string) {
}
buf
:=
make
([]
byte
,
n
)
msg
.
NEO
MsgEncode
(
buf
)
msg
.
neo
MsgEncode
(
buf
)
if
string
(
buf
)
!=
encoded
{
t
.
Errorf
(
"%v: encode result unexpected:"
,
typ
)
t
.
Errorf
(
"
\t
have: %s"
,
hexpkg
.
EncodeToString
(
buf
))
...
...
@@ -123,13 +123,13 @@ func testMsgMarshal(t *testing.T, msg Msg, encoded string) {
}
}()
msg
.
NEO
MsgEncode
(
buf
[
:
l
])
msg
.
neo
MsgEncode
(
buf
[
:
l
])
}()
}
// msg.decode() == expected
data
:=
[]
byte
(
encoded
+
"noise"
)
n
,
err
:=
msg2
.
NEO
MsgDecode
(
data
)
n
,
err
:=
msg2
.
neo
MsgDecode
(
data
)
if
err
!=
nil
{
t
.
Errorf
(
"%v: decode error %v"
,
typ
,
err
)
}
...
...
@@ -143,7 +143,7 @@ func testMsgMarshal(t *testing.T, msg Msg, encoded string) {
// decode must detect buffer overflow
for
l
:=
len
(
encoded
)
-
1
;
l
>=
0
;
l
--
{
n
,
err
=
msg2
.
NEO
MsgDecode
(
data
[
:
l
])
n
,
err
=
msg2
.
neo
MsgDecode
(
data
[
:
l
])
if
!
(
n
==
0
&&
err
==
ErrDecodeOverflow
)
{
t
.
Errorf
(
"%v: decode overflow not detected on [:%v]"
,
typ
,
l
)
}
...
...
@@ -271,11 +271,11 @@ func TestMsgMarshalAllOverflowLightly(t *testing.T) {
for
_
,
typ
:=
range
msgTypeRegistry
{
// zero-value for a type
msg
:=
reflect
.
New
(
typ
)
.
Interface
()
.
(
Msg
)
l
:=
msg
.
NEO
MsgEncodedLen
()
l
:=
msg
.
neo
MsgEncodedLen
()
zerol
:=
make
([]
byte
,
l
)
// decoding will turn nil slice & map into empty allocated ones.
// we need it so that reflect.DeepEqual works for msg encode/decode comparison
n
,
err
:=
msg
.
NEO
MsgDecode
(
zerol
)
n
,
err
:=
msg
.
neo
MsgDecode
(
zerol
)
if
!
(
n
==
l
&&
err
==
nil
)
{
t
.
Errorf
(
"%v: zero-decode unexpected: %v, %v ; want %v, nil"
,
typ
,
n
,
err
,
l
)
}
...
...
go/neo/protogen.go
View file @
69d5916b
...
...
@@ -25,10 +25,10 @@ NEO. Protocol module. Code generator
This program generates marshalling code for message types defined in proto.go .
For every type 4 methods are generated in accordance with neo.Msg interface:
NEO
MsgCode() uint16
NEO
MsgEncodedLen() int
NEO
MsgEncode(buf []byte)
NEO
MsgDecode(data []byte) (nread int, err error)
neo
MsgCode() uint16
neo
MsgEncodedLen() int
neo
MsgEncode(buf []byte)
neo
MsgDecode(data []byte) (nread int, err error)
List of message types is obtained via searching through proto.go AST - looking
for appropriate struct declarations there.
...
...
@@ -218,7 +218,7 @@ import (
case
*
ast
.
StructType
:
fmt
.
Fprintf
(
&
buf
,
"// %d. %s
\n\n
"
,
msgCode
,
typename
)
buf
.
emit
(
"func (*%s)
NEO
MsgCode() uint16 {"
,
typename
)
buf
.
emit
(
"func (*%s)
neo
MsgCode() uint16 {"
,
typename
)
buf
.
emit
(
"return %d"
,
msgCode
)
buf
.
emit
(
"}
\n
"
)
...
...
@@ -491,7 +491,7 @@ type sizer struct {
//
// when type is recursively walked, for every case code to update `data[n:]` is generated.
// no overflow checks are generated as by neo.Msg interface provided data
// buffer should have at least payloadLen length returned by
NEO
MsgEncodedInfo()
// buffer should have at least payloadLen length returned by
neo
MsgEncodedInfo()
// (the size computed by sizer).
//
// the code emitted looks like:
...
...
@@ -500,7 +500,7 @@ type sizer struct {
// encode<typ2>(data[n2:], path2)
// ...
//
// TODO encode have to care in
NEO
MsgEncode to emit preambule such that bound
// TODO encode have to care in
neo
MsgEncode to emit preambule such that bound
// checking is performed only once (currenty compiler emits many of them)
type
encoder
struct
{
commonCodeGen
...
...
@@ -548,7 +548,7 @@ var _ CodeGenerator = (*decoder)(nil)
func
(
s
*
sizer
)
generatedCode
()
string
{
code
:=
Buffer
{}
// prologue
code
.
emit
(
"func (%s *%s)
NEO
MsgEncodedLen() int {"
,
s
.
recvName
,
s
.
typeName
)
code
.
emit
(
"func (%s *%s)
neo
MsgEncodedLen() int {"
,
s
.
recvName
,
s
.
typeName
)
if
s
.
varUsed
[
"size"
]
{
code
.
emit
(
"var %s int"
,
s
.
var_
(
"size"
))
}
...
...
@@ -569,7 +569,7 @@ func (s *sizer) generatedCode() string {
func
(
e
*
encoder
)
generatedCode
()
string
{
code
:=
Buffer
{}
// prologue
code
.
emit
(
"func (%s *%s)
NEO
MsgEncode(data []byte) {"
,
e
.
recvName
,
e
.
typeName
)
code
.
emit
(
"func (%s *%s)
neo
MsgEncode(data []byte) {"
,
e
.
recvName
,
e
.
typeName
)
code
.
Write
(
e
.
buf
.
Bytes
())
...
...
@@ -676,7 +676,7 @@ func (d *decoder) generatedCode() string {
code
:=
Buffer
{}
// prologue
code
.
emit
(
"func (%s *%s)
NEO
MsgDecode(data []byte) (int, error) {"
,
d
.
recvName
,
d
.
typeName
)
code
.
emit
(
"func (%s *%s)
neo
MsgDecode(data []byte) (int, error) {"
,
d
.
recvName
,
d
.
typeName
)
if
d
.
varUsed
[
"nread"
]
{
code
.
emit
(
"var %v uint32"
,
d
.
var_
(
"nread"
))
}
...
...
go/neo/zproto-marshal.go
View file @
69d5916b
This diff is collapsed.
Click to expand it.
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