Browse Source

Upstream, parse and send to ckdb trusted remote server share errors.

master
Con Kolivas 8 years ago
parent
commit
aa121dbce2
  1. 2
      src/ckpool.h
  2. 46
      src/stratifier.c

2
src/ckpool.h

@ -290,6 +290,7 @@ enum stratum_msgtype {
SM_BLOCK, SM_BLOCK,
SM_PONG, SM_PONG,
SM_TRANSACTIONS, SM_TRANSACTIONS,
SM_SHAREERR,
SM_NONE SM_NONE
}; };
@ -313,6 +314,7 @@ static const char __maybe_unused *stratum_msgs[] = {
"block", "block",
"pong", "pong",
"transactions", "transactions",
"shareerr",
"" ""
}; };

46
src/stratifier.c

@ -5953,9 +5953,10 @@ out:
} }
if (!share) { if (!share) {
if (!CKP_STANDALONE(ckp)) { if (!CKP_STANDALONE(ckp) || ckp->remote) {
val = json_object(); val = json_object();
json_set_int(val, "clientid", client->id); json_set_int(val, "clientid", client->id);
if (user->secondaryuserid)
json_set_string(val, "secondaryuserid", user->secondaryuserid); json_set_string(val, "secondaryuserid", user->secondaryuserid);
json_set_string(val, "enonce1", client->enonce1); json_set_string(val, "enonce1", client->enonce1);
json_set_int(val, "workinfoid", sdata->current_workbase->id); json_set_int(val, "workinfoid", sdata->current_workbase->id);
@ -5967,6 +5968,10 @@ out:
json_set_string(val, "createby", "code"); json_set_string(val, "createby", "code");
json_set_string(val, "createcode", __func__); json_set_string(val, "createcode", __func__);
json_set_string(val, "createinet", ckp->serverurl[client->server]); json_set_string(val, "createinet", ckp->serverurl[client->server]);
if (ckp->remote) {
upstream_msgtype(ckp, val, SM_SHAREERR);
json_decref(val);
} else
ckdbq_add(ckp, ID_SHAREERR, val); ckdbq_add(ckp, ID_SHAREERR, val);
} }
LOGINFO("Invalid share from client %s: %s", client->identity, client->workername); LOGINFO("Invalid share from client %s: %s", client->identity, client->workername);
@ -6530,6 +6535,43 @@ static void parse_remote_share(ckpool_t *ckp, sdata_t *sdata, json_t *val, const
ckdbq_add(ckp, ID_SHARES, val); ckdbq_add(ckp, ID_SHARES, val);
} }
static void parse_remote_shareerr(ckpool_t *ckp, sdata_t *sdata, json_t *val, const char *buf)
{
user_instance_t *user = NULL;
int64_t id, mapped_id;
const char *workername;
workbase_t *wb;
workername = json_string_value(json_object_get(val, "workername"));
if (unlikely(!workername)) {
LOGWARNING("Failed to find workername in parse_remote_shareerr %s", buf);
return;
}
user = generate_remote_user(ckp, workername);
/* Remove unwanted entry, add extra info and submit it to ckdb */
json_object_del(val, "method");
/* Create a new copy for use by ckdbq_add */
val = json_deep_copy(val);
if (likely(user->secondaryuserid))
json_set_string(val, "secondaryuserid", user->secondaryuserid);
/* Adjust workinfo id to virtual value */
json_get_int64(&id, val, "workinfoid");
ck_rlock(&sdata->workbase_lock);
HASH_FIND_I64(sdata->remote_workbases, &id, wb);
if (likely(wb))
mapped_id = wb->mapped_id;
else
mapped_id = id;
ck_runlock(&sdata->workbase_lock);
/* Replace value with mapped id */
json_set_int64(val, "workinfoid", mapped_id);
ckdbq_add(ckp, ID_SHAREERR, val);
}
static void send_auth_response(sdata_t *sdata, const int64_t client_id, const bool ret, static void send_auth_response(sdata_t *sdata, const int64_t client_id, const bool ret,
json_t *id_val, json_t *err_val) json_t *id_val, json_t *err_val)
{ {
@ -6776,6 +6818,8 @@ static void parse_trusted_msg(ckpool_t *ckp, sdata_t *sdata, json_t *val, stratu
parse_remote_workinfo(ckp, val); parse_remote_workinfo(ckp, val);
else if (!safecmp(method, stratum_msgs[SM_AUTH])) else if (!safecmp(method, stratum_msgs[SM_AUTH]))
parse_remote_auth(ckp, sdata, val, client, client->id); parse_remote_auth(ckp, sdata, val, client, client->id);
else if (!safecmp(method, stratum_msgs[SM_SHAREERR]))
parse_remote_shareerr(ckp, sdata, val, buf);
else if (!safecmp(method, "workers")) else if (!safecmp(method, "workers"))
parse_remote_workers(sdata, val, buf); parse_remote_workers(sdata, val, buf);
else if (!safecmp(method, "submitblock")) else if (!safecmp(method, "submitblock"))

Loading…
Cancel
Save