From 046f8affb0d4209d52be70671463475e6ebd4250 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 21 Mar 2015 19:47:52 +1100 Subject: [PATCH] Reconnect clients not bound to a user proxy when a new notify creates more headroom --- src/stratifier.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/stratifier.c b/src/stratifier.c index c2c77942..a7850c7c 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -1544,6 +1544,41 @@ static void update_subscribe(ckpool_t *ckp, const char *cmd) json_decref(val); } +/* Check how much headroom the userid proxies have and reconnect any clients + * that are not bound to it */ +static void check_userproxies(sdata_t *sdata, const int userid) +{ + int64_t headroom = userproxy_headroom(sdata, userid); + stratum_instance_t *client, *tmpclient; + int reconnects = 0, hard = 0; + + if (!headroom) + return; + + ck_rlock(&sdata->instance_lock); + HASH_ITER(hh, sdata->stratum_instances, client, tmpclient) { + if (client->user_id != userid) + continue; + if (client->sdata && client->sdata->proxy && client->sdata->proxy->userid == userid) + continue; + if (headroom-- < 1) + continue; + reconnects++; + if (client->reconnect && hard <= SOMAXCONN / 2) { + hard++; + reconnect_client(sdata, client); + } else + client->reconnect = true; + } + ck_runlock(&sdata->instance_lock); + + if (reconnects) { + LOGNOTICE("%d clients flagged for reconnect to user %d proxies", + reconnects, userid); + } + /* FIXME: Recruit extra user proxies when headroom < 0 */ +} + static void update_notify(ckpool_t *ckp, const char *cmd) { sdata_t *sdata = ckp->data, *dsdata; @@ -1638,6 +1673,8 @@ static void update_notify(ckpool_t *ckp, const char *cmd) if (proxy->global) check_bestproxy(sdata); + else + check_userproxies(sdata, proxy->userid); clean |= new_block; LOGINFO("Proxy %d:%d broadcast updated stratum notify with%s clean", id, subid, clean ? "" : "out");