Commit 81ff7fb3dc66064b28d5e953e393d3d4ff848ba0

Con Kolivas 2011-07-19T13:01:08

Explicitly probe each pool to see if work can be retrieved from it and what it supports.

diff --git a/main.c b/main.c
index 096915d..1308eb1 100644
--- a/main.c
+++ b/main.c
@@ -2474,6 +2474,38 @@ int main (int argc, char *argv[])
 	} else
 		longpoll_thr_id = -1;
 
+	/* Test each pool to see if we can retrieve and use work and for what
+	 * it supports */
+	for (i = 0; i < total_pools; i++) {
+		struct pool *pool;
+		struct work work;
+		json_t *val;
+		CURL *curl;
+
+		curl = curl_easy_init();
+		if (unlikely(!curl)) {
+			applog(LOG_ERR, "CURL initialisation failed");
+			return 1;
+		}
+
+		pool = &pools[i];
+		val = json_rpc_call(curl, pool->rpc_url, pool->rpc_userpass, rpc_req,
+				true, false, pool);
+
+		if (val) {
+			bool rc;
+
+			rc = work_decode(json_object_get(val, "result"), &work);
+			if (rc)
+				applog(LOG_INFO, "Successfully retreived and deciphered work from pool %u %s", i, pool->rpc_url);
+			else
+				applog(LOG_WARNING, "Successfully retreived but FAILED to decipher work from pool %u %s", i, pool->rpc_url);
+			json_decref(val);
+		} else
+			applog(LOG_WARNING, "FAILED to retrieve work from pool %u %s", i, pool->rpc_url);
+		curl_easy_cleanup(curl);
+	}
+
 	if (opt_n_threads ) {
 		cpus = calloc(num_processors, sizeof(struct cgpu_info));
 		if (unlikely(!cpus)) {
diff --git a/miner.h b/miner.h
index 1442be0..63ab517 100644
--- a/miner.h
+++ b/miner.h
@@ -270,6 +270,7 @@ struct pool {
 	bool localgen;
 	bool idlenet;
 	bool has_rolltime;
+	bool probed;
 	unsigned int getwork_requested;
 	unsigned int stale_shares;
 	unsigned int discarded_work;
diff --git a/util.c b/util.c
index cabcfa7..75ee5d4 100644
--- a/util.c
+++ b/util.c
@@ -246,7 +246,7 @@ static bool comms_error = false;
 
 json_t *json_rpc_call(CURL *curl, const char *url,
 		      const char *userpass, const char *rpc_req,
-		      bool longpoll_scan, bool longpoll,
+		      bool probe, bool longpoll,
 		      struct pool *pool)
 {
 	json_t *val, *err_val, *res_val;
@@ -258,12 +258,12 @@ json_t *json_rpc_call(CURL *curl, const char *url,
 	char len_hdr[64], user_agent_hdr[128];
 	char curl_err_str[CURL_ERROR_SIZE];
 	struct header_info hi = { };
-	bool lp_scanning = false;
+	bool probing = false;
 
 	/* it is assumed that 'curl' is freshly [re]initialized at this pt */
 
-	if (longpoll_scan)
-		lp_scanning = want_longpoll && !have_longpoll;
+	if (probe)
+		probing = ((want_longpoll && !have_longpoll) || !pool->probed);
 
 	if (opt_protocol)
 		curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
@@ -278,7 +278,7 @@ json_t *json_rpc_call(CURL *curl, const char *url,
 	curl_easy_setopt(curl, CURLOPT_READDATA, &upload_data);
 	curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_err_str);
 	curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
-	if (lp_scanning) {
+	if (probing) {
 		curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, resp_hdr_cb);
 		curl_easy_setopt(curl, CURLOPT_HEADERDATA, &hi);
 	}
@@ -329,8 +329,13 @@ json_t *json_rpc_call(CURL *curl, const char *url,
 			tq_push(thr_info[longpoll_thr_id].q, hi.lp_path);
 		} else
 			free(hi.lp_path);
+	}
+
+	if (probing) {
+		pool->probed = true;
 		pool->has_rolltime = hi.has_rolltime;
 	}
+	
 	hi.lp_path = NULL;
 
 	val = JSON_LOADS(all_data.buf, &err);