summaryrefslogtreecommitdiffstats
path: root/xmrstak/net/jpsock.cpp
diff options
context:
space:
mode:
authorUnknown <fireice2@o2.pl>2017-11-14 15:52:18 +0000
committerUnknown <fireice2@o2.pl>2017-11-14 15:57:19 +0000
commit8130f656b6899c9a8ffc1741a0609d306c2bb449 (patch)
tree7f37e7fb2838481d30c329a669c04af1b8dff8ff /xmrstak/net/jpsock.cpp
parent288363814fb091ccfc452f0408bfa53727fc30c0 (diff)
downloadxmr-stak-8130f656b6899c9a8ffc1741a0609d306c2bb449.zip
xmr-stak-8130f656b6899c9a8ffc1741a0609d306c2bb449.tar.gz
jpsock changes
Diffstat (limited to 'xmrstak/net/jpsock.cpp')
-rw-r--r--xmrstak/net/jpsock.cpp72
1 files changed, 65 insertions, 7 deletions
diff --git a/xmrstak/net/jpsock.cpp b/xmrstak/net/jpsock.cpp
index cb586d2..cc88aa8 100644
--- a/xmrstak/net/jpsock.cpp
+++ b/xmrstak/net/jpsock.cpp
@@ -23,6 +23,7 @@
#include <stdarg.h>
#include <assert.h>
+#include <algorithm>
#include "jpsock.hpp"
#include "socks.hpp"
@@ -33,9 +34,6 @@
#include "xmrstak/misc/jext.hpp"
#include "xmrstak/version.hpp"
-
-#define AGENTID_STR XMR_STAK_NAME "/" XMR_STAK_VERSION
-
using namespace rapidjson;
struct jpsock::call_rsp
@@ -366,10 +364,11 @@ bool jpsock::process_pool_job(const opq_json_val* params)
if (!params->val->IsObject())
return set_socket_error("PARSE error: Job error 1");
- const Value * blob, *jobid, *target;
+ const Value *blob, *jobid, *target, *motd;
jobid = GetObjectMember(*params->val, "job_id");
blob = GetObjectMember(*params->val, "blob");
target = GetObjectMember(*params->val, "target");
+ motd = GetObjectMember(*params->val, "motd");
if (jobid == nullptr || blob == nullptr || target == nullptr ||
!jobid->IsString() || !blob->IsString() || !target->IsString())
@@ -415,6 +414,12 @@ bool jpsock::process_pool_job(const opq_json_val* params)
else
return set_socket_error("PARSE error: Job error 5");
+ if(motd != nullptr && motd->IsString())
+ {
+ std::unique_lock<std::mutex>(motd_mutex);
+ pool_motd.assign(motd->GetString());
+ }
+
iJobDiff = t64_to_diff(oPoolJob.iTarget);
executor::inst()->push_event(ex_event(oPoolJob, pool_id));
@@ -426,6 +431,7 @@ bool jpsock::process_pool_job(const opq_json_val* params)
bool jpsock::connect(std::string& sConnectError)
{
+ ext_algo = ext_backend = ext_hashcount = ext_motd = false;
bHaveSocketError = false;
sSocketError.clear();
iJobDiff = 0;
@@ -527,6 +533,7 @@ bool jpsock::cmd_login()
const Value* id = GetObjectMember(*oResult.val, "id");
const Value* job = GetObjectMember(*oResult.val, "job");
+ const Value* ext = GetObjectMember(*oResult.val, "extensions");
if (id == nullptr || job == nullptr || !id->IsString())
{
@@ -545,6 +552,29 @@ bool jpsock::cmd_login()
memset(sMinerId, 0, sizeof(sMinerId));
memcpy(sMinerId, id->GetString(), id->GetStringLength());
+ if(ext != nullptr && ext->IsArray())
+ {
+ for(size_t i=0; i < ext->Size(); i++)
+ {
+ const Value& jextname = ext->GetArray()[i];
+
+ if(!jextname.IsString())
+ continue;
+
+ std::string tmp(jextname.GetString());
+ std::transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);
+
+ if(tmp.compare("algo"))
+ ext_algo = true;
+ else if(tmp.compare("backend"))
+ ext_backend = true;
+ else if(tmp.compare("hashcount"))
+ ext_hashcount = true;
+ else if(tmp.compare("motd"))
+ ext_motd = true;
+ }
+ }
+
opq_json_val v(job);
if(!process_pool_job(&v))
{
@@ -558,20 +588,33 @@ bool jpsock::cmd_login()
return true;
}
-bool jpsock::cmd_submit(const char* sJobId, uint32_t iNonce, const uint8_t* bResult)
+bool jpsock::cmd_submit(const char* sJobId, uint32_t iNonce, const uint8_t* bResult, xmrstak::iBackend* bend, bool algo_full_cn)
{
char cmd_buffer[1024];
char sNonce[9];
char sResult[65];
+ /*Extensions*/
+ char sAlgo[64] = {0};
+ char sBackend[64] = {0};
+ char sHashcount[64] = {0};
+
+ if(ext_backend)
+ snprintf(sBackend, sizeof(sBackend), ",\"backend\":\"%s\"", "");
+
+ if(ext_hashcount)
+ snprintf(sHashcount, sizeof(sHashcount), ",\"hashcount\":\"%llu\"", int_port(bend->iHashCount.load(std::memory_order_relaxed)));
+ if(ext_algo)
+ snprintf(sAlgo, sizeof(sAlgo), ",\"algo\":\"%s\"", algo_full_cn ? "cryptonight" : "cryptonight-lite");
+
bin2hex((unsigned char*)&iNonce, 4, sNonce);
sNonce[8] = '\0';
bin2hex(bResult, 32, sResult);
sResult[64] = '\0';
- snprintf(cmd_buffer, sizeof(cmd_buffer), "{\"method\":\"submit\",\"params\":{\"id\":\"%s\",\"job_id\":\"%s\",\"nonce\":\"%s\",\"result\":\"%s\"},\"id\":1}\n",
- sMinerId, sJobId, sNonce, sResult);
+ snprintf(cmd_buffer, sizeof(cmd_buffer), "{\"method\":\"submit\",\"params\":{\"id\":\"%s\",\"job_id\":\"%s\",\"nonce\":\"%s\",\"result\":\"%s\"%s%s%s},\"id\":1}\n",
+ sMinerId, sJobId, sNonce, sResult, sBackend, sHashcount, sAlgo);
opq_json_val oResult(nullptr);
return cmd_ret_wait(cmd_buffer, oResult);
@@ -594,6 +637,21 @@ bool jpsock::get_current_job(pool_job& job)
return true;
}
+bool jpsock::get_pool_motd(std::string& strin)
+{
+ if(!ext_motd)
+ return false;
+
+ std::unique_lock<std::mutex>(motd_mutex);
+ if(pool_motd.size() > 0)
+ {
+ strin.assign(pool_motd);
+ return true;
+ }
+
+ return false;
+}
+
inline unsigned char hf_hex2bin(char c, bool &err)
{
if (c >= '0' && c <= '9')
OpenPOWER on IntegriCloud