|
|
@ -872,18 +872,38 @@ static void stratum_add_send(json_t *val, int client_id) |
|
|
|
ckmsgq_add(ssends, msg); |
|
|
|
ckmsgq_add(ssends, msg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void inc_worker(user_instance_t *instance) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
mutex_lock(&stats_lock); |
|
|
|
|
|
|
|
stats.workers++; |
|
|
|
|
|
|
|
if (!instance->workers++) |
|
|
|
|
|
|
|
stats.users++; |
|
|
|
|
|
|
|
mutex_unlock(&stats_lock); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void dec_worker(user_instance_t *instance) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
mutex_lock(&stats_lock); |
|
|
|
|
|
|
|
stats.workers--; |
|
|
|
|
|
|
|
if (!--instance->workers) |
|
|
|
|
|
|
|
stats.users--; |
|
|
|
|
|
|
|
mutex_unlock(&stats_lock); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void drop_client(int id) |
|
|
|
static void drop_client(int id) |
|
|
|
{ |
|
|
|
{ |
|
|
|
stratum_instance_t *client = NULL; |
|
|
|
stratum_instance_t *client = NULL; |
|
|
|
|
|
|
|
bool dec = false; |
|
|
|
|
|
|
|
|
|
|
|
ck_ilock(&instance_lock); |
|
|
|
ck_ilock(&instance_lock); |
|
|
|
client = __instance_by_id(id); |
|
|
|
client = __instance_by_id(id); |
|
|
|
if (client) { |
|
|
|
if (client) { |
|
|
|
stratum_instance_t *old_client = NULL; |
|
|
|
stratum_instance_t *old_client = NULL; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (client->authorised) |
|
|
|
|
|
|
|
dec = true; |
|
|
|
|
|
|
|
|
|
|
|
ck_ulock(&instance_lock); |
|
|
|
ck_ulock(&instance_lock); |
|
|
|
if (client->authorised && !--stats.workers) |
|
|
|
|
|
|
|
stats.users--; |
|
|
|
|
|
|
|
HASH_DEL(stratum_instances, client); |
|
|
|
HASH_DEL(stratum_instances, client); |
|
|
|
HASH_FIND(hh, disconnected_instances, &client->enonce1_64, sizeof(uint64_t), old_client); |
|
|
|
HASH_FIND(hh, disconnected_instances, &client->enonce1_64, sizeof(uint64_t), old_client); |
|
|
|
/* Only keep around one copy of the old client */ |
|
|
|
/* Only keep around one copy of the old client */ |
|
|
@ -894,6 +914,9 @@ static void drop_client(int id) |
|
|
|
ck_dwilock(&instance_lock); |
|
|
|
ck_dwilock(&instance_lock); |
|
|
|
} |
|
|
|
} |
|
|
|
ck_uilock(&instance_lock); |
|
|
|
ck_uilock(&instance_lock); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (dec) |
|
|
|
|
|
|
|
dec_worker(client->user_instance); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void stratum_broadcast_message(const char *msg) |
|
|
|
static void stratum_broadcast_message(const char *msg) |
|
|
@ -1287,12 +1310,8 @@ static json_t *parse_authorise(stratum_instance_t *client, json_t *params_val, j |
|
|
|
else |
|
|
|
else |
|
|
|
ret = send_recv_auth(client); |
|
|
|
ret = send_recv_auth(client); |
|
|
|
client->authorised = ret; |
|
|
|
client->authorised = ret; |
|
|
|
if (client->authorised) { |
|
|
|
if (client->authorised) |
|
|
|
mutex_lock(&stats_lock); |
|
|
|
inc_worker(client->user_instance); |
|
|
|
if (!stats.workers++) |
|
|
|
|
|
|
|
stats.users++; |
|
|
|
|
|
|
|
mutex_unlock(&stats_lock); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
out: |
|
|
|
out: |
|
|
|
return json_boolean(ret); |
|
|
|
return json_boolean(ret); |
|
|
|
} |
|
|
|
} |
|
|
|