Move network classes into xmrig namespace.
This commit is contained in:
parent
dbdcc14672
commit
ee667144e8
42 changed files with 481 additions and 332 deletions
|
@ -44,7 +44,7 @@
|
|||
#endif
|
||||
|
||||
|
||||
Pool::Pool() :
|
||||
xmrig::Pool::Pool() :
|
||||
m_nicehash(false),
|
||||
m_tls(false),
|
||||
m_keepAlive(0),
|
||||
|
@ -64,7 +64,7 @@ Pool::Pool() :
|
|||
*
|
||||
* @param url
|
||||
*/
|
||||
Pool::Pool(const char *url) :
|
||||
xmrig::Pool::Pool(const char *url) :
|
||||
m_nicehash(false),
|
||||
m_tls(false),
|
||||
m_keepAlive(0),
|
||||
|
@ -74,14 +74,54 @@ Pool::Pool(const char *url) :
|
|||
}
|
||||
|
||||
|
||||
Pool::Pool(const char *host, uint16_t port, const char *user, const char *password, int keepAlive, bool nicehash, bool tls) :
|
||||
xmrig::Pool::Pool(const rapidjson::Value &object) :
|
||||
m_nicehash(false),
|
||||
m_tls(false),
|
||||
m_keepAlive(0),
|
||||
m_port(kDefaultPort)
|
||||
{
|
||||
if (!parse(object["url"].GetString())) {
|
||||
return;
|
||||
}
|
||||
|
||||
setUser(object["user"].GetString());
|
||||
setPassword(object["pass"].GetString());
|
||||
setRigId(object["rig-id"].GetString());
|
||||
setNicehash(object["nicehash"].GetBool());
|
||||
|
||||
const rapidjson::Value &keepalive = object["keepalive"];
|
||||
if (keepalive.IsInt()) {
|
||||
setKeepAlive(keepalive.GetInt());
|
||||
}
|
||||
else if (keepalive.IsBool()) {
|
||||
setKeepAlive(keepalive.IsTrue() ? kKeepAliveTimeout : 0);
|
||||
}
|
||||
|
||||
const rapidjson::Value &variant = object["variant"];
|
||||
if (variant.IsString()) {
|
||||
algorithm().parseVariant(variant.GetString());
|
||||
}
|
||||
else if (variant.IsInt()) {
|
||||
algorithm().parseVariant(variant.GetInt());
|
||||
}
|
||||
|
||||
const rapidjson::Value &tls = object["tls"];
|
||||
if (tls.IsBool()) {
|
||||
m_tls = tls.IsTrue();
|
||||
}
|
||||
|
||||
m_fingerprint = object["tls-fingerprint"].GetString();
|
||||
}
|
||||
|
||||
|
||||
xmrig::Pool::Pool(const char *host, uint16_t port, const char *user, const char *password, int keepAlive, bool nicehash, bool tls) :
|
||||
m_nicehash(nicehash),
|
||||
m_tls(tls),
|
||||
m_keepAlive(keepAlive),
|
||||
m_port(port),
|
||||
m_host(host),
|
||||
m_password(password),
|
||||
m_user(user)
|
||||
m_user(user),
|
||||
m_port(port)
|
||||
{
|
||||
const size_t size = m_host.size() + 8;
|
||||
assert(size > 8);
|
||||
|
@ -93,7 +133,7 @@ Pool::Pool(const char *host, uint16_t port, const char *user, const char *passwo
|
|||
}
|
||||
|
||||
|
||||
bool Pool::isCompatible(const xmrig::Algorithm &algorithm) const
|
||||
bool xmrig::Pool::isCompatible(const Algorithm &algorithm) const
|
||||
{
|
||||
if (m_algorithms.empty()) {
|
||||
return true;
|
||||
|
@ -115,7 +155,7 @@ bool Pool::isCompatible(const xmrig::Algorithm &algorithm) const
|
|||
}
|
||||
|
||||
|
||||
bool Pool::isEqual(const Pool &other) const
|
||||
bool xmrig::Pool::isEqual(const Pool &other) const
|
||||
{
|
||||
return (m_nicehash == other.m_nicehash
|
||||
&& m_tls == other.m_tls
|
||||
|
@ -131,7 +171,7 @@ bool Pool::isEqual(const Pool &other) const
|
|||
}
|
||||
|
||||
|
||||
bool Pool::parse(const char *url)
|
||||
bool xmrig::Pool::parse(const char *url)
|
||||
{
|
||||
assert(url != nullptr);
|
||||
|
||||
|
@ -178,7 +218,7 @@ bool Pool::parse(const char *url)
|
|||
}
|
||||
|
||||
|
||||
bool Pool::setUserpass(const char *userpass)
|
||||
bool xmrig::Pool::setUserpass(const char *userpass)
|
||||
{
|
||||
const char *p = strchr(userpass, ':');
|
||||
if (!p) {
|
||||
|
@ -195,7 +235,7 @@ bool Pool::setUserpass(const char *userpass)
|
|||
}
|
||||
|
||||
|
||||
rapidjson::Value Pool::toJSON(rapidjson::Document &doc) const
|
||||
rapidjson::Value xmrig::Pool::toJSON(rapidjson::Document &doc) const
|
||||
{
|
||||
using namespace rapidjson;
|
||||
|
||||
|
@ -220,13 +260,13 @@ rapidjson::Value Pool::toJSON(rapidjson::Document &doc) const
|
|||
}
|
||||
|
||||
switch (m_algorithm.variant()) {
|
||||
case xmrig::VARIANT_AUTO:
|
||||
case xmrig::VARIANT_0:
|
||||
case xmrig::VARIANT_1:
|
||||
case VARIANT_AUTO:
|
||||
case VARIANT_0:
|
||||
case VARIANT_1:
|
||||
obj.AddMember("variant", m_algorithm.variant(), allocator);
|
||||
break;
|
||||
|
||||
case xmrig::VARIANT_2:
|
||||
case VARIANT_2:
|
||||
obj.AddMember("variant", 2, allocator);
|
||||
break;
|
||||
|
||||
|
@ -242,7 +282,7 @@ rapidjson::Value Pool::toJSON(rapidjson::Document &doc) const
|
|||
}
|
||||
|
||||
|
||||
void Pool::adjust(const xmrig::Algorithm &algorithm)
|
||||
void xmrig::Pool::adjust(const Algorithm &algorithm)
|
||||
{
|
||||
if (!isValid()) {
|
||||
return;
|
||||
|
@ -257,7 +297,7 @@ void Pool::adjust(const xmrig::Algorithm &algorithm)
|
|||
}
|
||||
|
||||
|
||||
void Pool::setAlgo(const xmrig::Algorithm &algorithm)
|
||||
void xmrig::Pool::setAlgo(const xmrig::Algorithm &algorithm)
|
||||
{
|
||||
m_algorithm = algorithm;
|
||||
|
||||
|
@ -266,7 +306,7 @@ void Pool::setAlgo(const xmrig::Algorithm &algorithm)
|
|||
|
||||
|
||||
#ifdef APP_DEBUG
|
||||
void Pool::print() const
|
||||
void xmrig::Pool::print() const
|
||||
{
|
||||
LOG_NOTICE("url: %s", m_url.data());
|
||||
LOG_DEBUG ("host: %s", m_host.data());
|
||||
|
@ -281,7 +321,7 @@ void Pool::print() const
|
|||
#endif
|
||||
|
||||
|
||||
bool Pool::parseIPv6(const char *addr)
|
||||
bool xmrig::Pool::parseIPv6(const char *addr)
|
||||
{
|
||||
const char *end = strchr(addr, ']');
|
||||
if (!end) {
|
||||
|
@ -304,7 +344,7 @@ bool Pool::parseIPv6(const char *addr)
|
|||
}
|
||||
|
||||
|
||||
void Pool::addVariant(xmrig::Variant variant)
|
||||
void xmrig::Pool::addVariant(xmrig::Variant variant)
|
||||
{
|
||||
const xmrig::Algorithm algorithm(m_algorithm.algo(), variant);
|
||||
if (!algorithm.isValid() || m_algorithm == algorithm) {
|
||||
|
@ -315,7 +355,7 @@ void Pool::addVariant(xmrig::Variant variant)
|
|||
}
|
||||
|
||||
|
||||
void Pool::adjustVariant(const xmrig::Variant variantHint)
|
||||
void xmrig::Pool::adjustVariant(const xmrig::Variant variantHint)
|
||||
{
|
||||
# ifndef XMRIG_PROXY_PROJECT
|
||||
using namespace xmrig;
|
||||
|
@ -401,7 +441,7 @@ void Pool::adjustVariant(const xmrig::Variant variantHint)
|
|||
}
|
||||
|
||||
|
||||
void Pool::rebuild()
|
||||
void xmrig::Pool::rebuild()
|
||||
{
|
||||
m_algorithms.clear();
|
||||
|
||||
|
@ -412,18 +452,18 @@ void Pool::rebuild()
|
|||
m_algorithms.push_back(m_algorithm);
|
||||
|
||||
# ifndef XMRIG_PROXY_PROJECT
|
||||
addVariant(xmrig::VARIANT_WOW);
|
||||
addVariant(xmrig::VARIANT_2);
|
||||
addVariant(xmrig::VARIANT_1);
|
||||
addVariant(xmrig::VARIANT_0);
|
||||
addVariant(xmrig::VARIANT_HALF);
|
||||
addVariant(xmrig::VARIANT_XTL);
|
||||
addVariant(xmrig::VARIANT_TUBE);
|
||||
addVariant(xmrig::VARIANT_MSR);
|
||||
addVariant(xmrig::VARIANT_XHV);
|
||||
addVariant(xmrig::VARIANT_XAO);
|
||||
addVariant(xmrig::VARIANT_RTO);
|
||||
addVariant(xmrig::VARIANT_GPU);
|
||||
addVariant(xmrig::VARIANT_AUTO);
|
||||
addVariant(VARIANT_WOW);
|
||||
addVariant(VARIANT_2);
|
||||
addVariant(VARIANT_1);
|
||||
addVariant(VARIANT_0);
|
||||
addVariant(VARIANT_HALF);
|
||||
addVariant(VARIANT_XTL);
|
||||
addVariant(VARIANT_TUBE);
|
||||
addVariant(VARIANT_MSR);
|
||||
addVariant(VARIANT_XHV);
|
||||
addVariant(VARIANT_XAO);
|
||||
addVariant(VARIANT_RTO);
|
||||
addVariant(VARIANT_GPU);
|
||||
addVariant(VARIANT_AUTO);
|
||||
# endif
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
|
@ -29,11 +29,14 @@
|
|||
#include <vector>
|
||||
|
||||
|
||||
#include "base/tools/String.h"
|
||||
#include "common/crypto/Algorithm.h"
|
||||
#include "common/utils/c_str.h"
|
||||
#include "rapidjson/fwd.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class Pool
|
||||
{
|
||||
public:
|
||||
|
@ -44,6 +47,7 @@ public:
|
|||
|
||||
Pool();
|
||||
Pool(const char *url);
|
||||
Pool(const rapidjson::Value &object);
|
||||
Pool(const char *host,
|
||||
uint16_t port,
|
||||
const char *user = nullptr,
|
||||
|
@ -62,8 +66,8 @@ public:
|
|||
inline const char *rigId() const { return m_rigId.data(); }
|
||||
inline const char *url() const { return m_url.data(); }
|
||||
inline const char *user() const { return !m_user.isNull() ? m_user.data() : kDefaultUser; }
|
||||
inline const xmrig::Algorithm &algorithm() const { return m_algorithm; }
|
||||
inline const xmrig::Algorithms &algorithms() const { return m_algorithms; }
|
||||
inline const Algorithm &algorithm() const { return m_algorithm; }
|
||||
inline const Algorithms &algorithms() const { return m_algorithms; }
|
||||
inline int keepAlive() const { return m_keepAlive; }
|
||||
inline uint16_t port() const { return m_port; }
|
||||
inline void setFingerprint(const char *fingerprint) { m_fingerprint = fingerprint; }
|
||||
|
@ -73,18 +77,18 @@ public:
|
|||
inline void setRigId(const char *rigId) { m_rigId = rigId; }
|
||||
inline void setTLS(bool tls) { m_tls = tls; }
|
||||
inline void setUser(const char *user) { m_user = user; }
|
||||
inline xmrig::Algorithm &algorithm() { return m_algorithm; }
|
||||
inline Algorithm &algorithm() { return m_algorithm; }
|
||||
|
||||
inline bool operator!=(const Pool &other) const { return !isEqual(other); }
|
||||
inline bool operator==(const Pool &other) const { return isEqual(other); }
|
||||
|
||||
bool isCompatible(const xmrig::Algorithm &algorithm) const;
|
||||
bool isCompatible(const Algorithm &algorithm) const;
|
||||
bool isEqual(const Pool &other) const;
|
||||
bool parse(const char *url);
|
||||
bool setUserpass(const char *userpass);
|
||||
rapidjson::Value toJSON(rapidjson::Document &doc) const;
|
||||
void adjust(const xmrig::Algorithm &algorithm);
|
||||
void setAlgo(const xmrig::Algorithm &algorithm);
|
||||
void adjust(const Algorithm &algorithm);
|
||||
void setAlgo(const Algorithm &algorithm);
|
||||
|
||||
# ifdef APP_DEBUG
|
||||
void print() const;
|
||||
|
@ -92,25 +96,26 @@ public:
|
|||
|
||||
private:
|
||||
bool parseIPv6(const char *addr);
|
||||
void addVariant(xmrig::Variant variant);
|
||||
void adjustVariant(const xmrig::Variant variantHint);
|
||||
void addVariant(Variant variant);
|
||||
void adjustVariant(const Variant variantHint);
|
||||
void rebuild();
|
||||
|
||||
Algorithm m_algorithm;
|
||||
Algorithms m_algorithms;
|
||||
bool m_nicehash;
|
||||
bool m_tls;
|
||||
int m_keepAlive;
|
||||
String m_fingerprint;
|
||||
String m_host;
|
||||
String m_password;
|
||||
String m_rigId;
|
||||
String m_url;
|
||||
String m_user;
|
||||
uint16_t m_port;
|
||||
xmrig::Algorithm m_algorithm;
|
||||
xmrig::Algorithms m_algorithms;
|
||||
xmrig::c_str m_fingerprint;
|
||||
xmrig::c_str m_host;
|
||||
xmrig::c_str m_password;
|
||||
xmrig::c_str m_rigId;
|
||||
xmrig::c_str m_url;
|
||||
xmrig::c_str m_user;
|
||||
};
|
||||
|
||||
|
||||
//typedef std::vector<Pool> Pools;
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* XMRIG_POOL_H */
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include "base/net/Pools.h"
|
||||
|
||||
|
||||
xmrig::Pools::Pools()
|
||||
xmrig::Pools::Pools() :
|
||||
m_index(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ public:
|
|||
Pools();
|
||||
|
||||
private:
|
||||
size_t m_index;
|
||||
std::vector<Pool> m_data;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue