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:04:28 -0300
committerbitflash <admin@bitflash.network>2026-08-18 10:04:28 -0300
commitdb84acfc5f99ac1ddf4962879b4cbaf1af9952dd (patch)
treeca7e4c67216880361dfd484c27fbf7b8c9d2d269 /src/net.h
parenta6eb8dab830be3135c054ae3ae442886f1867b4e (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.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/net.h b/src/net.h
index 984588b..4fdd1b3 100644
--- a/src/net.h
+++ b/src/net.h
@@ -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.
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.
122static 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