mirror of
https://github.com/xmrig/xmrig.git
synced 2025-02-03 03:36:43 +00:00
Add IClient and BaseClient.
This commit is contained in:
parent
1bd8d63508
commit
9a6944d694
16 changed files with 291 additions and 146 deletions
|
@ -11,6 +11,7 @@ set(HEADERS_BASE
|
|||
src/base/kernel/config/BaseTransform.h
|
||||
src/base/kernel/Entry.h
|
||||
src/base/kernel/interfaces/IBaseListener.h
|
||||
src/base/kernel/interfaces/IClient.h
|
||||
src/base/kernel/interfaces/IClientListener.h
|
||||
src/base/kernel/interfaces/IConfig.h
|
||||
src/base/kernel/interfaces/IConfigListener.h
|
||||
|
@ -29,6 +30,7 @@ set(HEADERS_BASE
|
|||
src/base/net/dns/Dns.h
|
||||
src/base/net/dns/DnsRecord.h
|
||||
src/base/net/http/Http.h
|
||||
src/base/net/stratum/BaseClient.h
|
||||
src/base/net/stratum/Client.h
|
||||
src/base/net/stratum/Job.h
|
||||
src/base/net/stratum/Pool.h
|
||||
|
@ -64,6 +66,7 @@ set(SOURCES_BASE
|
|||
src/base/net/dns/Dns.cpp
|
||||
src/base/net/dns/DnsRecord.cpp
|
||||
src/base/net/http/Http.cpp
|
||||
src/base/net/stratum/BaseClient.cpp
|
||||
src/base/net/stratum/Client.cpp
|
||||
src/base/net/stratum/Job.cpp
|
||||
src/base/net/stratum/Pool.cpp
|
||||
|
|
84
src/base/kernel/interfaces/IClient.h
Normal file
84
src/base/kernel/interfaces/IClient.h
Normal file
|
@ -0,0 +1,84 @@
|
|||
/* 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_ICLIENT_H
|
||||
#define XMRIG_ICLIENT_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class Algorithm;
|
||||
class Job;
|
||||
class JobResult;
|
||||
class Pool;
|
||||
class String;
|
||||
|
||||
|
||||
class IClient
|
||||
{
|
||||
public:
|
||||
enum Extension {
|
||||
EXT_ALGO,
|
||||
EXT_NICEHASH,
|
||||
EXT_CONNECT,
|
||||
EXT_TLS,
|
||||
EXT_KEEPALIVE,
|
||||
EXT_MAX
|
||||
};
|
||||
|
||||
virtual ~IClient() = default;
|
||||
|
||||
virtual bool disconnect() = 0;
|
||||
virtual bool hasExtension(Extension extension) const noexcept = 0;
|
||||
virtual bool isEnabled() const = 0;
|
||||
virtual bool isTLS() const = 0;
|
||||
virtual const char *tlsFingerprint() const = 0;
|
||||
virtual const char *tlsVersion() const = 0;
|
||||
virtual const Job &job() const = 0;
|
||||
virtual const Pool &pool() const = 0;
|
||||
virtual const String &ip() const = 0;
|
||||
virtual int id() const = 0;
|
||||
virtual int64_t submit(const JobResult &result) = 0;
|
||||
virtual void connect() = 0;
|
||||
virtual void connect(const Pool &pool) = 0;
|
||||
virtual void deleteLater() = 0;
|
||||
virtual void setAlgo(const Algorithm &algo) = 0;
|
||||
virtual void setEnabled(bool enabled) = 0;
|
||||
virtual void setPool(const Pool &pool) = 0;
|
||||
virtual void setQuiet(bool quiet) = 0;
|
||||
virtual void setRetries(int retries) = 0;
|
||||
virtual void setRetryPause(uint64_t ms) = 0;
|
||||
virtual void tick(uint64_t now) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif // XMRIG_ICLIENT_H
|
|
@ -35,7 +35,7 @@
|
|||
namespace xmrig {
|
||||
|
||||
|
||||
class Client;
|
||||
class IClient;
|
||||
class Job;
|
||||
class SubmitResult;
|
||||
|
||||
|
@ -45,11 +45,11 @@ class IClientListener
|
|||
public:
|
||||
virtual ~IClientListener() = default;
|
||||
|
||||
virtual void onClose(Client *client, int failures) = 0;
|
||||
virtual void onJobReceived(Client *client, const Job &job, const rapidjson::Value ¶ms) = 0;
|
||||
virtual void onLogin(Client *client, rapidjson::Document &doc, rapidjson::Value ¶ms) = 0;
|
||||
virtual void onLoginSuccess(Client *client) = 0;
|
||||
virtual void onResultAccepted(Client *client, const SubmitResult &result, const char *error) = 0;
|
||||
virtual void onClose(IClient *client, int failures) = 0;
|
||||
virtual void onJobReceived(IClient *client, const Job &job, const rapidjson::Value ¶ms) = 0;
|
||||
virtual void onLogin(IClient *client, rapidjson::Document &doc, rapidjson::Value ¶ms) = 0;
|
||||
virtual void onLoginSuccess(IClient *client) = 0;
|
||||
virtual void onResultAccepted(IClient *client, const SubmitResult &result, const char *error) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
namespace xmrig {
|
||||
|
||||
|
||||
class Client;
|
||||
class IClient;
|
||||
class IStrategy;
|
||||
class Job;
|
||||
class SubmitResult;
|
||||
|
@ -43,10 +43,10 @@ class IStrategyListener
|
|||
public:
|
||||
virtual ~IStrategyListener() = default;
|
||||
|
||||
virtual void onActive(IStrategy *strategy, Client *client) = 0;
|
||||
virtual void onJob(IStrategy *strategy, Client *client, const Job &job) = 0;
|
||||
virtual void onPause(IStrategy *strategy) = 0;
|
||||
virtual void onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) = 0;
|
||||
virtual void onActive(IStrategy *strategy, IClient *client) = 0;
|
||||
virtual void onJob(IStrategy *strategy, IClient *client, const Job &job) = 0;
|
||||
virtual void onPause(IStrategy *strategy) = 0;
|
||||
virtual void onResultAccepted(IStrategy *strategy, IClient *client, const SubmitResult &result, const char *error) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
|
37
src/base/net/stratum/BaseClient.cpp
Normal file
37
src/base/net/stratum/BaseClient.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* 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/BaseClient.h"
|
||||
|
||||
|
||||
xmrig::BaseClient::BaseClient(int id, IClientListener *listener) :
|
||||
m_quiet(false),
|
||||
m_listener(listener),
|
||||
m_id(id),
|
||||
m_retries(5),
|
||||
m_retryPause(5000)
|
||||
{
|
||||
|
||||
}
|
75
src/base/net/stratum/BaseClient.h
Normal file
75
src/base/net/stratum/BaseClient.h
Normal file
|
@ -0,0 +1,75 @@
|
|||
/* 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_BASECLIENT_H
|
||||
#define XMRIG_BASECLIENT_H
|
||||
|
||||
|
||||
#include "base/kernel/interfaces/IClient.h"
|
||||
#include "base/net/stratum/Job.h"
|
||||
#include "base/net/stratum/Pool.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class IClientListener;
|
||||
|
||||
|
||||
class BaseClient : public IClient
|
||||
{
|
||||
public:
|
||||
BaseClient(int id, IClientListener *listener);
|
||||
|
||||
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; }
|
||||
inline const String &ip() const override { return m_ip; }
|
||||
inline int id() const override { return m_id; }
|
||||
inline void setAlgo(const Algorithm &algo) override { m_pool.setAlgo(algo); }
|
||||
inline void setEnabled(bool enabled) override { m_enabled = enabled; }
|
||||
inline void setPool(const Pool &pool) override { if (pool.isValid()) { m_pool = pool; } }
|
||||
inline void setQuiet(bool quiet) override { m_quiet = quiet; }
|
||||
inline void setRetries(int retries) override { m_retries = retries; }
|
||||
inline void setRetryPause(uint64_t ms) override { m_retryPause = ms; }
|
||||
|
||||
protected:
|
||||
bool m_quiet;
|
||||
IClientListener *m_listener;
|
||||
int m_id;
|
||||
int m_retries;
|
||||
Job m_job;
|
||||
Pool m_pool;
|
||||
String m_ip;
|
||||
uint64_t m_retryPause;
|
||||
|
||||
private:
|
||||
bool m_enabled;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* XMRIG_BASECLIENT_H */
|
|
@ -75,14 +75,8 @@ static const char *states[] = {
|
|||
|
||||
|
||||
xmrig::Client::Client(int id, const char *agent, IClientListener *listener) :
|
||||
m_enabled(true),
|
||||
m_ipv6(false),
|
||||
m_quiet(false),
|
||||
BaseClient(id, listener),
|
||||
m_agent(agent),
|
||||
m_listener(listener),
|
||||
m_id(id),
|
||||
m_retries(5),
|
||||
m_retryPause(5000),
|
||||
m_failures(0),
|
||||
m_state(UnconnectedState),
|
||||
m_tls(nullptr),
|
||||
|
@ -117,14 +111,9 @@ void xmrig::Client::connect()
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Connect to server.
|
||||
*
|
||||
* @param url
|
||||
*/
|
||||
void xmrig::Client::connect(const Pool &url)
|
||||
void xmrig::Client::connect(const Pool &pool)
|
||||
{
|
||||
setPool(url);
|
||||
setPool(pool);
|
||||
connect();
|
||||
}
|
||||
|
||||
|
@ -143,17 +132,6 @@ void xmrig::Client::deleteLater()
|
|||
}
|
||||
|
||||
|
||||
|
||||
void xmrig::Client::setPool(const Pool &pool)
|
||||
{
|
||||
if (!pool.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_pool = pool;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Client::tick(uint64_t now)
|
||||
{
|
||||
if (m_state == ConnectedState) {
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
#include "base/kernel/interfaces/IDnsListener.h"
|
||||
#include "base/kernel/interfaces/ILineListener.h"
|
||||
#include "base/net/stratum/BaseClient.h"
|
||||
#include "base/net/stratum/Job.h"
|
||||
#include "base/net/stratum/Pool.h"
|
||||
#include "base/net/stratum/SubmitResult.h"
|
||||
|
@ -53,26 +54,9 @@ class IClientListener;
|
|||
class JobResult;
|
||||
|
||||
|
||||
class Client : public IDnsListener, public ILineListener
|
||||
class Client : public BaseClient, public IDnsListener, public ILineListener
|
||||
{
|
||||
public:
|
||||
enum SocketState {
|
||||
UnconnectedState,
|
||||
HostLookupState,
|
||||
ConnectingState,
|
||||
ConnectedState,
|
||||
ClosingState
|
||||
};
|
||||
|
||||
enum Extension {
|
||||
EXT_ALGO,
|
||||
EXT_NICEHASH,
|
||||
EXT_CONNECT,
|
||||
EXT_TLS,
|
||||
EXT_KEEPALIVE,
|
||||
EXT_MAX
|
||||
};
|
||||
|
||||
constexpr static int kResponseTimeout = 20 * 1000;
|
||||
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
|
@ -84,33 +68,17 @@ public:
|
|||
Client(int id, const char *agent, IClientListener *listener);
|
||||
~Client() override;
|
||||
|
||||
bool disconnect();
|
||||
bool isTLS() const;
|
||||
const char *tlsFingerprint() const;
|
||||
const char *tlsVersion() const;
|
||||
int64_t submit(const JobResult &result);
|
||||
void connect();
|
||||
void connect(const Pool &pool);
|
||||
void deleteLater();
|
||||
void setPool(const Pool &pool);
|
||||
void tick(uint64_t now);
|
||||
bool disconnect() override;
|
||||
bool isTLS() const override;
|
||||
const char *tlsFingerprint() const override;
|
||||
const char *tlsVersion() const override;
|
||||
int64_t submit(const JobResult &result) override;
|
||||
void connect() override;
|
||||
void connect(const Pool &pool) override;
|
||||
void deleteLater() override;
|
||||
void tick(uint64_t now) override;
|
||||
|
||||
inline bool isEnabled() const { return m_enabled; }
|
||||
inline bool isReady() const { return m_state == ConnectedState && m_failures == 0; }
|
||||
inline const char *host() const { return m_pool.host(); }
|
||||
inline const char *ip() const { return m_ip; }
|
||||
inline const Job &job() const { return m_job; }
|
||||
inline const Pool &pool() const { return m_pool; }
|
||||
inline int id() const { return m_id; }
|
||||
inline SocketState state() const { return m_state; }
|
||||
inline uint16_t port() const { return m_pool.port(); }
|
||||
inline void setAlgo(const Algorithm &algo) { m_pool.setAlgo(algo); }
|
||||
inline void setEnabled(bool enabled) { m_enabled = enabled; }
|
||||
inline void setQuiet(bool quiet) { m_quiet = quiet; }
|
||||
inline void setRetries(int retries) { m_retries = retries; }
|
||||
inline void setRetryPause(int ms) { m_retryPause = ms; }
|
||||
|
||||
template<Extension ext> inline bool has() const noexcept { return m_extensions.test(ext); }
|
||||
inline bool hasExtension(Extension extension) const noexcept override { return m_extensions.test(extension); }
|
||||
|
||||
protected:
|
||||
inline void onLine(char *line, size_t size) override { parse(line, size); }
|
||||
|
@ -118,6 +86,14 @@ protected:
|
|||
void onResolved(const Dns &dns, int status) override;
|
||||
|
||||
private:
|
||||
enum SocketState {
|
||||
UnconnectedState,
|
||||
HostLookupState,
|
||||
ConnectingState,
|
||||
ConnectedState,
|
||||
ClosingState
|
||||
};
|
||||
|
||||
class Tls;
|
||||
|
||||
bool close();
|
||||
|
@ -145,7 +121,9 @@ private:
|
|||
|
||||
inline bool isQuiet() const { return m_quiet || m_failures >= m_retries; }
|
||||
inline const char *url() const { return m_pool.url(); }
|
||||
inline SocketState state() const { return m_state; }
|
||||
inline void setExtension(Extension ext, bool enable) noexcept { m_extensions.set(ext, enable); }
|
||||
template<Extension ext> inline bool has() const noexcept { return m_extensions.test(ext); }
|
||||
|
||||
static void onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf);
|
||||
static void onClose(uv_handle_t *handle);
|
||||
|
@ -154,24 +132,14 @@ private:
|
|||
|
||||
static inline Client *getClient(void *data) { return m_storage.get(data); }
|
||||
|
||||
bool m_enabled;
|
||||
bool m_ipv6;
|
||||
bool m_quiet;
|
||||
char m_sendBuf[2048];
|
||||
const char *m_agent;
|
||||
Dns *m_dns;
|
||||
IClientListener *m_listener;
|
||||
int m_id;
|
||||
int m_retries;
|
||||
int m_retryPause;
|
||||
int64_t m_failures;
|
||||
Job m_job;
|
||||
Pool m_pool;
|
||||
RecvBuf<kInputBufferSize> m_recvBuf;
|
||||
SocketState m_state;
|
||||
std::bitset<EXT_MAX> m_extensions;
|
||||
std::map<int64_t, SubmitResult> m_results;
|
||||
String m_ip;
|
||||
String m_rpcId;
|
||||
Tls *m_tls;
|
||||
uint64_t m_expire;
|
||||
|
|
|
@ -129,7 +129,7 @@ void xmrig::FailoverStrategy::tick(uint64_t now)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::FailoverStrategy::onClose(Client *client, int failures)
|
||||
void xmrig::FailoverStrategy::onClose(IClient *client, int failures)
|
||||
{
|
||||
if (failures == -1) {
|
||||
return;
|
||||
|
@ -150,7 +150,7 @@ void xmrig::FailoverStrategy::onClose(Client *client, int failures)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::FailoverStrategy::onJobReceived(Client *client, const Job &job, const rapidjson::Value &)
|
||||
void xmrig::FailoverStrategy::onJobReceived(IClient *client, const Job &job, const rapidjson::Value &)
|
||||
{
|
||||
if (m_active == client->id()) {
|
||||
m_listener->onJob(this, client, job);
|
||||
|
@ -158,7 +158,7 @@ void xmrig::FailoverStrategy::onJobReceived(Client *client, const Job &job, cons
|
|||
}
|
||||
|
||||
|
||||
void xmrig::FailoverStrategy::onLoginSuccess(Client *client)
|
||||
void xmrig::FailoverStrategy::onLoginSuccess(IClient *client)
|
||||
{
|
||||
int active = m_active;
|
||||
|
||||
|
@ -179,7 +179,7 @@ void xmrig::FailoverStrategy::onLoginSuccess(Client *client)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::FailoverStrategy::onResultAccepted(Client *client, const SubmitResult &result, const char *error)
|
||||
void xmrig::FailoverStrategy::onResultAccepted(IClient *client, const SubmitResult &result, const char *error)
|
||||
{
|
||||
m_listener->onResultAccepted(this, client, result, error);
|
||||
}
|
||||
|
|
|
@ -51,9 +51,9 @@ public:
|
|||
void add(const Pool &pool);
|
||||
|
||||
protected:
|
||||
inline bool isActive() const override { return m_active >= 0; }
|
||||
inline Client *client() const override { return active(); }
|
||||
inline void onLogin(Client *, rapidjson::Document &, rapidjson::Value &) override {}
|
||||
inline bool isActive() const override { return m_active >= 0; }
|
||||
inline Client *client() const override { return active(); }
|
||||
inline void onLogin(IClient *, rapidjson::Document &, rapidjson::Value &) override {}
|
||||
|
||||
int64_t submit(const JobResult &result) override;
|
||||
void connect() override;
|
||||
|
@ -62,10 +62,10 @@ protected:
|
|||
void stop() override;
|
||||
void tick(uint64_t now) override;
|
||||
|
||||
void onClose(Client *client, int failures) override;
|
||||
void onJobReceived(Client *client, const Job &job, const rapidjson::Value ¶ms) override;
|
||||
void onLoginSuccess(Client *client) override;
|
||||
void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override;
|
||||
void onClose(IClient *client, int failures) override;
|
||||
void onJobReceived(IClient *client, const Job &job, const rapidjson::Value ¶ms) override;
|
||||
void onLoginSuccess(IClient *client) override;
|
||||
void onResultAccepted(IClient *client, const SubmitResult &result, const char *error) override;
|
||||
|
||||
private:
|
||||
inline Client *active() const { return m_pools[static_cast<size_t>(m_active)]; }
|
||||
|
|
|
@ -87,7 +87,7 @@ void xmrig::SinglePoolStrategy::tick(uint64_t now)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::SinglePoolStrategy::onClose(Client *, int)
|
||||
void xmrig::SinglePoolStrategy::onClose(IClient *, int)
|
||||
{
|
||||
if (!isActive()) {
|
||||
return;
|
||||
|
@ -98,20 +98,20 @@ void xmrig::SinglePoolStrategy::onClose(Client *, int)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::SinglePoolStrategy::onJobReceived(Client *client, const Job &job, const rapidjson::Value &)
|
||||
void xmrig::SinglePoolStrategy::onJobReceived(IClient *client, const Job &job, const rapidjson::Value &)
|
||||
{
|
||||
m_listener->onJob(this, client, job);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::SinglePoolStrategy::onLoginSuccess(Client *client)
|
||||
void xmrig::SinglePoolStrategy::onLoginSuccess(IClient *client)
|
||||
{
|
||||
m_active = true;
|
||||
m_listener->onActive(this, client);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::SinglePoolStrategy::onResultAccepted(Client *client, const SubmitResult &result, const char *error)
|
||||
void xmrig::SinglePoolStrategy::onResultAccepted(IClient *client, const SubmitResult &result, const char *error)
|
||||
{
|
||||
m_listener->onResultAccepted(this, client, result, error);
|
||||
}
|
||||
|
|
|
@ -45,9 +45,9 @@ public:
|
|||
~SinglePoolStrategy() override;
|
||||
|
||||
protected:
|
||||
inline bool isActive() const override { return m_active; }
|
||||
inline Client *client() const override { return m_client; }
|
||||
inline void onLogin(Client *, rapidjson::Document &, rapidjson::Value &) override {}
|
||||
inline bool isActive() const override { return m_active; }
|
||||
inline Client *client() const override { return m_client; }
|
||||
inline void onLogin(IClient *, rapidjson::Document &, rapidjson::Value &) override {}
|
||||
|
||||
int64_t submit(const JobResult &result) override;
|
||||
void connect() override;
|
||||
|
@ -56,10 +56,10 @@ protected:
|
|||
void stop() override;
|
||||
void tick(uint64_t now) override;
|
||||
|
||||
void onClose(Client *client, int failures) override;
|
||||
void onJobReceived(Client *client, const Job &job, const rapidjson::Value ¶ms) override;
|
||||
void onLoginSuccess(Client *client) override;
|
||||
void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override;
|
||||
void onClose(IClient *client, int failures) override;
|
||||
void onJobReceived(IClient *client, const Job &job, const rapidjson::Value ¶ms) override;
|
||||
void onLoginSuccess(IClient *client) override;
|
||||
void onResultAccepted(IClient *client, const SubmitResult &result, const char *error) override;
|
||||
|
||||
private:
|
||||
bool m_active;
|
||||
|
|
|
@ -91,18 +91,18 @@ void xmrig::Network::connect()
|
|||
}
|
||||
|
||||
|
||||
void xmrig::Network::onActive(IStrategy *strategy, Client *client)
|
||||
void xmrig::Network::onActive(IStrategy *strategy, IClient *client)
|
||||
{
|
||||
if (m_donate && m_donate == strategy) {
|
||||
LOG_NOTICE("dev donate started");
|
||||
return;
|
||||
}
|
||||
|
||||
m_state.setPool(client->host(), client->port(), client->ip());
|
||||
m_state.setPool(client->pool().host(), client->pool().port(), client->ip());
|
||||
|
||||
const char *tlsVersion = client->tlsVersion();
|
||||
LOG_INFO(WHITE_BOLD("use pool ") CYAN_BOLD("%s:%d ") GREEN_BOLD("%s") " " BLACK_BOLD("%s"),
|
||||
client->host(), client->port(), tlsVersion ? tlsVersion : "", client->ip());
|
||||
client->pool().host().data(), client->pool().port(), tlsVersion ? tlsVersion : "", client->ip().data());
|
||||
|
||||
const char *fingerprint = client->tlsFingerprint();
|
||||
if (fingerprint != nullptr) {
|
||||
|
@ -127,7 +127,7 @@ void xmrig::Network::onConfigChanged(Config *config, Config *previousConfig)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::Network::onJob(IStrategy *strategy, Client *client, const Job &job)
|
||||
void xmrig::Network::onJob(IStrategy *strategy, IClient *client, const Job &job)
|
||||
{
|
||||
if (m_donate && m_donate->isActive() && m_donate != strategy) {
|
||||
return;
|
||||
|
@ -176,7 +176,7 @@ void xmrig::Network::onRequest(IApiRequest &request)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::Network::onResultAccepted(IStrategy *, Client *, const SubmitResult &result, const char *error)
|
||||
void xmrig::Network::onResultAccepted(IStrategy *, IClient *, const SubmitResult &result, const char *error)
|
||||
{
|
||||
m_state.add(result, error);
|
||||
|
||||
|
@ -191,15 +191,15 @@ void xmrig::Network::onResultAccepted(IStrategy *, Client *, const SubmitResult
|
|||
}
|
||||
|
||||
|
||||
void xmrig::Network::setJob(Client *client, const Job &job, bool donate)
|
||||
void xmrig::Network::setJob(IClient *client, const Job &job, bool donate)
|
||||
{
|
||||
if (job.height()) {
|
||||
LOG_INFO(MAGENTA_BOLD("new job") " from " WHITE_BOLD("%s:%d") " diff " WHITE_BOLD("%" PRIu64) " algo " WHITE_BOLD("%s") " height " WHITE_BOLD("%" PRIu64),
|
||||
client->host(), client->port(), job.diff(), job.algorithm().shortName(), job.height());
|
||||
client->pool().host().data(), client->pool().port(), job.diff(), job.algorithm().shortName(), job.height());
|
||||
}
|
||||
else {
|
||||
LOG_INFO(MAGENTA_BOLD("new job") " from " WHITE_BOLD("%s:%d") " diff " WHITE_BOLD("%" PRIu64) " algo " WHITE_BOLD("%s"),
|
||||
client->host(), client->port(), job.diff(), job.algorithm().shortName());
|
||||
client->pool().host().data(), client->pool().port(), job.diff(), job.algorithm().shortName());
|
||||
}
|
||||
|
||||
if (!donate && m_donate) {
|
||||
|
|
|
@ -58,18 +58,18 @@ public:
|
|||
protected:
|
||||
inline void onTimer(const Timer *) override { tick(); }
|
||||
|
||||
void onActive(IStrategy *strategy, Client *client) override;
|
||||
void onActive(IStrategy *strategy, IClient *client) override;
|
||||
void onConfigChanged(Config *config, Config *previousConfig) override;
|
||||
void onJob(IStrategy *strategy, Client *client, const Job &job) override;
|
||||
void onJob(IStrategy *strategy, IClient *client, const Job &job) override;
|
||||
void onJobResult(const JobResult &result) override;
|
||||
void onPause(IStrategy *strategy) override;
|
||||
void onRequest(IApiRequest &request) override;
|
||||
void onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) override;
|
||||
void onResultAccepted(IStrategy *strategy, IClient *client, const SubmitResult &result, const char *error) override;
|
||||
|
||||
private:
|
||||
constexpr static int kTickInterval = 1 * 1000;
|
||||
|
||||
void setJob(Client *client, const Job &job, bool donate);
|
||||
void setJob(IClient *client, const Job &job, bool donate);
|
||||
void tick();
|
||||
|
||||
# ifdef XMRIG_FEATURE_API
|
||||
|
|
|
@ -157,7 +157,7 @@ void xmrig::DonateStrategy::tick(uint64_t now)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::DonateStrategy::onActive(IStrategy *, Client *client)
|
||||
void xmrig::DonateStrategy::onActive(IStrategy *, IClient *client)
|
||||
{
|
||||
if (isActive()) {
|
||||
return;
|
||||
|
@ -173,7 +173,7 @@ void xmrig::DonateStrategy::onPause(IStrategy *)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::DonateStrategy::onClose(Client *, int failures)
|
||||
void xmrig::DonateStrategy::onClose(IClient *, int failures)
|
||||
{
|
||||
if (failures == 2 && m_controller->config()->pools().proxyDonate() == Pools::PROXY_DONATE_AUTO) {
|
||||
m_proxy->deleteLater();
|
||||
|
@ -184,7 +184,7 @@ void xmrig::DonateStrategy::onClose(Client *, int failures)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::DonateStrategy::onLogin(Client *, rapidjson::Document &doc, rapidjson::Value ¶ms)
|
||||
void xmrig::DonateStrategy::onLogin(IClient *, rapidjson::Document &doc, rapidjson::Value ¶ms)
|
||||
{
|
||||
auto &allocator = doc.GetAllocator();
|
||||
|
||||
|
@ -203,7 +203,7 @@ void xmrig::DonateStrategy::onLogin(Client *, rapidjson::Document &doc, rapidjso
|
|||
}
|
||||
|
||||
|
||||
void xmrig::DonateStrategy::onLoginSuccess(Client *client)
|
||||
void xmrig::DonateStrategy::onLoginSuccess(IClient *client)
|
||||
{
|
||||
if (isActive()) {
|
||||
return;
|
||||
|
@ -227,14 +227,14 @@ xmrig::Client *xmrig::DonateStrategy::createProxy()
|
|||
}
|
||||
|
||||
IStrategy *strategy = m_controller->network()->strategy();
|
||||
if (!strategy->isActive() || !strategy->client()->has<Client::EXT_CONNECT>()) {
|
||||
if (!strategy->isActive() || !strategy->client()->hasExtension(IClient::EXT_CONNECT)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const Client *client = strategy->client();
|
||||
m_tls = client->has<Client::EXT_TLS>();
|
||||
m_tls = client->hasExtension(IClient::EXT_TLS);
|
||||
|
||||
Pool pool(client->ip(), client->port(), m_userId, client->pool().password(), 0, true, client->isTLS());
|
||||
Pool pool(client->ip(), client->pool().port(), m_userId, client->pool().password(), 0, true, client->isTLS());
|
||||
pool.setAlgo(client->pool().algorithm());
|
||||
|
||||
Client *proxy = new Client(-1, Platform::userAgent(), this);
|
||||
|
@ -251,7 +251,7 @@ void xmrig::DonateStrategy::idle(double min, double max)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::DonateStrategy::setJob(Client *client, const Job &job)
|
||||
void xmrig::DonateStrategy::setJob(IClient *client, const Job &job)
|
||||
{
|
||||
if (isActive()) {
|
||||
m_listener->onJob(this, client, job);
|
||||
|
@ -259,7 +259,7 @@ void xmrig::DonateStrategy::setJob(Client *client, const Job &job)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::DonateStrategy::setResult(Client *client, const SubmitResult &result, const char *error)
|
||||
void xmrig::DonateStrategy::setResult(IClient *client, const SubmitResult &result, const char *error)
|
||||
{
|
||||
m_listener->onResultAccepted(this, client, result, error);
|
||||
}
|
||||
|
|
|
@ -51,13 +51,13 @@ public:
|
|||
~DonateStrategy() override;
|
||||
|
||||
protected:
|
||||
inline bool isActive() const override { return state() == STATE_ACTIVE; }
|
||||
inline Client *client() const override { return m_proxy ? m_proxy : m_strategy->client(); }
|
||||
inline void onJob(IStrategy *, Client *client, const Job &job) override { setJob(client, job); }
|
||||
inline void onJobReceived(Client *client, const Job &job, const rapidjson::Value &) override { setJob(client, job); }
|
||||
inline void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override { setResult(client, result, error); }
|
||||
inline void onResultAccepted(IStrategy *, Client *client, const SubmitResult &result, const char *error) override { setResult(client, result, error); }
|
||||
inline void resume() override {}
|
||||
inline bool isActive() const override { return state() == STATE_ACTIVE; }
|
||||
inline Client *client() const override { return m_proxy ? m_proxy : m_strategy->client(); }
|
||||
inline void onJob(IStrategy *, IClient *client, const Job &job) override { setJob(client, job); }
|
||||
inline void onJobReceived(IClient *client, const Job &job, const rapidjson::Value &) override { setJob(client, job); }
|
||||
inline void onResultAccepted(IClient *client, const SubmitResult &result, const char *error) override { setResult(client, result, error); }
|
||||
inline void onResultAccepted(IStrategy *, IClient *client, const SubmitResult &result, const char *error) override { setResult(client, result, error); }
|
||||
inline void resume() override {}
|
||||
|
||||
int64_t submit(const JobResult &result) override;
|
||||
void connect() override;
|
||||
|
@ -65,12 +65,12 @@ protected:
|
|||
void stop() override;
|
||||
void tick(uint64_t now) override;
|
||||
|
||||
void onActive(IStrategy *strategy, Client *client) override;
|
||||
void onActive(IStrategy *strategy, IClient *client) override;
|
||||
void onPause(IStrategy *strategy) override;
|
||||
|
||||
void onClose(Client *client, int failures) override;
|
||||
void onLogin(Client *client, rapidjson::Document &doc, rapidjson::Value ¶ms) override;
|
||||
void onLoginSuccess(Client *client) override;
|
||||
void onClose(IClient *client, int failures) override;
|
||||
void onLogin(IClient *client, rapidjson::Document &doc, rapidjson::Value ¶ms) override;
|
||||
void onLoginSuccess(IClient *client) override;
|
||||
|
||||
void onTimer(const Timer *timer) override;
|
||||
|
||||
|
@ -87,8 +87,8 @@ private:
|
|||
|
||||
Client *createProxy();
|
||||
void idle(double min, double max);
|
||||
void setJob(Client *client, const Job &job);
|
||||
void setResult(Client *client, const SubmitResult &result, const char *error);
|
||||
void setJob(IClient *client, const Job &job);
|
||||
void setResult(IClient *client, const SubmitResult &result, const char *error);
|
||||
void setState(State state);
|
||||
|
||||
bool m_tls;
|
||||
|
|
Loading…
Reference in a new issue