From 783af8768b595613ee5e4aabfefde24c0830e71a Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Wed, 10 Oct 2012 23:41:29 +1100 Subject: [PATCH] Implement rudimentary mining.reconnect support for stratum. --- util.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/util.c b/util.c index 42644406..d5243ae7 100644 --- a/util.c +++ b/util.c @@ -850,6 +850,7 @@ bool extract_sockaddr(struct pool *pool, char *url) pool->server = (struct sockaddr_in *)res->ai_addr; pool->sockaddr_url = strdup(url_address); + return true; } @@ -1096,6 +1097,27 @@ static bool parse_diff(struct pool *pool, json_t *val) return true; } +static bool parse_reconnect(struct pool *pool, json_t *val) +{ + char *url; + + url = (char *)json_string_value(json_array_get(val, 0)); + if (!url) + return false; + + if (!extract_sockaddr(pool, url)) + return false; + + pool->stratum_url = pool->sockaddr_url; + + applog(LOG_NOTICE, "Reconnect requested from pool %d to %s", pool->pool_no, pool->stratum_url); + + if (!initiate_stratum(pool) || !auth_stratum(pool)) + return false; + + return true; +} + bool parse_method(struct pool *pool, char *s) { json_t *val = NULL, *method, *err_val, *params; @@ -1147,6 +1169,11 @@ bool parse_method(struct pool *pool, char *s) goto out; } + if (!strncasecmp(buf, "mining.reconnect", 16) && parse_reconnect(pool, params)) { + ret = true; + goto out; + } + out: if (val) json_decref(val);