* [WIP] More unification in Pools class.
This commit is contained in:
parent
f6699b5929
commit
ee4f6e28f0
10 changed files with 118 additions and 66 deletions
|
@ -24,10 +24,18 @@
|
|||
|
||||
|
||||
#include "base/net/Pools.h"
|
||||
#include "common/log/Log.h"
|
||||
#include "rapidjson/document.h"
|
||||
|
||||
|
||||
xmrig::Pools::Pools()
|
||||
xmrig::Pools::Pools() :
|
||||
m_retries(5),
|
||||
m_retryPause(5)
|
||||
{
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
m_retries = 2;
|
||||
m_retryPause = 1;
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -60,6 +68,21 @@ bool xmrig::Pools::setUrl(const char *url)
|
|||
}
|
||||
|
||||
|
||||
rapidjson::Value xmrig::Pools::toJSON(rapidjson::Document &doc) const
|
||||
{
|
||||
using namespace rapidjson;
|
||||
auto &allocator = doc.GetAllocator();
|
||||
|
||||
Value pools(kArrayType);
|
||||
|
||||
for (const Pool &pool : m_data) {
|
||||
pools.PushBack(pool.toJSON(doc), allocator);
|
||||
}
|
||||
|
||||
return pools;
|
||||
}
|
||||
|
||||
|
||||
size_t xmrig::Pools::active() const
|
||||
{
|
||||
size_t count = 0;
|
||||
|
@ -79,3 +102,56 @@ void xmrig::Pools::adjust(const Algorithm &algorithm)
|
|||
pool.adjust(algorithm);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Pools::print()
|
||||
{
|
||||
size_t i = 1;
|
||||
for (const Pool &pool : m_data) {
|
||||
if (Log::colors) {
|
||||
const int color = pool.isEnabled() ? (pool.isTLS() ? 32 : 36) : 31;
|
||||
|
||||
Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("POOL #%-7zu") "\x1B[1;%dm%s\x1B[0m algo " WHITE_BOLD("%s"),
|
||||
i,
|
||||
color,
|
||||
pool.url(),
|
||||
pool.algorithm().shortName()
|
||||
);
|
||||
}
|
||||
else {
|
||||
Log::i()->text(" * POOL #%-7zu%s%s algo=%s %s",
|
||||
i,
|
||||
pool.isEnabled() ? "" : "-",
|
||||
pool.url(),
|
||||
pool.algorithm().shortName(),
|
||||
pool.isTLS() ? "TLS" : ""
|
||||
);
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
# ifdef APP_DEBUG
|
||||
LOG_NOTICE("POOLS --------------------------------------------------------------------");
|
||||
for (const Pool &pool : m_data) {
|
||||
pool.print();
|
||||
}
|
||||
LOG_NOTICE("--------------------------------------------------------------------------");
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Pools::setRetries(int retries)
|
||||
{
|
||||
if (retries > 0 && retries <= 1000) {
|
||||
m_retries = retries;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Pools::setRetryPause(int retryPause)
|
||||
{
|
||||
if (retryPause > 0 && retryPause <= 3600) {
|
||||
m_retryPause = retryPause;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,8 @@ public:
|
|||
|
||||
inline bool setUserpass(const char *userpass) { return current().setUserpass(userpass); }
|
||||
inline const std::vector<Pool> &data() const { return m_data; }
|
||||
inline int retries() const { return m_retries; }
|
||||
inline int retryPause() const { return m_retryPause; }
|
||||
inline void setFingerprint(const char *fingerprint) { current().setFingerprint(fingerprint); }
|
||||
inline void setKeepAlive(bool enable) { setKeepAlive(enable ? Pool::kKeepAliveTimeout : 0); }
|
||||
inline void setKeepAlive(int keepAlive) { current().setKeepAlive(keepAlive); }
|
||||
|
@ -54,12 +56,18 @@ public:
|
|||
inline void setVariant(int variant) { current().algorithm().parseVariant(variant); }
|
||||
|
||||
bool setUrl(const char *url);
|
||||
rapidjson::Value toJSON(rapidjson::Document &doc) const;
|
||||
size_t active() const;
|
||||
void adjust(const Algorithm &algorithm);
|
||||
void print();
|
||||
void setRetries(int retries);
|
||||
void setRetryPause(int retryPause);
|
||||
|
||||
private:
|
||||
Pool ¤t();
|
||||
|
||||
int m_retries;
|
||||
int m_retryPause;
|
||||
std::vector<Pool> m_data;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue