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/net.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/net.cpp') diff --git a/src/net.cpp b/src/net.cpp index 8ab9ccc..659de05 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -441,15 +441,24 @@ void ThreadBtfAccept(void* parg) return; Sleep(5000); } + size_t iRelay = 0; loop { if (fShutdown) return; - string strMeeting = strBtfMeetingRelay; + if (vBtfMeetingRelays.empty()) + { + Sleep(10000); // no meeting relay configured + continue; + } + // Stick to the current relay while it works; on failure, fail over to + // the next seed so a DDoS'd/blocked relay IP can't keep us offline. + string strMeeting = vBtfMeetingRelays[iRelay % vBtfMeetingRelays.size()]; size_t colon = strMeeting.rfind(':'); if (colon == string::npos) { - Sleep(10000); // no meeting relay configured + iRelay++; + Sleep(2000); continue; } string strHost = strMeeting.substr(0, colon); @@ -465,9 +474,13 @@ void ThreadBtfAccept(void* parg) } if (rv == btf::RV_INVALID) { - Sleep(10000); // relay unreachable; retry + iRelay++; // this relay is down/attacked -> try the next one + Sleep(3000); continue; } + // Registered OK: advertise THIS relay in our descriptor so clients dial + // us here, and keep using it (iRelay unchanged) until it fails. + BtfSetActiveRelay(strMeeting); btf_socket_t hSocket = btf::BtfServiceWrap(rv, sk); if (hSocket == INVALID_SOCKET) continue; @@ -1146,7 +1159,7 @@ bool StartNode(string& strError) // Anonymous inbound: this node's .btf hidden service, reachable through the // meeting relay without exposing our IP or needing a public port. - if (!strBtfMeetingRelay.empty()) + if (!vBtfMeetingRelays.empty()) if (_beginthread(ThreadBtfAccept, 0, NULL) == -1) printf("Error: _beginthread(ThreadBtfAccept) failed\n"); -- cgit v1.2.3