diff options
| author | bitflash-maintainer <noreply@bitflash.invalid> | 2026-08-26 22:41:53 +0000 |
|---|---|---|
| committer | bitflash-maintainer <noreply@bitflash.invalid> | 2026-08-26 22:41:53 +0000 |
| commit | bbe04dc8c96b4c4766d2771d3438233bf82687c0 (patch) | |
| tree | 62e5a1febfb8e9bc38d133ac7981e9ef93918484 /src/proxy.cpp | |
| parent | 991853fa55a749d28d6f9e507ce72b289df92785 (diff) | |
| parent | 9e39a50d1f110020b0841d31e4b931aa877cc448 (diff) | |
Merge upstream v1.2.19 into the fork
Merges upstream tag v1.2.19 (9e39a50) into merge/upstream-1.2.18 (991853f).
Unlike the 1.2.15->1.2.18 replay, bc3de30 is a true ancestor of our branch via
a9b4f89, so this is an ordinary three-way merge with merge-base bc3de30.
Delta: 36 files, +3265/-163, the Tor onion transport (managed Tor, signed
direct onion endpoints, onion-only dial mode) and the nHDNext restore fix.
src/main.cpp, main.h, script.cpp/h and db.cpp/h are byte-identical between the
two tags, and the poll() socket loop carries no diff hunks, so the merge is
consensus-neutral and the soak-tested socket paths are unchanged. relay/ is
untouched; the payout ledger (rpc.cpp) is untouched.
7 conflict blocks in 6 files, resolved as follows.
Makefile -- VERSION. Ours: stays 1.2.19+sec with the naming comment updated,
so artifacts from this tree cannot be mistaken for the upstream release.
src/Makefile, src/makefile.mingw -- HEADERS list. Ours (no market.h) plus
their tor.h. NODE_OBJS auto-merged correctly: no market.o, tor.o present.
src/selftest.cpp -- known-tests list. Union: payout-ledger (ours) and
managed-tor (theirs).
src/main_gui.cpp -- one block. Our /dumpaddresses kept; their
BtfStopManagedTor() on the StartNode failure path taken. The /rvrelay pin,
/noannounce and the marketplace removal auto-merged and were verified intact.
src/nostr.cpp -- two blocks in ResolveDescriptor. Signature takes both
out-params (our fExchangeOk, their rawOut). The body keeps our
drain-to-EOSE read -- returning early poisons the pooled socket for the next
caller -- and adds their rawOut capture. Our TLS 1.2 floor
(SSL_CTX_set_min_proto_version) is untouched by this merge; upstream 1.2.19
still has no floor of its own.
Upstream's release commit also added four build logs and a compiled Python
cache (build-1219.log, build-17.log, build-appimage.log, build-node.log,
scripts/__pycache__/bitflash_chain.cpython-313.pyc). Removed here; they are
build output, not source.
Diffstat (limited to 'src/proxy.cpp')
| -rw-r--r-- | src/proxy.cpp | 51 |
1 files changed, 48 insertions, 3 deletions
diff --git a/src/proxy.cpp b/src/proxy.cpp index 7d30911..eed054c 100644 --- a/src/proxy.cpp +++ b/src/proxy.cpp | |||
| @@ -13,6 +13,7 @@ static bool g_fTorProxy = false; | |||
| 13 | static std::string g_socks5Host; | 13 | static std::string g_socks5Host; |
| 14 | static unsigned short g_socks5Port = 0; | 14 | static unsigned short g_socks5Port = 0; |
| 15 | static const char* DEFAULT_TOR_SOCKS5_PROXY = "127.0.0.1:9050"; | 15 | static const char* DEFAULT_TOR_SOCKS5_PROXY = "127.0.0.1:9050"; |
| 16 | static const int TOR_CONNECT_TIMEOUT_SECS = 120; | ||
| 16 | 17 | ||
| 17 | static void SetSocketTimeout(SOCKET s, int nTimeoutSecs) | 18 | static void SetSocketTimeout(SOCKET s, int nTimeoutSecs) |
| 18 | { | 19 | { |
| @@ -297,10 +298,25 @@ static bool Socks5Connect(SOCKET s, const std::string& destHost, | |||
| 297 | 298 | ||
| 298 | unsigned char hello[3] = { 0x05, 0x01, 0x00 }; // SOCKS5, one method, no auth | 299 | unsigned char hello[3] = { 0x05, 0x01, 0x00 }; // SOCKS5, one method, no auth |
| 299 | if (!WriteN(s, hello, sizeof(hello))) | 300 | if (!WriteN(s, hello, sizeof(hello))) |
| 301 | { | ||
| 302 | error("SOCKS5 hello write failed for %s:%u\n", | ||
| 303 | destHost.c_str(), (unsigned)destPort); | ||
| 300 | return false; | 304 | return false; |
| 305 | } | ||
| 301 | unsigned char choice[2] = { 0, 0 }; | 306 | unsigned char choice[2] = { 0, 0 }; |
| 302 | if (!ReadN(s, choice, sizeof(choice)) || choice[0] != 0x05 || choice[1] != 0x00) | 307 | if (!ReadN(s, choice, sizeof(choice))) |
| 308 | { | ||
| 309 | error("SOCKS5 method selection read failed for %s:%u\n", | ||
| 310 | destHost.c_str(), (unsigned)destPort); | ||
| 311 | return false; | ||
| 312 | } | ||
| 313 | if (choice[0] != 0x05 || choice[1] != 0x00) | ||
| 314 | { | ||
| 315 | error("SOCKS5 proxy rejected no-auth method for %s:%u (version=0x%02x method=0x%02x)\n", | ||
| 316 | destHost.c_str(), (unsigned)destPort, | ||
| 317 | (unsigned)choice[0], (unsigned)choice[1]); | ||
| 303 | return false; | 318 | return false; |
| 319 | } | ||
| 304 | 320 | ||
| 305 | std::vector<unsigned char> req; | 321 | std::vector<unsigned char> req; |
| 306 | req.reserve(7 + destHost.size()); | 322 | req.reserve(7 + destHost.size()); |
| @@ -313,11 +329,25 @@ static bool Socks5Connect(SOCKET s, const std::string& destHost, | |||
| 313 | req.push_back((unsigned char)(destPort >> 8)); | 329 | req.push_back((unsigned char)(destPort >> 8)); |
| 314 | req.push_back((unsigned char)(destPort & 0xff)); | 330 | req.push_back((unsigned char)(destPort & 0xff)); |
| 315 | if (!WriteN(s, &req[0], (int)req.size())) | 331 | if (!WriteN(s, &req[0], (int)req.size())) |
| 332 | { | ||
| 333 | error("SOCKS5 CONNECT request write failed for %s:%u\n", | ||
| 334 | destHost.c_str(), (unsigned)destPort); | ||
| 316 | return false; | 335 | return false; |
| 336 | } | ||
| 317 | 337 | ||
| 318 | unsigned char rep[4] = {0,0,0,0}; | 338 | unsigned char rep[4] = {0,0,0,0}; |
| 319 | if (!ReadN(s, rep, sizeof(rep)) || rep[0] != 0x05) | 339 | if (!ReadN(s, rep, sizeof(rep))) |
| 340 | { | ||
| 341 | error("SOCKS5 CONNECT reply read failed for %s:%u\n", | ||
| 342 | destHost.c_str(), (unsigned)destPort); | ||
| 320 | return false; | 343 | return false; |
| 344 | } | ||
| 345 | if (rep[0] != 0x05) | ||
| 346 | { | ||
| 347 | error("SOCKS5 CONNECT reply has invalid version 0x%02x for %s:%u\n", | ||
| 348 | (unsigned)rep[0], destHost.c_str(), (unsigned)destPort); | ||
| 349 | return false; | ||
| 350 | } | ||
| 321 | if (rep[1] != 0x00) | 351 | if (rep[1] != 0x00) |
| 322 | { | 352 | { |
| 323 | error("SOCKS5 CONNECT to %s:%u failed with reply 0x%02x\n", | 353 | error("SOCKS5 CONNECT to %s:%u failed with reply 0x%02x\n", |
| @@ -335,10 +365,20 @@ static bool Socks5Connect(SOCKET s, const std::string& destHost, | |||
| 335 | nAddr = len; | 365 | nAddr = len; |
| 336 | } | 366 | } |
| 337 | else | 367 | else |
| 368 | { | ||
| 369 | error("SOCKS5 CONNECT reply has invalid address type 0x%02x for %s:%u\n", | ||
| 370 | (unsigned)rep[3], destHost.c_str(), (unsigned)destPort); | ||
| 338 | return false; | 371 | return false; |
| 372 | } | ||
| 339 | 373 | ||
| 340 | std::vector<unsigned char> discard(nAddr + 2); | 374 | std::vector<unsigned char> discard(nAddr + 2); |
| 341 | return ReadN(s, &discard[0], (int)discard.size()); | 375 | if (!ReadN(s, &discard[0], (int)discard.size())) |
| 376 | { | ||
| 377 | error("SOCKS5 CONNECT bind address read failed for %s:%u\n", | ||
| 378 | destHost.c_str(), (unsigned)destPort); | ||
| 379 | return false; | ||
| 380 | } | ||
| 381 | return true; | ||
| 342 | } | 382 | } |
| 343 | 383 | ||
| 344 | SOCKET BtfConnectSocket(const std::string& destHost, unsigned short destPort, | 384 | SOCKET BtfConnectSocket(const std::string& destHost, unsigned short destPort, |
| @@ -347,9 +387,11 @@ SOCKET BtfConnectSocket(const std::string& destHost, unsigned short destPort, | |||
| 347 | std::string proxyHost; | 387 | std::string proxyHost; |
| 348 | unsigned short proxyPort = 0; | 388 | unsigned short proxyPort = 0; |
| 349 | bool fProxy = false; | 389 | bool fProxy = false; |
| 390 | bool fTorProxy = false; | ||
| 350 | CRITICAL_BLOCK(cs_socks5) | 391 | CRITICAL_BLOCK(cs_socks5) |
| 351 | { | 392 | { |
| 352 | fProxy = g_fSocks5Proxy; | 393 | fProxy = g_fSocks5Proxy; |
| 394 | fTorProxy = g_fTorProxy; | ||
| 353 | proxyHost = g_socks5Host; | 395 | proxyHost = g_socks5Host; |
| 354 | proxyPort = g_socks5Port; | 396 | proxyPort = g_socks5Port; |
| 355 | } | 397 | } |
| @@ -365,6 +407,9 @@ SOCKET BtfConnectSocket(const std::string& destHost, unsigned short destPort, | |||
| 365 | return ConnectDirect(destHost, destPort, nSockSite, nTimeoutSecs); | 407 | return ConnectDirect(destHost, destPort, nSockSite, nTimeoutSecs); |
| 366 | } | 408 | } |
| 367 | 409 | ||
| 410 | if (fTorProxy && nTimeoutSecs > 0 && nTimeoutSecs < TOR_CONNECT_TIMEOUT_SECS) | ||
| 411 | nTimeoutSecs = TOR_CONNECT_TIMEOUT_SECS; | ||
| 412 | |||
| 368 | SOCKET s = ConnectDirect(proxyHost, proxyPort, nSockSite, nTimeoutSecs); | 413 | SOCKET s = ConnectDirect(proxyHost, proxyPort, nSockSite, nTimeoutSecs); |
| 369 | if (s == INVALID_SOCKET) | 414 | if (s == INVALID_SOCKET) |
| 370 | return INVALID_SOCKET; | 415 | return INVALID_SOCKET; |