Skip to content

Commit d3e837a

Browse files
committed
merge bitcoin#24830: Allow -proxy="" setting values
1 parent 0e01d5b commit d3e837a

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

src/init.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ void SetupServerArgs(ArgsManager& argsman)
583583
argsman.AddArg("-peertimeout=<n>", strprintf("Specify a p2p connection timeout delay in seconds. After connecting to a peer, wait this amount of time before considering disconnection based on inactivity (minimum: 1, default: %d)", DEFAULT_PEER_CONNECT_TIMEOUT), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
584584
argsman.AddArg("-permitbaremultisig", strprintf("Relay non-P2SH multisig (default: %u)", DEFAULT_PERMIT_BAREMULTISIG), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
585585
argsman.AddArg("-port=<port>", strprintf("Listen for connections on <port>. Nodes not using the default ports (default: %u, testnet: %u, regtest: %u) are unlikely to get incoming connections. Not relevant for I2P (see doc/i2p.md).", defaultChainParams->GetDefaultPort(), testnetChainParams->GetDefaultPort(), regtestChainParams->GetDefaultPort()), ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::CONNECTION);
586-
argsman.AddArg("-proxy=<ip:port>", "Connect through SOCKS5 proxy, set -noproxy to disable (default: disabled)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
586+
argsman.AddArg("-proxy=<ip:port>", "Connect through SOCKS5 proxy, set -noproxy to disable (default: disabled)", ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_ELISION, OptionsCategory::CONNECTION);
587587
argsman.AddArg("-proxyrandomize", strprintf("Randomize credentials for every proxy connection. This enables Tor stream isolation (default: %u)", DEFAULT_PROXYRANDOMIZE), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
588588
argsman.AddArg("-seednode=<ip>", "Connect to a node to retrieve peer addresses, and disconnect. This option can be specified multiple times to connect to multiple nodes.", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
589589
argsman.AddArg("-socketevents=<mode>", "Socket events mode, which must be one of 'select', 'poll', 'epoll' or 'kqueue', depending on your system (default: Linux - 'epoll', FreeBSD/Apple - 'kqueue', Windows - 'select')", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
@@ -1337,10 +1337,6 @@ bool AppInitParameterInteraction(const ArgsManager& args)
13371337

13381338
nMaxTipAge = args.GetArg("-maxtipage", DEFAULT_MAX_TIP_AGE);
13391339

1340-
if (args.IsArgSet("-proxy") && args.GetArg("-proxy", "").empty()) {
1341-
return InitError(_("No proxy server specified. Use -proxy=<ip> or -proxy=<ip:port>."));
1342-
}
1343-
13441340
if (args.GetBoolArg("-reindex-chainstate", false)) {
13451341
// indexes that must be deactivated to prevent index corruption, see #24630
13461342
if (args.GetBoolArg("-coinstatsindex", DEFAULT_COINSTATSINDEX)) {

src/util/system.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ KeyInfo InterpretKey(std::string key)
248248
* @return parsed settings value if it is valid, otherwise nullopt accompanied
249249
* by a descriptive error string
250250
*/
251-
static std::optional<util::SettingsValue> InterpretValue(const KeyInfo& key, const std::string& value,
251+
static std::optional<util::SettingsValue> InterpretValue(const KeyInfo& key, const std::string* value,
252252
unsigned int flags, std::string& error)
253253
{
254254
// Return negated settings as false values.
@@ -258,13 +258,17 @@ static std::optional<util::SettingsValue> InterpretValue(const KeyInfo& key, con
258258
return std::nullopt;
259259
}
260260
// Double negatives like -nofoo=0 are supported (but discouraged)
261-
if (!InterpretBool(value)) {
262-
LogPrintf("Warning: parsed potentially confusing double-negative -%s=%s\n", key.name, value);
261+
if (value && !InterpretBool(*value)) {
262+
LogPrintf("Warning: parsed potentially confusing double-negative -%s=%s\n", key.name, *value);
263263
return true;
264264
}
265265
return false;
266266
}
267-
return value;
267+
if (!value && (flags & ArgsManager::DISALLOW_ELISION)) {
268+
error = strprintf("Can not set -%s with no value. Please specify value with -%s=value.", key.name, key.name);
269+
return std::nullopt;
270+
}
271+
return value ? *value : "";
268272
}
269273

270274
// Define default constructor and destructor that are not inline, so code instantiating this class doesn't need to
@@ -337,7 +341,7 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
337341
if (key.substr(0, 5) == "-psn_") continue;
338342
#endif
339343

340-
std::string val;
344+
std::optional<std::string> val;
341345
size_t is_index = key.find('=');
342346
if (is_index != std::string::npos) {
343347
val = key.substr(is_index + 1);
@@ -383,7 +387,7 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
383387
return false;
384388
}
385389

386-
std::optional<util::SettingsValue> value = InterpretValue(keyinfo, val, *flags, error);
390+
std::optional<util::SettingsValue> value = InterpretValue(keyinfo, val ? &*val : nullptr, *flags, error);
387391
if (!value) return false;
388392

389393
m_settings.command_line_options[keyinfo.name].push_back(*value);
@@ -934,7 +938,7 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& file
934938
KeyInfo key = InterpretKey(option.first);
935939
std::optional<unsigned int> flags = GetArgFlags('-' + key.name);
936940
if (flags) {
937-
std::optional<util::SettingsValue> value = InterpretValue(key, option.second, *flags, error);
941+
std::optional<util::SettingsValue> value = InterpretValue(key, &option.second, *flags, error);
938942
if (!value) {
939943
return false;
940944
}

src/util/system.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ class ArgsManager
189189
ALLOW_STRING = 0x08, //!< unimplemented, draft implementation in #16545
190190
ALLOW_LIST = 0x10, //!< unimplemented, draft implementation in #16545
191191
DISALLOW_NEGATION = 0x20, //!< disallow -nofoo syntax
192+
DISALLOW_ELISION = 0x40, //!< disallow -foo syntax that doesn't assign any value
192193

193194
DEBUG_ONLY = 0x100,
194195
/* Some options would cause cross-contamination if values for

test/functional/feature_config_args.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def test_config_file_parser(self):
8484

8585
def test_invalid_command_line_options(self):
8686
self.nodes[0].assert_start_raises_init_error(
87-
expected_msg='Error: No proxy server specified. Use -proxy=<ip> or -proxy=<ip:port>.',
87+
expected_msg='Error: Error parsing command line arguments: Can not set -proxy with no value. Please specify value with -proxy=value.',
8888
extra_args=['-proxy'],
8989
)
9090

0 commit comments

Comments
 (0)