Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
f1537b77
Commit
f1537b77
authored
Feb 19, 2019
by
Matthew Halpern
Committed by
Felix Lange
Feb 19, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
p2p/discover: make maximum packet size a constant (#19061)
parent
bf42535d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
7 deletions
+9
-7
udp.go
p2p/discover/udp.go
+9
-7
No files found.
p2p/discover/udp.go
View file @
f1537b77
...
@@ -54,6 +54,11 @@ const (
...
@@ -54,6 +54,11 @@ const (
ntpFailureThreshold
=
32
// Continuous timeouts after which to check NTP
ntpFailureThreshold
=
32
// Continuous timeouts after which to check NTP
ntpWarningCooldown
=
10
*
time
.
Minute
// Minimum amount of time to pass before repeating NTP warning
ntpWarningCooldown
=
10
*
time
.
Minute
// Minimum amount of time to pass before repeating NTP warning
driftThreshold
=
10
*
time
.
Second
// Allowed clock drift before warning user
driftThreshold
=
10
*
time
.
Second
// Allowed clock drift before warning user
// Discovery packets are defined to be no larger than 1280 bytes.
// Packets larger than this size will be cut at the end and treated
// as invalid because their hash won't match.
maxPacketSize
=
1280
)
)
// RPC packet types
// RPC packet types
...
@@ -496,7 +501,7 @@ var (
...
@@ -496,7 +501,7 @@ var (
headSpace
=
make
([]
byte
,
headSize
)
headSpace
=
make
([]
byte
,
headSize
)
// Neighbors replies are sent across multiple packets to
// Neighbors replies are sent across multiple packets to
// stay below the
1280 byt
e limit. We compute the maximum number
// stay below the
packet siz
e limit. We compute the maximum number
// of entries by stuffing a packet until it grows too large.
// of entries by stuffing a packet until it grows too large.
maxNeighbors
int
maxNeighbors
int
)
)
...
@@ -511,7 +516,7 @@ func init() {
...
@@ -511,7 +516,7 @@ func init() {
// If this ever happens, it will be caught by the unit tests.
// If this ever happens, it will be caught by the unit tests.
panic
(
"cannot encode: "
+
err
.
Error
())
panic
(
"cannot encode: "
+
err
.
Error
())
}
}
if
headSize
+
size
+
1
>=
1280
{
if
headSize
+
size
+
1
>=
maxPacketSize
{
maxNeighbors
=
n
maxNeighbors
=
n
break
break
}
}
...
@@ -562,10 +567,7 @@ func (t *udp) readLoop(unhandled chan<- ReadPacket) {
...
@@ -562,10 +567,7 @@ func (t *udp) readLoop(unhandled chan<- ReadPacket) {
defer
close
(
unhandled
)
defer
close
(
unhandled
)
}
}
// Discovery packets are defined to be no larger than 1280 bytes.
buf
:=
make
([]
byte
,
maxPacketSize
)
// Packets larger than this size will be cut at the end and treated
// as invalid because their hash won't match.
buf
:=
make
([]
byte
,
1280
)
for
{
for
{
nbytes
,
from
,
err
:=
t
.
conn
.
ReadFromUDP
(
buf
)
nbytes
,
from
,
err
:=
t
.
conn
.
ReadFromUDP
(
buf
)
if
netutil
.
IsTemporaryError
(
err
)
{
if
netutil
.
IsTemporaryError
(
err
)
{
...
@@ -715,7 +717,7 @@ func (req *findnode) handle(t *udp, from *net.UDPAddr, fromID enode.ID, mac []by
...
@@ -715,7 +717,7 @@ func (req *findnode) handle(t *udp, from *net.UDPAddr, fromID enode.ID, mac []by
t
.
tab
.
mutex
.
Unlock
()
t
.
tab
.
mutex
.
Unlock
()
// Send neighbors in chunks with at most maxNeighbors per packet
// Send neighbors in chunks with at most maxNeighbors per packet
// to stay below the
1280 byt
e limit.
// to stay below the
packet siz
e limit.
p
:=
neighbors
{
Expiration
:
uint64
(
time
.
Now
()
.
Add
(
expiration
)
.
Unix
())}
p
:=
neighbors
{
Expiration
:
uint64
(
time
.
Now
()
.
Add
(
expiration
)
.
Unix
())}
var
sent
bool
var
sent
bool
for
_
,
n
:=
range
closest
{
for
_
,
n
:=
range
closest
{
...
...
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