Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(p2p): limit inbound connections #1919

Open
wants to merge 4 commits into
base: stage
Choose a base branch
from
Open

Conversation

y0sher
Copy link
Contributor

@y0sher y0sher commented Dec 5, 2024

Description

This code calculates the amount of inbound connections we have on every new connection and makes sure we're not passing the limit of 80% of our max peers in inbound connections. if we are at the limit we just drop the peer.

Comment on lines +50 to +51
// inboundRatio is the ratio of inbound connections to outbound connections
inboundRatio = float64(0.8)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably inboundShare or inboundFraction and not inboundRatio (which would imply totalInboud = 0.8 * totalOutbound or something similar)

network/p2p/p2p_setup.go Outdated Show resolved Hide resolved
network/p2p/p2p_setup.go Outdated Show resolved Hide resolved
network/peers/connections/conn_gater.go Outdated Show resolved Hide resolved
Comment on lines 121 to 123
if n.idx == nil {
return false
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could maybe just use n.IsBadPeer (instead of this and n.idx.IsBad(lg, peerID) below)

Copy link
Contributor

@iurii-ssv iurii-ssv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple more suggestions

Comment on lines 63 to 68
if n.isBadPeer(n.logger, id) {
if n.isBadOutbound(n.logger, id) {
n.logger.Debug("preventing outbound connection due to bad peer", fields.PeerID(id))
return false
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't InterceptAddrDial seem a better place to check for this ?

Comment on lines 92 to 102
if n.isBadPeer(n.logger, id) {
n.logger.Debug("rejecting inbound connection due to bad peer", fields.PeerID(id))
if direction == libp2pnetwork.DirUnknown {
return false
}
return true

if direction == libp2pnetwork.DirOutbound {
return n.isBadOutbound(n.logger, id)
} else {
return n.isBadInbound(n.logger, id)
}
Copy link
Contributor

@iurii-ssv iurii-ssv Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here we essentially do isBadOutbound check 2nd time (because the first time, I think, we did it in InterceptAddrDial), which maybe means - instead of all this added code to InterceptSecured we maybe should just check isBadInbound in InterceptAccept ?

Although in InterceptAccept we don't have peerID looks like ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants