Reform Inbound Limit (#8465)

* clean up

* name

* comment

* change back

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
Nishant Das
2021-02-18 01:48:44 +08:00
committed by GitHub
parent 1ba414bd77
commit 6391dec5de
4 changed files with 42 additions and 6 deletions

View File

@@ -62,7 +62,7 @@ const (
maxLimitBuffer = 150
// InboundRatio is the proportion of our connected peer limit at which we will allow inbound peers.
InboundRatio = float64(1)
InboundRatio = float64(0.8)
)
// Status is the structure holding the peer status information.
@@ -208,6 +208,14 @@ func (p *Status) IsAboveInboundLimit() bool {
return totalInbound > inboundLimit
}
// InboundLimit returns the current inbound
// peer limit.
func (p *Status) InboundLimit() int {
p.store.RLock()
defer p.store.RUnlock()
return int(float64(p.ConnectedPeerLimit()) * InboundRatio)
}
// SetMetadata sets the metadata of the given remote peer.
func (p *Status) SetMetadata(pid peer.ID, metaData *pb.MetaData) {
p.store.Lock()
@@ -662,7 +670,7 @@ func (p *Status) PeersToPrune() []peer.ID {
badResp int
}
peersToPrune := make([]*peerResp, 0)
// Select disconnected peers with a smaller bad response count.
// Select connected and inbound peers to prune.
for pid, peerData := range p.store.Peers() {
if peerData.ConnState == PeerConnected && peerData.Direction == network.DirInbound {
peersToPrune = append(peersToPrune, &peerResp{