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
86435f98
Commit
86435f98
authored
Jul 06, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
b29c53e9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
14 deletions
+20
-14
go/neo/neonet/connection.go
go/neo/neonet/connection.go
+3
-3
go/neo/neonet/pkt.go
go/neo/neonet/pkt.go
+17
-11
No files found.
go/neo/neonet/connection.go
View file @
86435f98
...
...
@@ -1119,7 +1119,7 @@ func (nl *NodeLink) sendPkt(pkt *pktBuf) error {
}
// NOTE Write writes data in full, or it is error
_
,
err
:=
nl
.
peerLink
.
Write
(
pkt
.
D
ata
)
_
,
err
:=
nl
.
peerLink
.
Write
(
pkt
.
d
ata
)
pkt
.
Free
()
return
err
}
...
...
@@ -1137,7 +1137,7 @@ func (nl *NodeLink) recvPkt() (*pktBuf, error) {
pkt
:=
pktAlloc
(
4096
)
// len=4K but cap can be more since pkt is from pool - use all space to buffer reads
// XXX vvv -> pktAlloc() ?
data
:=
pkt
.
Data
[
:
cap
(
pkt
.
D
ata
)]
data
:=
pkt
.
data
[
:
cap
(
pkt
.
d
ata
)]
n
:=
0
// number of pkt bytes obtained so far
...
...
@@ -1190,7 +1190,7 @@ func (nl *NodeLink) recvPkt() (*pktBuf, error) {
// fixup data/pkt
data
=
data
[
:
n
]
pkt
.
D
ata
=
data
pkt
.
d
ata
=
data
if
/* XXX temp show only tx */
true
&&
dumpio
{
// XXX -> log
...
...
go/neo/neonet/pkt.go
View file @
86435f98
...
...
@@ -36,31 +36,37 @@ import (
//
// Allocate pktBuf via pktAlloc() and free via pktBuf.Free().
type
pktBuf
struct
{
D
ata
[]
byte
// whole packet data including all headers
d
ata
[]
byte
// whole packet data including all headers
}
// Header returns pointer to packet header.
func
(
pkt
*
pktBuf
)
Header
()
*
proto
.
PktHeader
{
// XXX check len(Data) < PktHeader ? -> no, Data has to be allocated with cap >= PktHeaderLen
return
(
*
proto
.
PktHeader
)(
unsafe
.
Pointer
(
&
pkt
.
Data
[
0
]))
// NOTE no need to check len(.data) < PktHeader:
// .data is always allocated with cap >= PktHeaderLen
return
(
*
proto
.
PktHeader
)(
unsafe
.
Pointer
(
&
pkt
.
data
[
0
]))
}
// Payload returns []byte representing packet payload.
func
(
pkt
*
pktBuf
)
Payload
()
[]
byte
{
return
pkt
.
D
ata
[
proto
.
PktHeaderLen
:
]
return
pkt
.
d
ata
[
proto
.
PktHeaderLen
:
]
}
// ---- pktBuf freelist ----
// pktBufPool is sync.Pool<pktBuf>
var
pktBufPool
=
sync
.
Pool
{
New
:
func
()
interface
{}
{
return
&
pktBuf
{
D
ata
:
make
([]
byte
,
0
,
4096
)}
return
&
pktBuf
{
d
ata
:
make
([]
byte
,
0
,
4096
)}
}}
// pktAlloc allocates pktBuf with len=n
// pktAlloc allocates pktBuf with len=n.
//
// n must be >= sizeof(proto.PktHeader).
func
pktAlloc
(
n
int
)
*
pktBuf
{
if
n
<
proto
.
PktHeaderLen
{
panic
(
"pktAlloc: n < sizeof(PktHeader)"
)
}
pkt
:=
pktBufPool
.
Get
()
.
(
*
pktBuf
)
pkt
.
Data
=
xbytes
.
Realloc
(
pkt
.
D
ata
,
n
)
pkt
.
data
=
xbytes
.
Realloc
(
pkt
.
d
ata
,
n
)
return
pkt
}
...
...
@@ -74,8 +80,8 @@ func (pkt *pktBuf) Free() {
// Strings dumps a packet in human-readable form
func
(
pkt
*
pktBuf
)
String
()
string
{
if
len
(
pkt
.
D
ata
)
<
proto
.
PktHeaderLen
{
return
fmt
.
Sprintf
(
"(! < PktHeaderLen) % x"
,
pkt
.
D
ata
)
if
len
(
pkt
.
d
ata
)
<
proto
.
PktHeaderLen
{
return
fmt
.
Sprintf
(
"(! < PktHeaderLen) % x"
,
pkt
.
d
ata
)
}
h
:=
pkt
.
Header
()
...
...
@@ -109,8 +115,8 @@ func (pkt *pktBuf) String() string {
// Dump dumps a packet in raw form
func
(
pkt
*
pktBuf
)
Dump
()
string
{
if
len
(
pkt
.
D
ata
)
<
proto
.
PktHeaderLen
{
return
fmt
.
Sprintf
(
"(! < pktHeaderLen) % x"
,
pkt
.
D
ata
)
if
len
(
pkt
.
d
ata
)
<
proto
.
PktHeaderLen
{
return
fmt
.
Sprintf
(
"(! < pktHeaderLen) % x"
,
pkt
.
d
ata
)
}
h
:=
pkt
.
Header
()
...
...
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