From 5532de0f1b7db988568b012e3fbee4ffefaa6633 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 7 Oct 2014 23:47:36 +1100 Subject: [PATCH] Implement a stratum reconnect function --- src/ckpool.c | 8 ++++++-- src/stratifier.c | 13 +++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/ckpool.c b/src/ckpool.c index 1a2ce6bd..a013e5d2 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -288,12 +288,16 @@ retry: LOGWARNING("Failed to send_procmsg to connector"); } else if (cmdmatch(buf, "accept")) { LOGWARNING("Listener received accept message, accepting clients"); - send_unix_msg(sockd, "accepting"); send_procmsg(ckp->connector, "accept"); + send_unix_msg(sockd, "accepting"); } else if (cmdmatch(buf, "reject")) { LOGWARNING("Listener received reject message, rejecting clients"); - send_unix_msg(sockd, "rejecting"); send_procmsg(ckp->connector, "reject"); + send_unix_msg(sockd, "rejecting"); + } else if (cmdmatch(buf, "reconnect")) { + LOGWARNING("Listener received request to send reconnect to clients"); + send_procmsg(ckp->stratifier, "reconnect"); + send_unix_msg(sockd, "reconnecting"); } else if (cmdmatch(buf, "restart")) { LOGWARNING("Listener received restart message, attempting handover"); send_unix_msg(sockd, "restarting"); diff --git a/src/stratifier.c b/src/stratifier.c index 47ef38ca..6bc8e952 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -1138,6 +1138,17 @@ static void stratum_broadcast_message(const char *msg) stratum_broadcast(json_msg); } +/* Send a generic reconnect to all clients without parameters to make them + * reconnect to the same server. */ +static void reconnect_clients(void) +{ + json_t *json_msg; + + JSON_CPACK(json_msg, "{sosss[]}", "id", json_null(), "method", "client.reconnect", + "params"); + stratum_broadcast(json_msg); +} + static void block_solve(ckpool_t *ckp) { char cdfield[64]; @@ -1281,6 +1292,8 @@ retry: drop_allclients(ckp); } else if (cmdmatch(buf, "block")) { block_solve(ckp); + } else if (cmdmatch(buf, "reconnect")) { + reconnect_clients(); } else if (cmdmatch(buf, "loglevel")) { sscanf(buf, "loglevel=%d", &ckp->loglevel); } else {