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
46b8b4f7
Commit
46b8b4f7
authored
Jul 04, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
607e8e46
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
75 deletions
+72
-75
go/neo/proto/error.go
go/neo/proto/error.go
+1
-2
go/neo/proto/proto-misc.go
go/neo/proto/proto-misc.go
+8
-10
go/neo/proto/proto_test.go
go/neo/proto/proto_test.go
+56
-56
go/neo/proto/protogen.go
go/neo/proto/protogen.go
+7
-7
No files found.
go/neo/proto/error.go
View file @
46b8b4f7
...
...
@@ -26,7 +26,6 @@ import (
"lab.nexedi.com/kirr/neo/go/zodb"
)
// XXX name -> zodbErrEncode, zodbErrDecode ?
// XXX should be not in proto/ ?
...
...
@@ -71,7 +70,7 @@ func ErrDecode(e *Error) error {
return
&
zodb
.
NoDataError
{
Oid
:
oid
,
DeletedAt
:
del
}
case
OID_DOES_NOT_EXIST
:
oid
,
err
:=
zodb
.
ParseOid
(
e
.
Message
)
// XXX abusing message for oid
oid
,
err
:=
zodb
.
ParseOid
(
e
.
Message
)
// XXX abusing message for oid
if
err
==
nil
{
return
&
zodb
.
NoObjectError
{
oid
}
}
...
...
go/neo/proto/proto-misc.go
View file @
46b8b4f7
...
...
@@ -79,8 +79,7 @@ func (nodeUUID NodeUUID) String() string {
//temp := typ&(1 << 7) != 0
//typ &= 1<<7 - 1
//nodeType := typ >> 4
typ
:=
uint8
(
-
int8
(
nodeUUID
>>
24
))
>>
4
typ
:=
uint8
(
-
int8
(
nodeUUID
>>
24
))
>>
4
if
typ
<
4
{
return
fmt
.
Sprintf
(
"%c%d"
,
nodeTypeChar
[
typ
],
num
)
...
...
@@ -88,7 +87,6 @@ func (nodeUUID NodeUUID) String() string {
return
fmt
.
Sprintf
(
"?(%d)%d"
,
typ
,
num
)
/*
// 's1', 'm2', for temporary nids
if temp {
...
...
@@ -101,11 +99,11 @@ func (nodeUUID NodeUUID) String() string {
// XXX goes out of sync wrt NodeType constants
var
nodeTypeNum
=
[
...
]
int8
{
STORAGE
:
0x00
,
MASTER
:
-
0x10
,
CLIENT
:
-
0x20
,
ADMIN
:
-
0x30
,
var
nodeTypeNum
=
[
...
]
int8
{
STORAGE
:
0x00
,
MASTER
:
-
0x10
,
CLIENT
:
-
0x20
,
ADMIN
:
-
0x30
,
}
// UUID creates node uuid from node type and number.
func
UUID
(
typ
NodeType
,
num
int32
)
NodeUUID
{
...
...
@@ -124,12 +122,12 @@ func UUID(typ NodeType, num int32) NodeUUID {
typn
:=
nodeTypeNum
[
typ
]
if
(
num
<
0
)
||
num
>>
24
!=
0
{
if
(
num
<
0
)
||
num
>>
24
!=
0
{
panic
(
"node number out of range"
)
}
//uuid := temp << (7 + 3*8) | uint32(typ) << (4 + 3*8) | uint32(num)
uuid
:=
uint32
(
uint8
(
typn
))
<<
(
3
*
8
)
|
uint32
(
num
)
uuid
:=
uint32
(
uint8
(
typn
))
<<
(
3
*
8
)
|
uint32
(
num
)
return
NodeUUID
(
uuid
)
}
...
...
go/neo/proto/proto_test.go
View file @
46b8b4f7
...
...
@@ -21,8 +21,8 @@ package proto
// NEO. protocol encoding tests
import
(
hexpkg
"encoding/hex"
"encoding/binary"
hexpkg
"encoding/hex"
"fmt"
"reflect"
"runtime"
...
...
@@ -75,12 +75,12 @@ func TestPktHeader(t *testing.T) {
// test marshalling for one message type
func
testMsgMarshal
(
t
*
testing
.
T
,
msg
Msg
,
encoded
string
)
{
typ
:=
reflect
.
TypeOf
(
msg
)
.
Elem
()
// type of *msg
typ
:=
reflect
.
TypeOf
(
msg
)
.
Elem
()
// type of *msg
msg2
:=
reflect
.
New
(
typ
)
.
Interface
()
.
(
Msg
)
defer
func
()
{
if
e
:=
recover
();
e
!=
nil
{
t
.
Errorf
(
"%v: panic ↓↓↓:"
,
typ
)
panic
(
e
)
// to show traceback
panic
(
e
)
// to show traceback
}
}()
...
...
@@ -104,7 +104,7 @@ func testMsgMarshal(t *testing.T, msg Msg, encoded string) {
}
// encode must panic if passed a smaller buffer
for
l
:=
len
(
buf
)
-
1
;
l
>=
0
;
l
--
{
for
l
:=
len
(
buf
)
-
1
;
l
>=
0
;
l
--
{
func
()
{
defer
func
()
{
subj
:=
fmt
.
Sprintf
(
"%v: encode(buf[:encodedLen-%v])"
,
typ
,
len
(
encoded
)
-
l
)
...
...
@@ -120,9 +120,9 @@ func testMsgMarshal(t *testing.T, msg Msg, encoded string) {
}
estr
:=
err
.
Error
()
if
!
(
strings
.
Contains
(
estr
,
"slice bounds out of range"
)
||
strings
.
Contains
(
estr
,
"index out of range"
))
{
t
.
Errorf
(
"%s unexpected runtime panic: %v"
,
subj
,
estr
)
if
!
(
strings
.
Contains
(
estr
,
"slice bounds out of range"
)
||
strings
.
Contains
(
estr
,
"index out of range"
))
{
t
.
Errorf
(
"%s unexpected runtime panic: %v"
,
subj
,
estr
)
}
}()
...
...
@@ -145,9 +145,9 @@ func testMsgMarshal(t *testing.T, msg Msg, encoded string) {
}
// decode must detect buffer overflow
for
l
:=
len
(
encoded
)
-
1
;
l
>=
0
;
l
--
{
for
l
:=
len
(
encoded
)
-
1
;
l
>=
0
;
l
--
{
n
,
err
=
msg2
.
NEOMsgDecode
(
data
[
:
l
])
if
!
(
n
==
0
&&
err
==
ErrDecodeOverflow
)
{
if
!
(
n
==
0
&&
err
==
ErrDecodeOverflow
)
{
t
.
Errorf
(
"%v: decode overflow not detected on [:%v]"
,
typ
,
l
)
}
...
...
@@ -158,8 +158,8 @@ func testMsgMarshal(t *testing.T, msg Msg, encoded string) {
func
TestMsgMarshal
(
t
*
testing
.
T
)
{
var
testv
=
[]
struct
{
msg
Msg
encoded
string
// []byte
}
{
encoded
string
// []byte
}{
// empty
{
&
Ping
{},
""
},
...
...
@@ -168,55 +168,55 @@ func TestMsgMarshal(t *testing.T) {
// Oid, Tid, bool, Checksum, []byte
{
&
StoreObject
{
Oid
:
0x0102030405060708
,
Serial
:
0x0a0b0c0d0e0f0102
,
Oid
:
0x0102030405060708
,
Serial
:
0x0a0b0c0d0e0f0102
,
Compression
:
false
,
Checksum
:
Checksum
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
,
16
,
17
,
18
,
19
,
20
},
// XXX simpler?
Data
:
[]
byte
(
"hello world"
),
DataSerial
:
0x0a0b0c0d0e0f0103
,
Tid
:
0x0a0b0c0d0e0f0104
,
Checksum
:
Checksum
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
,
16
,
17
,
18
,
19
,
20
},
// XXX simpler?
Data
:
[]
byte
(
"hello world"
),
DataSerial
:
0x0a0b0c0d0e0f0103
,
Tid
:
0x0a0b0c0d0e0f0104
,
},
hex
(
"01020304050607080a0b0c0d0e0f010200"
)
+
hex
(
"0102030405060708090a0b0c0d0e0f1011121314"
)
+
hex
(
"0000000b"
)
+
"hello world"
+
hex
(
"0a0b0c0d0e0f01030a0b0c0d0e0f0104"
)},
hex
(
"01020304050607080a0b0c0d0e0f010200"
)
+
hex
(
"0102030405060708090a0b0c0d0e0f1011121314"
)
+
hex
(
"0000000b"
)
+
"hello world"
+
hex
(
"0a0b0c0d0e0f01030a0b0c0d0e0f0104"
)},
// PTid, [] (of [] of {UUID, CellState})
{
&
AnswerPartitionTable
{
PTid
:
0x0102030405060708
,
PTid
:
0x0102030405060708
,
RowList
:
[]
RowInfo
{
{
1
,
[]
CellInfo
{{
11
,
UP_TO_DATE
},
{
17
,
OUT_OF_DATE
}}},
{
2
,
[]
CellInfo
{{
11
,
FEEDING
}}},
{
7
,
[]
CellInfo
{{
11
,
CORRUPTED
},
{
15
,
DISCARDED
},
{
23
,
UP_TO_DATE
}}},
},
},
},
hex
(
"0102030405060708"
)
+
hex
(
"00000003"
)
+
hex
(
"00000001000000020000000b000000000000001100000001"
)
+
hex
(
"00000002000000010000000b00000002"
)
+
hex
(
"00000007000000030000000b000000040000000f000000030000001700000000"
),
hex
(
"0102030405060708"
)
+
hex
(
"00000003"
)
+
hex
(
"00000001000000020000000b000000000000001100000001"
)
+
hex
(
"00000002000000010000000b00000002"
)
+
hex
(
"00000007000000030000000b000000040000000f000000030000001700000000"
),
},
// map[Oid]struct {Tid,Tid,bool}
{
&
AnswerObjectUndoSerial
{
ObjectTIDDict
:
map
[
zodb
.
Oid
]
struct
{
CurrentSerial
zodb
.
Tid
UndoSerial
zodb
.
Tid
IsCurrent
bool
}
{
ObjectTIDDict
:
map
[
zodb
.
Oid
]
struct
{
CurrentSerial
zodb
.
Tid
UndoSerial
zodb
.
Tid
IsCurrent
bool
}
{
1
:
{
1
,
0
,
false
},
2
:
{
7
,
1
,
true
},
8
:
{
7
,
1
,
false
},
5
:
{
4
,
3
,
true
},
}},
u32
(
4
)
+
u64
(
1
)
+
u64
(
1
)
+
u64
(
0
)
+
hex
(
"00"
)
+
u64
(
2
)
+
u64
(
7
)
+
u64
(
1
)
+
hex
(
"01"
)
+
u64
(
5
)
+
u64
(
4
)
+
u64
(
3
)
+
hex
(
"01"
)
+
u64
(
8
)
+
u64
(
7
)
+
u64
(
1
)
+
hex
(
"00"
),
u32
(
4
)
+
u64
(
1
)
+
u64
(
1
)
+
u64
(
0
)
+
hex
(
"00"
)
+
u64
(
2
)
+
u64
(
7
)
+
u64
(
1
)
+
hex
(
"01"
)
+
u64
(
5
)
+
u64
(
4
)
+
u64
(
3
)
+
hex
(
"01"
)
+
u64
(
8
)
+
u64
(
7
)
+
u64
(
1
)
+
hex
(
"00"
),
},
// map[uint32]UUID + trailing ...
...
...
@@ -231,35 +231,35 @@ func TestMsgMarshal(t *testing.T) {
MaxTID
:
128
,
},
u32
(
4
)
+
u32
(
1
)
+
u32
(
7
)
+
u32
(
2
)
+
u32
(
9
)
+
u32
(
4
)
+
u32
(
17
)
+
u32
(
7
)
+
u32
(
3
)
+
u64
(
23
)
+
u64
(
128
),
u32
(
4
)
+
u32
(
1
)
+
u32
(
7
)
+
u32
(
2
)
+
u32
(
9
)
+
u32
(
4
)
+
u32
(
17
)
+
u32
(
7
)
+
u32
(
3
)
+
u64
(
23
)
+
u64
(
128
),
},
// uint32, []uint32
{
&
PartitionCorrupted
{
7
,
[]
NodeUUID
{
1
,
3
,
9
,
4
}},
u32
(
7
)
+
u32
(
4
)
+
u32
(
1
)
+
u32
(
3
)
+
u32
(
9
)
+
u32
(
4
),
{
&
PartitionCorrupted
{
7
,
[]
NodeUUID
{
1
,
3
,
9
,
4
}},
u32
(
7
)
+
u32
(
4
)
+
u32
(
1
)
+
u32
(
3
)
+
u32
(
9
)
+
u32
(
4
),
},
// uint32, Address, string, IdTime
{
&
RequestIdentification
{
CLIENT
,
17
,
Address
{
"localhost"
,
7777
},
"myname"
,
0.12345678
},
u32
(
2
)
+
u32
(
17
)
+
u32
(
9
)
+
"localhost"
+
u16
(
7777
)
+
u32
(
6
)
+
"myname"
+
hex
(
"3fbf9add1091c895"
),
u32
(
2
)
+
u32
(
17
)
+
u32
(
9
)
+
"localhost"
+
u16
(
7777
)
+
u32
(
6
)
+
"myname"
+
hex
(
"3fbf9add1091c895"
),
},
// IdTime, empty Address, int32
{
&
NotifyNodeInformation
{
1504466245.926185
,
[]
NodeInfo
{
{
CLIENT
,
Address
{},
UUID
(
CLIENT
,
1
),
RUNNING
,
1504466245.925599
}}},
hex
(
"41d66b15517b469d"
)
+
u32
(
1
)
+
u32
(
2
)
+
u32
(
0
)
/* <- ø Address */
+
hex
(
"e0000001"
)
+
u32
(
2
)
+
hex
(
"41d66b15517b3d04"
),
hex
(
"41d66b15517b469d"
)
+
u32
(
1
)
+
u32
(
2
)
+
u32
(
0
)
/* <- ø Address */
+
hex
(
"e0000001"
)
+
u32
(
2
)
+
hex
(
"41d66b15517b3d04"
),
},
// empty IdTime
...
...
@@ -297,9 +297,9 @@ func TestMsgMarshalAllOverflowLightly(t *testing.T) {
// Verify overflow handling on decode len checks
func
TestMsgDecodeLenOverflow
(
t
*
testing
.
T
)
{
var
testv
=
[]
struct
{
msg
Msg
// of type to decode into
data
string
// []byte - tricky data to exercise decoder u32 len checks overflow
}
{
msg
Msg
// of type to decode into
data
string
// []byte - tricky data to exercise decoder u32 len checks overflow
}{
// [] with sizeof(item) = 8 -> len*sizeof(item) = 0 if u32
{
&
AnswerTIDs
{},
u32
(
0x20000000
)},
...
...
go/neo/proto/protogen.go
View file @
46b8b4f7
...
...
@@ -89,7 +89,7 @@ var typeInfo = &types.Info{
}
// complete position of something with .Pos()
func
pos
(
x
interface
{
Pos
()
token
.
Pos
})
token
.
Position
{
func
pos
(
x
interface
{
Pos
()
token
.
Pos
})
token
.
Position
{
return
fset
.
Position
(
x
.
Pos
())
}
...
...
@@ -234,8 +234,8 @@ func (v BySerial) Less(i, j int) bool {
return
(
v
[
i
]
.
msgSerial
<
v
[
j
]
.
msgSerial
)
||
(
v
[
i
]
.
msgSerial
==
v
[
j
]
.
msgSerial
&&
!
v
[
i
]
.
answer
&&
v
[
j
]
.
answer
)
}
func
(
v
BySerial
)
Swap
(
i
,
j
int
)
{
v
[
i
],
v
[
j
]
=
v
[
j
],
v
[
i
]
}
func
(
v
BySerial
)
Len
()
int
{
return
len
(
v
)
}
func
(
v
BySerial
)
Swap
(
i
,
j
int
)
{
v
[
i
],
v
[
j
]
=
v
[
j
],
v
[
i
]
}
func
(
v
BySerial
)
Len
()
int
{
return
len
(
v
)
}
// ----------------------------------------
...
...
@@ -326,7 +326,7 @@ import (
}
// `//neo:proto ...` annotation for this particular type
specAnnotation
:=
declAnnotation
// inheriting from decl
specAnnotation
:=
declAnnotation
// inheriting from decl
specAnnotation
.
parse
(
typespec
.
Doc
)
// type only -> don't generate message interface for it
...
...
@@ -954,11 +954,11 @@ func (d *decoder) genSlice1(assignto string, typ types.Type) {
// emit code to size/encode/decode mem.Buf
// same as slice1 but buffer is allocated via mem.BufAlloc
func
(
s
*
sizer
)
genBuf
(
path
string
)
{
s
.
genSlice1
(
path
+
".XData()"
,
nil
/* typ unused */
)
s
.
genSlice1
(
path
+
".XData()"
,
nil
/* typ unused */
)
}
func
(
e
*
encoder
)
genBuf
(
path
string
)
{
e
.
genSlice1
(
path
+
".XData()"
,
nil
/* typ unused */
)
e
.
genSlice1
(
path
+
".XData()"
,
nil
/* typ unused */
)
}
func
(
d
*
decoder
)
genBuf
(
path
string
)
{
...
...
@@ -1092,7 +1092,7 @@ func (e *encoder) genMap(path string, typ *types.Map, obj types.Object) {
// output keys in sorted order on the wire
// (easier for debugging & deterministic for testing)
e
.
emit
(
"keyv := make([]%s, 0, l)"
,
typeName
(
typ
.
Key
()))
// FIXME do not throw old slice away -> do xslice.Realloc()
e
.
emit
(
"keyv := make([]%s, 0, l)"
,
typeName
(
typ
.
Key
()))
// FIXME do not throw old slice away -> do xslice.Realloc()
e
.
emit
(
"for key := range %s {"
,
path
)
e
.
emit
(
" keyv = append(keyv, key)"
)
e
.
emit
(
"}"
)
...
...
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