This commit is contained in:
MoneroOcean 2020-04-13 09:07:40 -07:00
commit df7a8d1a52
42 changed files with 1040 additions and 893 deletions

View file

@ -25,7 +25,6 @@
#include "base/crypto/Algorithm.h"
#include "base/crypto/CnAlgo.h"
#include "rapidjson/document.h"
@ -173,15 +172,26 @@ size_t xmrig::Algorithm::l2() const
size_t xmrig::Algorithm::l3() const
{
# if defined(XMRIG_ALGO_RANDOMX) || defined(XMRIG_ALGO_ARGON2) || defined(XMRIG_ALGO_ASTROBWT)
constexpr size_t oneMiB = 0x100000;
# endif
const Family f = family();
const auto f = family();
assert(f != UNKNOWN);
if (f < RANDOM_X) {
return CnAlgo<>::memory(m_id);
switch (f) {
case CN:
return oneMiB * 2;
case CN_LITE:
return oneMiB;
case CN_HEAVY:
return oneMiB * 4;
case CN_PICO:
return oneMiB / 4;
default:
break;
}
# ifdef XMRIG_ALGO_RANDOMX

View file

@ -53,24 +53,9 @@ public:
inline static size_t memory(Algorithm::Id algo)
{
switch (Algorithm::family(algo)) {
case Algorithm::CN:
return CN_MEMORY;
Algorithm algorithm(algo);
case Algorithm::CN_LITE:
return CN_MEMORY / 2;
case Algorithm::CN_HEAVY:
return CN_MEMORY * 2;
case Algorithm::CN_PICO:
return CN_MEMORY / 8;
default:
break;
}
return 0;
return algorithm.isCN() ? algorithm.l3() : 0;
}
inline static uint32_t iterations(Algorithm::Id algo)

View file

@ -45,7 +45,7 @@ public:
AAAA
};
DnsRecord() = default;
DnsRecord() {}
DnsRecord(const addrinfo *addr);
sockaddr *addr(uint16_t port = 0) const;

View file

@ -52,7 +52,7 @@ public:
m_ctx(ctx),
m_body(std::move(body))
{
m_buf = uv_buf_init(const_cast<char *>(m_body.c_str()), m_body.size());
m_buf = uv_buf_init(&m_body.front(), m_body.size());
}
inline ~HttpWriteBaton()

View file

@ -61,7 +61,6 @@ private:
std::weak_ptr<IHttpListener> m_listener;
TlsContext *m_tls = nullptr;
uv_tcp_t *m_tcp = nullptr;
};

View file

@ -155,8 +155,6 @@ int64_t xmrig::Client::send(const rapidjson::Value &obj)
{
using namespace rapidjson;
Value value;
StringBuffer buffer(nullptr, 512);
Writer<StringBuffer> writer(buffer);
obj.Accept(writer);
@ -481,7 +479,7 @@ bool xmrig::Client::send(BIO *bio)
LOG_DEBUG("[%s] TLS send (%d bytes)", url(), static_cast<int>(buf.len));
bool result = false;
if (state() == ConnectedState && uv_is_writable(m_stream)) {
if (state() == ConnectedState && uv_is_writable(stream())) {
result = write(buf);
}
else {
@ -525,7 +523,7 @@ bool xmrig::Client::verifyAlgorithm(const Algorithm &algorithm, const char *algo
bool xmrig::Client::write(const uv_buf_t &buf)
{
const int rc = uv_try_write(m_stream, &buf, 1);
const int rc = uv_try_write(stream(), &buf, 1);
if (static_cast<size_t>(rc) == buf.len) {
return true;
}
@ -575,7 +573,7 @@ int64_t xmrig::Client::send(size_t size)
else
# endif
{
if (state() != ConnectedState || !uv_is_writable(m_stream)) {
if (state() != ConnectedState || !uv_is_writable(stream())) {
LOG_DEBUG_ERR("[%s] send failed, invalid state: %d", url(), m_state);
return -1;
}
@ -664,7 +662,6 @@ void xmrig::Client::onClose()
{
delete m_socket;
m_stream = nullptr;
m_socket = nullptr;
setState(UnconnectedState);
@ -966,8 +963,9 @@ void xmrig::Client::onClose(uv_handle_t *handle)
void xmrig::Client::onConnect(uv_connect_t *req, int status)
{
auto client = getClient(req->data);
delete req;
if (!client) {
delete req;
return;
}
@ -988,7 +986,6 @@ void xmrig::Client::onConnect(uv_connect_t *req, int status)
return;
}
delete req;
client->close();
return;
}
@ -999,12 +996,9 @@ void xmrig::Client::onConnect(uv_connect_t *req, int status)
return;
}
client->m_stream = static_cast<uv_stream_t*>(req->handle);
client->m_stream->data = req->data;
client->setState(ConnectedState);
uv_read_start(client->m_stream, NetBuffer::onAlloc, onRead);
delete req;
uv_read_start(client->stream(), NetBuffer::onAlloc, onRead);
client->handshake();
}

View file

@ -112,10 +112,11 @@ private:
void setState(SocketState state);
void startTimeout();
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); }
inline const char *url() const { return m_pool.url(); }
inline SocketState state() const { return m_state; }
inline uv_stream_t *stream() const { return reinterpret_cast<uv_stream_t *>(m_socket); }
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 onClose(uv_handle_t *handle);
static void onConnect(uv_connect_t *req, int status);
@ -135,7 +136,6 @@ private:
uint64_t m_jobs = 0;
uint64_t m_keepAlive = 0;
uintptr_t m_key = 0;
uv_stream_t *m_stream = nullptr;
uv_tcp_t *m_socket = nullptr;
static Storage<Client> m_storage;