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
12a2af21
Commit
12a2af21
authored
Sep 05, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
082ba218
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
78 additions
and
44 deletions
+78
-44
go/neo/neo.go
go/neo/neo.go
+1
-1
go/neo/nodetab.go
go/neo/nodetab.go
+1
-5
go/neo/proto-misc.go
go/neo/proto-misc.go
+3
-5
go/neo/proto.go
go/neo/proto.go
+3
-3
go/neo/proto_test.go
go/neo/proto_test.go
+1
-1
go/neo/zproto-marshal.go
go/neo/zproto-marshal.go
+69
-29
No files found.
go/neo/neo.go
View file @
12a2af21
...
@@ -79,7 +79,7 @@ func NewNodeApp(net xnet.Networker, typ NodeType, clusterName, masterAddr, serve
...
@@ -79,7 +79,7 @@ func NewNodeApp(net xnet.Networker, typ NodeType, clusterName, masterAddr, serve
}
}
app
:=
&
NodeApp
{
app
:=
&
NodeApp
{
MyInfo
:
NodeInfo
{
Type
:
typ
,
Addr
:
addr
,
IdTime
:
0
},
MyInfo
:
NodeInfo
{
Type
:
typ
,
Addr
:
addr
,
IdTime
:
IdTimeNone
},
ClusterName
:
clusterName
,
ClusterName
:
clusterName
,
Net
:
net
,
Net
:
net
,
MasterAddr
:
masterAddr
,
MasterAddr
:
masterAddr
,
...
...
go/neo/nodetab.go
View file @
12a2af21
...
@@ -178,11 +178,7 @@ func (nt *NodeTable) String() string {
...
@@ -178,11 +178,7 @@ func (nt *NodeTable) String() string {
// XXX also for .storv
// XXX also for .storv
for
_
,
n
:=
range
nt
.
nodev
{
for
_
,
n
:=
range
nt
.
nodev
{
// XXX recheck output
// XXX recheck output
fmt
.
Fprintf
(
&
buf
,
"%s (%s)
\t
%s
\t
%s"
,
n
.
UUID
,
n
.
Type
,
n
.
State
,
n
.
Addr
)
fmt
.
Fprintf
(
&
buf
,
"%s (%s)
\t
%s
\t
%s
\t
@ %s
\n
"
,
n
.
UUID
,
n
.
Type
,
n
.
State
,
n
.
Addr
,
n
.
IdTime
)
if
n
.
IdTime
.
Valid
()
{
fmt
.
Fprintf
(
&
buf
,
"
\t
@ %v"
,
n
.
IdTime
)
}
fmt
.
Fprintf
(
&
buf
,
"
\n
"
)
}
}
return
buf
.
String
()
return
buf
.
String
()
...
...
go/neo/proto-misc.go
View file @
12a2af21
...
@@ -24,6 +24,7 @@ package neo
...
@@ -24,6 +24,7 @@ package neo
import
(
import
(
"fmt"
"fmt"
"math"
"net"
"net"
"strconv"
"strconv"
"strings"
"strings"
...
@@ -121,13 +122,10 @@ func UUID(typ NodeType, num int32) NodeUUID {
...
@@ -121,13 +122,10 @@ func UUID(typ NodeType, num int32) NodeUUID {
// ----------------------------------------
// ----------------------------------------
// Valid returns whether t was initialized
var
IdTimeNone
=
IdTime
(
math
.
Inf
(
-
1
))
func
(
t
IdTime
)
Valid
()
bool
{
return
t
!=
0
}
func
(
t
IdTime
)
String
()
string
{
func
(
t
IdTime
)
String
()
string
{
if
!
t
.
Valid
(
)
{
if
float64
(
t
)
==
math
.
Inf
(
-
1
)
{
return
"ø"
return
"ø"
}
}
...
...
go/neo/proto.go
View file @
12a2af21
...
@@ -277,10 +277,10 @@ func (t IdTime) neoEncodedLen() int {
...
@@ -277,10 +277,10 @@ func (t IdTime) neoEncodedLen() int {
}
}
func
(
t
IdTime
)
neoEncode
(
b
[]
byte
)
int
{
func
(
t
IdTime
)
neoEncode
(
b
[]
byte
)
int
{
// use
0 as value for no data
(NaN != NaN -> hard to use NaN in tests)
// use
-inf as value for no data
(NaN != NaN -> hard to use NaN in tests)
// NOTE neo/py uses None for "no data"; we use 0 for "no data" to avoid pointer
// NOTE neo/py uses None for "no data"; we use 0 for "no data" to avoid pointer
tt
:=
float64
(
t
)
tt
:=
float64
(
t
)
if
tt
==
0
{
if
tt
==
math
.
Inf
(
-
1
)
{
tt
=
math
.
NaN
()
tt
=
math
.
NaN
()
}
}
float64_neoEncode
(
b
,
tt
)
float64_neoEncode
(
b
,
tt
)
...
@@ -293,7 +293,7 @@ func (t *IdTime) neoDecode(data []byte) (uint32, bool) {
...
@@ -293,7 +293,7 @@ func (t *IdTime) neoDecode(data []byte) (uint32, bool) {
}
}
tt
:=
float64_neoDecode
(
data
)
tt
:=
float64_neoDecode
(
data
)
if
math
.
IsNaN
(
tt
)
{
if
math
.
IsNaN
(
tt
)
{
tt
=
0
tt
=
math
.
Inf
(
-
1
)
}
}
*
t
=
IdTime
(
tt
)
*
t
=
IdTime
(
tt
)
return
8
,
true
return
8
,
true
...
...
go/neo/proto_test.go
View file @
12a2af21
...
@@ -263,7 +263,7 @@ func TestMsgMarshal(t *testing.T) {
...
@@ -263,7 +263,7 @@ func TestMsgMarshal(t *testing.T) {
},
},
// empty IdTime
// empty IdTime
{
&
NotifyNodeInformation
{
0
,
[]
NodeInfo
{}},
hex
(
"ffffffffffffffff"
)
+
hex
(
"00000000"
)},
{
&
NotifyNodeInformation
{
IdTimeNone
,
[]
NodeInfo
{}},
hex
(
"ffffffffffffffff"
)
+
hex
(
"00000000"
)},
// TODO we need tests for:
// TODO we need tests for:
// []varsize + trailing
// []varsize + trailing
...
...
go/neo/zproto-marshal.go
View file @
12a2af21
...
@@ -64,7 +64,7 @@ func (*RequestIdentification) neoMsgCode() uint16 {
...
@@ -64,7 +64,7 @@ func (*RequestIdentification) neoMsgCode() uint16 {
}
}
func
(
p
*
RequestIdentification
)
neoMsgEncodedLen
()
int
{
func
(
p
*
RequestIdentification
)
neoMsgEncodedLen
()
int
{
return
20
+
p
.
Address
.
neoEncodedLen
()
+
len
(
p
.
ClusterName
)
return
12
+
p
.
Address
.
neoEncodedLen
()
+
len
(
p
.
ClusterName
)
+
p
.
IdTime
.
neoEncodedLen
(
)
}
}
func
(
p
*
RequestIdentification
)
neoMsgEncode
(
data
[]
byte
)
{
func
(
p
*
RequestIdentification
)
neoMsgEncode
(
data
[]
byte
)
{
...
@@ -81,7 +81,10 @@ func (p *RequestIdentification) neoMsgEncode(data []byte) {
...
@@ -81,7 +81,10 @@ func (p *RequestIdentification) neoMsgEncode(data []byte) {
copy
(
data
,
p
.
ClusterName
)
copy
(
data
,
p
.
ClusterName
)
data
=
data
[
l
:
]
data
=
data
[
l
:
]
}
}
float64_NEOEncode
(
data
[
0
:
],
p
.
IdTimestamp
)
{
n
:=
p
.
IdTime
.
neoEncode
(
data
[
0
:
])
data
=
data
[
0
+
n
:
]
}
}
}
func
(
p
*
RequestIdentification
)
neoMsgDecode
(
data
[]
byte
)
(
int
,
error
)
{
func
(
p
*
RequestIdentification
)
neoMsgDecode
(
data
[]
byte
)
(
int
,
error
)
{
...
@@ -106,14 +109,21 @@ func (p *RequestIdentification) neoMsgDecode(data []byte) (int, error) {
...
@@ -106,14 +109,21 @@ func (p *RequestIdentification) neoMsgDecode(data []byte) (int, error) {
{
{
l
:=
binary
.
BigEndian
.
Uint32
(
data
[
0
:
])
l
:=
binary
.
BigEndian
.
Uint32
(
data
[
0
:
])
data
=
data
[
4
:
]
data
=
data
[
4
:
]
if
uint32
(
len
(
data
))
<
8
+
l
{
if
uint32
(
len
(
data
))
<
l
{
goto
overflow
goto
overflow
}
}
nread
+=
8
+
l
nread
+=
l
p
.
ClusterName
=
string
(
data
[
:
l
])
p
.
ClusterName
=
string
(
data
[
:
l
])
data
=
data
[
l
:
]
data
=
data
[
l
:
]
}
}
p
.
IdTimestamp
=
float64_NEODecode
(
data
[
0
:
])
{
n
,
ok
:=
p
.
IdTime
.
neoDecode
(
data
)
if
!
ok
{
goto
overflow
}
data
=
data
[
n
:
]
nread
+=
n
}
return
12
+
int
(
nread
),
nil
return
12
+
int
(
nread
),
nil
overflow
:
overflow
:
...
@@ -316,17 +326,20 @@ func (p *NotifyNodeInformation) neoMsgEncodedLen() int {
...
@@ -316,17 +326,20 @@ func (p *NotifyNodeInformation) neoMsgEncodedLen() int {
var
size
int
var
size
int
for
i
:=
0
;
i
<
len
(
p
.
NodeList
);
i
++
{
for
i
:=
0
;
i
<
len
(
p
.
NodeList
);
i
++
{
a
:=
&
p
.
NodeList
[
i
]
a
:=
&
p
.
NodeList
[
i
]
size
+=
(
*
a
)
.
Addr
.
neoEncodedLen
()
size
+=
(
*
a
)
.
Addr
.
neoEncodedLen
()
+
(
*
a
)
.
IdTime
.
neoEncodedLen
()
}
}
return
12
+
len
(
p
.
NodeList
)
*
20
+
size
return
4
+
p
.
IdTime
.
neoEncodedLen
()
+
len
(
p
.
NodeList
)
*
12
+
size
}
}
func
(
p
*
NotifyNodeInformation
)
neoMsgEncode
(
data
[]
byte
)
{
func
(
p
*
NotifyNodeInformation
)
neoMsgEncode
(
data
[]
byte
)
{
float64_NEOEncode
(
data
[
0
:
],
p
.
IdTimestamp
)
{
n
:=
p
.
IdTime
.
neoEncode
(
data
[
0
:
])
data
=
data
[
0
+
n
:
]
}
{
{
l
:=
uint32
(
len
(
p
.
NodeList
))
l
:=
uint32
(
len
(
p
.
NodeList
))
binary
.
BigEndian
.
PutUint32
(
data
[
8
:
],
l
)
binary
.
BigEndian
.
PutUint32
(
data
[
0
:
],
l
)
data
=
data
[
12
:
]
data
=
data
[
4
:
]
for
i
:=
0
;
uint32
(
i
)
<
l
;
i
++
{
for
i
:=
0
;
uint32
(
i
)
<
l
;
i
++
{
a
:=
&
p
.
NodeList
[
i
]
a
:=
&
p
.
NodeList
[
i
]
binary
.
BigEndian
.
PutUint32
(
data
[
0
:
],
uint32
(
int32
((
*
a
)
.
Type
)))
binary
.
BigEndian
.
PutUint32
(
data
[
0
:
],
uint32
(
int32
((
*
a
)
.
Type
)))
...
@@ -336,21 +349,31 @@ func (p *NotifyNodeInformation) neoMsgEncode(data []byte) {
...
@@ -336,21 +349,31 @@ func (p *NotifyNodeInformation) neoMsgEncode(data []byte) {
}
}
binary
.
BigEndian
.
PutUint32
(
data
[
0
:
],
uint32
(
int32
((
*
a
)
.
UUID
)))
binary
.
BigEndian
.
PutUint32
(
data
[
0
:
],
uint32
(
int32
((
*
a
)
.
UUID
)))
binary
.
BigEndian
.
PutUint32
(
data
[
4
:
],
uint32
(
int32
((
*
a
)
.
State
)))
binary
.
BigEndian
.
PutUint32
(
data
[
4
:
],
uint32
(
int32
((
*
a
)
.
State
)))
float64_NEOEncode
(
data
[
8
:
],
(
*
a
)
.
IdTimestamp
)
{
data
=
data
[
16
:
]
n
:=
(
*
a
)
.
IdTime
.
neoEncode
(
data
[
8
:
])
data
=
data
[
8
+
n
:
]
}
data
=
data
[
0
:
]
}
}
}
}
}
}
func
(
p
*
NotifyNodeInformation
)
neoMsgDecode
(
data
[]
byte
)
(
int
,
error
)
{
func
(
p
*
NotifyNodeInformation
)
neoMsgDecode
(
data
[]
byte
)
(
int
,
error
)
{
var
nread
uint32
var
nread
uint32
if
uint32
(
len
(
data
))
<
12
{
{
n
,
ok
:=
p
.
IdTime
.
neoDecode
(
data
)
if
!
ok
{
goto
overflow
}
data
=
data
[
n
:
]
nread
+=
n
}
if
uint32
(
len
(
data
))
<
4
{
goto
overflow
goto
overflow
}
}
p
.
IdTimestamp
=
float64_NEODecode
(
data
[
0
:
])
{
{
l
:=
binary
.
BigEndian
.
Uint32
(
data
[
8
:
])
l
:=
binary
.
BigEndian
.
Uint32
(
data
[
0
:
])
data
=
data
[
12
:
]
data
=
data
[
4
:
]
p
.
NodeList
=
make
([]
NodeInfo
,
l
)
p
.
NodeList
=
make
([]
NodeInfo
,
l
)
for
i
:=
0
;
uint32
(
i
)
<
l
;
i
++
{
for
i
:=
0
;
uint32
(
i
)
<
l
;
i
++
{
a
:=
&
p
.
NodeList
[
i
]
a
:=
&
p
.
NodeList
[
i
]
...
@@ -367,17 +390,24 @@ func (p *NotifyNodeInformation) neoMsgDecode(data []byte) (int, error) {
...
@@ -367,17 +390,24 @@ func (p *NotifyNodeInformation) neoMsgDecode(data []byte) (int, error) {
data
=
data
[
n
:
]
data
=
data
[
n
:
]
nread
+=
n
nread
+=
n
}
}
if
uint32
(
len
(
data
))
<
16
{
if
uint32
(
len
(
data
))
<
8
{
goto
overflow
goto
overflow
}
}
(
*
a
)
.
UUID
=
NodeUUID
(
int32
(
binary
.
BigEndian
.
Uint32
(
data
[
0
:
])))
(
*
a
)
.
UUID
=
NodeUUID
(
int32
(
binary
.
BigEndian
.
Uint32
(
data
[
0
:
])))
(
*
a
)
.
State
=
NodeState
(
int32
(
binary
.
BigEndian
.
Uint32
(
data
[
4
:
])))
(
*
a
)
.
State
=
NodeState
(
int32
(
binary
.
BigEndian
.
Uint32
(
data
[
4
:
])))
(
*
a
)
.
IdTimestamp
=
float64_NEODecode
(
data
[
8
:
])
data
=
data
[
8
:
]
data
=
data
[
16
:
]
{
n
,
ok
:=
(
*
a
)
.
IdTime
.
neoDecode
(
data
)
if
!
ok
{
goto
overflow
}
data
=
data
[
n
:
]
nread
+=
n
}
}
}
nread
+=
l
*
20
nread
+=
l
*
12
}
}
return
12
+
int
(
nread
),
nil
return
4
+
int
(
nread
),
nil
overflow
:
overflow
:
return
0
,
ErrDecodeOverflow
return
0
,
ErrDecodeOverflow
...
@@ -2380,9 +2410,9 @@ func (p *AnswerNodeList) neoMsgEncodedLen() int {
...
@@ -2380,9 +2410,9 @@ func (p *AnswerNodeList) neoMsgEncodedLen() int {
var
size
int
var
size
int
for
i
:=
0
;
i
<
len
(
p
.
NodeList
);
i
++
{
for
i
:=
0
;
i
<
len
(
p
.
NodeList
);
i
++
{
a
:=
&
p
.
NodeList
[
i
]
a
:=
&
p
.
NodeList
[
i
]
size
+=
(
*
a
)
.
Addr
.
neoEncodedLen
()
size
+=
(
*
a
)
.
Addr
.
neoEncodedLen
()
+
(
*
a
)
.
IdTime
.
neoEncodedLen
()
}
}
return
4
+
len
(
p
.
NodeList
)
*
20
+
size
return
4
+
len
(
p
.
NodeList
)
*
12
+
size
}
}
func
(
p
*
AnswerNodeList
)
neoMsgEncode
(
data
[]
byte
)
{
func
(
p
*
AnswerNodeList
)
neoMsgEncode
(
data
[]
byte
)
{
...
@@ -2399,8 +2429,11 @@ func (p *AnswerNodeList) neoMsgEncode(data []byte) {
...
@@ -2399,8 +2429,11 @@ func (p *AnswerNodeList) neoMsgEncode(data []byte) {
}
}
binary
.
BigEndian
.
PutUint32
(
data
[
0
:
],
uint32
(
int32
((
*
a
)
.
UUID
)))
binary
.
BigEndian
.
PutUint32
(
data
[
0
:
],
uint32
(
int32
((
*
a
)
.
UUID
)))
binary
.
BigEndian
.
PutUint32
(
data
[
4
:
],
uint32
(
int32
((
*
a
)
.
State
)))
binary
.
BigEndian
.
PutUint32
(
data
[
4
:
],
uint32
(
int32
((
*
a
)
.
State
)))
float64_NEOEncode
(
data
[
8
:
],
(
*
a
)
.
IdTimestamp
)
{
data
=
data
[
16
:
]
n
:=
(
*
a
)
.
IdTime
.
neoEncode
(
data
[
8
:
])
data
=
data
[
8
+
n
:
]
}
data
=
data
[
0
:
]
}
}
}
}
}
}
...
@@ -2429,15 +2462,22 @@ func (p *AnswerNodeList) neoMsgDecode(data []byte) (int, error) {
...
@@ -2429,15 +2462,22 @@ func (p *AnswerNodeList) neoMsgDecode(data []byte) (int, error) {
data
=
data
[
n
:
]
data
=
data
[
n
:
]
nread
+=
n
nread
+=
n
}
}
if
uint32
(
len
(
data
))
<
16
{
if
uint32
(
len
(
data
))
<
8
{
goto
overflow
goto
overflow
}
}
(
*
a
)
.
UUID
=
NodeUUID
(
int32
(
binary
.
BigEndian
.
Uint32
(
data
[
0
:
])))
(
*
a
)
.
UUID
=
NodeUUID
(
int32
(
binary
.
BigEndian
.
Uint32
(
data
[
0
:
])))
(
*
a
)
.
State
=
NodeState
(
int32
(
binary
.
BigEndian
.
Uint32
(
data
[
4
:
])))
(
*
a
)
.
State
=
NodeState
(
int32
(
binary
.
BigEndian
.
Uint32
(
data
[
4
:
])))
(
*
a
)
.
IdTimestamp
=
float64_NEODecode
(
data
[
8
:
])
data
=
data
[
8
:
]
data
=
data
[
16
:
]
{
n
,
ok
:=
(
*
a
)
.
IdTime
.
neoDecode
(
data
)
if
!
ok
{
goto
overflow
}
data
=
data
[
n
:
]
nread
+=
n
}
}
}
nread
+=
l
*
20
nread
+=
l
*
12
}
}
return
4
+
int
(
nread
),
nil
return
4
+
int
(
nread
),
nil
...
...
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