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
35d32ba6
Commit
35d32ba6
authored
Jan 12, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
1cf2712f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
21 deletions
+32
-21
go/neo/neonet/connection.go
go/neo/neonet/connection.go
+18
-5
go/neo/neonet/pkt.go
go/neo/neonet/pkt.go
+14
-16
No files found.
go/neo/neonet/connection.go
View file @
35d32ba6
...
...
@@ -1187,7 +1187,7 @@ const dumpio = false
func
(
nl
*
NodeLink
)
sendPkt
(
pkt
*
pktBuf
)
error
{
if
dumpio
{
// XXX -> log
fmt
.
Printf
(
"%
v > %v: %v
\n
"
,
nl
.
peerLink
.
LocalAddr
(),
nl
.
peerLink
.
RemoteAddr
(),
pkt
)
fmt
.
Printf
(
"%
s > %s: %s
\n
"
,
nl
.
peerLink
.
LocalAddr
(),
nl
.
peerLink
.
RemoteAddr
(),
pktString
(
nl
.
enc
,
pkt
)
)
//defer fmt.Printf("\t-> sendPkt err: %v\n", err)
}
...
...
@@ -1213,7 +1213,13 @@ func (nl *NodeLink) recvPkt() (pkt *pktBuf, err error) {
if
dumpio
{
// XXX -> log
fmt
.
Printf
(
"%v < %v: %v
\n
"
,
nl
.
peerLink
.
LocalAddr
(),
nl
.
peerLink
.
RemoteAddr
(),
pkt
)
s
:=
fmt
.
Sprintf
(
"%s < %s: "
,
nl
.
peerLink
.
LocalAddr
(),
nl
.
peerLink
.
RemoteAddr
())
if
err
!=
nil
{
s
+=
err
.
Error
()
}
else
{
s
+=
pktString
(
nl
.
enc
,
pkt
)
}
fmt
.
Println
(
s
)
}
return
pkt
,
err
...
...
@@ -1387,10 +1393,15 @@ func pktEncode(e proto.Encoding, connId uint32, msg proto.Msg) *pktBuf {
// pktDecodeHead decodes header of a packet.
func
pktDecodeHead
(
e
proto
.
Encoding
,
pkt
*
pktBuf
)
(
connID
uint32
,
msgCode
uint16
,
payload
[]
byte
,
err
error
)
{
switch
e
{
case
'N'
:
return
pktDecodeHeadN
(
pkt
)
case
'M'
:
return
pktDecodeHeadM
(
pkt
)
case
'N'
:
connID
,
msgCode
,
payload
,
err
=
pktDecodeHeadN
(
pkt
)
case
'M'
:
connID
,
msgCode
,
payload
,
err
=
pktDecodeHeadM
(
pkt
)
default
:
panic
(
"bug"
)
}
if
err
!=
nil
{
err
=
fmt
.
Errorf
(
"decode header: %s"
,
err
)
}
return
connID
,
msgCode
,
payload
,
err
}
...
...
@@ -1408,6 +1419,9 @@ func pktEncodeN(connId uint32, msg proto.Msg) *pktBuf {
}
func
pktDecodeHeadN
(
pkt
*
pktBuf
)
(
connID
uint32
,
msgCode
uint16
,
payload
[]
byte
,
err
error
)
{
if
len
(
pkt
.
data
)
<
proto
.
PktHeaderLen
{
return
0
,
0
,
nil
,
fmt
.
Errorf
(
"packet too short"
)
// XXX -> ErrTooShort?
}
pkth
:=
pkt
.
HeaderN
()
connID
=
packed
.
Ntoh32
(
pkth
.
ConnId
)
msgCode
=
packed
.
Ntoh16
(
pkth
.
MsgCode
)
...
...
@@ -1442,7 +1456,6 @@ func pktEncodeM(connId uint32, msg proto.Msg) *pktBuf {
}
func
pktDecodeHeadM
(
pkt
*
pktBuf
)
(
connID
uint32
,
msgCode
uint16
,
payload
[]
byte
,
err
error
)
{
// XXX errctx = "decode header"
b
:=
pkt
.
data
sz
,
b
,
err
:=
msgp
.
ReadArrayHeaderBytes
(
b
)
if
err
!=
nil
{
...
...
go/neo/neonet/pkt.go
View file @
35d32ba6
...
...
@@ -28,7 +28,6 @@ import (
"lab.nexedi.com/kirr/go123/xbytes"
"lab.nexedi.com/kirr/neo/go/internal/packed"
"lab.nexedi.com/kirr/neo/go/neo/proto"
)
...
...
@@ -80,35 +79,31 @@ func (pkt *pktBuf) Free() {
// ---- pktBuf dump ----
// String dumps a packet in human-readable form.
func
(
pkt
*
pktBuf
)
String
()
string
{
if
len
(
pkt
.
data
)
<
proto
.
PktHeaderLen
{
return
fmt
.
Sprintf
(
"(! < PktHeaderLen) % x"
,
pkt
.
data
)
// pktString dumps a packet in human-readable form.
func
pktString
(
e
proto
.
Encoding
,
pkt
*
pktBuf
)
string
{
connID
,
msgCode
,
payload
,
err
:=
pktDecodeHead
(
e
,
pkt
)
if
err
!=
nil
{
return
fmt
.
Sprintf
(
"(%s) % x"
,
err
,
pkt
.
data
)
}
h
:=
pkt
.
Header
()
s
:=
fmt
.
Sprintf
(
".%d"
,
packed
.
Ntoh32
(
h
.
ConnId
))
s
:=
fmt
.
Sprintf
(
".%d"
,
connID
)
// XXX encN-specific
msgCode
:=
packed
.
Ntoh16
(
h
.
MsgCode
)
msgLen
:=
packed
.
Ntoh32
(
h
.
MsgLen
)
data
:=
pkt
.
Payload
()
msgType
:=
proto
.
MsgType
(
msgCode
)
if
msgType
==
nil
{
s
+=
fmt
.
Sprintf
(
" ? (%d)
#%d [%d]: % x"
,
msgCode
,
msgLen
,
len
(
data
),
data
)
s
+=
fmt
.
Sprintf
(
" ? (%d)
[%d]: % x"
,
msgCode
,
len
(
payload
),
payload
)
return
s
}
// XXX dup wrt Conn.Recv
msg
:=
reflect
.
New
(
msgType
)
.
Interface
()
.
(
proto
.
Msg
)
n
,
err
:=
e
ncN
.
NEOMsgDecode
(
msg
,
data
)
// XXX encN hardcoded
n
,
err
:=
e
.
NEOMsgDecode
(
msg
,
payload
)
if
err
!=
nil
{
s
+=
fmt
.
Sprintf
(
" (%s) %v;
#%d [%d]: % x"
,
msgType
.
Name
(),
err
,
msgLen
,
len
(
data
),
data
)
s
+=
fmt
.
Sprintf
(
" (%s) %v;
[%d]: % x"
,
msgType
.
Name
(),
err
,
len
(
payload
),
payload
)
}
else
{
s
+=
fmt
.
Sprintf
(
" %s %v"
,
msgType
.
Name
(),
msg
)
// XXX or %+v better?
if
n
<
len
(
data
)
{
tail
:=
data
[
n
:
]
if
n
<
len
(
payload
)
{
tail
:=
payload
[
n
:
]
s
+=
fmt
.
Sprintf
(
" ; [%d]tail: % x"
,
len
(
tail
),
tail
)
}
}
...
...
@@ -116,8 +111,10 @@ func (pkt *pktBuf) String() string {
return
s
}
/*
// Dump dumps a packet in raw form.
func (pkt *pktBuf) Dump() string {
// XXX encN-specific
if len(pkt.data) < proto.PktHeaderLen {
return fmt.Sprintf("(! < pktHeaderLen) % x", pkt.data)
}
...
...
@@ -127,3 +124,4 @@ func (pkt *pktBuf) Dump() string {
return fmt.Sprintf(".%d (%d) #%d [%d]: % x",
packed.Ntoh32(h.ConnId), packed.Ntoh16(h.MsgCode), packed.Ntoh32(h.MsgLen), len(data), 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