Merge branch 'dev' into sync-base
This commit is contained in:
commit
3ded8e6734
119 changed files with 5867 additions and 14547 deletions
|
@ -74,14 +74,6 @@ static constexpr size_t kZMQGreetingSize1 = 11;
|
|||
static const char kZMQHandshake[] = "\4\x19\5READY\xbSocket-Type\0\0\0\3SUB";
|
||||
static const char kZMQSubscribe[] = "\0\x18\1json-minimal-chain_main";
|
||||
|
||||
static const char kWSSLogin[] = "\
|
||||
GET /ws/%s HTTP/1.1\r\n\
|
||||
Host: %s\r\n\
|
||||
Upgrade: websocket\r\n\
|
||||
Connection: Upgrade\r\n\
|
||||
Sec-WebSocket-Key: %s\r\n\
|
||||
Sec-WebSocket-Version: 13\r\n\r\n";
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
|
@ -98,21 +90,11 @@ xmrig::DaemonClient::~DaemonClient()
|
|||
{
|
||||
delete m_timer;
|
||||
delete m_ZMQSocket;
|
||||
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
delete m_wss.m_socket;
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
void xmrig::DaemonClient::deleteLater()
|
||||
{
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
if (m_pool.isWSS()) {
|
||||
WSSClose(true);
|
||||
}
|
||||
else
|
||||
# endif
|
||||
if (m_pool.zmq_port() >= 0) {
|
||||
ZMQClose(true);
|
||||
}
|
||||
|
@ -142,19 +124,13 @@ bool xmrig::DaemonClient::isTLS() const
|
|||
}
|
||||
|
||||
|
||||
bool xmrig::DaemonClient::isWSS() const
|
||||
{
|
||||
return m_pool.isWSS();
|
||||
}
|
||||
|
||||
|
||||
int64_t xmrig::DaemonClient::submit(const JobResult &result)
|
||||
{
|
||||
if (result.jobId != m_currentJobId) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *data = (m_apiVersion == API_DERO) ? m_blockhashingblob.data() : m_blocktemplateStr.data();
|
||||
char *data = m_blocktemplateStr.data();
|
||||
|
||||
const size_t sig_offset = m_job.nonceOffset() + m_job.nonceSize();
|
||||
|
||||
|
@ -176,17 +152,6 @@ int64_t xmrig::DaemonClient::submit(const JobResult &result)
|
|||
|
||||
Cvt::toHex(data + m_job.nonceOffset() * 2, 8, reinterpret_cast<const uint8_t*>(&result.nonce), 4);
|
||||
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
if (m_pool.isWSS() && (m_apiVersion == API_DERO) && (m_pool.algorithm().id() == Algorithm::ASTROBWT_DERO_2)) {
|
||||
char buf[256];
|
||||
const int n = snprintf(buf, sizeof(buf), "{\"jobid\":\"%s\",\"mbl_blob\":\"%s\"}", m_job.id().data(), data);
|
||||
if (0 <= n && n < static_cast<int>(sizeof(buf))) {
|
||||
return WSSWrite(buf, n) ? 1 : -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
# endif
|
||||
|
||||
if (m_blocktemplate.hasMinerSignature()) {
|
||||
Cvt::toHex(data + sig_offset * 2, 128, result.minerSignature(), 64);
|
||||
}
|
||||
|
@ -197,13 +162,7 @@ int64_t xmrig::DaemonClient::submit(const JobResult &result)
|
|||
Document doc(kObjectType);
|
||||
|
||||
Value params(kArrayType);
|
||||
if (m_apiVersion == API_DERO) {
|
||||
params.PushBack(m_blocktemplateStr.toJSON(), doc.GetAllocator());
|
||||
params.PushBack(m_blockhashingblob.toJSON(), doc.GetAllocator());
|
||||
}
|
||||
else {
|
||||
params.PushBack(m_blocktemplateStr.toJSON(), doc.GetAllocator());
|
||||
}
|
||||
params.PushBack(m_blocktemplateStr.toJSON(), doc.GetAllocator());
|
||||
|
||||
JsonRequest::create(doc, m_sequence, "submitblock", params);
|
||||
|
||||
|
@ -237,16 +196,11 @@ void xmrig::DaemonClient::connect()
|
|||
m_pool.setAlgo(m_coin.algorithm());
|
||||
}
|
||||
|
||||
const xmrig::Algorithm algo = m_pool.algorithm();
|
||||
if ((algo == Algorithm::ASTROBWT_DERO_2) || (m_coin == Coin::DERO) || (m_coin == Coin::DERO_HE)) {
|
||||
m_apiVersion = API_DERO;
|
||||
}
|
||||
|
||||
if ((m_apiVersion == API_MONERO) && !m_walletAddress.isValid()) {
|
||||
return connectError("Invalid wallet address.");
|
||||
}
|
||||
|
||||
if ((m_pool.zmq_port() >= 0) || m_pool.isWSS()) {
|
||||
if (m_pool.zmq_port() >= 0) {
|
||||
m_dns = Dns::resolve(m_pool.host(), this);
|
||||
}
|
||||
else {
|
||||
|
@ -347,15 +301,7 @@ void xmrig::DaemonClient::onTimer(const Timer *)
|
|||
connect();
|
||||
}
|
||||
else if (m_state == ConnectedState) {
|
||||
if (m_pool.isWSS()) {
|
||||
return;
|
||||
}
|
||||
if (m_apiVersion == API_DERO) {
|
||||
rpcSend(JsonRequest::create(m_sequence, "get_info"));
|
||||
}
|
||||
else {
|
||||
send((m_apiVersion == API_MONERO) ? kGetHeight : kGetInfo);
|
||||
}
|
||||
send((m_apiVersion == API_MONERO) ? kGetHeight : kGetInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -390,14 +336,6 @@ void xmrig::DaemonClient::onResolved(const DnsRecords &records, int status, cons
|
|||
uv_tcp_keepalive(s, 1, 60);
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
if (m_pool.isWSS()) {
|
||||
delete m_wss.m_socket;
|
||||
m_wss.m_socket = s;
|
||||
uv_tcp_connect(req, s, record.addr(m_pool.port()), onWSSConnect);
|
||||
}
|
||||
else
|
||||
# endif
|
||||
if (m_pool.zmq_port() > 0) {
|
||||
delete m_ZMQSocket;
|
||||
m_ZMQSocket = s;
|
||||
|
@ -505,11 +443,6 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value ¶ms, int *code)
|
|||
# endif
|
||||
}
|
||||
|
||||
if (m_apiVersion == API_DERO) {
|
||||
const uint64_t offset = Json::getUint64(params, "reserved_offset");
|
||||
Cvt::toHex(m_blockhashingblob.data() + offset * 2, kBlobReserveSize * 2, Cvt::randomBytes(kBlobReserveSize).data(), kBlobReserveSize);
|
||||
}
|
||||
|
||||
if (m_coin.isValid()) {
|
||||
job.setAlgorithm(m_coin.algorithm(m_blocktemplate.majorVersion()));
|
||||
}
|
||||
|
@ -530,13 +463,6 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value ¶ms, int *code)
|
|||
m_blocktemplateStr = std::move(blocktemplate);
|
||||
m_prevHash = Json::getString(params, "prev_hash");
|
||||
|
||||
if (m_apiVersion == API_DERO) {
|
||||
// Truncate to 32 bytes to have the same data as in get_info RPC
|
||||
if (m_prevHash.size() > 64) {
|
||||
m_prevHash.data()[64] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
if (m_state == ConnectingState) {
|
||||
setState(ConnectedState);
|
||||
}
|
||||
|
@ -580,13 +506,6 @@ bool xmrig::DaemonClient::parseResponse(int64_t id, const rapidjson::Value &resu
|
|||
|
||||
const char* error_msg = nullptr;
|
||||
|
||||
if ((m_apiVersion == API_DERO) && result.HasMember("status")) {
|
||||
error_msg = result["status"].GetString();
|
||||
if (!error_msg || (strlen(error_msg) == 0) || (strcmp(error_msg, "OK") == 0)) {
|
||||
error_msg = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (handleSubmitResponse(id, error_msg)) {
|
||||
if (error_msg || (m_pool.zmq_port() < 0)) {
|
||||
getBlockTemplate();
|
||||
|
@ -607,12 +526,7 @@ int64_t xmrig::DaemonClient::getBlockTemplate()
|
|||
|
||||
Value params(kObjectType);
|
||||
params.AddMember("wallet_address", m_user.toJSON(), allocator);
|
||||
if (m_apiVersion == API_DERO) {
|
||||
params.AddMember("reserve_size", static_cast<uint64_t>(kBlobReserveSize), allocator);
|
||||
}
|
||||
else {
|
||||
params.AddMember("extra_nonce", Cvt::toHex(Cvt::randomBytes(kBlobReserveSize)).toJSON(doc), allocator);
|
||||
}
|
||||
params.AddMember("extra_nonce", Cvt::toHex(Cvt::randomBytes(kBlobReserveSize)).toJSON(doc), allocator);
|
||||
|
||||
JsonRequest::create(doc, m_sequence, "getblocktemplate", params);
|
||||
|
||||
|
@ -642,12 +556,6 @@ void xmrig::DaemonClient::retry()
|
|||
setState(ConnectingState);
|
||||
}
|
||||
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
if (m_wss.m_socket) {
|
||||
uv_close(reinterpret_cast<uv_handle_t*>(m_wss.m_socket), onWSSClose);
|
||||
}
|
||||
else
|
||||
# endif
|
||||
if ((m_ZMQConnectionState != ZMQ_NOT_CONNECTED) && (m_ZMQConnectionState != ZMQ_DISCONNECTING)) {
|
||||
uv_close(reinterpret_cast<uv_handle_t*>(m_ZMQSocket), onZMQClose);
|
||||
}
|
||||
|
@ -944,10 +852,14 @@ void xmrig::DaemonClient::ZMQParse()
|
|||
m_ZMQRecvBuf.erase(m_ZMQRecvBuf.begin(), m_ZMQRecvBuf.begin() + (data - m_ZMQRecvBuf.data()));
|
||||
|
||||
# ifdef APP_DEBUG
|
||||
LOG_DEBUG(CYAN("tcp-zmq://%s:%u") BLACK_BOLD(" read ") CYAN_BOLD("%zu") BLACK_BOLD(" bytes") " %s", m_pool.host().data(), m_pool.zmq_port(), msg.size(), msg.data());
|
||||
msg.push_back('\0');
|
||||
LOG_DEBUG(CYAN("tcp-zmq://%s:%u") BLACK_BOLD(" read ") CYAN_BOLD("%zu") BLACK_BOLD(" bytes") " %s", m_pool.host().data(), m_pool.zmq_port(), msg.size() - 1, msg.data());
|
||||
# endif
|
||||
|
||||
getBlockTemplate();
|
||||
// Clear previous hash and check daemon height to guarantee that xmrig will call get_block_template RPC later
|
||||
// We can't call get_block_template directly because daemon is not ready yet
|
||||
m_prevHash = nullptr;
|
||||
send(kGetHeight);
|
||||
}
|
||||
|
||||
|
||||
|
@ -972,377 +884,3 @@ bool xmrig::DaemonClient::ZMQClose(bool shutdown)
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_TLS
|
||||
void xmrig::DaemonClient::onWSSConnect(uv_connect_t* req, int status)
|
||||
{
|
||||
DaemonClient* client = getClient(req->data);
|
||||
delete req;
|
||||
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (status < 0) {
|
||||
LOG_ERR("%s " RED("WSS connect error: ") RED_BOLD("\"%s\""), client->tag(), uv_strerror(status));
|
||||
client->retry();
|
||||
return;
|
||||
}
|
||||
|
||||
client->WSSConnected();
|
||||
}
|
||||
|
||||
|
||||
void xmrig::DaemonClient::onWSSRead(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf)
|
||||
{
|
||||
DaemonClient* client = getClient(stream->data);
|
||||
if (client) {
|
||||
client->WSSRead(nread, buf);
|
||||
}
|
||||
|
||||
NetBuffer::release(buf);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::DaemonClient::onWSSClose(uv_handle_t* handle)
|
||||
{
|
||||
DaemonClient* client = getClient(handle->data);
|
||||
if (client) {
|
||||
# ifdef APP_DEBUG
|
||||
LOG_DEBUG(CYAN("%s") BLACK_BOLD(" disconnected"), client->m_pool.url().data());
|
||||
# endif
|
||||
client->m_wss.cleanup();
|
||||
client->retry();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xmrig::DaemonClient::onWSSShutdown(uv_handle_t* handle)
|
||||
{
|
||||
DaemonClient* client = getClient(handle->data);
|
||||
if (client) {
|
||||
# ifdef APP_DEBUG
|
||||
LOG_DEBUG(CYAN("%s") BLACK_BOLD(" shutdown"), client->m_pool.url().data());
|
||||
# endif
|
||||
client->m_wss.cleanup();
|
||||
m_storage.remove(client->m_key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xmrig::DaemonClient::WSSConnected()
|
||||
{
|
||||
m_wss.m_ctx = SSL_CTX_new(SSLv23_method());
|
||||
m_wss.m_write = BIO_new(BIO_s_mem());
|
||||
m_wss.m_read = BIO_new(BIO_s_mem());
|
||||
|
||||
SSL_CTX_set_options(m_wss.m_ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3);
|
||||
m_wss.m_ssl = SSL_new(m_wss.m_ctx);
|
||||
SSL_set_connect_state(m_wss.m_ssl);
|
||||
SSL_set_bio(m_wss.m_ssl, m_wss.m_read, m_wss.m_write);
|
||||
SSL_do_handshake(m_wss.m_ssl);
|
||||
|
||||
if (WSSWrite(nullptr, 0)) {
|
||||
uv_read_start(reinterpret_cast<uv_stream_t*>(m_wss.m_socket), NetBuffer::onAlloc, onWSSRead);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::DaemonClient::WSSWrite(const char* data, size_t size)
|
||||
{
|
||||
if (!m_wss.m_socket) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (data && size) {
|
||||
# ifdef APP_DEBUG
|
||||
LOG_DEBUG(CYAN("%s") BLACK_BOLD(" write ") CYAN_BOLD("%zu") BLACK_BOLD(" bytes") " %s", m_pool.url().data(), size, data);
|
||||
# endif
|
||||
|
||||
if (!m_wss.m_handshake) {
|
||||
WSS::Header h{};
|
||||
h.fin = 1;
|
||||
h.mask = 1;
|
||||
h.opcode = 1;
|
||||
|
||||
uint8_t size_buf[8];
|
||||
if (size < 126) {
|
||||
h.payload_len = static_cast<uint8_t>(size);
|
||||
}
|
||||
else if (size < 65536) {
|
||||
h.payload_len = 126;
|
||||
size_buf[0] = static_cast<uint8_t>(size >> 8);
|
||||
size_buf[1] = static_cast<uint8_t>(size & 0xFF);
|
||||
}
|
||||
else {
|
||||
h.payload_len = 127;
|
||||
uint64_t k = size;
|
||||
for (int i = 7; i >= 0; --i, k >>= 8) {
|
||||
size_buf[i] = static_cast<uint8_t>(k & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
// Header
|
||||
SSL_write(m_wss.m_ssl, &h, sizeof(h));
|
||||
|
||||
// Optional extended payload length
|
||||
if (h.payload_len == 126) SSL_write(m_wss.m_ssl, size_buf, 2);
|
||||
if (h.payload_len == 127) SSL_write(m_wss.m_ssl, size_buf, 8);
|
||||
|
||||
// Masking-key
|
||||
SSL_write(m_wss.m_ssl, "\0\0\0\0", 4);
|
||||
}
|
||||
|
||||
SSL_write(m_wss.m_ssl, data, static_cast<int>(size));
|
||||
}
|
||||
|
||||
uv_buf_t buf;
|
||||
buf.len = BIO_get_mem_data(m_wss.m_write, &buf.base);
|
||||
|
||||
if (buf.len == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const int rc = uv_try_write(reinterpret_cast<uv_stream_t*>(m_wss.m_socket), &buf, 1);
|
||||
|
||||
BIO_reset(m_wss.m_write);
|
||||
|
||||
if (static_cast<size_t>(rc) == buf.len) {
|
||||
return true;
|
||||
}
|
||||
|
||||
LOG_ERR("%s " RED("WSS write failed, rc = %d"), tag(), rc);
|
||||
WSSClose();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::DaemonClient::WSSRead(ssize_t nread, const uv_buf_t* read_buf)
|
||||
{
|
||||
if (nread <= 0) {
|
||||
LOG_ERR("%s " RED("WSS read failed, nread = %" PRId64), tag(), nread);
|
||||
WSSClose();
|
||||
return;
|
||||
}
|
||||
|
||||
BIO_write(m_wss.m_read, read_buf->base, static_cast<int>(nread));
|
||||
|
||||
if (!SSL_is_init_finished(m_wss.m_ssl)) {
|
||||
const int rc = SSL_connect(m_wss.m_ssl);
|
||||
|
||||
if ((rc < 0) && (SSL_get_error(m_wss.m_ssl, rc) == SSL_ERROR_WANT_READ)) {
|
||||
WSSWrite(nullptr, 0);
|
||||
}
|
||||
else if (rc == 1) {
|
||||
// login
|
||||
static constexpr char Base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
char key[25];
|
||||
std::random_device r;
|
||||
|
||||
for (int i = 0; i < 21; ++i) {
|
||||
key[i] = Base64[r() % 64];
|
||||
}
|
||||
|
||||
key[21] = Base64[0];
|
||||
key[22] = '=';
|
||||
key[23] = '=';
|
||||
key[24] = '\0';
|
||||
|
||||
const int n = snprintf(m_wss.m_buf, sizeof(m_wss.m_buf), kWSSLogin, m_pool.user().data(), m_pool.host().data(), key);
|
||||
if (0 <= n && n < static_cast<int>(sizeof(m_wss.m_buf))) {
|
||||
WSSWrite(m_wss.m_buf, n);
|
||||
}
|
||||
else {
|
||||
WSSClose();
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int n = 0;
|
||||
while ((n = SSL_read(m_wss.m_ssl, m_wss.m_buf, sizeof(m_wss.m_buf))) > 0) {
|
||||
m_wss.m_data.insert(m_wss.m_data.end(), m_wss.m_buf, m_wss.m_buf + n);
|
||||
|
||||
// Skip the first message (HTTP upgrade response)
|
||||
if (m_wss.m_handshake) {
|
||||
const size_t len = m_wss.m_data.size();
|
||||
if (len >= 4) {
|
||||
for (size_t k = 0; k <= len - 4; ++k) {
|
||||
if (memcmp(m_wss.m_data.data() + k, "\r\n\r\n", 4) == 0) {
|
||||
m_wss.m_handshake = false;
|
||||
m_wss.m_data.erase(m_wss.m_data.begin(), m_wss.m_data.begin() + k + 4);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
const uint8_t* p0 = reinterpret_cast<uint8_t*>(m_wss.m_data.data());
|
||||
const uint8_t* p = p0;
|
||||
const uint8_t* e = p0 + m_wss.m_data.size();
|
||||
|
||||
if (e - p < static_cast<int>(sizeof(WSS::Header)))
|
||||
continue;
|
||||
|
||||
const WSS::Header* h = reinterpret_cast<const WSS::Header*>(p);
|
||||
p += sizeof(WSS::Header);
|
||||
|
||||
uint64_t len = h->payload_len;
|
||||
|
||||
if (len == 126) {
|
||||
if (e - p < static_cast<int>(sizeof(uint16_t))) {
|
||||
continue;
|
||||
}
|
||||
len = 0;
|
||||
for (size_t i = 0; i < sizeof(uint16_t); ++i, ++p) {
|
||||
len = (len << 8) | *p;
|
||||
}
|
||||
}
|
||||
else if (len == 127) {
|
||||
if (e - p < static_cast<int>(sizeof(uint64_t))) {
|
||||
continue;
|
||||
}
|
||||
len = 0;
|
||||
for (size_t i = 0; i < sizeof(uint64_t); ++i, ++p) {
|
||||
len = (len << 8) | *p;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t mask_key[4] = {};
|
||||
if (h->mask) {
|
||||
if (e - p < 4)
|
||||
continue;
|
||||
memcpy(mask_key, p, 4);
|
||||
p += 4;
|
||||
}
|
||||
|
||||
if (static_cast<uint64_t>(e - p) < len)
|
||||
continue;
|
||||
|
||||
for (uint64_t i = 0; i < len; ++i) {
|
||||
m_wss.m_message.push_back(p[i] ^ mask_key[i % 4]);
|
||||
}
|
||||
p += len;
|
||||
|
||||
m_wss.m_data.erase(m_wss.m_data.begin(), m_wss.m_data.begin() + (p - p0));
|
||||
|
||||
if (h->fin) {
|
||||
if (m_wss.m_message.back() == '\n') {
|
||||
m_wss.m_message.back() = '\0';
|
||||
}
|
||||
else {
|
||||
m_wss.m_message.push_back('\0');
|
||||
}
|
||||
WSSParse();
|
||||
m_wss.m_message.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xmrig::DaemonClient::WSSParse()
|
||||
{
|
||||
# ifdef APP_DEBUG
|
||||
LOG_DEBUG(CYAN("%s") BLACK_BOLD(" read ") CYAN_BOLD("%zu") BLACK_BOLD(" bytes") " %s", m_pool.url().data(), m_wss.m_message.size(), m_wss.m_message.data());
|
||||
# endif
|
||||
|
||||
using namespace rapidjson;
|
||||
|
||||
Document doc;
|
||||
if (doc.ParseInsitu(m_wss.m_message.data()).HasParseError() || !doc.IsObject()) {
|
||||
if (!isQuiet()) {
|
||||
LOG_ERR("%s " RED("JSON decode failed: ") RED_BOLD("\"%s\""), tag(), GetParseError_En(doc.GetParseError()));
|
||||
}
|
||||
|
||||
return retry();
|
||||
}
|
||||
|
||||
if (doc.HasMember(kLastError)) {
|
||||
String err = Json::getString(doc, kLastError, "");
|
||||
if (!err.isEmpty()) {
|
||||
LOG_ERR("%s " RED_BOLD("\"%s\""), tag(), err.data());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (doc.HasMember(kBlockhashingBlob)) {
|
||||
Job job(false, m_pool.algorithm(), String());
|
||||
|
||||
m_blockhashingblob = Json::getString(doc, kBlockhashingBlob, "");
|
||||
if (m_blockhashingblob.isEmpty()) {
|
||||
LOG_ERR("%s " RED_BOLD("blockhashing_blob is empty"), tag());
|
||||
return;
|
||||
}
|
||||
job.setBlob(m_blockhashingblob);
|
||||
memset(job.blob() + job.nonceOffset(), 0, job.nonceSize());
|
||||
|
||||
const uint64_t height = Json::getUint64(doc, kHeight);
|
||||
|
||||
job.setHeight(height);
|
||||
job.setDiff(Json::getUint64(doc, "difficultyuint64"));
|
||||
//job.setDiff(100000);
|
||||
|
||||
m_currentJobId = Json::getString(doc, "jobid");
|
||||
job.setId(m_currentJobId);
|
||||
|
||||
m_job = std::move(job);
|
||||
|
||||
if (m_state == ConnectingState) {
|
||||
setState(ConnectedState);
|
||||
}
|
||||
|
||||
const uint64_t blocks = Json::getUint64(doc, "blocks");
|
||||
const uint64_t miniblocks = Json::getUint64(doc, "miniblocks");
|
||||
|
||||
if ((blocks != m_wss.m_blocks) || (miniblocks != m_wss.m_miniblocks) || (height != m_wss.m_height)) {
|
||||
LOG_INFO("%s " GREEN_BOLD("%" PRIu64 " blocks, %" PRIu64 " mini blocks"), tag(), blocks, miniblocks);
|
||||
m_wss.m_blocks = blocks;
|
||||
m_wss.m_miniblocks = miniblocks;
|
||||
m_wss.m_height = height;
|
||||
}
|
||||
|
||||
m_listener->onJobReceived(this, m_job, doc);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::DaemonClient::WSSClose(bool shutdown)
|
||||
{
|
||||
if (m_wss.m_socket && (uv_is_closing(reinterpret_cast<uv_handle_t*>(m_wss.m_socket)) == 0)) {
|
||||
uv_close(reinterpret_cast<uv_handle_t*>(m_wss.m_socket), shutdown ? onWSSShutdown : onWSSClose);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::DaemonClient::WSS::cleanup()
|
||||
{
|
||||
delete m_socket;
|
||||
m_socket = nullptr;
|
||||
|
||||
if (m_ctx) {
|
||||
SSL_CTX_free(m_ctx);
|
||||
m_ctx = nullptr;
|
||||
}
|
||||
if (m_ssl) {
|
||||
SSL_free(m_ssl);
|
||||
m_ssl = nullptr;
|
||||
}
|
||||
|
||||
m_read = nullptr;
|
||||
m_write = nullptr;
|
||||
m_handshake = true;
|
||||
m_blocks = 0;
|
||||
m_miniblocks = 0;
|
||||
m_height = 0;
|
||||
m_data.clear();
|
||||
m_message.clear();
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue