Implements #9836
- Add flag to ADD_ONION command
- Provide a way for external configuration
Implements #9836
371 | @@ -372,6 +372,8 @@ class TorController 372 | bool reconnect; 373 | struct event *reconnect_ev; 374 | float reconnect_timeout; 375 | + /** Flag for Single Onion Service */ 376 | + bool non_anonymous;
+1 on calling this flag non_anonymous
415 | @@ -414,6 +416,9 @@ TorController::TorController(struct event_base* _base, const std::string& _targe 416 | LogPrint(BCLog::TOR, "tor: Reading cached private key from %s\n", GetPrivateKeyFile()); 417 | private_key = pkf.second; 418 | } 419 | + // Set Single Onion Service flag 420 | + // TODO: provide a way to configure it externally 421 | + non_anonymous = false;
As for option: maybe -listenonion=2?
Yes, thanks for the advice. That should be OK. Will finish it this evening.
415 | @@ -414,6 +416,12 @@ TorController::TorController(struct event_base* _base, const std::string& _targe 416 | LogPrint(BCLog::TOR, "tor: Reading cached private key from %s\n", GetPrivateKeyFile()); 417 | private_key = pkf.second; 418 | } 419 | + // Set Single Onion Service flag 420 | + if (mode == 1)
Having -listenonion=<n> flag requires allowed values checks and isn't obvious enough as for anonymous/non-anonymous service option. Maybe it would be better to just add another boolean flag instead, with some obvious name?
Yeah could do that. Though I think the number of options of bitcoind is kind of getting out of hand, and this seems quite obscure so I don't mind hiding it a bit. Could wait and see what other dev's opinions about this are.
Added allowed values check for -listenonion and mentioned it in documentation.
I am unable to reproduce this failure on my machine. Any advise on what might cause it?
101 | @@ -102,7 +102,9 @@ affect the number of available .onion nodes. 102 | This new feature is enabled by default if Bitcoin Core is listening (`-listen`), and 103 | requires a Tor connection to work. It can be explicitly disabled with `-listenonion=0` 104 | and, if not disabled, configured using the `-torcontrol` and `-torpassword` settings. 105 | -To show verbose debugging information, pass `-debug=tor`. 106 | +To show verbose debugging information, pass `-debug=tor`. Hidded service can also be
language: Hidded -> Hidden
Thanks for a thorough review!
380 | @@ -381,7 +381,7 @@ std::string HelpMessage(HelpMessageMode mode) 381 | strUsage += HelpMessageOpt("-externalip=<ip>", _("Specify your own public address")); 382 | strUsage += HelpMessageOpt("-forcednsseed", strprintf(_("Always query for peer addresses via DNS lookup (default: %u)"), DEFAULT_FORCEDNSSEED)); 383 | strUsage += HelpMessageOpt("-listen", _("Accept connections from outside (default: 1 if no -proxy or -connect)")); 384 | - strUsage += HelpMessageOpt("-listenonion", strprintf(_("Automatically create Tor hidden service (default: %d)"), DEFAULT_LISTEN_ONION)); 385 | + strUsage += HelpMessageOpt("-listenonion", strprintf(_("Run Tor hidden service (0 - disabled, 1 - normal mode, 2 - single onion service, default: %d)"), DEFAULT_LISTEN_ONION));
I'm assuming the problem will be with %d and int64_t. I see you've changed DEFAULT_LISTEN_ONION from a bool to int64_t but did not change it here.
The format for int64_t (to (str)printf etc) is typically
I suspect int64_t might not be the right type to use for DEFAULT_LISTEN_ONION.
Oh, right, that was lame. Thanks for pointing it out.
We don't use the OS' printf function but tinyformat, so you must use %d for any kind of integer. It doesn't understand most of the size specifiers and ignores them as it's typesafe and regards the actual argument types.
10 | @@ -11,7 +11,7 @@ 11 | #include "scheduler.h" 12 | 13 | extern const std::string DEFAULT_TOR_CONTROL; 14 | -static const bool DEFAULT_LISTEN_ONION = true; 15 | +static const std::string DEFAULT_LISTEN_ONION = "0";
String constant cannot be defined reliably in headers. It must be extern and defined in a c++ file. Otherwise it will get included into every single compilation unit that includes this header. Sometimes that runs into linker errors or causes executable bloat at the least.
Yes thanks, my bad. It's been a long time without c++ preprocessor.
396 | @@ -395,7 +397,7 @@ class TorController 397 | static void reconnect_cb(evutil_socket_t fd, short what, void *arg); 398 | }; 399 | 400 | -TorController::TorController(struct event_base* _base, const std::string& _target): 401 | +TorController::TorController(struct event_base* _base, const std::string& _target, const std::string& mode):
Please make this interface take an enum mode, to make the available choices clear in the API and to maintainers of this code.
Conversion between the argument and the enum should be done outside this class at the call site
(for example TorControlThread())
Thought of enum in the first place, but then Ocham's razor principle, don't multiply entities etc:) Anyway, done.
@mrwhythat Agreed. And sure, makes sense to keep the branch, maybe someone wants to add this patch manually, doesn't hurt to have the code available.