mirror of
https://github.com/xmrig/xmrig.git
synced 2025-01-10 21:04:37 +00:00
Added SelfSelectClient stub.
This commit is contained in:
parent
72c45d882b
commit
e9d2e194f3
17 changed files with 209 additions and 51 deletions
|
@ -139,6 +139,7 @@ if (WITH_HTTP)
|
|||
src/base/net/http/HttpResponse.h
|
||||
src/base/net/http/HttpServer.h
|
||||
src/base/net/stratum/DaemonClient.h
|
||||
src/base/net/stratum/SelfSelectClient.h
|
||||
src/base/net/tools/TcpServer.h
|
||||
)
|
||||
|
||||
|
@ -154,6 +155,7 @@ if (WITH_HTTP)
|
|||
src/base/net/http/HttpResponse.cpp
|
||||
src/base/net/http/HttpServer.cpp
|
||||
src/base/net/stratum/DaemonClient.cpp
|
||||
src/base/net/stratum/SelfSelectClient.cpp
|
||||
src/base/net/tools/TcpServer.cpp
|
||||
)
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#define XMRIG_ICLIENT_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#define XMRIG_ICLIENTLISTENER_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
#include "rapidjson/fwd.h"
|
||||
|
|
|
@ -46,6 +46,7 @@ class BaseClient : public IClient
|
|||
public:
|
||||
BaseClient(int id, IClientListener *listener);
|
||||
|
||||
protected:
|
||||
inline bool isEnabled() const override { return m_enabled; }
|
||||
inline const Job &job() const override { return m_job; }
|
||||
inline const Pool &pool() const override { return m_pool; }
|
||||
|
|
|
@ -22,11 +22,11 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
#include <cassert>
|
||||
#include <cinttypes>
|
||||
#include <iterator>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <utility>
|
||||
|
||||
|
||||
|
|
|
@ -40,10 +40,11 @@
|
|||
#include "base/net/stratum/SubmitResult.h"
|
||||
#include "base/net/tools/RecvBuf.h"
|
||||
#include "base/net/tools/Storage.h"
|
||||
#include "base/tools/Object.h"
|
||||
#include "crypto/common/Algorithm.h"
|
||||
|
||||
|
||||
typedef struct bio_st BIO;
|
||||
using BIO = struct bio_st;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
@ -56,6 +57,8 @@ class JobResult;
|
|||
class Client : public BaseClient, public IDnsListener, public ILineListener
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Client)
|
||||
|
||||
constexpr static uint64_t kConnectTimeout = 20 * 1000;
|
||||
constexpr static uint64_t kResponseTimeout = 20 * 1000;
|
||||
|
||||
|
|
|
@ -27,9 +27,10 @@
|
|||
#define XMRIG_DAEMONCLIENT_H
|
||||
|
||||
|
||||
#include "base/net/stratum/BaseClient.h"
|
||||
#include "base/kernel/interfaces/ITimerListener.h"
|
||||
#include "base/kernel/interfaces/IHttpListener.h"
|
||||
#include "base/kernel/interfaces/ITimerListener.h"
|
||||
#include "base/net/stratum/BaseClient.h"
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
@ -38,6 +39,8 @@ namespace xmrig {
|
|||
class DaemonClient : public BaseClient, public ITimerListener, public IHttpListener
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(DaemonClient)
|
||||
|
||||
DaemonClient(int id, IClientListener *listener);
|
||||
~DaemonClient() override;
|
||||
|
||||
|
|
|
@ -33,9 +33,17 @@
|
|||
#include "base/net/stratum/Pool.h"
|
||||
#include "base/io/json/Json.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/kernel/Platform.h"
|
||||
#include "base/net/stratum/Client.h"
|
||||
#include "rapidjson/document.h"
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_HTTP
|
||||
# include "base/net/stratum/DaemonClient.h"
|
||||
# include "base/net/stratum/SelfSelectClient.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
static const char *kAlgo = "algo";
|
||||
|
@ -128,7 +136,13 @@ bool xmrig::Pool::isEnabled() const
|
|||
# endif
|
||||
|
||||
# ifndef XMRIG_FEATURE_HTTP
|
||||
if (isDaemon()) {
|
||||
if (m_mode == MODE_DAEMON) {
|
||||
return false;
|
||||
}
|
||||
# endif
|
||||
|
||||
# ifndef XMRIG_FEATURE_HTTP
|
||||
if (m_mode == MODE_SELF_SELECT) {
|
||||
return false;
|
||||
}
|
||||
# endif
|
||||
|
@ -158,6 +172,32 @@ bool xmrig::Pool::isEqual(const Pool &other) const
|
|||
}
|
||||
|
||||
|
||||
xmrig::IClient *xmrig::Pool::createClient(int id, IClientListener *listener) const
|
||||
{
|
||||
IClient *client = nullptr;
|
||||
|
||||
if (m_mode == MODE_POOL) {
|
||||
client = new Client(id, Platform::userAgent(), listener);
|
||||
}
|
||||
# ifdef XMRIG_FEATURE_HTTP
|
||||
else if (m_mode == MODE_DAEMON) {
|
||||
client = new DaemonClient(id, listener);
|
||||
}
|
||||
else if (m_mode == MODE_SELF_SELECT) {
|
||||
client = new SelfSelectClient(id, Platform::userAgent(), listener);
|
||||
}
|
||||
# endif
|
||||
|
||||
assert(client != nullptr);
|
||||
|
||||
if (client) {
|
||||
client->setPool(*this);
|
||||
}
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
|
||||
rapidjson::Value xmrig::Pool::toJSON(rapidjson::Document &doc) const
|
||||
{
|
||||
using namespace rapidjson;
|
||||
|
|
|
@ -39,6 +39,10 @@
|
|||
namespace xmrig {
|
||||
|
||||
|
||||
class IClient;
|
||||
class IClientListener;
|
||||
|
||||
|
||||
class Pool
|
||||
{
|
||||
public:
|
||||
|
@ -67,7 +71,6 @@ public:
|
|||
bool tls = false
|
||||
);
|
||||
|
||||
inline bool isDaemon() const { return m_mode == MODE_DAEMON; }
|
||||
inline bool isNicehash() const { return m_flags.test(FLAG_NICEHASH); }
|
||||
inline bool isTLS() const { return m_flags.test(FLAG_TLS); }
|
||||
inline bool isValid() const { return m_url.isValid(); }
|
||||
|
@ -94,6 +97,7 @@ public:
|
|||
|
||||
bool isEnabled() const;
|
||||
bool isEqual(const Pool &other) const;
|
||||
IClient *createClient(int id, IClientListener *listener) const;
|
||||
rapidjson::Value toJSON(rapidjson::Document &doc) const;
|
||||
std::string printableName() const;
|
||||
|
||||
|
|
40
src/base/net/stratum/SelfSelectClient.cpp
Normal file
40
src/base/net/stratum/SelfSelectClient.cpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* 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-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
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/net/stratum/SelfSelectClient.h"
|
||||
#include "base/net/stratum/Client.h"
|
||||
|
||||
|
||||
xmrig::SelfSelectClient::SelfSelectClient(int id, const char *agent, IClientListener *listener) :
|
||||
m_listener(listener)
|
||||
{
|
||||
m_client = new Client(id, agent, this);
|
||||
}
|
||||
|
||||
|
||||
xmrig::SelfSelectClient::~SelfSelectClient()
|
||||
{
|
||||
delete m_client;
|
||||
}
|
87
src/base/net/stratum/SelfSelectClient.h
Normal file
87
src/base/net/stratum/SelfSelectClient.h
Normal file
|
@ -0,0 +1,87 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* 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-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
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_SELFSELECTCLIENT_H
|
||||
#define XMRIG_SELFSELECTCLIENT_H
|
||||
|
||||
|
||||
#include "base/kernel/interfaces/IClientListener.h"
|
||||
#include "base/tools/Object.h"
|
||||
#include "base/kernel/interfaces/IClient.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class SelfSelectClient : public IClient, public IClientListener
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(SelfSelectClient)
|
||||
|
||||
SelfSelectClient(int id, const char *agent, IClientListener *listener);
|
||||
~SelfSelectClient() override;
|
||||
|
||||
protected:
|
||||
// IClient
|
||||
bool disconnect() override { return m_client->disconnect(); }
|
||||
bool hasExtension(Extension extension) const noexcept override { return m_client->hasExtension(extension); }
|
||||
bool isEnabled() const override { return m_client->isEnabled(); }
|
||||
bool isTLS() const override { return m_client->isTLS(); }
|
||||
const char *mode() const override { return m_client->mode(); }
|
||||
const char *tlsFingerprint() const override { return m_client->tlsFingerprint(); }
|
||||
const char *tlsVersion() const override { return m_client->tlsVersion(); }
|
||||
const Job &job() const override { return m_client->job(); }
|
||||
const Pool &pool() const override { return m_client->pool(); }
|
||||
const String &ip() const override { return m_client->ip(); }
|
||||
int id() const override { return m_client->id(); }
|
||||
int64_t submit(const JobResult &result) override { return m_client->submit(result); }
|
||||
void connect() override { m_client->connect(); }
|
||||
void connect(const Pool &pool) override { m_client->connect(pool); }
|
||||
void deleteLater() override { m_client->deleteLater(); }
|
||||
void setAlgo(const Algorithm &algo) override { m_client->setAlgo(algo); }
|
||||
void setEnabled(bool enabled) override { m_client->setEnabled(enabled); }
|
||||
void setPool(const Pool &pool) override { m_client->setPool(pool); }
|
||||
void setQuiet(bool quiet) override { m_client->setQuiet(quiet); }
|
||||
void setRetries(int retries) override { m_client->setRetries(retries); }
|
||||
void setRetryPause(uint64_t ms) override { m_client->setRetryPause(ms); }
|
||||
void tick(uint64_t now) override { m_client->tick(now); }
|
||||
|
||||
// IClientListener
|
||||
void onClose(IClient *, int failures) override { m_listener->onClose(this, failures); }
|
||||
void onJobReceived(IClient *, const Job &job, const rapidjson::Value ¶ms) override { m_listener->onJobReceived(this, job, params); }
|
||||
void onLogin(IClient *, rapidjson::Document &doc, rapidjson::Value ¶ms) override { m_listener->onLogin(this, doc, params); }
|
||||
void onLoginSuccess(IClient *) override { m_listener->onLoginSuccess(this); }
|
||||
void onResultAccepted(IClient *, const SubmitResult &result, const char *error) override { m_listener->onResultAccepted(this, result, error); }
|
||||
void onVerifyAlgorithm(const IClient *, const Algorithm &algorithm, bool *ok) override { m_listener->onVerifyAlgorithm(this, algorithm, ok); }
|
||||
|
||||
private:
|
||||
IClient *m_client;
|
||||
IClientListener *m_listener;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* XMRIG_SELFSELECTCLIENT_H */
|
|
@ -23,15 +23,10 @@
|
|||
*/
|
||||
|
||||
|
||||
#include "base/net/stratum/strategies/FailoverStrategy.h"
|
||||
#include "base/kernel/interfaces/IClient.h"
|
||||
#include "base/kernel/interfaces/IStrategyListener.h"
|
||||
#include "base/kernel/Platform.h"
|
||||
#include "base/net/stratum/Client.h"
|
||||
#include "base/net/stratum/strategies/FailoverStrategy.h"
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_HTTP
|
||||
# include "base/net/stratum/DaemonClient.h"
|
||||
#endif
|
||||
|
||||
|
||||
xmrig::FailoverStrategy::FailoverStrategy(const std::vector<Pool> &pools, int retryPause, int retries, IStrategyListener *listener, bool quiet) :
|
||||
|
@ -69,16 +64,8 @@ xmrig::FailoverStrategy::~FailoverStrategy()
|
|||
|
||||
void xmrig::FailoverStrategy::add(const Pool &pool)
|
||||
{
|
||||
const int id = static_cast<int>(m_pools.size());
|
||||
IClient *client = pool.createClient(static_cast<int>(m_pools.size()), this);
|
||||
|
||||
# ifdef XMRIG_FEATURE_HTTP
|
||||
IClient *client = !pool.isDaemon() ? static_cast<IClient *>(new Client(id, Platform::userAgent(), this))
|
||||
: static_cast<IClient *>(new DaemonClient(id, this));
|
||||
# else
|
||||
IClient *client = new Client(id, Platform::userAgent(), this);
|
||||
# endif
|
||||
|
||||
client->setPool(pool);
|
||||
client->setRetries(m_retries);
|
||||
client->setRetryPause(m_retryPause * 1000);
|
||||
client->setQuiet(m_quiet);
|
||||
|
@ -123,8 +110,8 @@ void xmrig::FailoverStrategy::setAlgo(const Algorithm &algo)
|
|||
|
||||
void xmrig::FailoverStrategy::stop()
|
||||
{
|
||||
for (size_t i = 0; i < m_pools.size(); ++i) {
|
||||
m_pools[i]->disconnect();
|
||||
for (auto &pool : m_pools) {
|
||||
pool->disconnect();
|
||||
}
|
||||
|
||||
m_index = 0;
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "base/kernel/interfaces/IClientListener.h"
|
||||
#include "base/kernel/interfaces/IStrategy.h"
|
||||
#include "base/net/stratum/Pool.h"
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
@ -44,6 +45,8 @@ class IStrategyListener;
|
|||
class FailoverStrategy : public IStrategy, public IClientListener
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(FailoverStrategy)
|
||||
|
||||
FailoverStrategy(const std::vector<Pool> &pool, int retryPause, int retries, IStrategyListener *listener, bool quiet = false);
|
||||
FailoverStrategy(int retryPause, int retries, IStrategyListener *listener, bool quiet = false);
|
||||
~FailoverStrategy() override;
|
||||
|
|
|
@ -23,33 +23,18 @@
|
|||
*/
|
||||
|
||||
|
||||
#include "base/net/stratum/strategies/SinglePoolStrategy.h"
|
||||
#include "base/kernel/interfaces/IClient.h"
|
||||
#include "base/kernel/interfaces/IStrategyListener.h"
|
||||
#include "base/kernel/Platform.h"
|
||||
#include "base/net/stratum/Client.h"
|
||||
#include "base/net/stratum/strategies/SinglePoolStrategy.h"
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_HTTP
|
||||
# include "base/net/stratum/DaemonClient.h"
|
||||
#endif
|
||||
#include "base/net/stratum/Pool.h"
|
||||
|
||||
|
||||
xmrig::SinglePoolStrategy::SinglePoolStrategy(const Pool &pool, int retryPause, int retries, IStrategyListener *listener, bool quiet) :
|
||||
m_active(false),
|
||||
m_listener(listener)
|
||||
{
|
||||
# ifdef XMRIG_FEATURE_HTTP
|
||||
if (!pool.isDaemon()) {
|
||||
m_client = new Client(0, Platform::userAgent(), this);
|
||||
}
|
||||
else {
|
||||
m_client = new DaemonClient(0, this);
|
||||
}
|
||||
# else
|
||||
m_client = new Client(0, Platform::userAgent(), this);
|
||||
# endif
|
||||
|
||||
m_client->setPool(pool);
|
||||
m_client = pool.createClient(0, this);
|
||||
m_client->setRetries(retries);
|
||||
m_client->setRetryPause(retryPause * 1000);
|
||||
m_client->setQuiet(quiet);
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include "base/kernel/interfaces/IClientListener.h"
|
||||
#include "base/kernel/interfaces/IStrategy.h"
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
@ -41,6 +42,8 @@ class Pool;
|
|||
class SinglePoolStrategy : public IStrategy, public IClientListener
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(SinglePoolStrategy)
|
||||
|
||||
SinglePoolStrategy(const Pool &pool, int retryPause, int retries, IStrategyListener *listener, bool quiet = false);
|
||||
~SinglePoolStrategy() override;
|
||||
|
||||
|
|
|
@ -234,7 +234,7 @@ void xmrig::DonateStrategy::onTimer(const Timer *)
|
|||
}
|
||||
|
||||
|
||||
xmrig::Client *xmrig::DonateStrategy::createProxy()
|
||||
xmrig::IClient *xmrig::DonateStrategy::createProxy()
|
||||
{
|
||||
if (m_controller->config()->pools().proxyDonate() == Pools::PROXY_DONATE_NONE) {
|
||||
return nullptr;
|
||||
|
@ -251,7 +251,7 @@ xmrig::Client *xmrig::DonateStrategy::createProxy()
|
|||
Pool pool(client->ip(), client->pool().port(), m_userId, client->pool().password(), 0, true, client->isTLS());
|
||||
pool.setAlgo(client->pool().algorithm());
|
||||
|
||||
auto proxy = new Client(-1, Platform::userAgent(), this);
|
||||
IClient *proxy = new Client(-1, Platform::userAgent(), this);
|
||||
proxy->setPool(pool);
|
||||
proxy->setQuiet(true);
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ private:
|
|||
|
||||
inline State state() const { return m_state; }
|
||||
|
||||
Client *createProxy();
|
||||
IClient *createProxy();
|
||||
void idle(double min, double max);
|
||||
void setAlgorithms(rapidjson::Document &doc, rapidjson::Value ¶ms);
|
||||
void setJob(IClient *client, const Job &job);
|
||||
|
|
Loading…
Reference in a new issue