upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/main_gui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main_gui.cpp')
-rw-r--r--src/main_gui.cpp65
1 files changed, 44 insertions, 21 deletions
diff --git a/src/main_gui.cpp b/src/main_gui.cpp
index 239fb60..deed471 100644
--- a/src/main_gui.cpp
+++ b/src/main_gui.cpp
@@ -4,6 +4,7 @@
4#include "nostr.h" 4#include "nostr.h"
5#include "proxy.h" 5#include "proxy.h"
6#include "selftest.h" 6#include "selftest.h"
7#include "tor.h"
7#include "walletcmd.h" 8#include "walletcmd.h"
8#include <thread> // hardware_concurrency, to sanity-check /genproclimit 9#include <thread> // hardware_concurrency, to sanity-check /genproclimit
9#ifndef _WIN32 10#ifndef _WIN32
@@ -113,7 +114,7 @@ static void PrintUsage()
113 printf(" /gen\n"); 114 printf(" /gen\n");
114 printf(" /nogui or /daemon\n"); 115 printf(" /nogui or /daemon\n");
115 printf(" /selftest=wallet-keypool, wallet-hd, wallet-format, wallet-crypto, wallet-encrypt,\n"); 116 printf(" /selftest=wallet-keypool, wallet-hd, wallet-format, wallet-crypto, wallet-encrypt,\n");
116 printf(" net-message, consensus-limits, pool-stratum, parse-money, or socks5-proxy\n"); 117 printf(" net-message, consensus-limits, pool-stratum, parse-money, socks5-proxy, or managed-tor\n");
117 printf("\n"); 118 printf("\n");
118 printf("Mining mode:\n"); 119 printf("Mining mode:\n");
119 printf(" /operator\n"); 120 printf(" /operator\n");
@@ -141,6 +142,7 @@ static void PrintUsage()
141 printf(" /port=N (P2P listen port, default 8433)\n"); 142 printf(" /port=N (P2P listen port, default 8433)\n");
142 printf(" /socks=HOST:PORT (SOCKS5 proxy for Nostr, .btf relay, and onion dials)\n"); 143 printf(" /socks=HOST:PORT (SOCKS5 proxy for Nostr, .btf relay, and onion dials)\n");
143 printf(" /tor[=HOST:PORT] (Tor mode; default SOCKS5 proxy is 127.0.0.1:9050)\n"); 144 printf(" /tor[=HOST:PORT] (Tor mode; default SOCKS5 proxy is 127.0.0.1:9050)\n");
145 printf(" /managedtor[=PATH] (start Tor, create a hidden service, advertise its onion)\n");
144 printf(" /btfseed=ADDRESS:ENCHEX (extra bootstrap peer, repeatable)\n"); 146 printf(" /btfseed=ADDRESS:ENCHEX (extra bootstrap peer, repeatable)\n");
145 printf("\n"); 147 printf("\n");
146 printf("Wallet:\n"); 148 printf("Wallet:\n");
@@ -284,6 +286,24 @@ static void ParseStartupArguments(int argc, char* argv[])
284 vBtfMeetingRelays.push_back(rvRelay); 286 vBtfMeetingRelays.push_back(rvRelay);
285 } 287 }
286 288
289 // net.cpp has described nListenPort as "tunable via /port" since it was
290 // written, but nothing ever read the option, so the port was fixed at 8433
291 // and a second node could not start on a machine already running one. Parse
292 // it before Tor setup so a managed hidden service maps the real listener.
293 string strPort = argval2(argc, argv, "/port", "-port");
294 if (!strPort.empty())
295 {
296 int nPort = atoi(strPort.c_str());
297 if (nPort <= 0 || nPort > 65535)
298 fprintf(stderr, "Ignoring /port=%s: not a port number\n", strPort.c_str());
299 else
300 {
301 nListenPort = htons((unsigned short)nPort);
302 // Or we would announce a port we never bound.
303 addrLocalHost.port = nListenPort;
304 }
305 }
306
287 string announceRelay = argval2(argc, argv, "/announcerelay", "-announcerelay"); 307 string announceRelay = argval2(argc, argv, "/announcerelay", "-announcerelay");
288 if (!announceRelay.empty()) 308 if (!announceRelay.empty())
289 strBtfAnnounceRelay = announceRelay; 309 strBtfAnnounceRelay = announceRelay;
@@ -299,10 +319,23 @@ static void ParseStartupArguments(int argc, char* argv[])
299 BtfLocalOnionEndpoint().c_str()); 319 BtfLocalOnionEndpoint().c_str());
300 } 320 }
301 321
322 bool fManagedTor = arg(argc, argv, "/managedtor") || arg(argc, argv, "-managedtor");
302 bool fTorMode = arg(argc, argv, "/tor") || arg(argc, argv, "-tor"); 323 bool fTorMode = arg(argc, argv, "/tor") || arg(argc, argv, "-tor");
303 if (fTorMode) 324 string socksProxy = argval2(argc, argv, "/socks", "-socks");
325 if (fManagedTor)
326 {
327 if (fTorMode || !socksProxy.empty())
328 fprintf(stderr, "Warning: /managedtor takes precedence over /tor and /socks\n");
329
330 string torPath = argval2(argc, argv, "/managedtor", "-managedtor");
331 string err;
332 if (!BtfStartManagedTor(torPath, err))
333 fprintf(stderr, "Ignoring /managedtor=%s: %s\n", torPath.c_str(), err.c_str());
334 else
335 fprintf(stderr, "Managed Tor enabled: %s\n", BtfManagedTorStatus().c_str());
336 }
337 else if (fTorMode)
304 { 338 {
305 string socksProxy = argval2(argc, argv, "/socks", "-socks");
306 if (!socksProxy.empty()) 339 if (!socksProxy.empty())
307 fprintf(stderr, "Warning: /tor takes precedence over /socks=%s\n", 340 fprintf(stderr, "Warning: /tor takes precedence over /socks=%s\n",
308 socksProxy.c_str()); 341 socksProxy.c_str());
@@ -317,7 +350,6 @@ static void ParseStartupArguments(int argc, char* argv[])
317 } 350 }
318 else 351 else
319 { 352 {
320 string socksProxy = argval2(argc, argv, "/socks", "-socks");
321 if (!socksProxy.empty()) 353 if (!socksProxy.empty())
322 { 354 {
323 string err; 355 string err;
@@ -348,22 +380,6 @@ static void ParseStartupArguments(int argc, char* argv[])
348 vBtfExtraSeeds.push_back(make_pair(val.substr(0, colon), val.substr(colon + 1))); 380 vBtfExtraSeeds.push_back(make_pair(val.substr(0, colon), val.substr(colon + 1)));
349 } 381 }
350 382
351 // net.cpp has described nListenPort as "tunable via /port" since it was
352 // written, but nothing ever read the option, so the port was fixed at 8433
353 // and a second node could not start on a machine already running one.
354 string strPort = argval2(argc, argv, "/port", "-port");
355 if (!strPort.empty())
356 {
357 int nPort = atoi(strPort.c_str());
358 if (nPort <= 0 || nPort > 65535)
359 fprintf(stderr, "Ignoring /port=%s: not a port number\n", strPort.c_str());
360 else
361 {
362 nListenPort = htons((unsigned short)nPort);
363 // Or we would announce a port we never bound.
364 addrLocalHost.port = nListenPort;
365 }
366 }
367} 383}
368 384
369// Report a startup failure somewhere the user will actually see it. 385// Report a startup failure somewhere the user will actually see it.
@@ -715,7 +731,12 @@ int main(int argc, char* argv[])
715 731
716 ReacceptWalletTransactions(); 732 ReacceptWalletTransactions();
717 733
718 if (!StartNode(strErrors)) { fprintf(stderr,"StartNode: %s\n",strErrors.c_str()); return 1; } 734 if (!StartNode(strErrors))
735 {
736 fprintf(stderr,"StartNode: %s\n",strErrors.c_str());
737 BtfStopManagedTor();
738 return 1;
739 }
719 740
720 if (nMineMode == MINE_OPERATOR) { 741 if (nMineMode == MINE_OPERATOR) {
721 gPoolServerRunning = true; 742 gPoolServerRunning = true;
@@ -748,6 +769,7 @@ int main(int argc, char* argv[])
748 printf("Running headless. Ctrl-C to stop.\n"); 769 printf("Running headless. Ctrl-C to stop.\n");
749 while (!fShutdown) Sleep(500); 770 while (!fShutdown) Sleep(500);
750 StopNode(); 771 StopNode();
772 BtfStopManagedTor();
751 // Checkpoints, releases wallet.dat from this directory's Berkeley DB 773 // Checkpoints, releases wallet.dat from this directory's Berkeley DB
752 // environment, and closes it. Declared since 2009 and never once 774 // environment, and closes it. Declared since 2009 and never once
753 // called here, which is why a wallet.dat copied elsewhere would not 775 // called here, which is why a wallet.dat copied elsewhere would not
@@ -767,6 +789,7 @@ int main(int argc, char* argv[])
767 int ret = RunGUI(argc, argv); 789 int ret = RunGUI(argc, argv);
768 fShutdown = true; 790 fShutdown = true;
769 StopNode(); 791 StopNode();
792 BtfStopManagedTor();
770 DBFlush(true); 793 DBFlush(true);
771 return ret; 794 return ret;
772#endif 795#endif