Removed deprecated AstroBWTv1 and v2
This commit is contained in:
parent
1bbbff7d17
commit
22d6a7525e
110 changed files with 5822 additions and 14513 deletions
|
@ -59,8 +59,6 @@ protected:
|
|||
void setPool(const Pool &pool) override;
|
||||
|
||||
protected:
|
||||
bool isWSS() const override { return false; }
|
||||
|
||||
enum SocketState {
|
||||
UnconnectedState,
|
||||
HostLookupState,
|
||||
|
|
|
@ -81,14 +81,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
|
||||
|
||||
|
||||
|
@ -105,20 +97,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);
|
||||
}
|
||||
|
@ -148,19 +131,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();
|
||||
|
||||
|
@ -182,17 +159,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);
|
||||
}
|
||||
|
@ -203,13 +169,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);
|
||||
|
||||
|
@ -243,16 +203,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 {
|
||||
|
@ -353,15 +308,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -396,14 +343,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;
|
||||
|
@ -511,11 +450,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()));
|
||||
}
|
||||
|
@ -536,13 +470,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);
|
||||
}
|
||||
|
@ -586,13 +513,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();
|
||||
|
@ -613,12 +533,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);
|
||||
|
||||
|
@ -648,12 +563,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);
|
||||
}
|
||||
|
@ -978,377 +887,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
|
||||
|
|
|
@ -63,7 +63,6 @@ public:
|
|||
protected:
|
||||
bool disconnect() override;
|
||||
bool isTLS() const override;
|
||||
bool isWSS() const override;
|
||||
int64_t submit(const JobResult &result) override;
|
||||
void connect() override;
|
||||
void connect(const Pool &pool) override;
|
||||
|
@ -95,7 +94,6 @@ private:
|
|||
enum {
|
||||
API_CRYPTONOTE_DEFAULT,
|
||||
API_MONERO,
|
||||
API_DERO,
|
||||
} m_apiVersion = API_MONERO;
|
||||
|
||||
BlockTemplate m_blocktemplate;
|
||||
|
@ -143,45 +141,6 @@ private:
|
|||
|
||||
std::vector<char> m_ZMQSendBuf;
|
||||
std::vector<char> m_ZMQRecvBuf;
|
||||
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
static void onWSSConnect(uv_connect_t* req, int status);
|
||||
static void onWSSRead(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf);
|
||||
static void onWSSClose(uv_handle_t* handle);
|
||||
static void onWSSShutdown(uv_handle_t* handle);
|
||||
|
||||
void WSSConnected();
|
||||
bool WSSWrite(const char* data, size_t size);
|
||||
void WSSRead(ssize_t nread, const uv_buf_t* buf);
|
||||
void WSSParse();
|
||||
bool WSSClose(bool shutdown = false);
|
||||
|
||||
struct WSS {
|
||||
struct Header
|
||||
{
|
||||
uint8_t opcode : 4;
|
||||
uint8_t reserved : 3;
|
||||
uint8_t fin : 1;
|
||||
uint8_t payload_len : 7;
|
||||
uint8_t mask : 1;
|
||||
};
|
||||
|
||||
uv_tcp_t* m_socket = nullptr;
|
||||
SSL_CTX* m_ctx = nullptr;
|
||||
BIO* m_read = nullptr;
|
||||
BIO* m_write = nullptr;
|
||||
SSL* m_ssl = nullptr;
|
||||
char m_buf[512] = {};
|
||||
bool m_handshake = true;
|
||||
uint64_t m_blocks = 0;
|
||||
uint64_t m_miniblocks = 0;
|
||||
uint64_t m_height = 0;
|
||||
std::vector<char> m_data;
|
||||
std::vector<char> m_message;
|
||||
|
||||
void cleanup();
|
||||
} m_wss;
|
||||
# endif
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -169,10 +169,6 @@ int32_t xmrig::Job::nonceOffset() const
|
|||
auto f = algorithm().family();
|
||||
if (f == Algorithm::KAWPOW) return 32;
|
||||
if (f == Algorithm::GHOSTRIDER) return 76;
|
||||
|
||||
auto id = algorithm().id();
|
||||
if (id == Algorithm::ASTROBWT_DERO_2) return 44;
|
||||
|
||||
return 39;
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,6 @@ const char *Pool::kSelfSelect = "self-select";
|
|||
const char *Pool::kSOCKS5 = "socks5";
|
||||
const char *Pool::kSubmitToOrigin = "submit-to-origin";
|
||||
const char *Pool::kTls = "tls";
|
||||
const char *Pool::kWSS = "wss";
|
||||
const char *Pool::kUrl = "url";
|
||||
const char *Pool::kUser = "user";
|
||||
const char *Pool::kSpendSecretKey = "spend-secret-key";
|
||||
|
@ -94,7 +93,7 @@ xmrig::Pool::Pool(const char *url) :
|
|||
}
|
||||
|
||||
|
||||
xmrig::Pool::Pool(const char *host, uint16_t port, const char *user, const char *password, const char* spendSecretKey, int keepAlive, bool nicehash, bool tls, bool wss, Mode mode) :
|
||||
xmrig::Pool::Pool(const char *host, uint16_t port, const char *user, const char *password, const char* spendSecretKey, int keepAlive, bool nicehash, bool tls, Mode mode) :
|
||||
m_keepAlive(keepAlive),
|
||||
m_mode(mode),
|
||||
m_flags(1 << FLAG_ENABLED),
|
||||
|
@ -106,7 +105,6 @@ xmrig::Pool::Pool(const char *host, uint16_t port, const char *user, const char
|
|||
{
|
||||
m_flags.set(FLAG_NICEHASH, nicehash || strstr(host, kNicehashHost));
|
||||
m_flags.set(FLAG_TLS, tls);
|
||||
m_flags.set(FLAG_WSS, wss);
|
||||
}
|
||||
|
||||
|
||||
|
@ -134,7 +132,6 @@ xmrig::Pool::Pool(const rapidjson::Value &object) :
|
|||
m_flags.set(FLAG_ENABLED, Json::getBool(object, kEnabled, true));
|
||||
m_flags.set(FLAG_NICEHASH, Json::getBool(object, kNicehash) || m_url.host().contains(kNicehashHost));
|
||||
m_flags.set(FLAG_TLS, Json::getBool(object, kTls) || m_url.isTLS());
|
||||
m_flags.set(FLAG_WSS, Json::getBool(object, kWSS) || m_url.isWSS());
|
||||
|
||||
setKeepAlive(Json::getValue(object, kKeepalive));
|
||||
|
||||
|
@ -296,7 +293,6 @@ rapidjson::Value xmrig::Pool::toJSON(rapidjson::Document &doc) const
|
|||
|
||||
obj.AddMember(StringRef(kEnabled), m_flags.test(FLAG_ENABLED), allocator);
|
||||
obj.AddMember(StringRef(kTls), isTLS(), allocator);
|
||||
obj.AddMember(StringRef(kWSS), isWSS(), allocator);
|
||||
obj.AddMember(StringRef(kFingerprint), m_fingerprint.toJSON(), allocator);
|
||||
obj.AddMember(StringRef(kDaemon), m_mode == MODE_DAEMON, allocator);
|
||||
obj.AddMember(StringRef(kSOCKS5), m_proxy.toJSON(doc), allocator);
|
||||
|
|
|
@ -69,12 +69,10 @@ public:
|
|||
static const char *kSOCKS5;
|
||||
static const char *kSubmitToOrigin;
|
||||
static const char *kTls;
|
||||
static const char* kWSS;
|
||||
static const char *kUrl;
|
||||
static const char *kUser;
|
||||
static const char* kSpendSecretKey;
|
||||
static const char* kDaemonZMQPort;
|
||||
static const char* kDaemonWSSPort;
|
||||
static const char *kNicehashHost;
|
||||
|
||||
constexpr static int kKeepAliveTimeout = 60;
|
||||
|
@ -82,7 +80,7 @@ public:
|
|||
constexpr static uint64_t kDefaultPollInterval = 1000;
|
||||
|
||||
Pool() = default;
|
||||
Pool(const char *host, uint16_t port, const char *user, const char *password, const char* spendSecretKey, int keepAlive, bool nicehash, bool tls, bool wss, Mode mode);
|
||||
Pool(const char *host, uint16_t port, const char *user, const char *password, const char* spendSecretKey, int keepAlive, bool nicehash, bool tls, Mode mode);
|
||||
Pool(const char *url);
|
||||
Pool(const rapidjson::Value &object);
|
||||
|
||||
|
@ -95,7 +93,6 @@ public:
|
|||
|
||||
inline bool isNicehash() const { return m_flags.test(FLAG_NICEHASH); }
|
||||
inline bool isTLS() const { return m_flags.test(FLAG_TLS) || m_url.isTLS(); }
|
||||
inline bool isWSS() const { return m_flags.test(FLAG_WSS) || m_url.isWSS(); }
|
||||
inline bool isValid() const { return m_url.isValid(); }
|
||||
inline const Algorithm &algorithm() const { return m_algorithm; }
|
||||
inline const Coin &coin() const { return m_coin; }
|
||||
|
@ -138,7 +135,6 @@ private:
|
|||
FLAG_ENABLED,
|
||||
FLAG_NICEHASH,
|
||||
FLAG_TLS,
|
||||
FLAG_WSS,
|
||||
FLAG_MAX
|
||||
};
|
||||
|
||||
|
|
|
@ -49,7 +49,6 @@ protected:
|
|||
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 bool isWSS() const override { return m_client->isWSS(); }
|
||||
inline const char *mode() const override { return m_client->mode(); }
|
||||
inline const char *tag() const override { return m_client->tag(); }
|
||||
inline const char *tlsFingerprint() const override { return m_client->tlsFingerprint(); }
|
||||
|
|
|
@ -39,7 +39,6 @@ static const char kSOCKS5[] = "socks5://";
|
|||
#ifdef XMRIG_FEATURE_HTTP
|
||||
static const char kDaemonHttp[] = "daemon+http://";
|
||||
static const char kDaemonHttps[] = "daemon+https://";
|
||||
static const char kDaemonWss[] = "daemon+wss://";
|
||||
#endif
|
||||
|
||||
} // namespace xmrig
|
||||
|
@ -104,11 +103,6 @@ bool xmrig::Url::parse(const char *url)
|
|||
m_scheme = DAEMON;
|
||||
m_tls = false;
|
||||
}
|
||||
else if (strncasecmp(url, kDaemonWss, sizeof(kDaemonWss) - 1) == 0) {
|
||||
m_scheme = DAEMON;
|
||||
m_tls = true;
|
||||
m_wss = true;
|
||||
}
|
||||
# endif
|
||||
else {
|
||||
return false;
|
||||
|
|
|
@ -41,7 +41,6 @@ public:
|
|||
Url(const char *host, uint16_t port, bool tls = false, Scheme scheme = UNSPECIFIED);
|
||||
|
||||
inline bool isTLS() const { return m_tls; }
|
||||
inline bool isWSS() const { return m_wss; }
|
||||
inline bool isValid() const { return !m_host.isNull() && m_port > 0; }
|
||||
inline const String &host() const { return m_host; }
|
||||
inline const String &url() const { return m_url; }
|
||||
|
@ -58,7 +57,6 @@ protected:
|
|||
bool parseIPv6(const char *addr);
|
||||
|
||||
bool m_tls = false;
|
||||
bool m_wss = false;
|
||||
Scheme m_scheme = UNSPECIFIED;
|
||||
String m_host;
|
||||
String m_url;
|
||||
|
|
|
@ -41,7 +41,6 @@ public:
|
|||
inline bool hasExtension(Extension) const noexcept override { return false; }
|
||||
inline bool isEnabled() const override { return true; }
|
||||
inline bool isTLS() const override { return false; }
|
||||
inline bool isWSS() const override { return false; }
|
||||
inline const char *mode() const override { return "benchmark"; }
|
||||
inline const char *tlsFingerprint() const override { return nullptr; }
|
||||
inline const char *tlsVersion() const override { return nullptr; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue