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
baf7f580
Commit
baf7f580
authored
Jan 15, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
70dfb639
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
23 deletions
+19
-23
go/neo/neonet/connection.go
go/neo/neonet/connection.go
+7
-7
go/neo/neonet/pkt.go
go/neo/neonet/pkt.go
+1
-1
go/neo/proto/proto.go
go/neo/proto/proto.go
+11
-15
No files found.
go/neo/neonet/connection.go
View file @
baf7f580
...
...
@@ -1309,7 +1309,7 @@ func (nl *NodeLink) recvPktN() (*pktBuf, error) {
func
(
nl
*
NodeLink
)
recvPktM
()
(
*
pktBuf
,
error
)
{
pkt
:=
pktAlloc
(
4096
)
mraw
:=
msgp
.
Raw
(
pkt
.
data
)
err
:=
mraw
.
DecodeMsg
(
nl
.
rxbufM
)
// XXX limit size of one packet to
e.g. 0x4000000
(= UNPACK_BUFFER_SIZE in NEO/py speak)
err
:=
mraw
.
DecodeMsg
(
nl
.
rxbufM
)
// XXX limit size of one packet to
proto.PktMaxSize
(= UNPACK_BUFFER_SIZE in NEO/py speak)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -1418,7 +1418,7 @@ func pktDecodeHead(e proto.Encoding, pkt *pktBuf) (connID uint32, msgCode uint16
func
pktEncodeN
(
connId
uint32
,
msg
proto
.
Msg
)
*
pktBuf
{
const
enc
=
proto
.
Encoding
(
'N'
)
l
:=
enc
.
NEO
MsgEncodedLen
(
msg
)
l
:=
enc
.
MsgEncodedLen
(
msg
)
buf
:=
pktAlloc
(
proto
.
PktHeaderLenN
+
l
)
h
:=
buf
.
HeaderN
()
...
...
@@ -1426,7 +1426,7 @@ func pktEncodeN(connId uint32, msg proto.Msg) *pktBuf {
h
.
MsgCode
=
packed
.
Hton16
(
proto
.
MsgCode
(
msg
))
h
.
MsgLen
=
packed
.
Hton32
(
uint32
(
l
))
// XXX casting: think again
enc
.
NEO
MsgEncode
(
msg
,
buf
.
PayloadN
())
enc
.
MsgEncode
(
msg
,
buf
.
PayloadN
())
return
buf
}
...
...
@@ -1453,7 +1453,7 @@ func pktEncodeM(connId uint32, msg proto.Msg) *pktBuf {
hroom
:=
msgpack
.
ArrayHeadSize
(
3
)
+
msgpack
.
Uint32Size
(
connId
)
+
msgpack
.
Uint16Size
(
msgCode
)
l
:=
enc
.
NEO
MsgEncodedLen
(
msg
)
l
:=
enc
.
MsgEncodedLen
(
msg
)
buf
:=
pktAlloc
(
hroom
+
l
)
...
...
@@ -1465,7 +1465,7 @@ func pktEncodeM(connId uint32, msg proto.Msg) *pktBuf {
if
i
!=
hroom
{
panic
(
"bug"
)
}
enc
.
NEO
MsgEncode
(
msg
,
b
[
hroom
:
])
enc
.
MsgEncode
(
msg
,
b
[
hroom
:
])
return
buf
}
...
...
@@ -1518,7 +1518,7 @@ func (c *Conn) Recv() (proto.Msg, error) {
// msg := reflect.NewAt(msgType, bufAlloc(msgType.Size())
_
,
err
=
c
.
link
.
enc
.
NEO
MsgDecode
(
msg
,
payload
)
_
,
err
=
c
.
link
.
enc
.
MsgDecode
(
msg
,
payload
)
if
err
!=
nil
{
return
nil
,
c
.
err
(
"decode"
,
err
)
// XXX "decode:" is already in ErrDecodeOverflow
}
...
...
@@ -1575,7 +1575,7 @@ func (c *Conn) Expect(msgv ...proto.Msg) (which int, err error) {
for
i
,
msg
:=
range
msgv
{
if
proto
.
MsgCode
(
msg
)
==
msgCode
{
_
,
err
:=
c
.
link
.
enc
.
NEO
MsgDecode
(
msg
,
payload
)
_
,
err
:=
c
.
link
.
enc
.
MsgDecode
(
msg
,
payload
)
if
err
!=
nil
{
return
-
1
,
c
.
err
(
"decode"
,
err
)
}
...
...
go/neo/neonet/pkt.go
View file @
baf7f580
...
...
@@ -95,7 +95,7 @@ func pktString(e proto.Encoding, pkt *pktBuf) string {
// XXX dup wrt Conn.Recv
msg
:=
reflect
.
New
(
msgType
)
.
Interface
()
.
(
proto
.
Msg
)
n
,
err
:=
e
.
NEO
MsgDecode
(
msg
,
payload
)
n
,
err
:=
e
.
MsgDecode
(
msg
,
payload
)
if
err
!=
nil
{
s
+=
fmt
.
Sprintf
(
" (%s) %v; [%d]: % x"
,
msgType
.
Name
(),
err
,
len
(
payload
),
payload
)
}
else
{
...
...
go/neo/proto/proto.go
View file @
baf7f580
...
...
@@ -28,7 +28,7 @@
//
// Messages are represented by corresponding types that all implement Msg interface.
//
// A message type can be looked up by message code with MsgType.
// A message type can be looked up by message code with MsgType.
XXX unpublish ?
//
// The proto packages provides only message definitions and low-level
// primitives for their marshalling. Package lab.nexedi.com/kirr/neo/go/neo/neonet
...
...
@@ -58,9 +58,6 @@ package proto
//go:generate gotrace gen .
// TODO regroup messages definitions to stay more close to 1 communication topic
// TODO document protocol itself better (who sends who what with which semantic)
// NOTE for some packets it is possible to decode raw packet -> go version from
// PktBuf in place. E.g. for GetObject.
//
...
...
@@ -80,10 +77,10 @@ import (
const
(
// The protocol version must be increased whenever upgrading a node may require
// to upgrade other nodes. It is encoded as a 4-bytes big-endian integer and
// the high order byte 0 is different from TLS Handshake (0x16).
// the high order byte 0 is different from TLS Handshake (0x16).
XXX update for msgpack
Version
=
6
// length of packet header in 'N'-encoding
// length of packet header in 'N'-encoding
XXX unpublish?
PktHeaderLenN
=
10
// = unsafe.Sizeof(PktHeaderN{}), but latter gives typed constant (uintptr)
// packets larger than PktMaxSize are not allowed.
...
...
@@ -99,7 +96,7 @@ const (
INVALID_OID
zodb
.
Oid
=
1
<<
64
-
1
)
// PktHeaderN represents header of a raw packet in 'N'-encoding.
// PktHeaderN represents header of a raw packet in 'N'-encoding.
XXX unexport?
//
// A packet contains connection ID and message.
//
...
...
@@ -142,9 +139,8 @@ type Msg interface {
// Encoding represents messages encoding.
type
Encoding
byte
// XXX drop "NEO" prefix?
// NEOMsgEncodedLen returns how much space is needed to encode msg payload via encoding e.
func
(
e
Encoding
)
NEOMsgEncodedLen
(
msg
Msg
)
int
{
// MsgEncodedLen returns how much space is needed to encode msg payload via encoding e.
func
(
e
Encoding
)
MsgEncodedLen
(
msg
Msg
)
int
{
switch
e
{
default
:
panic
(
"bug"
)
case
'N'
:
return
msg
.
neoMsgEncodedLenN
()
...
...
@@ -152,10 +148,10 @@ func (e Encoding) NEOMsgEncodedLen(msg Msg) int {
}
}
//
NEO
MsgEncode encodes msg state into buf via encoding e.
// MsgEncode encodes msg state into buf via encoding e.
//
// len(buf) must be >= e.
NEO
MsgEncodedLen(m).
func
(
e
Encoding
)
NEO
MsgEncode
(
msg
Msg
,
buf
[]
byte
)
{
// len(buf) must be >= e.MsgEncodedLen(m).
func
(
e
Encoding
)
MsgEncode
(
msg
Msg
,
buf
[]
byte
)
{
switch
e
{
default
:
panic
(
"bug"
)
case
'N'
:
msg
.
neoMsgEncodeN
(
buf
)
...
...
@@ -163,8 +159,8 @@ func (e Encoding) NEOMsgEncode(msg Msg, buf []byte) {
}
}
//
NEO
MsgDecode decodes data via encoding e into msg in-place.
func
(
e
Encoding
)
NEO
MsgDecode
(
msg
Msg
,
data
[]
byte
)
(
nread
int
,
err
error
)
{
// MsgDecode decodes data via encoding e into msg in-place.
func
(
e
Encoding
)
MsgDecode
(
msg
Msg
,
data
[]
byte
)
(
nread
int
,
err
error
)
{
switch
e
{
default
:
panic
(
"bug"
)
case
'N'
:
return
msg
.
neoMsgDecodeN
(
data
)
...
...
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