|
@@ -4054,6 +4054,7 @@ void remove_pool(struct pool *pool)
|
|
|
/* Give it an invalid number */
|
|
/* Give it an invalid number */
|
|
|
pool->pool_no = total_pools;
|
|
pool->pool_no = total_pools;
|
|
|
pool->removed = true;
|
|
pool->removed = true;
|
|
|
|
|
+ pool->has_stratum = false;
|
|
|
total_pools--;
|
|
total_pools--;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -4971,7 +4972,19 @@ out:
|
|
|
return ret;
|
|
return ret;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+static void shutdown_stratum(struct pool *pool)
|
|
|
|
|
+{
|
|
|
|
|
+ // Shut down Stratum as if we never had it
|
|
|
|
|
+ pool->has_stratum = false;
|
|
|
|
|
+ shutdown(pool->sock, SHUT_RDWR);
|
|
|
|
|
+ free(pool->stratum_url);
|
|
|
|
|
+ if (pool->sockaddr_url == pool->stratum_url)
|
|
|
|
|
+ pool->sockaddr_url = NULL;
|
|
|
|
|
+ pool->stratum_url = NULL;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
static void pool_resus(struct pool *pool);
|
|
static void pool_resus(struct pool *pool);
|
|
|
|
|
+static bool pool_active(struct pool *pool, bool pinging);
|
|
|
|
|
|
|
|
/* One stratum thread per pool that has stratum waits on the socket checking
|
|
/* One stratum thread per pool that has stratum waits on the socket checking
|
|
|
* for new messages and for the integrity of the socket connection. We reset
|
|
* for new messages and for the integrity of the socket connection. We reset
|
|
@@ -4988,7 +5001,7 @@ static void *stratum_thread(void *userdata)
|
|
|
fd_set rd;
|
|
fd_set rd;
|
|
|
char *s;
|
|
char *s;
|
|
|
|
|
|
|
|
- if (unlikely(pool->removed))
|
|
|
|
|
|
|
+ if (unlikely(!pool->has_stratum))
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
FD_ZERO(&rd);
|
|
FD_ZERO(&rd);
|
|
@@ -5003,6 +5016,9 @@ static void *stratum_thread(void *userdata)
|
|
|
select(pool->sock + 1, &rd, NULL, NULL, &timeout);
|
|
select(pool->sock + 1, &rd, NULL, NULL, &timeout);
|
|
|
s = recv_line(pool);
|
|
s = recv_line(pool);
|
|
|
if (!s) {
|
|
if (!s) {
|
|
|
|
|
+ if (!pool->has_stratum)
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
applog(LOG_INFO, "Stratum connection to pool %d interrupted", pool->pool_no);
|
|
applog(LOG_INFO, "Stratum connection to pool %d interrupted", pool->pool_no);
|
|
|
pool->getfail_occasions++;
|
|
pool->getfail_occasions++;
|
|
|
total_go++;
|
|
total_go++;
|
|
@@ -5011,6 +5027,12 @@ static void *stratum_thread(void *userdata)
|
|
|
if (initiate_stratum(pool) && auth_stratum(pool))
|
|
if (initiate_stratum(pool) && auth_stratum(pool))
|
|
|
continue;
|
|
continue;
|
|
|
|
|
|
|
|
|
|
+ if (pool->rpc_url[0] != 's') {
|
|
|
|
|
+ shutdown_stratum(pool);
|
|
|
|
|
+ pool_active(pool, false);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
pool_died(pool);
|
|
pool_died(pool);
|
|
|
while (!initiate_stratum(pool) || !auth_stratum(pool)) {
|
|
while (!initiate_stratum(pool) || !auth_stratum(pool)) {
|
|
|
if (pool->removed)
|
|
if (pool->removed)
|
|
@@ -5107,23 +5129,6 @@ static bool pool_active(struct pool *pool, bool pinging)
|
|
|
applog(LOG_INFO, "Testing pool %s", pool->rpc_url);
|
|
applog(LOG_INFO, "Testing pool %s", pool->rpc_url);
|
|
|
|
|
|
|
|
/* This is the central point we activate stratum when we can */
|
|
/* This is the central point we activate stratum when we can */
|
|
|
-retry_stratum:
|
|
|
|
|
- if (pool->has_stratum) {
|
|
|
|
|
- /* We create the stratum thread for each pool just after
|
|
|
|
|
- * successful authorisation. Once the auth flag has been set
|
|
|
|
|
- * we never unset it and the stratum thread is responsible for
|
|
|
|
|
- * setting/unsetting the active flag */
|
|
|
|
|
- if (pool->stratum_auth)
|
|
|
|
|
- return pool->stratum_active;
|
|
|
|
|
- if (!pool->stratum_active && !initiate_stratum(pool))
|
|
|
|
|
- return false;
|
|
|
|
|
- if (!auth_stratum(pool))
|
|
|
|
|
- return false;
|
|
|
|
|
- pool->idle = false;
|
|
|
|
|
- init_stratum_thread(pool);
|
|
|
|
|
- return true;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
curl = curl_easy_init();
|
|
curl = curl_easy_init();
|
|
|
if (unlikely(!curl)) {
|
|
if (unlikely(!curl)) {
|
|
|
applog(LOG_ERR, "CURL initialisation failed");
|
|
applog(LOG_ERR, "CURL initialisation failed");
|
|
@@ -5147,14 +5152,33 @@ tryagain:
|
|
|
|
|
|
|
|
/* Detect if a http getwork pool has an X-Stratum header at startup,
|
|
/* Detect if a http getwork pool has an X-Stratum header at startup,
|
|
|
* and if so, switch to that in preference to getwork if it works */
|
|
* and if so, switch to that in preference to getwork if it works */
|
|
|
- if (pool->stratum_url && want_stratum && stratum_works(pool)) {
|
|
|
|
|
|
|
+ if (pool->stratum_url && want_stratum && (pool->has_stratum || stratum_works(pool))) {
|
|
|
|
|
+ curl_easy_cleanup(curl);
|
|
|
|
|
+
|
|
|
|
|
+ if (!pool->has_stratum) {
|
|
|
|
|
+
|
|
|
applog(LOG_NOTICE, "Switching pool %d %s to %s", pool->pool_no, pool->rpc_url, pool->stratum_url);
|
|
applog(LOG_NOTICE, "Switching pool %d %s to %s", pool->pool_no, pool->rpc_url, pool->stratum_url);
|
|
|
- pool->rpc_url = strdup(pool->stratum_url);
|
|
|
|
|
pool->has_stratum = true;
|
|
pool->has_stratum = true;
|
|
|
- curl_easy_cleanup(curl);
|
|
|
|
|
|
|
|
|
|
- goto retry_stratum;
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+retry_stratum:
|
|
|
|
|
+ /* We create the stratum thread for each pool just after
|
|
|
|
|
+ * successful authorisation. Once the auth flag has been set
|
|
|
|
|
+ * we never unset it and the stratum thread is responsible for
|
|
|
|
|
+ * setting/unsetting the active flag */
|
|
|
|
|
+ if (pool->stratum_auth)
|
|
|
|
|
+ return pool->stratum_active;
|
|
|
|
|
+ if (!pool->stratum_active && !initiate_stratum(pool))
|
|
|
|
|
+ return false;
|
|
|
|
|
+ if (!auth_stratum(pool))
|
|
|
|
|
+ return false;
|
|
|
|
|
+ pool->idle = false;
|
|
|
|
|
+ init_stratum_thread(pool);
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
|
|
+ else if (pool->has_stratum)
|
|
|
|
|
+ shutdown_stratum(pool);
|
|
|
|
|
|
|
|
if (val) {
|
|
if (val) {
|
|
|
bool rc;
|
|
bool rc;
|