diff options
| author | bitflash <admin@bitflash.network> | 2026-08-18 10:04:28 -0300 |
|---|---|---|
| committer | bitflash <admin@bitflash.network> | 2026-08-18 10:04:28 -0300 |
| commit | db84acfc5f99ac1ddf4962879b4cbaf1af9952dd (patch) | |
| tree | ca7e4c67216880361dfd484c27fbf7b8c9d2d269 /src/net.h | |
| parent | a6eb8dab830be3135c054ae3ae442886f1867b4e (diff) | |
net: cap inbound connections per address
A single IP could hold every inbound slot up to MAX_CONNECTIONS -- which
is what a connection-exhaustion flood did to the rendezvous relays, one
address parking hundreds of sockets and starving real peers. Add
MAX_CONNECTIONS_PER_IP (32): the accept path counts existing connections
from the same address and refuses a new one past the cap. The relays'
firewall connlimit does the same a layer lower; this makes every build
carry the defense, including future poll()-based relays with no FD ceiling.
Diffstat (limited to 'src/net.h')
| -rw-r--r-- | src/net.h | 9 |
1 files changed, 9 insertions, 0 deletions
| @@ -112,6 +112,15 @@ static const int BTF_INCOMPLETE_MESSAGE_TIMEOUT_SECS = 2 * 60; | |||
| 112 | // 125 is Bitcoin's number and remains a conservative public-node default. | 112 | // 125 is Bitcoin's number and remains a conservative public-node default. |
| 113 | static const unsigned int MAX_CONNECTIONS = 125; | 113 | static const unsigned int MAX_CONNECTIONS = 125; |
| 114 | 114 | ||
| 115 | // Cap inbound connections from any single address. Without it one source can | ||
| 116 | // hold every slot up to MAX_CONNECTIONS -- exactly what happened to the | ||
| 117 | // rendezvous relays, where a single IP parked hundreds of connections and | ||
| 118 | // starved real peers. A legitimate peer, even a relay talking to a relay, | ||
| 119 | // needs only a handful; 32 leaves generous room while denying any one address | ||
| 120 | // more than a quarter of the table. The firewall connlimit on the relays does | ||
| 121 | // the same thing a layer lower; this makes every build carry the defense. | ||
| 122 | static const unsigned int MAX_CONNECTIONS_PER_IP = 32; | ||
| 123 | |||
| 115 | // A node marked for disconnect is normally held until its buffers drain, so | 124 | // A node marked for disconnect is normally held until its buffers drain, so |
| 116 | // a last message still goes out. But vSend cannot drain through a socket | 125 | // a last message still goes out. But vSend cannot drain through a socket |
| 117 | // whose far end is gone, and that made such a node immortal: it stayed in | 126 | // whose far end is gone, and that made such a node immortal: it stayed in |