Self-select initial working implementation.
This commit is contained in:
parent
a62f6f9552
commit
3752551e53
9 changed files with 302 additions and 74 deletions
|
@ -6,6 +6,7 @@
|
|||
* 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 2019 jtgrassie <https://github.com/jtgrassie>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
|
@ -26,15 +27,17 @@
|
|||
#define XMRIG_SELFSELECTCLIENT_H
|
||||
|
||||
|
||||
#include "base/kernel/interfaces/IClientListener.h"
|
||||
#include "base/tools/Object.h"
|
||||
#include "base/kernel/interfaces/IClient.h"
|
||||
#include "base/kernel/interfaces/IClientListener.h"
|
||||
#include "base/kernel/interfaces/IHttpListener.h"
|
||||
#include "base/net/stratum/Job.h"
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class SelfSelectClient : public IClient, public IClientListener
|
||||
class SelfSelectClient : public IClient, public IClientListener, public IHttpListener
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(SelfSelectClient)
|
||||
|
@ -44,40 +47,55 @@ public:
|
|||
|
||||
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); }
|
||||
inline bool disconnect() override { return m_client->disconnect(); }
|
||||
inline bool hasExtension(Extension extension) const noexcept override { return m_client->hasExtension(extension); }
|
||||
inline bool isEnabled() const override { return m_client->isEnabled(); }
|
||||
inline bool isTLS() const override { return m_client->isTLS(); }
|
||||
inline const char *mode() const override { return m_client->mode(); }
|
||||
inline const char *tlsFingerprint() const override { return m_client->tlsFingerprint(); }
|
||||
inline const char *tlsVersion() const override { return m_client->tlsVersion(); }
|
||||
inline const Job &job() const override { return m_client->job(); }
|
||||
inline const Pool &pool() const override { return m_client->pool(); }
|
||||
inline const String &ip() const override { return m_client->ip(); }
|
||||
inline int id() const override { return m_client->id(); }
|
||||
inline int64_t send(const rapidjson::Value &obj) override { return m_client->send(obj); }
|
||||
inline int64_t sequence() const override { return m_client->sequence(); }
|
||||
inline int64_t submit(const JobResult &result) override { return m_client->submit(result); }
|
||||
inline void connect() override { m_client->connect(); }
|
||||
inline void connect(const Pool &pool) override { m_client->connect(pool); }
|
||||
inline void deleteLater() override { m_client->deleteLater(); }
|
||||
inline void setAlgo(const Algorithm &algo) override { m_client->setAlgo(algo); }
|
||||
inline void setEnabled(bool enabled) override { m_client->setEnabled(enabled); }
|
||||
inline void setPool(const Pool &pool) override { m_client->setPool(pool); }
|
||||
inline void setQuiet(bool quiet) override { m_client->setQuiet(quiet); m_quiet = quiet; }
|
||||
inline void setRetries(int retries) override { m_client->setRetries(retries); }
|
||||
inline void setRetryPause(uint64_t ms) override { m_client->setRetryPause(ms); }
|
||||
inline 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); }
|
||||
inline void onClose(IClient *, int failures) override { m_listener->onClose(this, failures); }
|
||||
inline void onLoginSuccess(IClient *) override { m_listener->onLoginSuccess(this); }
|
||||
inline void onResultAccepted(IClient *, const SubmitResult &result, const char *error) override { m_listener->onResultAccepted(this, result, error); }
|
||||
inline void onVerifyAlgorithm(const IClient *, const Algorithm &algorithm, bool *ok) override { m_listener->onVerifyAlgorithm(this, algorithm, ok); }
|
||||
|
||||
void onJobReceived(IClient *, const Job &job, const rapidjson::Value ¶ms) override;
|
||||
void onLogin(IClient *, rapidjson::Document &doc, rapidjson::Value ¶ms) override;
|
||||
|
||||
// IHttpListener
|
||||
void onHttpData(const HttpData &data) override;
|
||||
|
||||
private:
|
||||
bool parseResponse(int64_t id, rapidjson::Value &result, const rapidjson::Value &error);
|
||||
void getBlockTemplate();
|
||||
void retry();
|
||||
void send(int method, const char *url, const char *data = nullptr, size_t size = 0);
|
||||
void send(int method, const char *url, const rapidjson::Document &doc);
|
||||
void submitBlockTemplate(rapidjson::Value &result);
|
||||
|
||||
bool m_quiet = false;
|
||||
IClient *m_client;
|
||||
IClientListener *m_listener;
|
||||
Job m_job;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue