mirror of
https://github.com/xmrig/xmrig.git
synced 2024-11-17 00:07:44 +00:00
Add support for skip invalid pools.
This commit is contained in:
parent
230962230f
commit
bc2660f509
7 changed files with 45 additions and 25 deletions
|
@ -55,7 +55,8 @@ xmrig::CommonConfig::CommonConfig() :
|
|||
m_donateLevel(kDefaultDonateLevel),
|
||||
m_printTime(60),
|
||||
m_retries(5),
|
||||
m_retryPause(5)
|
||||
m_retryPause(5),
|
||||
m_state(NoneState)
|
||||
{
|
||||
m_pools.push_back(Pool());
|
||||
|
||||
|
@ -71,13 +72,15 @@ xmrig::CommonConfig::~CommonConfig()
|
|||
}
|
||||
|
||||
|
||||
bool xmrig::CommonConfig::adjust()
|
||||
bool xmrig::CommonConfig::finalize()
|
||||
{
|
||||
if (m_adjusted) {
|
||||
return false;
|
||||
if (m_state == ReadyState) {
|
||||
return true;
|
||||
}
|
||||
|
||||
m_adjusted = true;
|
||||
if (m_state == ErrorState) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_algorithm.isValid()) {
|
||||
m_algorithm.setAlgo(CRYPTONIGHT);
|
||||
|
@ -85,18 +88,24 @@ bool xmrig::CommonConfig::adjust()
|
|||
|
||||
for (Pool &pool : m_pools) {
|
||||
pool.adjust(m_algorithm.algo());
|
||||
|
||||
if (pool.isValid() && pool.algorithm().isValid()) {
|
||||
m_activePools.push_back(std::move(pool));
|
||||
}
|
||||
}
|
||||
|
||||
m_pools.clear();
|
||||
|
||||
if (m_activePools.empty()) {
|
||||
m_state = ErrorState;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_state = ReadyState;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::CommonConfig::isValid() const
|
||||
{
|
||||
return m_pools[0].isValid() && m_algorithm.isValid();
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::CommonConfig::parseBoolean(int key, bool enable)
|
||||
{
|
||||
switch (key) {
|
||||
|
|
|
@ -53,7 +53,7 @@ public:
|
|||
inline const char *apiWorkerId() const { return m_apiWorkerId.data(); }
|
||||
inline const char *logFile() const { return m_logFile.data(); }
|
||||
inline const char *userAgent() const { return m_userAgent.data(); }
|
||||
inline const std::vector<Pool> &pools() const { return m_pools; }
|
||||
inline const std::vector<Pool> &pools() const { return m_activePools; }
|
||||
inline int apiPort() const { return m_apiPort; }
|
||||
inline int donateLevel() const { return m_donateLevel; }
|
||||
inline int printTime() const { return m_printTime; }
|
||||
|
@ -65,8 +65,13 @@ public:
|
|||
inline const char *fileName() const override { return m_fileName.data(); }
|
||||
|
||||
protected:
|
||||
bool adjust() override;
|
||||
bool isValid() const override;
|
||||
enum State {
|
||||
NoneState,
|
||||
ReadyState,
|
||||
ErrorState
|
||||
};
|
||||
|
||||
bool finalize() override;
|
||||
bool parseBoolean(int key, bool enable) override;
|
||||
bool parseString(int key, const char *arg) override;
|
||||
bool parseUint64(int key, uint64_t arg) override;
|
||||
|
@ -86,6 +91,8 @@ protected:
|
|||
int m_printTime;
|
||||
int m_retries;
|
||||
int m_retryPause;
|
||||
State m_state;
|
||||
std::vector<Pool> m_activePools;
|
||||
std::vector<Pool> m_pools;
|
||||
xmrig::c_str m_apiToken;
|
||||
xmrig::c_str m_apiWorkerId;
|
||||
|
|
|
@ -108,9 +108,8 @@ bool xmrig::ConfigLoader::loadFromJSON(xmrig::IConfig *config, const rapidjson::
|
|||
}
|
||||
|
||||
config->parseJSON(doc);
|
||||
config->adjust();
|
||||
|
||||
return config->isValid();
|
||||
return config->finalize();
|
||||
}
|
||||
|
||||
|
||||
|
@ -163,11 +162,14 @@ xmrig::IConfig *xmrig::ConfigLoader::load(int argc, char **argv, IConfigCreator
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
if (!config->isValid()) {
|
||||
if (!config->finalize()) {
|
||||
delete config;
|
||||
|
||||
config = m_creator->create();
|
||||
loadFromFile(config, Platform::defaultConfigName());
|
||||
}
|
||||
|
||||
if (!config->isValid()) {
|
||||
if (!config->finalize()) {
|
||||
fprintf(stderr, "No valid configuration found. Exiting.\n");
|
||||
delete config;
|
||||
return nullptr;
|
||||
|
@ -177,7 +179,6 @@ xmrig::IConfig *xmrig::ConfigLoader::load(int argc, char **argv, IConfigCreator
|
|||
m_watcher = new xmrig::ConfigWatcher(config->fileName(), creator, listener);
|
||||
}
|
||||
|
||||
config->adjust();
|
||||
return config;
|
||||
}
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ void xmrig::ConfigWatcher::reload()
|
|||
IConfig *config = m_creator->create();
|
||||
ConfigLoader::loadFromFile(config, m_path.data());
|
||||
|
||||
if (!config->isValid()) {
|
||||
if (!config->finalize()) {
|
||||
LOG_ERR("reloading failed");
|
||||
|
||||
delete config;
|
||||
|
|
|
@ -141,9 +141,13 @@ xmrig::Config *xmrig::Config::load(int argc, char **argv, IWatcherListener *list
|
|||
}
|
||||
|
||||
|
||||
bool xmrig::Config::adjust()
|
||||
bool xmrig::Config::finalize()
|
||||
{
|
||||
if (!CommonConfig::adjust()) {
|
||||
if (m_state != NoneState) {
|
||||
return CommonConfig::finalize();
|
||||
}
|
||||
|
||||
if (!CommonConfig::finalize()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ public:
|
|||
static Config *load(int argc, char **argv, IWatcherListener *listener);
|
||||
|
||||
protected:
|
||||
bool adjust() override;
|
||||
bool finalize() override;
|
||||
bool parseBoolean(int key, bool enable) override;
|
||||
bool parseString(int key, const char *arg) override;
|
||||
bool parseUint64(int key, uint64_t arg) override;
|
||||
|
|
|
@ -91,8 +91,7 @@ public:
|
|||
|
||||
virtual ~IConfig() {}
|
||||
|
||||
virtual bool adjust() = 0;
|
||||
virtual bool isValid() const = 0;
|
||||
virtual bool finalize() = 0;
|
||||
virtual bool isWatch() const = 0;
|
||||
virtual bool parseBoolean(int key, bool enable) = 0;
|
||||
virtual bool parseString(int key, const char *arg) = 0;
|
||||
|
|
Loading…
Reference in a new issue