upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/net.h
diff options
context:
space:
mode:
authorBitflash <admin@bitflash.network>2026-08-18 10:34:30 -0300
committerBitflash <admin@bitflash.network>2026-08-18 10:34:30 -0300
commitbeb5c1435a0d85b7b24d4d371933758ebed90907 (patch)
tree79501a648da78ec6962405fabd58e2d70ca6589f /src/net.h
parent243b635267b6d34ef3b4b50ed559f743db161ad7 (diff)
parent33092ffe8ee5fb5f7c080a44831e5557b63deb63 (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.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/net.h b/src/net.h
index 984588b..e3d4a93 100644
--- a/src/net.h
+++ b/src/net.h
@@ -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.
113static const unsigned int MAX_CONNECTIONS = 125; 113static 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.
130static 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