mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-19 03:10:48 +00:00
p2p/connmanager: avoid dropping peers too early
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
parent
91c1c30996
commit
75e4c26564
1 changed files with 5 additions and 1 deletions
|
|
@ -30,6 +30,8 @@ import (
|
||||||
const (
|
const (
|
||||||
// Interval between peer drop events
|
// Interval between peer drop events
|
||||||
peerDropInterval = 30 * time.Second
|
peerDropInterval = 30 * time.Second
|
||||||
|
// Avoid dropping peers for some time after connection
|
||||||
|
doNotDropBefore = 2 * peerDropInterval
|
||||||
// How close to max should we initiate the drop timer. O should be fine,
|
// How close to max should we initiate the drop timer. O should be fine,
|
||||||
// dropping when no more peers can be added. Larger numbers result in more
|
// dropping when no more peers can be added. Larger numbers result in more
|
||||||
// aggressive drop behavior.
|
// aggressive drop behavior.
|
||||||
|
|
@ -133,8 +135,10 @@ func (cm *connManager) dropRandomPeer() bool {
|
||||||
peers := cm.peersFunc()
|
peers := cm.peersFunc()
|
||||||
|
|
||||||
// Only drop from dyndialed peers. Avoid dropping trusted peers.
|
// Only drop from dyndialed peers. Avoid dropping trusted peers.
|
||||||
|
// Give some time to peers before considering them for a drop.
|
||||||
selectDroppable := func(p *Peer) bool {
|
selectDroppable := func(p *Peer) bool {
|
||||||
return p.rw.is(dynDialedConn) && !p.rw.is(trustedConn)
|
return p.rw.is(dynDialedConn) && !p.rw.is(trustedConn) &&
|
||||||
|
mclock.Now()-p.created >= mclock.AbsTime(doNotDropBefore)
|
||||||
}
|
}
|
||||||
droppable := filter(peers, selectDroppable)
|
droppable := filter(peers, selectDroppable)
|
||||||
if len(droppable) > 0 {
|
if len(droppable) > 0 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue