Check for unknown command line parameters

pull/137/head
SChernykh 2 years ago
parent 272d206741
commit de9f13d393

@ -21,7 +21,7 @@
#include "stratum_server.h" #include "stratum_server.h"
#include "p2p_server.h" #include "p2p_server.h"
static void usage() void p2pool_usage()
{ {
printf("P2Pool %s\n" printf("P2Pool %s\n"
"\nUsage:\n\n" \ "\nUsage:\n\n" \
@ -68,13 +68,13 @@ void memory_tracking_stop();
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
if (argc == 1) { if (argc == 1) {
usage(); p2pool_usage();
return 0; return 0;
} }
for (int i = 1; i < argc; ++i) { for (int i = 1; i < argc; ++i) {
if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "/help") || !strcmp(argv[i], "-h") || !strcmp(argv[i], "/h")) { if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "/help") || !strcmp(argv[i], "-h") || !strcmp(argv[i], "/h")) {
usage(); p2pool_usage();
return 0; return 0;
} }
} }

@ -20,86 +20,115 @@
#include "stratum_server.h" #include "stratum_server.h"
#include "p2p_server.h" #include "p2p_server.h"
void p2pool_usage();
namespace p2pool { namespace p2pool {
Params::Params(int argc, char* argv[]) Params::Params(int argc, char* argv[])
{ {
for (int i = 1; i < argc; ++i) { for (int i = 1; i < argc; ++i) {
bool ok = false;
if ((strcmp(argv[i], "--host") == 0) && (i + 1 < argc)) { if ((strcmp(argv[i], "--host") == 0) && (i + 1 < argc)) {
m_host = argv[++i]; m_host = argv[++i];
ok = true;
} }
if ((strcmp(argv[i], "--rpc-port") == 0) && (i + 1 < argc)) { if ((strcmp(argv[i], "--rpc-port") == 0) && (i + 1 < argc)) {
m_rpcPort = strtoul(argv[++i], nullptr, 10); m_rpcPort = strtoul(argv[++i], nullptr, 10);
ok = true;
} }
if ((strcmp(argv[i], "--zmq-port") == 0) && (i + 1 < argc)) { if ((strcmp(argv[i], "--zmq-port") == 0) && (i + 1 < argc)) {
m_zmqPort = strtoul(argv[++i], nullptr, 10); m_zmqPort = strtoul(argv[++i], nullptr, 10);
ok = true;
} }
if (strcmp(argv[i], "--light-mode") == 0) { if (strcmp(argv[i], "--light-mode") == 0) {
m_lightMode = true; m_lightMode = true;
ok = true;
} }
if ((strcmp(argv[i], "--wallet") == 0) && (i + 1 < argc)) { if ((strcmp(argv[i], "--wallet") == 0) && (i + 1 < argc)) {
m_wallet.decode(argv[++i]); m_wallet.decode(argv[++i]);
ok = true;
} }
if ((strcmp(argv[i], "--stratum") == 0) && (i + 1 < argc)) { if ((strcmp(argv[i], "--stratum") == 0) && (i + 1 < argc)) {
m_stratumAddresses = argv[++i]; m_stratumAddresses = argv[++i];
ok = true;
} }
if ((strcmp(argv[i], "--p2p") == 0) && (i + 1 < argc)) { if ((strcmp(argv[i], "--p2p") == 0) && (i + 1 < argc)) {
m_p2pAddresses = argv[++i]; m_p2pAddresses = argv[++i];
ok = true;
} }
if ((strcmp(argv[i], "--addpeers") == 0) && (i + 1 < argc)) { if ((strcmp(argv[i], "--addpeers") == 0) && (i + 1 < argc)) {
m_p2pPeerList = argv[++i]; m_p2pPeerList = argv[++i];
ok = true;
} }
if ((strcmp(argv[i], "--loglevel") == 0) && (i + 1 < argc)) { if ((strcmp(argv[i], "--loglevel") == 0) && (i + 1 < argc)) {
const int level = std::min(std::max<int>(strtol(argv[++i], nullptr, 10), 0), log::MAX_GLOBAL_LOG_LEVEL); const int level = std::min(std::max<int>(strtol(argv[++i], nullptr, 10), 0), log::MAX_GLOBAL_LOG_LEVEL);
log::GLOBAL_LOG_LEVEL = level; log::GLOBAL_LOG_LEVEL = level;
ok = true;
} }
if ((strcmp(argv[i], "--config") == 0) && (i + 1 < argc)) { if ((strcmp(argv[i], "--config") == 0) && (i + 1 < argc)) {
m_config = argv[++i]; m_config = argv[++i];
ok = true;
} }
if ((strcmp(argv[i], "--data-api") == 0) && (i + 1 < argc)) { if ((strcmp(argv[i], "--data-api") == 0) && (i + 1 < argc)) {
m_apiPath = argv[++i]; m_apiPath = argv[++i];
ok = true;
} }
if ((strcmp(argv[i], "--local-api") == 0) || (strcmp(argv[i], "--stratum-api") == 0)) { if ((strcmp(argv[i], "--local-api") == 0) || (strcmp(argv[i], "--stratum-api") == 0)) {
m_localStats = true; m_localStats = true;
ok = true;
} }
if (strcmp(argv[i], "--no-cache") == 0) { if (strcmp(argv[i], "--no-cache") == 0) {
m_blockCache = false; m_blockCache = false;
ok = true;
} }
if (strcmp(argv[i], "--no-color") == 0) { if (strcmp(argv[i], "--no-color") == 0) {
log::CONSOLE_COLORS = false; log::CONSOLE_COLORS = false;
ok = true;
} }
if (strcmp(argv[i], "--no-randomx") == 0) { if (strcmp(argv[i], "--no-randomx") == 0) {
m_disableRandomX = true; m_disableRandomX = true;
ok = true;
} }
if ((strcmp(argv[i], "--out-peers") == 0) && (i + 1 < argc)) { if ((strcmp(argv[i], "--out-peers") == 0) && (i + 1 < argc)) {
m_maxOutgoingPeers = std::min(std::max(strtoul(argv[++i], nullptr, 10), 10UL), 1000UL); m_maxOutgoingPeers = std::min(std::max(strtoul(argv[++i], nullptr, 10), 10UL), 1000UL);
ok = true;
} }
if ((strcmp(argv[i], "--in-peers") == 0) && (i + 1 < argc)) { if ((strcmp(argv[i], "--in-peers") == 0) && (i + 1 < argc)) {
m_maxIncomingPeers = std::min(std::max(strtoul(argv[++i], nullptr, 10), 10UL), 1000UL); m_maxIncomingPeers = std::min(std::max(strtoul(argv[++i], nullptr, 10), 10UL), 1000UL);
ok = true;
} }
if ((strcmp(argv[i], "--start-mining") == 0) && (i + 1 < argc)) { if ((strcmp(argv[i], "--start-mining") == 0) && (i + 1 < argc)) {
m_minerThreads = std::min(std::max(strtoul(argv[++i], nullptr, 10), 1UL), 64UL); m_minerThreads = std::min(std::max(strtoul(argv[++i], nullptr, 10), 1UL), 64UL);
ok = true;
} }
if (strcmp(argv[i], "--mini") == 0) { if (strcmp(argv[i], "--mini") == 0) {
m_mini = true; m_mini = true;
ok = true;
}
if (!ok) {
fprintf(stderr, "Unknown command line parameter %s\n\n", argv[i]);
p2pool_usage();
panic();
} }
} }

Loading…
Cancel
Save