aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-06-29 22:06:07 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-07-01 00:00:01 +0800
commit5db8f447d597e55718263ba5ed1770290e3e0893 (patch)
tree255dbb5565d249823a081a87db810ec27986addd
parent6fc85f1ec221f976399af071a75ad7264b0ee905 (diff)
downloadgo-tangerine-5db8f447d597e55718263ba5ed1770290e3e0893.tar.gz
go-tangerine-5db8f447d597e55718263ba5ed1770290e3e0893.tar.zst
go-tangerine-5db8f447d597e55718263ba5ed1770290e3e0893.zip
eth: fix #1319, put an upper limit on the known txns and blocks
-rw-r--r--eth/peer.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/eth/peer.go b/eth/peer.go
index 9160ac718..0120cd033 100644
--- a/eth/peer.go
+++ b/eth/peer.go
@@ -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)
}