From 3efd9a089cc6b924d9bc917d3d8145f7c01265ad Mon Sep 17 00:00:00 2001 From: Bitflash-sh Date: Fri, 24 Jul 2026 12:13:30 -0300 Subject: Multi-relay rendezvous with failover + relay rate-limiting Seed list of 3 geographically-spread relays (Sao Paulo, New Jersey, Almaty); nodes register at the first reachable one and fail over if it is attacked or goes down, so no single relay IP is a point of failure. Relay installer now applies iptables connection rate-limits to soak up single-source floods. --- src/nostr.cpp | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'src/nostr.cpp') diff --git a/src/nostr.cpp b/src/nostr.cpp index 8e2a07d..59817f5 100644 --- a/src/nostr.cpp +++ b/src/nostr.cpp @@ -55,7 +55,32 @@ const int nNostrRelays = ARRAYLEN(pszNostrRelays); // Rendezvous meeting relay this node registers at (ThreadBtfAccept in net.cpp) // and advertises in its .btf descriptor. Seed default; /rvrelay overrides. -string strBtfMeetingRelay = "90.156.222.107:8434"; +// Seed rendezvous relays. More entries = more resilience: the node fails over +// between them (see ThreadBtfAccept), so DDoSing one relay IP can't take the +// network down. /rvrelay overrides this list with a single entry. +vector vBtfMeetingRelays = { + "92.246.128.180:8434", // Sao Paulo, BR + "31.44.4.249:8434", // New Jersey, US + "90.156.222.107:8434", // Almaty, KZ +}; +string strBtfActiveRelay; +static CCriticalSection cs_activeRelay; + +string BtfActiveRelay() +{ + CRITICAL_BLOCK(cs_activeRelay) + if (!strBtfActiveRelay.empty()) + return strBtfActiveRelay; + if (!vBtfMeetingRelays.empty()) + return vBtfMeetingRelays[0]; + return ""; +} + +void BtfSetActiveRelay(const string& relay) +{ + CRITICAL_BLOCK(cs_activeRelay) + strBtfActiveRelay = relay; +} // @@ -519,8 +544,9 @@ static void PublishDescriptor(CWebSocket& ws, CNostrKey& key) { // meeting_node is the rendezvous relay this node's hidden service // (ThreadBtfAccept in net.cpp) is registered at -- where clients dial us. - string meeting_node = strBtfMeetingRelay.empty() ? "rendezvous-pending" - : strBtfMeetingRelay; + string meeting_node = BtfActiveRelay(); + if (meeting_node.empty()) + meeting_node = "rendezvous-pending"; string desc = btf::SignDescriptor(key.ctx, key.seckey, key.EncPubHex(), meeting_node, (uint64_t)GetTime()); if (desc.empty()) -- cgit v1.2.3