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
Show 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 (
...
@@ -26,7 +26,6 @@ import (
"lab.nexedi.com/kirr/neo/go/zodb"
"lab.nexedi.com/kirr/neo/go/zodb"
)
)
// XXX name -> zodbErrEncode, zodbErrDecode ?
// XXX name -> zodbErrEncode, zodbErrDecode ?
// XXX should be not in proto/ ?
// XXX should be not in proto/ ?
...
...
go/neo/proto/proto-misc.go
View file @
46b8b4f7
...
@@ -79,8 +79,7 @@ func (nodeUUID NodeUUID) String() string {
...
@@ -79,8 +79,7 @@ func (nodeUUID NodeUUID) String() string {
//temp := typ&(1 << 7) != 0
//temp := typ&(1 << 7) != 0
//typ &= 1<<7 - 1
//typ &= 1<<7 - 1
//nodeType := typ >> 4
//nodeType := typ >> 4
typ
:=
uint8
(
-
int8
(
nodeUUID
>>
24
))
>>
4
typ
:=
uint8
(
-
int8
(
nodeUUID
>>
24
))
>>
4
if
typ
<
4
{
if
typ
<
4
{
return
fmt
.
Sprintf
(
"%c%d"
,
nodeTypeChar
[
typ
],
num
)
return
fmt
.
Sprintf
(
"%c%d"
,
nodeTypeChar
[
typ
],
num
)
...
@@ -88,7 +87,6 @@ func (nodeUUID NodeUUID) String() string {
...
@@ -88,7 +87,6 @@ func (nodeUUID NodeUUID) String() string {
return
fmt
.
Sprintf
(
"?(%d)%d"
,
typ
,
num
)
return
fmt
.
Sprintf
(
"?(%d)%d"
,
typ
,
num
)
/*
/*
// 's1', 'm2', for temporary nids
// 's1', 'm2', for temporary nids
if temp {
if temp {
...
@@ -101,7 +99,7 @@ func (nodeUUID NodeUUID) String() string {
...
@@ -101,7 +99,7 @@ func (nodeUUID NodeUUID) String() string {
// XXX goes out of sync wrt NodeType constants
// XXX goes out of sync wrt NodeType constants
var
nodeTypeNum
=
[
...
]
int8
{
var
nodeTypeNum
=
[
...
]
int8
{
STORAGE
:
0x00
,
STORAGE
:
0x00
,
MASTER
:
-
0x10
,
MASTER
:
-
0x10
,
CLIENT
:
-
0x20
,
CLIENT
:
-
0x20
,
...
@@ -124,12 +122,12 @@ func UUID(typ NodeType, num int32) NodeUUID {
...
@@ -124,12 +122,12 @@ func UUID(typ NodeType, num int32) NodeUUID {
typn
:=
nodeTypeNum
[
typ
]
typn
:=
nodeTypeNum
[
typ
]
if
(
num
<
0
)
||
num
>>
24
!=
0
{
if
(
num
<
0
)
||
num
>>
24
!=
0
{
panic
(
"node number out of range"
)
panic
(
"node number out of range"
)
}
}
//uuid := temp << (7 + 3*8) | uint32(typ) << (4 + 3*8) | uint32(num)
//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
)
return
NodeUUID
(
uuid
)
}
}
...
...
go/neo/proto/proto_test.go
View file @
46b8b4f7
...
@@ -21,8 +21,8 @@ package proto
...
@@ -21,8 +21,8 @@ package proto
// NEO. protocol encoding tests
// NEO. protocol encoding tests
import
(
import
(
hexpkg
"encoding/hex"
"encoding/binary"
"encoding/binary"
hexpkg
"encoding/hex"
"fmt"
"fmt"
"reflect"
"reflect"
"runtime"
"runtime"
...
@@ -104,7 +104,7 @@ func testMsgMarshal(t *testing.T, msg Msg, encoded string) {
...
@@ -104,7 +104,7 @@ func testMsgMarshal(t *testing.T, msg Msg, encoded string) {
}
}
// encode must panic if passed a smaller buffer
// 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
()
{
func
()
{
defer
func
()
{
defer
func
()
{
subj
:=
fmt
.
Sprintf
(
"%v: encode(buf[:encodedLen-%v])"
,
typ
,
len
(
encoded
)
-
l
)
subj
:=
fmt
.
Sprintf
(
"%v: encode(buf[:encodedLen-%v])"
,
typ
,
len
(
encoded
)
-
l
)
...
@@ -120,7 +120,7 @@ func testMsgMarshal(t *testing.T, msg Msg, encoded string) {
...
@@ -120,7 +120,7 @@ func testMsgMarshal(t *testing.T, msg Msg, encoded string) {
}
}
estr
:=
err
.
Error
()
estr
:=
err
.
Error
()
if
!
(
strings
.
Contains
(
estr
,
"slice bounds out of range"
)
||
if
!
(
strings
.
Contains
(
estr
,
"slice bounds out of range"
)
||
strings
.
Contains
(
estr
,
"index out of range"
))
{
strings
.
Contains
(
estr
,
"index out of range"
))
{
t
.
Errorf
(
"%s unexpected runtime panic: %v"
,
subj
,
estr
)
t
.
Errorf
(
"%s unexpected runtime panic: %v"
,
subj
,
estr
)
}
}
...
@@ -145,9 +145,9 @@ func testMsgMarshal(t *testing.T, msg Msg, encoded string) {
...
@@ -145,9 +145,9 @@ func testMsgMarshal(t *testing.T, msg Msg, encoded string) {
}
}
// decode must detect buffer overflow
// 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
])
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
)
t
.
Errorf
(
"%v: decode overflow not detected on [:%v]"
,
typ
,
l
)
}
}
...
@@ -159,7 +159,7 @@ func TestMsgMarshal(t *testing.T) {
...
@@ -159,7 +159,7 @@ func TestMsgMarshal(t *testing.T) {
var
testv
=
[]
struct
{
var
testv
=
[]
struct
{
msg
Msg
msg
Msg
encoded
string
// []byte
encoded
string
// []byte
}
{
}{
// empty
// empty
{
&
Ping
{},
""
},
{
&
Ping
{},
""
},
...
@@ -201,11 +201,11 @@ func TestMsgMarshal(t *testing.T) {
...
@@ -201,11 +201,11 @@ func TestMsgMarshal(t *testing.T) {
// map[Oid]struct {Tid,Tid,bool}
// map[Oid]struct {Tid,Tid,bool}
{
&
AnswerObjectUndoSerial
{
{
&
AnswerObjectUndoSerial
{
ObjectTIDDict
:
map
[
zodb
.
Oid
]
struct
{
ObjectTIDDict
:
map
[
zodb
.
Oid
]
struct
{
CurrentSerial
zodb
.
Tid
CurrentSerial
zodb
.
Tid
UndoSerial
zodb
.
Tid
UndoSerial
zodb
.
Tid
IsCurrent
bool
IsCurrent
bool
}
{
}
{
1
:
{
1
,
0
,
false
},
1
:
{
1
,
0
,
false
},
2
:
{
7
,
1
,
true
},
2
:
{
7
,
1
,
true
},
8
:
{
7
,
1
,
false
},
8
:
{
7
,
1
,
false
},
...
@@ -240,7 +240,7 @@ func TestMsgMarshal(t *testing.T) {
...
@@ -240,7 +240,7 @@ func TestMsgMarshal(t *testing.T) {
},
},
// uint32, []uint32
// uint32, []uint32
{
&
PartitionCorrupted
{
7
,
[]
NodeUUID
{
1
,
3
,
9
,
4
}},
{
&
PartitionCorrupted
{
7
,
[]
NodeUUID
{
1
,
3
,
9
,
4
}},
u32
(
7
)
+
u32
(
4
)
+
u32
(
1
)
+
u32
(
3
)
+
u32
(
9
)
+
u32
(
4
),
u32
(
7
)
+
u32
(
4
)
+
u32
(
1
)
+
u32
(
3
)
+
u32
(
9
)
+
u32
(
4
),
},
},
...
@@ -299,7 +299,7 @@ func TestMsgDecodeLenOverflow(t *testing.T) {
...
@@ -299,7 +299,7 @@ func TestMsgDecodeLenOverflow(t *testing.T) {
var
testv
=
[]
struct
{
var
testv
=
[]
struct
{
msg
Msg
// of type to decode into
msg
Msg
// of type to decode into
data
string
// []byte - tricky data to exercise decoder u32 len checks overflow
data
string
// []byte - tricky data to exercise decoder u32 len checks overflow
}
{
}{
// [] with sizeof(item) = 8 -> len*sizeof(item) = 0 if u32
// [] with sizeof(item) = 8 -> len*sizeof(item) = 0 if u32
{
&
AnswerTIDs
{},
u32
(
0x20000000
)},
{
&
AnswerTIDs
{},
u32
(
0x20000000
)},
...
...
go/neo/proto/protogen.go
View file @
46b8b4f7
...
@@ -89,7 +89,7 @@ var typeInfo = &types.Info{
...
@@ -89,7 +89,7 @@ var typeInfo = &types.Info{
}
}
// complete position of something with .Pos()
// 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
())
return
fset
.
Position
(
x
.
Pos
())
}
}
...
@@ -954,11 +954,11 @@ func (d *decoder) genSlice1(assignto string, typ types.Type) {
...
@@ -954,11 +954,11 @@ func (d *decoder) genSlice1(assignto string, typ types.Type) {
// emit code to size/encode/decode mem.Buf
// emit code to size/encode/decode mem.Buf
// same as slice1 but buffer is allocated via mem.BufAlloc
// same as slice1 but buffer is allocated via mem.BufAlloc
func
(
s
*
sizer
)
genBuf
(
path
string
)
{
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
)
{
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
)
{
func
(
d
*
decoder
)
genBuf
(
path
string
)
{
...
...
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