diff options
| author | bitflash-maintainer <noreply@bitflash.invalid> | 2026-09-04 05:59:40 +0000 |
|---|---|---|
| committer | bitflash-maintainer <noreply@bitflash.invalid> | 2026-09-04 05:59:40 +0000 |
| commit | 152c859b18b222a7c11a82b5485110e902267d40 (patch) | |
| tree | 1ceadf421609a2e58da81103165a2fb7085387de /src/net.cpp | |
| parent | e4f898c4a6b9900553c64b9804889b5fdae3e55f (diff) | |
| parent | b810d86752ddb2674118f737582c924bb9eb74c1 (diff) | |
Merge branch 'deploy/all-2026-08-24' into 'deploy/soak-2026-08-21'
deploy: land MRs 1-12 and upstream 1.2.20, as shipped in relay component
See merge request !13
Diffstat (limited to 'src/net.cpp')
| -rw-r--r-- | src/net.cpp | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/net.cpp b/src/net.cpp index fed6123..bb05259 100644 --- a/src/net.cpp +++ b/src/net.cpp | |||
| @@ -1560,12 +1560,41 @@ void ThreadSocketHandler2(void* parg) | |||
| 1560 | unsigned int nNodes = 0; | 1560 | unsigned int nNodes = 0; |
| 1561 | CRITICAL_BLOCK(cs_vNodes) | 1561 | CRITICAL_BLOCK(cs_vNodes) |
| 1562 | nNodes = (unsigned int)vNodes.size(); | 1562 | nNodes = (unsigned int)vNodes.size(); |
| 1563 | // Also count how many connections this one address already | ||
| 1564 | // holds. A single IP that keeps opening sockets -- a broken | ||
| 1565 | // node or a deliberate connection-exhaustion flood -- must not | ||
| 1566 | // be able to take the whole table, which is what starved the | ||
| 1567 | // relays. | ||
| 1568 | // | ||
| 1569 | // Loopback is exempt. Onion peers reach a managed-Tor node | ||
| 1570 | // through its local hidden-service listener, so every one of | ||
| 1571 | // them accepts as 127.0.0.1; capping loopback would cap all | ||
| 1572 | // inbound onion peers as a single group, which is the opposite | ||
| 1573 | // of where the network is headed. The global MAX_CONNECTIONS | ||
| 1574 | // still bounds the total, and the direct-IP flood this defends | ||
| 1575 | // against never arrives over loopback. (Per-onion-identity | ||
| 1576 | // limiting, once a peer's identity is known past accept(), is | ||
| 1577 | // the right tool for onion and is left for later.) | ||
| 1578 | bool fLoopback = (addr.GetByte(3) == 127); | ||
| 1579 | unsigned int nFromThisIP = 0; | ||
| 1580 | if (!fLoopback) | ||
| 1581 | CRITICAL_BLOCK(cs_vNodes) | ||
| 1582 | for (vector<CNode*>::iterator it = vNodes.begin(); it != vNodes.end(); ++it) | ||
| 1583 | if ((*it)->addr.ip == addr.ip) | ||
| 1584 | nFromThisIP++; | ||
| 1585 | |||
| 1563 | if (nNodes >= MAX_CONNECTIONS) | 1586 | if (nNodes >= MAX_CONNECTIONS) |
| 1564 | { | 1587 | { |
| 1565 | LogPrint("net", "refusing connection from %s, already at %u\n", | 1588 | LogPrint("net", "refusing connection from %s, already at %u\n", |
| 1566 | addr.ToString().c_str(), nNodes); | 1589 | addr.ToString().c_str(), nNodes); |
| 1567 | BtfCloseSocket(hSocket); | 1590 | BtfCloseSocket(hSocket); |
| 1568 | } | 1591 | } |
| 1592 | else if (!fLoopback && nFromThisIP >= MAX_CONNECTIONS_PER_IP) | ||
| 1593 | { | ||
| 1594 | LogPrint("net", "refusing connection from %s, already %u from that address\n", | ||
| 1595 | addr.ToString().c_str(), nFromThisIP); | ||
| 1596 | BtfCloseSocket(hSocket); | ||
| 1597 | } | ||
| 1569 | else | 1598 | else |
| 1570 | { | 1599 | { |
| 1571 | LogPrint("net", "accepted connection from %s\n", addr.ToString().c_str()); | 1600 | LogPrint("net", "accepted connection from %s\n", addr.ToString().c_str()); |
| @@ -2090,7 +2119,7 @@ bool StartNode(string& strError) | |||
| 2090 | if (addrIncoming.ip) | 2119 | if (addrIncoming.ip) |
| 2091 | addrLocalHost.ip = addrIncoming.ip; | 2120 | addrLocalHost.ip = addrIncoming.ip; |
| 2092 | 2121 | ||
| 2093 | _beginthread([](void*) { | 2122 | if (_beginthread([](void*) { |
| 2094 | unsigned int ip = addrLocalHost.ip; | 2123 | unsigned int ip = addrLocalHost.ip; |
| 2095 | if (GetMyExternalIP(ip)) { | 2124 | if (GetMyExternalIP(ip)) { |
| 2096 | addrLocalHost.ip = ip; | 2125 | addrLocalHost.ip = ip; |
| @@ -2098,7 +2127,8 @@ bool StartNode(string& strError) | |||
| 2098 | CWalletDB().WriteSetting("addrIncoming", addrIncoming); | 2127 | CWalletDB().WriteSetting("addrIncoming", addrIncoming); |
| 2099 | printf("External IP updated: %s\n", addrLocalHost.ToStringIP().c_str()); | 2128 | printf("External IP updated: %s\n", addrLocalHost.ToStringIP().c_str()); |
| 2100 | } | 2129 | } |
| 2101 | }, 0, NULL); | 2130 | }, 0, NULL) == (uintptr_t)-1) |
| 2131 | printf("Error: _beginthread(GetMyExternalIP) failed\n"); | ||
| 2102 | 2132 | ||
| 2103 | // Peers that answered last time, dialled straight away. The relays are the | 2133 | // Peers that answered last time, dialled straight away. The relays are the |
| 2104 | // only way to find anyone otherwise, and reaching them plus walking their | 2134 | // only way to find anyone otherwise, and reaching them plus walking their |