Merged v4.0.0-beta
This commit is contained in:
commit
993733cb1f
231 changed files with 32642 additions and 3380 deletions
|
@ -139,6 +139,9 @@ void xmrig::Api::exec(IApiRequest &request)
|
|||
# endif
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
features.PushBack("tls", allocator);
|
||||
# endif
|
||||
# ifdef XMRIG_FEATURE_OPENCL
|
||||
features.PushBack("opencl", allocator);
|
||||
# endif
|
||||
request.reply().AddMember("features", features, allocator);
|
||||
}
|
||||
|
|
|
@ -35,6 +35,11 @@
|
|||
# include <hwloc.h>
|
||||
#endif
|
||||
|
||||
#ifdef XMRIG_FEATURE_OPENCL
|
||||
# include "backend/opencl/wrappers/OclLib.h"
|
||||
# include "backend/opencl/wrappers/OclPlatform.h"
|
||||
#endif
|
||||
|
||||
#include "base/kernel/Entry.h"
|
||||
#include "base/kernel/Process.h"
|
||||
#include "core/config/usage.h"
|
||||
|
@ -142,6 +147,12 @@ xmrig::Entry::Id xmrig::Entry::get(const Process &process)
|
|||
}
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_OPENCL
|
||||
if (args.hasArg("--print-platforms")) {
|
||||
return Platforms;
|
||||
}
|
||||
# endif
|
||||
|
||||
return Default;
|
||||
}
|
||||
|
||||
|
@ -161,6 +172,14 @@ int xmrig::Entry::exec(const Process &process, Id id)
|
|||
return exportTopology(process);
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_OPENCL
|
||||
case Platforms:
|
||||
if (OclLib::init()) {
|
||||
OclPlatform::print();
|
||||
}
|
||||
return 0;
|
||||
# endif
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -39,7 +39,8 @@ public:
|
|||
Default,
|
||||
Usage,
|
||||
Version,
|
||||
Topo
|
||||
Topo,
|
||||
Platforms
|
||||
};
|
||||
|
||||
static Id get(const Process &process);
|
||||
|
|
|
@ -900,6 +900,12 @@ void xmrig::Client::onConnect(uv_connect_t *req, int status)
|
|||
LOG_ERR("[%s] connect error: \"%s\"", client->url(), uv_strerror(status));
|
||||
}
|
||||
|
||||
if (client->state() != ConnectingState) {
|
||||
LOG_ERR("[%s] connect error: \"invalid state: %d\"", client->url(), client->state());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
delete req;
|
||||
client->close();
|
||||
return;
|
||||
|
|
|
@ -25,32 +25,18 @@
|
|||
*/
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
#include "base/net/stratum/Job.h"
|
||||
#include "base/tools/Buffer.h"
|
||||
|
||||
|
||||
xmrig::Job::Job() :
|
||||
m_blob(),
|
||||
m_seedHash()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
xmrig::Job::Job(bool nicehash, const Algorithm &algorithm, const String &clientId) :
|
||||
m_algorithm(algorithm),
|
||||
m_nicehash(nicehash),
|
||||
m_clientId(clientId),
|
||||
m_blob(),
|
||||
m_seedHash()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
xmrig::Job::~Job()
|
||||
m_clientId(clientId)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -96,7 +82,7 @@ bool xmrig::Job::setBlob(const char *blob)
|
|||
|
||||
bool xmrig::Job::setSeedHash(const char *hash)
|
||||
{
|
||||
if (!hash || (strlen(hash) != sizeof(m_seedHash) * 2)) {
|
||||
if (!hash || (strlen(hash) != kMaxSeedSize * 2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -104,7 +90,9 @@ bool xmrig::Job::setSeedHash(const char *hash)
|
|||
m_rawSeedHash = hash;
|
||||
# endif
|
||||
|
||||
return Buffer::fromHex(hash, sizeof(m_seedHash) * 2, m_seedHash);
|
||||
m_seed = Buffer::fromHex(hash, kMaxSeedSize * 2);
|
||||
|
||||
return !m_seed.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
|
@ -173,9 +161,9 @@ void xmrig::Job::copy(const Job &other)
|
|||
m_height = other.m_height;
|
||||
m_target = other.m_target;
|
||||
m_index = other.m_index;
|
||||
m_seed = other.m_seed;
|
||||
|
||||
memcpy(m_blob, other.m_blob, sizeof(m_blob));
|
||||
memcpy(m_seedHash, other.m_seedHash, sizeof(m_seedHash));
|
||||
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
m_rawSeedHash = other.m_rawSeedHash;
|
||||
|
|
|
@ -28,10 +28,11 @@
|
|||
#define XMRIG_JOB_H
|
||||
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
#include "base/tools/Buffer.h"
|
||||
#include "base/tools/String.h"
|
||||
#include "crypto/common/Algorithm.h"
|
||||
|
||||
|
@ -45,10 +46,11 @@ public:
|
|||
// Max blob size is 84 (75 fixed + 9 variable), aligned to 96. https://github.com/xmrig/xmrig/issues/1 Thanks fireice-uk.
|
||||
// SECOR increase requirements for blob size: https://github.com/xmrig/xmrig/issues/913
|
||||
static constexpr const size_t kMaxBlobSize = 128;
|
||||
static constexpr const size_t kMaxSeedSize = 32;
|
||||
|
||||
Job();
|
||||
Job() = default;
|
||||
Job(bool nicehash, const Algorithm &algorithm, const String &clientId);
|
||||
~Job();
|
||||
~Job() = default;
|
||||
|
||||
bool isEqual(const Job &other) const;
|
||||
bool setBlob(const char *blob);
|
||||
|
@ -60,11 +62,11 @@ public:
|
|||
inline bool isValid() const { return m_size > 0 && m_diff > 0; }
|
||||
inline bool setId(const char *id) { return m_id = id; }
|
||||
inline const Algorithm &algorithm() const { return m_algorithm; }
|
||||
inline const Buffer &seed() const { return m_seed; }
|
||||
inline const String &clientId() const { return m_clientId; }
|
||||
inline const String &id() const { return m_id; }
|
||||
inline const uint32_t *nonce() const { return reinterpret_cast<const uint32_t*>(m_blob + 39); }
|
||||
inline const uint8_t *blob() const { return m_blob; }
|
||||
inline const uint8_t *seedHash() const { return m_seedHash; }
|
||||
inline size_t size() const { return m_size; }
|
||||
inline uint32_t *nonce() { return reinterpret_cast<uint32_t*>(m_blob + 39); }
|
||||
inline uint64_t diff() const { return m_diff; }
|
||||
|
@ -97,15 +99,15 @@ private:
|
|||
|
||||
Algorithm m_algorithm;
|
||||
bool m_nicehash = false;
|
||||
Buffer m_seed;
|
||||
size_t m_size = 0;
|
||||
String m_clientId;
|
||||
String m_id;
|
||||
uint64_t m_diff = 0;
|
||||
uint64_t m_height = 0;
|
||||
uint64_t m_target = 0;
|
||||
uint8_t m_blob[kMaxBlobSize];
|
||||
uint8_t m_blob[kMaxBlobSize]{ 0 };
|
||||
uint8_t m_index = 0;
|
||||
uint8_t m_seedHash[32];
|
||||
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
char m_rawBlob[kMaxBlobSize * 2 + 8];
|
||||
|
|
|
@ -53,14 +53,7 @@ static inline uint8_t hf_bin2hex(uint8_t c)
|
|||
}
|
||||
|
||||
|
||||
xmrig::Buffer::Buffer() :
|
||||
m_data(nullptr),
|
||||
m_size(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
xmrig::Buffer::Buffer(Buffer &&other) :
|
||||
xmrig::Buffer::Buffer(Buffer &&other) noexcept :
|
||||
m_data(other.m_data),
|
||||
m_size(other.m_size)
|
||||
{
|
||||
|
@ -138,11 +131,13 @@ bool xmrig::Buffer::fromHex(const uint8_t *in, size_t size, uint8_t *out)
|
|||
xmrig::Buffer xmrig::Buffer::fromHex(const char *data, size_t size)
|
||||
{
|
||||
if (data == nullptr || size % 2 != 0) {
|
||||
return Buffer();
|
||||
return {};
|
||||
}
|
||||
|
||||
Buffer buf(size / 2);
|
||||
fromHex(data, size, buf.data());
|
||||
if (!fromHex(data, size, buf.data())) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
@ -157,12 +152,6 @@ void xmrig::Buffer::toHex(const uint8_t *in, size_t size, uint8_t *out)
|
|||
}
|
||||
|
||||
|
||||
xmrig::String xmrig::Buffer::toHex(const uint8_t *in, size_t size)
|
||||
{
|
||||
return Buffer(reinterpret_cast<const char *>(in), size).toHex();
|
||||
}
|
||||
|
||||
|
||||
xmrig::String xmrig::Buffer::toHex() const
|
||||
{
|
||||
if (m_size == 0) {
|
||||
|
|
|
@ -35,14 +35,15 @@ namespace xmrig {
|
|||
class Buffer
|
||||
{
|
||||
public:
|
||||
Buffer();
|
||||
Buffer(Buffer &&other);
|
||||
Buffer() = default;
|
||||
Buffer(Buffer &&other) noexcept;
|
||||
Buffer(const Buffer &other);
|
||||
Buffer(const char *data, size_t size);
|
||||
Buffer(size_t size);
|
||||
~Buffer();
|
||||
|
||||
|
||||
inline bool isEmpty() const { return size() == 0; }
|
||||
inline bool isEqual(const Buffer &other) const { return m_size == other.m_size && (m_size == 0 || memcmp(m_data, other.m_data, m_size) == 0); }
|
||||
inline char *data() { return m_data; }
|
||||
inline const char *data() const { return m_data; }
|
||||
|
@ -55,7 +56,7 @@ public:
|
|||
|
||||
inline bool operator!=(const Buffer &other) const { return !isEqual(other); }
|
||||
inline bool operator==(const Buffer &other) const { return isEqual(other); }
|
||||
inline Buffer &operator=(Buffer &&other) { move(std::move(other)); return *this; }
|
||||
inline Buffer &operator=(Buffer &&other) noexcept { move(std::move(other)); return *this; }
|
||||
inline Buffer &operator=(const Buffer &other) { from(other); return *this; }
|
||||
|
||||
|
||||
|
@ -67,12 +68,13 @@ public:
|
|||
inline static bool fromHex(const char *in, size_t size, uint8_t *out) { return fromHex(reinterpret_cast<const uint8_t *>(in), size, out); }
|
||||
inline static Buffer fromHex(const char *data) { return fromHex(data, strlen(data)); }
|
||||
inline static Buffer fromHex(const String &str) { return fromHex(str.data(), str.size()); }
|
||||
inline static String toHex(const char *in, size_t size) { return Buffer(in, size).toHex(); }
|
||||
inline static String toHex(const uint8_t *in, size_t size) { return Buffer(reinterpret_cast<const char *>(in), size).toHex(); }
|
||||
inline static void toHex(const char *in, size_t size, char *out) { return toHex(reinterpret_cast<const uint8_t *>(in), size, reinterpret_cast<uint8_t *>(out)); }
|
||||
inline static void toHex(const uint8_t *in, size_t size, char *out) { return toHex(in, size, reinterpret_cast<uint8_t *>(out)); }
|
||||
|
||||
static bool fromHex(const uint8_t *in, size_t size, uint8_t *out);
|
||||
static Buffer fromHex(const char *data, size_t size);
|
||||
static String toHex(const uint8_t *in, size_t size);
|
||||
static void toHex(const uint8_t *in, size_t size, uint8_t *out);
|
||||
String toHex() const;
|
||||
|
||||
|
@ -80,8 +82,8 @@ private:
|
|||
void copy(const char *data, size_t size);
|
||||
void move(Buffer &&other);
|
||||
|
||||
char *m_data;
|
||||
size_t m_size;
|
||||
char *m_data = nullptr;
|
||||
size_t m_size = 0;
|
||||
};
|
||||
|
||||
|
||||
|
|
52
src/base/tools/Object.h
Normal file
52
src/base/tools/Object.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
/* 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_OBJECT_H
|
||||
#define XMRIG_OBJECT_H
|
||||
|
||||
|
||||
#include <chrono>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
#define XMRIG_DISABLE_COPY_MOVE(X) \
|
||||
X(const X &other) = delete; \
|
||||
X(X &&other) = delete; \
|
||||
X &operator=(const X &other) = delete; \
|
||||
X &operator=(X &&other) = delete;
|
||||
|
||||
|
||||
#define XMRIG_DISABLE_COPY_MOVE_DEFAULT(X) \
|
||||
X() = delete; \
|
||||
X(const X &other) = delete; \
|
||||
X(X &&other) = delete; \
|
||||
X &operator=(const X &other) = delete; \
|
||||
X &operator=(X &&other) = delete;
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
#endif /* XMRIG_OBJECT_H */
|
|
@ -31,7 +31,6 @@
|
|||
|
||||
|
||||
xmrig::String::String(const char *str) :
|
||||
m_data(nullptr),
|
||||
m_size(str == nullptr ? 0 : strlen(str))
|
||||
{
|
||||
if (m_size == 0) {
|
||||
|
@ -44,7 +43,6 @@ xmrig::String::String(const char *str) :
|
|||
|
||||
|
||||
xmrig::String::String(const char *str, size_t size) :
|
||||
m_data(nullptr),
|
||||
m_size(size)
|
||||
{
|
||||
if (str == nullptr) {
|
||||
|
@ -60,7 +58,6 @@ xmrig::String::String(const char *str, size_t size) :
|
|||
|
||||
|
||||
xmrig::String::String(const String &other) :
|
||||
m_data(nullptr),
|
||||
m_size(other.m_size)
|
||||
{
|
||||
if (other.m_data == nullptr) {
|
||||
|
@ -117,7 +114,7 @@ std::vector<xmrig::String> xmrig::String::split(char sep) const
|
|||
for (pos = 0; pos < m_size; ++pos) {
|
||||
if (m_data[pos] == sep) {
|
||||
if ((pos - start) > 0) {
|
||||
out.push_back(String(m_data + start, pos - start));
|
||||
out.emplace_back(m_data + start, pos - start);
|
||||
}
|
||||
|
||||
start = pos + 1;
|
||||
|
@ -125,7 +122,7 @@ std::vector<xmrig::String> xmrig::String::split(char sep) const
|
|||
}
|
||||
|
||||
if ((pos - start) > 0) {
|
||||
out.push_back(String(m_data + start, pos - start));
|
||||
out.emplace_back(m_data + start, pos - start);
|
||||
}
|
||||
|
||||
return out;
|
||||
|
@ -146,6 +143,20 @@ xmrig::String &xmrig::String::toLower()
|
|||
}
|
||||
|
||||
|
||||
xmrig::String &xmrig::String::toUpper()
|
||||
{
|
||||
if (isNull() || isEmpty()) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < size(); ++i) {
|
||||
m_data[i] = static_cast<char>(toupper(m_data[i]));
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
xmrig::String xmrig::String::join(const std::vector<xmrig::String> &vec, char sep)
|
||||
{
|
||||
if (vec.empty()) {
|
||||
|
|
|
@ -46,9 +46,9 @@ namespace xmrig {
|
|||
class String
|
||||
{
|
||||
public:
|
||||
inline String() : m_data(nullptr), m_size(0) {}
|
||||
inline String(char *str) : m_data(str), m_size(str == nullptr ? 0 : strlen(str)) {}
|
||||
inline String(String &&other) : m_data(other.m_data), m_size(other.m_size) { other.m_data = nullptr; other.m_size = 0; }
|
||||
inline String() = default;
|
||||
inline String(char *str) : m_data(str), m_size(str == nullptr ? 0 : strlen(str)) {}
|
||||
inline String(String &&other) noexcept : m_data(other.m_data), m_size(other.m_size) { other.m_data = nullptr; other.m_size = 0; }
|
||||
|
||||
String(const char *str);
|
||||
String(const char *str, size_t size);
|
||||
|
@ -81,12 +81,13 @@ public:
|
|||
inline String &operator=(const char *str) { copy(str); return *this; }
|
||||
inline String &operator=(const String &str) { copy(str); return *this; }
|
||||
inline String &operator=(std::nullptr_t) { delete [] m_data; m_data = nullptr; m_size = 0; return *this; }
|
||||
inline String &operator=(String &&other) { move(std::move(other)); return *this; }
|
||||
inline String &operator=(String &&other) noexcept { move(std::move(other)); return *this; }
|
||||
|
||||
rapidjson::Value toJSON() const;
|
||||
rapidjson::Value toJSON(rapidjson::Document &doc) const;
|
||||
std::vector<xmrig::String> split(char sep) const;
|
||||
String &toLower();
|
||||
String &toUpper();
|
||||
|
||||
static String join(const std::vector<xmrig::String> &vec, char sep);
|
||||
|
||||
|
@ -96,8 +97,8 @@ private:
|
|||
void move(char *str);
|
||||
void move(String &&other);
|
||||
|
||||
char *m_data;
|
||||
size_t m_size;
|
||||
char *m_data = nullptr;
|
||||
size_t m_size = 0;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue