|
|
@ -231,6 +231,7 @@ struct stratum_instance { |
|
|
|
time_t start_time; |
|
|
|
time_t start_time; |
|
|
|
|
|
|
|
|
|
|
|
char address[INET6_ADDRSTRLEN]; |
|
|
|
char address[INET6_ADDRSTRLEN]; |
|
|
|
|
|
|
|
bool subscribed; |
|
|
|
bool authorised; |
|
|
|
bool authorised; |
|
|
|
bool idle; |
|
|
|
bool idle; |
|
|
|
bool notified_idle; |
|
|
|
bool notified_idle; |
|
|
@ -1244,9 +1245,8 @@ static void new_enonce1(stratum_instance_t *client) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Extranonce1 must be set here */ |
|
|
|
/* Extranonce1 must be set here */ |
|
|
|
static json_t *parse_subscribe(int64_t client_id, json_t *params_val) |
|
|
|
static json_t *parse_subscribe(stratum_instance_t *client, int64_t client_id, json_t *params_val) |
|
|
|
{ |
|
|
|
{ |
|
|
|
stratum_instance_t *client = NULL; |
|
|
|
|
|
|
|
bool old_match = false; |
|
|
|
bool old_match = false; |
|
|
|
int arr_size; |
|
|
|
int arr_size; |
|
|
|
json_t *ret; |
|
|
|
json_t *ret; |
|
|
@ -1255,15 +1255,6 @@ static json_t *parse_subscribe(int64_t client_id, json_t *params_val) |
|
|
|
if (unlikely(!json_is_array(params_val))) |
|
|
|
if (unlikely(!json_is_array(params_val))) |
|
|
|
return json_string("params not an array"); |
|
|
|
return json_string("params not an array"); |
|
|
|
|
|
|
|
|
|
|
|
ck_rlock(&instance_lock); |
|
|
|
|
|
|
|
client = __instance_by_id(client_id); |
|
|
|
|
|
|
|
ck_runlock(&instance_lock); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (unlikely(!client)) { |
|
|
|
|
|
|
|
LOGERR("Failed to find client id %d in hashtable!", client_id); |
|
|
|
|
|
|
|
return NULL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (unlikely(!current_workbase)) |
|
|
|
if (unlikely(!current_workbase)) |
|
|
|
return json_string("Initialising"); |
|
|
|
return json_string("Initialising"); |
|
|
|
|
|
|
|
|
|
|
@ -1308,6 +1299,8 @@ static json_t *parse_subscribe(int64_t client_id, json_t *params_val) |
|
|
|
n2len); |
|
|
|
n2len); |
|
|
|
ck_runlock(&workbase_lock); |
|
|
|
ck_runlock(&workbase_lock); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client->subscribed = true; |
|
|
|
|
|
|
|
|
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -2131,16 +2124,20 @@ static void parse_method(const int64_t client_id, json_t *id_val, json_t *method |
|
|
|
* the json item for id_val as is for the response. */ |
|
|
|
* the json item for id_val as is for the response. */ |
|
|
|
method = json_string_value(method_val); |
|
|
|
method = json_string_value(method_val); |
|
|
|
if (cmdmatch(method, "mining.subscribe")) { |
|
|
|
if (cmdmatch(method, "mining.subscribe")) { |
|
|
|
json_t *val, *result_val = parse_subscribe(client_id, params_val); |
|
|
|
json_t *val, *result_val = parse_subscribe(client, client_id, params_val); |
|
|
|
|
|
|
|
|
|
|
|
if (!result_val) |
|
|
|
/* Shouldn't happen, sanity check */ |
|
|
|
|
|
|
|
if (unlikely(!result_val)) { |
|
|
|
|
|
|
|
LOGWARNING("parse_subscribe returned NULL result_val"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
val = json_object(); |
|
|
|
val = json_object(); |
|
|
|
json_object_set_new_nocheck(val, "result", result_val); |
|
|
|
json_object_set_new_nocheck(val, "result", result_val); |
|
|
|
json_object_set_nocheck(val, "id", id_val); |
|
|
|
json_object_set_nocheck(val, "id", id_val); |
|
|
|
json_object_set_new_nocheck(val, "error", json_null()); |
|
|
|
json_object_set_new_nocheck(val, "error", json_null()); |
|
|
|
stratum_add_send(val, client_id); |
|
|
|
stratum_add_send(val, client_id); |
|
|
|
update_client(client, client_id); |
|
|
|
if (likely(client->subscribed)) |
|
|
|
|
|
|
|
update_client(client, client_id); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -2160,7 +2157,7 @@ static void parse_method(const int64_t client_id, json_t *id_val, json_t *method |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (cmdmatch(method, "mining.auth")) { |
|
|
|
if (cmdmatch(method, "mining.auth") && client->subscribed) { |
|
|
|
json_params_t *jp = create_json_params(client_id, params_val, id_val, address); |
|
|
|
json_params_t *jp = create_json_params(client_id, params_val, id_val, address); |
|
|
|
|
|
|
|
|
|
|
|
ckmsgq_add(sauthq, jp); |
|
|
|
ckmsgq_add(sauthq, jp); |
|
|
|