mirror of
https://github.com/xmrig/xmrig.git
synced 2026-04-19 05:33:33 -04:00
Added BenchConfig class.
This commit is contained in:
57
src/base/net/stratum/benchmark/BenchClient.cpp
Normal file
57
src/base/net/stratum/benchmark/BenchClient.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 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/benchmark/BenchClient.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "base/kernel/interfaces/IClientListener.h"
|
||||
#include "base/net/stratum/benchmark/BenchConfig.h"
|
||||
|
||||
|
||||
xmrig::BenchClient::BenchClient(const std::shared_ptr<BenchConfig> &benchmark, IClientListener* listener) :
|
||||
m_listener(listener)
|
||||
{
|
||||
m_job.setAlgorithm(benchmark->algorithm());
|
||||
|
||||
std::vector<char> blob(112 * 2 + 1, '0');
|
||||
|
||||
blob.back() = '\0';
|
||||
m_job.setBlob(blob.data());
|
||||
|
||||
blob[Job::kMaxSeedSize * 2] = '\0';
|
||||
m_job.setSeedHash(blob.data());
|
||||
|
||||
m_job.setDiff(uint64_t(-1));
|
||||
m_job.setHeight(1);
|
||||
|
||||
m_job.setId("00000000");
|
||||
}
|
||||
|
||||
|
||||
void xmrig::BenchClient::connect()
|
||||
{
|
||||
m_listener->onLoginSuccess(this);
|
||||
|
||||
rapidjson::Value params;
|
||||
m_listener->onJobReceived(this, m_job, params);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::BenchClient::setPool(const Pool &pool)
|
||||
{
|
||||
m_pool = pool;
|
||||
}
|
||||
78
src/base/net/stratum/benchmark/BenchClient.h
Normal file
78
src/base/net/stratum/benchmark/BenchClient.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 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_BENCHCLIENT_H
|
||||
#define XMRIG_BENCHCLIENT_H
|
||||
|
||||
|
||||
#include "base/net/stratum/Client.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class BenchClient : public IClient
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(BenchClient)
|
||||
|
||||
BenchClient(const std::shared_ptr<BenchConfig> &benchmark, IClientListener* listener);
|
||||
~BenchClient() override = default;
|
||||
|
||||
inline bool disconnect() override { return true; }
|
||||
inline bool hasExtension(Extension) const noexcept override { return false; }
|
||||
inline bool isEnabled() const override { return true; }
|
||||
inline bool isTLS() const override { return false; }
|
||||
inline const char *mode() const override { return "benchmark"; }
|
||||
inline const char *tag() const override { return "null"; }
|
||||
inline const char *tlsFingerprint() const override { return nullptr; }
|
||||
inline const char *tlsVersion() const override { return nullptr; }
|
||||
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 0; }
|
||||
inline int64_t send(const rapidjson::Value &, Callback) override { return 0; }
|
||||
inline int64_t send(const rapidjson::Value &) override { return 0; }
|
||||
inline int64_t sequence() const override { return 0; }
|
||||
inline int64_t submit(const JobResult &) override { return 0; }
|
||||
inline void connect(const Pool &pool) override { setPool(pool); }
|
||||
inline void deleteLater() override {}
|
||||
inline void setAlgo(const Algorithm &algo) override {}
|
||||
inline void setEnabled(bool enabled) override {}
|
||||
inline void setProxy(const ProxyUrl &proxy) override {}
|
||||
inline void setQuiet(bool quiet) override {}
|
||||
inline void setRetries(int retries) override {}
|
||||
inline void setRetryPause(uint64_t ms) override {}
|
||||
inline void tick(uint64_t now) override {}
|
||||
|
||||
void connect() override;
|
||||
void setPool(const Pool &pool) override;
|
||||
|
||||
private:
|
||||
IClientListener* m_listener;
|
||||
Job m_job;
|
||||
Pool m_pool;
|
||||
std::shared_ptr<BenchConfig> m_benchmark;
|
||||
String m_ip;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* XMRIG_BENCHCLIENT_H */
|
||||
86
src/base/net/stratum/benchmark/BenchConfig.cpp
Normal file
86
src/base/net/stratum/benchmark/BenchConfig.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 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/benchmark/BenchConfig.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "base/io/json/Json.h"
|
||||
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
const char *BenchConfig::kAlgo = "algo";
|
||||
const char *BenchConfig::kBenchmark = "benchmark";
|
||||
const char *BenchConfig::kHash = "hash";
|
||||
const char *BenchConfig::kSeed = "seed";
|
||||
const char *BenchConfig::kSize = "size";
|
||||
const char *BenchConfig::kSubmit = "submit";
|
||||
const char *BenchConfig::kVerify = "verify";
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::BenchConfig::BenchConfig(uint32_t size, const String &id, const rapidjson::Value &object) :
|
||||
m_algorithm(Json::getString(object, kAlgo)),
|
||||
m_submit(Json::getBool(object, kSubmit)),
|
||||
m_id(id),
|
||||
m_seed(Json::getString(object, kSeed)),
|
||||
m_size(size),
|
||||
m_hash(0)
|
||||
{
|
||||
if (!m_algorithm.isValid() || m_algorithm.family() != Algorithm::RANDOM_X) {
|
||||
m_algorithm = Algorithm::RX_0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
xmrig::BenchConfig *xmrig::BenchConfig::create(const rapidjson::Value &object)
|
||||
{
|
||||
if (!object.IsObject() || object.ObjectEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const uint32_t size = getSize(Json::getString(object, kSize));
|
||||
const String id = Json::getString(object, kVerify);
|
||||
|
||||
if (size == 0 && id.isEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return new BenchConfig(size, id, object);
|
||||
}
|
||||
|
||||
|
||||
uint32_t xmrig::BenchConfig::getSize(const char *benchmark)
|
||||
{
|
||||
if (!benchmark) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto size = strtoul(benchmark, nullptr, 10);
|
||||
if (size < 1 || size > 10) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string s = std::to_string(size) + "M";
|
||||
return strcasecmp(benchmark, s.c_str()) == 0 ? size * 1000000 : 0;
|
||||
}
|
||||
67
src/base/net/stratum/benchmark/BenchConfig.h
Normal file
67
src/base/net/stratum/benchmark/BenchConfig.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 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_BENCHCONFIG_H
|
||||
#define XMRIG_BENCHCONFIG_H
|
||||
|
||||
|
||||
#include "base/crypto/Algorithm.h"
|
||||
#include "base/tools/String.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class BenchConfig
|
||||
{
|
||||
public:
|
||||
static const char *kAlgo;
|
||||
static const char *kBenchmark;
|
||||
static const char *kHash;
|
||||
static const char *kSeed;
|
||||
static const char *kSize;
|
||||
static const char *kSubmit;
|
||||
static const char *kVerify;
|
||||
|
||||
BenchConfig(uint32_t size, const String &id, const rapidjson::Value &object);
|
||||
|
||||
static BenchConfig *create(const rapidjson::Value &object);
|
||||
|
||||
inline bool isSubmit() const { return m_submit; }
|
||||
inline const Algorithm &algorithm() const { return m_algorithm; }
|
||||
inline const String &id() const { return m_id; }
|
||||
inline const String &seed() const { return m_seed; }
|
||||
inline uint32_t size() const { return m_size; }
|
||||
inline uint64_t hash() const { return m_hash; }
|
||||
|
||||
private:
|
||||
static uint32_t getSize(const char *benchmark);
|
||||
|
||||
Algorithm m_algorithm;
|
||||
bool m_submit;
|
||||
String m_id;
|
||||
String m_seed;
|
||||
uint32_t m_size;
|
||||
uint64_t m_hash;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* XMRIG_BENCHCONFIG_H */
|
||||
Reference in New Issue
Block a user