diff --git a/src/App.cpp b/src/App.cpp index 28e61df31..83ead3af6 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -81,7 +81,7 @@ App::App(int argc, char **argv) : } # endif - Platform::init(); + Platform::init(m_options->userAgent()); Platform::setProcessPriority(m_options->priority()); m_network = new Network(m_options); diff --git a/src/Options.cpp b/src/Options.cpp index 9d2e35042..95d099d51 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -67,6 +67,7 @@ Options:\n\ --cpu-priority set process priority (0 idle, 2 normal to 5 highest)\n\ --no-color disable colored output\n\ --donate-level=N donate level, default 5%% (5 minutes in 100 minutes)\n\ + --user-agent set custom user-agent string for pool\n\ -B, --background run the miner in the background\n\ -c, --config=FILE load a JSON-format configuration file\n\ -l, --log-file=FILE log all output to a file\n" @@ -110,6 +111,7 @@ static struct option const options[] = { { "threads", 1, nullptr, 't' }, { "url", 1, nullptr, 'o' }, { "user", 1, nullptr, 'u' }, + { "user-agent", 1, nullptr, 1008 }, { "userpass", 1, nullptr, 'O' }, { "version", 0, nullptr, 'V' }, { 0, 0, 0, 0 } @@ -120,6 +122,7 @@ static struct option const config_options[] = { { "algo", 1, nullptr, 'a' }, { "av", 1, nullptr, 'v' }, { "background", 0, nullptr, 'B' }, + { "colors", 0, nullptr, 2000 }, { "cpu-affinity", 1, nullptr, 1020 }, { "cpu-priority", 1, nullptr, 1021 }, { "donate-level", 1, nullptr, 1003 }, @@ -131,7 +134,7 @@ static struct option const config_options[] = { { "safe", 0, nullptr, 1005 }, { "syslog", 0, nullptr, 'S' }, { "threads", 1, nullptr, 't' }, - { "colors", 0, nullptr, 2000 }, + { "user-agent", 1, nullptr, 1008 }, { 0, 0, 0, 0 } }; @@ -182,6 +185,7 @@ Options::Options(int argc, char **argv) : m_safe(false), m_syslog(false), m_logFile(nullptr), + m_userAgent(nullptr), m_algo(0), m_algoVariant(0), m_donateLevel(kDonateLevel), @@ -329,6 +333,11 @@ bool Options::parseArg(int key, const char *arg) return parseArg(key, p ? strtoull(p, nullptr, 16) : strtoull(arg, nullptr, 10)); } + case 1008: /* --user-agent */ + free(m_userAgent); + m_userAgent = strdup(arg); + break; + default: showUsage(1); return false; diff --git a/src/Options.h b/src/Options.h index 0e57100e3..ae2a29285 100644 --- a/src/Options.h +++ b/src/Options.h @@ -59,6 +59,7 @@ public: inline bool doubleHash() const { return m_doubleHash; } inline bool syslog() const { return m_syslog; } inline const char *logFile() const { return m_logFile; } + inline const char *userAgent() const { return m_userAgent; } inline const std::vector &pools() const { return m_pools; } inline int algo() const { return m_algo; } inline int algoVariant() const { return m_algoVariant; } @@ -105,6 +106,7 @@ private: bool m_safe; bool m_syslog; char *m_logFile; + char *m_userAgent; int m_algo; int m_algoVariant; int m_donateLevel; diff --git a/src/Platform.h b/src/Platform.h index 1c1d5ce9d..87c8cc4db 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -29,7 +29,7 @@ class Platform { public: static const char *defaultConfigName(); - static void init(); + static void init(const char *userAgent); static void release(); static void setProcessPriority(int priority); static void setThreadPriority(int priority); diff --git a/src/Platform_mac.cpp b/src/Platform_mac.cpp index f57c7ea1c..3b5daef59 100644 --- a/src/Platform_mac.cpp +++ b/src/Platform_mac.cpp @@ -42,9 +42,9 @@ static inline char *createUserAgent() } -void Platform::init() +void Platform::init(const char *userAgent) { - m_userAgent = createUserAgent(); + m_userAgent = userAgent ? strdup(userAgent) : createUserAgent(); } diff --git a/src/Platform_unix.cpp b/src/Platform_unix.cpp index 0873e954c..5a8271aba 100644 --- a/src/Platform_unix.cpp +++ b/src/Platform_unix.cpp @@ -53,9 +53,9 @@ static inline char *createUserAgent() } -void Platform::init() +void Platform::init(const char *userAgent) { - m_userAgent = createUserAgent(); + m_userAgent = userAgent ? strdup(userAgent) : createUserAgent(); } diff --git a/src/Platform_win.cpp b/src/Platform_win.cpp index 3d520586a..e61dc7735 100644 --- a/src/Platform_win.cpp +++ b/src/Platform_win.cpp @@ -73,9 +73,9 @@ static inline char *createUserAgent() } -void Platform::init() +void Platform::init(const char *userAgent) { - m_userAgent = createUserAgent(); + m_userAgent = userAgent ? strdup(userAgent) : createUserAgent(); }