Skip to content
This repository was archived by the owner on Apr 3, 2022. It is now read-only.

Commit 4dde5a1

Browse files
committed
P2P memory consuming bug fixed.
1 parent 0f2e589 commit 4dde5a1

4 files changed

Lines changed: 14 additions & 5 deletions

File tree

p2p/chain_request.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (connection *Connection) Handle_ChainRequest(buf []byte) {
9999
return
100100
}
101101

102-
if len(request.Block_list) != len(request.TopoHeights) {
102+
if len(request.Block_list) != len(request.TopoHeights) || len(request.Block_list) > 1024 {
103103
rlog.Warnf("Peer chain request has %d block %d topos, therefore invalid", len(request.Block_list), len(request.TopoHeights))
104104
connection.Exit()
105105
return

p2p/chain_response.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (connection *Connection) Handle_ChainResponse(buf []byte) {
6262
}
6363

6464
// we were expecting something else ban
65-
if len(response.Block_list) < 1 {
65+
if len(response.Block_list) < 1 || len(response.TopBlocks) > 100 {
6666
rlog.Warnf("Malformed chain response %s", err, connection.logid)
6767
connection.Exit()
6868
return

p2p/handshake.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ func (connection *Connection) Handle_Handshake(buf []byte) {
181181
// parse delivered peer list as grey list
182182
rlog.Debugf("Peer provides %d peers", len(handshake.PeerList))
183183
for i := range handshake.PeerList {
184-
Peer_Add(&Peer{Address: handshake.PeerList[i].Addr})
184+
if i < 13 {
185+
Peer_Add(&Peer{Address: handshake.PeerList[i].Addr})
186+
}
185187
}
186188

187189
atomic.StoreUint32(&connection.State, ACTIVE)

p2p/peer_pool.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,17 @@ func clean_up() {
118118
peer_mutex.Lock()
119119
defer peer_mutex.Unlock()
120120
for k, v := range peer_map {
121-
if v.FailCount >= 16 { // roughly 16 tries, 18 hrs before we discard the peer
121+
if v.FailCount >= 8 { // roughly 16 tries, 18 hrs before we discard the peer
122122
delete(peer_map, k)
123123
}
124-
}
124+
if v.LastConnected == 0 { // if never connected, purge the peer
125+
delete(peer_map, k)
126+
}
125127

128+
if uint64(time.Now().UTC().Unix()) > ( v.LastConnected + 42000) { // purge all peers which were not connected in
129+
delete(peer_map, k)
130+
}
131+
}
126132
}
127133

128134
// check whether an IP is in the map already
@@ -147,6 +153,7 @@ func GetPeerInList(address string) *Peer {
147153

148154
// add connection to map
149155
func Peer_Add(p *Peer) {
156+
clean_up();
150157
peer_mutex.Lock()
151158
defer peer_mutex.Unlock()
152159

0 commit comments

Comments
 (0)