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
e938faba
Commit
e938faba
authored
Jun 01, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
X fix current tests
parent
7ee9a615
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
14 deletions
+33
-14
go/neo/proto.go
go/neo/proto.go
+4
-4
go/neo/proto_test.go
go/neo/proto_test.go
+2
-2
go/neo/server.go
go/neo/server.go
+27
-8
No files found.
go/neo/proto.go
View file @
e938faba
...
@@ -137,19 +137,19 @@ type NodeUUID int32
...
@@ -137,19 +137,19 @@ type NodeUUID int32
var
ErrDecodeOverflow
=
errors
.
New
(
"decode: bufer overflow"
)
var
ErrDecodeOverflow
=
errors
.
New
(
"decode: bufer overflow"
)
// NEOEncoder is interface for marshaling
objec
ts to wire format
// NEOEncoder is interface for marshaling
packe
ts to wire format
type
NEOEncoder
interface
{
type
NEOEncoder
interface
{
// NEOEncodedInfo returns message code needed to be used for the packet
// NEOEncodedInfo returns message code needed to be used for the packet
// on the wire and
how much space is needed to encode payload
// on the wire and how much space is needed to encode payload
// XXX naming?
// XXX naming?
NEOEncodedInfo
()
(
msgCode
uint16
,
payloadLen
int
)
NEOEncodedInfo
()
(
msgCode
uint16
,
payloadLen
int
)
//
perform
the encoding.
//
NEOEncode performs
the encoding.
// len(buf) must be >= payloadLen returned by NEOEncodedInfo
// len(buf) must be >= payloadLen returned by NEOEncodedInfo
NEOEncode
(
buf
[]
byte
)
NEOEncode
(
buf
[]
byte
)
}
}
// NEODecoder is interface for unmarshalling
objec
ts from wire format
// NEODecoder is interface for unmarshalling
packe
ts from wire format
type
NEODecoder
interface
{
type
NEODecoder
interface
{
NEODecode
(
data
[]
byte
)
(
nread
int
,
err
error
)
NEODecode
(
data
[]
byte
)
(
nread
int
,
err
error
)
}
}
...
...
go/neo/proto_test.go
View file @
e938faba
...
@@ -215,7 +215,7 @@ func TestPktMarshal(t *testing.T) {
...
@@ -215,7 +215,7 @@ func TestPktMarshal(t *testing.T) {
// map[uint32]UUID + trailing ...
// map[uint32]UUID + trailing ...
{
&
CheckReplicas
{
{
&
CheckReplicas
{
PartitionDict
:
map
[
uint32
]
NodeID
{
PartitionDict
:
map
[
uint32
]
Node
UU
ID
{
1
:
7
,
1
:
7
,
2
:
9
,
2
:
9
,
7
:
3
,
7
:
3
,
...
@@ -234,7 +234,7 @@ func TestPktMarshal(t *testing.T) {
...
@@ -234,7 +234,7 @@ func TestPktMarshal(t *testing.T) {
},
},
// uint32, []uint32
// uint32, []uint32
{
&
PartitionCorrupted
{
7
,
[]
NodeID
{
1
,
3
,
9
,
4
}},
{
&
PartitionCorrupted
{
7
,
[]
Node
UU
ID
{
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
),
},
},
...
...
go/neo/server.go
View file @
e938faba
...
@@ -235,40 +235,59 @@ func Ask(conn *Conn, req NEOEncoder, resp NEODecoder) error {
...
@@ -235,40 +235,59 @@ func Ask(conn *Conn, req NEOEncoder, resp NEODecoder) error {
return
err
return
err
}
}
// ProtoError is returned when there waa a protocol error, like receiving
// unexpected packet or packet with wrong header
type
ProtoError
struct
{
Conn
*
Conn
Err
error
}
func
(
e
*
ProtoError
)
Error
()
string
{
return
fmt
.
Sprintf
(
"%v: %v"
,
e
.
Conn
,
e
.
Err
)
}
// Expect receives 1 packet and expects it to be exactly of msg type
// Expect receives 1 packet and expects it to be exactly of msg type
// XXX naming (-> Recv1 ?)
// XXX naming (-> Recv1 ?)
func
Expect
(
conn
*
Conn
,
msg
NEODecoder
)
error
{
func
Expect
(
conn
*
Conn
,
msg
NEODecoder
)
(
err
error
)
{
pkt
,
err
:=
conn
.
Recv
()
pkt
,
err
:=
conn
.
Recv
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
// received ok. Now it is all decoding
// XXX dup wrt RecvAndDecode
// XXX dup wrt RecvAndDecode
pkth
:=
pkt
.
Header
()
pkth
:=
pkt
.
Header
()
msgCode
:=
ntoh16
(
pkth
.
MsgCode
)
msgCode
:=
ntoh16
(
pkth
.
MsgCode
)
msgType
:=
pktTypeRegistry
[
msgCode
]
msgType
:=
pktTypeRegistry
[
msgCode
]
if
msgType
==
nil
{
if
msgType
==
nil
{
return
fmt
.
Errorf
(
"invalid msgCode (%d)"
,
msgCode
)
// XXX err ctx
return
&
ProtoError
{
conn
,
fmt
.
Errorf
(
"invalid msgCode (%d)"
,
msgCode
)}
}
}
if
msgType
!=
reflect
.
TypeOf
(
msg
)
{
// FIXME -> better compare on just msgCode
// Error response
if
msgType
!=
reflect
.
TypeOf
(
msg
)
.
Elem
()
{
// unexpected Error response
if
msgType
==
reflect
.
TypeOf
(
Error
{})
{
if
msgType
==
reflect
.
TypeOf
(
Error
{})
{
errResp
:=
Error
{}
errResp
:=
Error
{}
_
,
err
=
errResp
.
NEODecode
(
pkt
.
Payload
())
_
,
err
=
errResp
.
NEODecode
(
pkt
.
Payload
())
if
err
!=
nil
{
if
err
!=
nil
{
return
err
// XXX err ctx
return
&
ProtoError
{
conn
,
err
}
}
}
return
errDecode
(
&
errResp
)
// XXX err ctx
// FIXME clarify error decoding logic:
// - in some cases Error is one of "expected" answers (e.g. Ask(GetObject))
// - in other cases Error is completely not expected
// (e.g. getting 1st packet on connection)
return
errDecode
(
&
errResp
)
// XXX err ctx vs ^^^ errcontextf ?
}
}
return
fmt
.
Errorf
(
"unexpected packet: %T"
,
msgType
)
// XXX err ctx -> + conn ?
return
&
ProtoError
{
conn
,
fmt
.
Errorf
(
"unexpected packet: %v"
,
msgType
)}
}
}
_
,
err
=
msg
.
NEODecode
(
pkt
.
Payload
())
_
,
err
=
msg
.
NEODecode
(
pkt
.
Payload
())
if
err
!=
nil
{
if
err
!=
nil
{
return
err
// XXX err ctx
return
&
ProtoError
{
conn
,
err
}
}
}
return
nil
return
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