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
5db8f447
Commit
5db8f447
authored
Jun 29, 2015
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth: fix #1319, put an upper limit on the known txns and blocks
parent
6fc85f1e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
0 deletions
+19
-0
peer.go
eth/peer.go
+19
-0
No files found.
eth/peer.go
View file @
5db8f447
...
...
@@ -20,6 +20,11 @@ var (
errNotRegistered
=
errors
.
New
(
"peer is not registered"
)
)
const
(
maxKnownTxs
=
32768
// Maximum transactions hashes to keep in the known list (prevent DOS)
maxKnownBlocks
=
1024
// Maximum block hashes to keep in the known list (prevent DOS)
)
type
statusMsgData
struct
{
ProtocolVersion
uint32
NetworkId
uint32
...
...
@@ -101,12 +106,26 @@ func (p *peer) SetTd(td *big.Int) {
// MarkBlock marks a block as known for the peer, ensuring that the block will
// never be propagated to this particular peer.
func
(
p
*
peer
)
MarkBlock
(
hash
common
.
Hash
)
{
// If we reached the memory allowance, drop a previously known block hash
if
p
.
knownBlocks
.
Size
()
>=
maxKnownBlocks
{
p
.
knownBlocks
.
Each
(
func
(
item
interface
{})
bool
{
p
.
knownBlocks
.
Remove
(
item
)
return
p
.
knownBlocks
.
Size
()
>=
maxKnownBlocks
})
}
p
.
knownBlocks
.
Add
(
hash
)
}
// MarkTransaction marks a transaction as known for the peer, ensuring that it
// will never be propagated to this particular peer.
func
(
p
*
peer
)
MarkTransaction
(
hash
common
.
Hash
)
{
// If we reached the memory allowance, drop a previously known transaction hash
if
p
.
knownTxs
.
Size
()
>=
maxKnownTxs
{
p
.
knownTxs
.
Each
(
func
(
item
interface
{})
bool
{
p
.
knownTxs
.
Remove
(
item
)
return
p
.
knownTxs
.
Size
()
>=
maxKnownTxs
})
}
p
.
knownTxs
.
Add
(
hash
)
}
...
...
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