Browse Source

Look for other clients that should have been dropped in the stratifier and inform or query the connector about them

master
Con Kolivas 10 years ago
parent
commit
4ff3972ef0
  1. 26
      src/connector.c
  2. 29
      src/stratifier.c

26
src/connector.c

@ -239,7 +239,7 @@ static int drop_client(cdata_t *cdata, client_instance_t *client)
return fd;
}
static void stratifier_drop_client(ckpool_t *ckp, int64_t id)
static void stratifier_drop_client(ckpool_t *ckp, const int64_t id)
{
char buf[256];
@ -601,6 +601,17 @@ static void send_client(cdata_t *cdata, int64_t id, char *buf)
mutex_unlock(&cdata->sender_lock);
}
static bool client_exists(cdata_t *cdata, const int64_t id)
{
client_instance_t *client;
ck_rlock(&cdata->lock);
HASH_FIND_I64(cdata->clients, &id, client);
ck_runlock(&cdata->lock);
return !!client;
}
static client_instance_t *ref_client_by_id(cdata_t *cdata, int64_t id)
{
client_instance_t *client;
@ -774,7 +785,7 @@ retry:
client_instance_t *client;
ret = sscanf(buf, "dropclient=%"PRId64, &client_id64);
if (ret < 0) {
if (unlikely(ret < 0)) {
LOGDEBUG("Connector failed to parse dropclient command: %s", buf);
goto retry;
}
@ -788,6 +799,17 @@ retry:
dec_instance_ref(cdata, client);
if (ret >= 0)
LOGINFO("Connector dropped client id: %"PRId64, client_id);
} else if (cmdmatch(buf, "testclient")) {
ret = sscanf(buf, "testclient=%"PRId64, &client_id64);
if (unlikely(ret < 0)) {
LOGDEBUG("Connector failed to parse testclient command: %s", buf);
goto retry;
}
client_id = client_id64 & 0xffffffffll;
if (client_exists(cdata, client_id))
goto retry;
LOGINFO("Connector detected non-existent client id: %"PRId64, client_id);
stratifier_drop_client(ckp, client_id);
} else if (cmdmatch(buf, "ping")) {
LOGDEBUG("Connector received ping request");
send_unix_msg(sockd, "pong");

29
src/stratifier.c

@ -1805,6 +1805,17 @@ static void dec_worker(ckpool_t *ckp, user_instance_t *instance)
mutex_unlock(&sdata->stats_lock);
}
/* Ask the connector asynchronously to send us dropclient commands if this
* client no longer exists. */
static void connector_test_client(ckpool_t *ckp, const int64_t id)
{
char buf[256];
LOGDEBUG("Stratifier requesting connector test client %"PRId64, id);
snprintf(buf, 255, "testclient=%"PRId64, id);
async_send_proc(ckp, ckp->connector, buf);
}
static void drop_client(ckpool_t *ckp, sdata_t *sdata, const int64_t id)
{
stratum_instance_t *client, *tmp;
@ -1814,7 +1825,25 @@ static void drop_client(ckpool_t *ckp, sdata_t *sdata, const int64_t id)
LOGINFO("Stratifier asked to drop client %"PRId64, id);
/* Use this locking as an opportunity to test other clients. */
ck_ilock(&sdata->instance_lock);
/* Test for clients that haven't authed in over a minute and drop them */
HASH_ITER(hh, sdata->stratum_instances, client, tmp) {
if (client->authorised)
continue;
if (now_t > client->start_time + 60) {
client->dropped = true;
connector_drop_client(ckp, client->id);
}
}
/* Look for clients that may have been dropped which the stratifer has
* not been informed about and ask the connector of they still exist */
HASH_ITER(hh, sdata->stratum_instances, client, tmp) {
if (client->dropped || client->reconnect)
connector_test_client(ckp, client->id);
}
client = __instance_by_id(sdata, id);
/* Upgrade to write lock */
ck_ulock(&sdata->instance_lock);

Loading…
Cancel
Save