mirror of
https://git.wownero.com/wownero/wownero-puddle.git
synced 2024-08-15 01:03:20 +00:00
free client and fix edge count bug
This commit is contained in:
parent
98bda36af4
commit
2efa10a194
1 changed files with 21 additions and 14 deletions
35
src/pool.c
35
src/pool.c
|
@ -314,7 +314,7 @@ static struct bufferevent *upstream_event;
|
||||||
static struct event *timer_10s;
|
static struct event *timer_10s;
|
||||||
static time_t upstream_last_time;
|
static time_t upstream_last_time;
|
||||||
static uint64_t upstream_last_height;
|
static uint64_t upstream_last_height;
|
||||||
static uint32_t miner_count;
|
static uint32_t account_count;
|
||||||
static client_t *clients_by_fd = NULL;
|
static client_t *clients_by_fd = NULL;
|
||||||
static account_t *accounts = NULL;
|
static account_t *accounts = NULL;
|
||||||
static gbag_t *bag_accounts;
|
static gbag_t *bag_accounts;
|
||||||
|
@ -2668,9 +2668,9 @@ upstream_on_event(struct bufferevent *bev, short error, void *ctx)
|
||||||
log_debug("Upstream timeout");
|
log_debug("Upstream timeout");
|
||||||
}
|
}
|
||||||
/* Update stats due to upstream disconnect */
|
/* Update stats due to upstream disconnect */
|
||||||
if (pool_stats.connected_accounts != miner_count)
|
if (pool_stats.connected_accounts != account_count)
|
||||||
{
|
{
|
||||||
pool_stats.connected_accounts = miner_count;
|
pool_stats.connected_accounts = account_count;
|
||||||
update_pool_hr();
|
update_pool_hr();
|
||||||
}
|
}
|
||||||
/* Wait and try to reconnect */
|
/* Wait and try to reconnect */
|
||||||
|
@ -2798,34 +2798,39 @@ static void
|
||||||
client_clear(struct bufferevent *bev)
|
client_clear(struct bufferevent *bev)
|
||||||
{
|
{
|
||||||
client_t *client = NULL;
|
client_t *client = NULL;
|
||||||
|
account_t *account = NULL;
|
||||||
client_find(bev, &client);
|
client_find(bev, &client);
|
||||||
if (!client)
|
if (!client)
|
||||||
return;
|
return;
|
||||||
client_clear_jobs(client);
|
if (client->downstream)
|
||||||
account_t *account = NULL;
|
{
|
||||||
|
pool_stats.connected_accounts -= client->downstream_accounts;
|
||||||
|
goto clear;
|
||||||
|
}
|
||||||
pthread_rwlock_rdlock(&rwlock_acc);
|
pthread_rwlock_rdlock(&rwlock_acc);
|
||||||
HASH_FIND_STR(accounts, client->address, account);
|
HASH_FIND_STR(accounts, client->address, account);
|
||||||
pthread_rwlock_unlock(&rwlock_acc);
|
pthread_rwlock_unlock(&rwlock_acc);
|
||||||
if (account && account->worker_count == 1)
|
if (!account)
|
||||||
|
goto clear;
|
||||||
|
if (account->worker_count == 1)
|
||||||
{
|
{
|
||||||
if (client->downstream)
|
account_count--;
|
||||||
pool_stats.connected_accounts -= client->downstream_accounts;
|
pool_stats.connected_accounts--;
|
||||||
else
|
|
||||||
pool_stats.connected_accounts--;
|
|
||||||
if (upstream_event)
|
if (upstream_event)
|
||||||
upstream_send_account_disconnect();
|
upstream_send_account_disconnect();
|
||||||
miner_count--;
|
|
||||||
pthread_rwlock_wrlock(&rwlock_acc);
|
pthread_rwlock_wrlock(&rwlock_acc);
|
||||||
HASH_DEL(accounts, account);
|
HASH_DEL(accounts, account);
|
||||||
pthread_rwlock_unlock(&rwlock_acc);
|
pthread_rwlock_unlock(&rwlock_acc);
|
||||||
gbag_put(bag_accounts, account);
|
gbag_put(bag_accounts, account);
|
||||||
}
|
}
|
||||||
else if (account && account->worker_count > 1)
|
else if (account->worker_count > 1)
|
||||||
account->worker_count--;
|
account->worker_count--;
|
||||||
|
clear:
|
||||||
|
client_clear_jobs(client);
|
||||||
pthread_rwlock_wrlock(&rwlock_cfd);
|
pthread_rwlock_wrlock(&rwlock_cfd);
|
||||||
HASH_DEL(clients_by_fd, client);
|
HASH_DEL(clients_by_fd, client);
|
||||||
pthread_rwlock_unlock(&rwlock_cfd);
|
pthread_rwlock_unlock(&rwlock_cfd);
|
||||||
memset(client, 0, sizeof(client_t));
|
gbag_put(bag_clients, client);
|
||||||
bufferevent_free(bev);
|
bufferevent_free(bev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2896,13 +2901,14 @@ miner_on_login(json_object *message, client_t *client)
|
||||||
|
|
||||||
strncpy(client->address, address, sizeof(client->address)-1);
|
strncpy(client->address, address, sizeof(client->address)-1);
|
||||||
strncpy(client->worker_id, worker_id, sizeof(client->worker_id)-1);
|
strncpy(client->worker_id, worker_id, sizeof(client->worker_id)-1);
|
||||||
|
|
||||||
account_t *account = NULL;
|
account_t *account = NULL;
|
||||||
pthread_rwlock_rdlock(&rwlock_acc);
|
pthread_rwlock_rdlock(&rwlock_acc);
|
||||||
HASH_FIND_STR(accounts, client->address, account);
|
HASH_FIND_STR(accounts, client->address, account);
|
||||||
pthread_rwlock_unlock(&rwlock_acc);
|
pthread_rwlock_unlock(&rwlock_acc);
|
||||||
if (!account)
|
if (!account)
|
||||||
{
|
{
|
||||||
miner_count++;
|
account_count++;
|
||||||
if (!client->downstream)
|
if (!client->downstream)
|
||||||
pool_stats.connected_accounts++;
|
pool_stats.connected_accounts++;
|
||||||
if (upstream_event)
|
if (upstream_event)
|
||||||
|
@ -2918,6 +2924,7 @@ miner_on_login(json_object *message, client_t *client)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
account->worker_count++;
|
account->worker_count++;
|
||||||
|
|
||||||
uuid_t cid;
|
uuid_t cid;
|
||||||
uuid_generate(cid);
|
uuid_generate(cid);
|
||||||
bin_to_hex((const unsigned char*)cid, sizeof(uuid_t),
|
bin_to_hex((const unsigned char*)cid, sizeof(uuid_t),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue