diff options
| author | Bitflash <admin@bitflash.network> | 2026-08-18 10:34:30 -0300 |
|---|---|---|
| committer | Bitflash <admin@bitflash.network> | 2026-08-18 10:34:30 -0300 |
| commit | beb5c1435a0d85b7b24d4d371933758ebed90907 (patch) | |
| tree | 79501a648da78ec6962405fabd58e2d70ca6589f /src/net.h | |
| parent | 243b635267b6d34ef3b4b50ed559f743db161ad7 (diff) | |
| parent | 33092ffe8ee5fb5f7c080a44831e5557b63deb63 (diff) | |
Merge pull request 'net: cap inbound connections per address' (#60) from net-per-ip-connlimit into main
Diffstat (limited to 'src/net.h')
| -rw-r--r-- | src/net.h | 17 |
1 files changed, 17 insertions, 0 deletions
| @@ -112,6 +112,23 @@ 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 | // | ||
| 123 | // Loopback (127.0.0.0/8) is exempt in the accept path. A managed-Tor node | ||
| 124 | // receives every inbound onion peer over its local hidden-service listener, so | ||
| 125 | // they all appear as 127.0.0.1 -- capping loopback would cap onion peers as a | ||
| 126 | // group, which is exactly wrong for a network moving toward onion-only. The | ||
| 127 | // global MAX_CONNECTIONS still bounds the total; a per-onion-identity limit, | ||
| 128 | // applied once identity is known after accept(), is the right future tool for | ||
| 129 | // onion floods. | ||
| 130 | static const unsigned int MAX_CONNECTIONS_PER_IP = 32; | ||
| 131 | |||
| 115 | // A node marked for disconnect is normally held until its buffers drain, so | 132 | // 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 | 133 | // 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 | 134 | // whose far end is gone, and that made such a node immortal: it stayed in |