Browse Source

Merge branch 'cgminer' into stratum

Luke Dashjr 13 years ago
parent
commit
a0bdebee96
2 changed files with 25 additions and 20 deletions
  1. 14 16
      miner.c
  2. 11 4
      util.c

+ 14 - 16
miner.c

@@ -662,10 +662,10 @@ static char *set_rr(enum pool_strategy *strategy)
  * stratum+tcp or by detecting a stratum server response */
 bool detect_stratum(struct pool *pool, char *url)
 {
-	if (opt_scrypt)
+	if (!extract_sockaddr(pool, url))
 		return false;
 
-	if (!extract_sockaddr(pool, url))
+	if (opt_scrypt)
 		return false;
 
 	if (!strncasecmp(url, "stratum+tcp://", 14)) {
@@ -2012,13 +2012,13 @@ static void curses_print_status(void)
 	wclrtoeol(statuswin);
 	if (pool->has_stratum) {
 		mvwprintw(statuswin, 4, 0, " Connected to %s with stratum as user %s",
-			pool->stratum_url, pool->rpc_user);
+			pool->sockaddr_url, pool->rpc_user);
 	} else if ((pool_strategy == POOL_LOADBALANCE  || pool_strategy == POOL_BALANCE) && total_pools > 1) {
 		mvwprintw(statuswin, 4, 0, " Connected to multiple pools with%s LP",
 			have_longpoll ? "": "out");
 	} else {
 		mvwprintw(statuswin, 4, 0, " Connected to %s with%s LP as user %s",
-			pool->rpc_url, have_longpoll ? "": "out", pool->rpc_user);
+			pool->sockaddr_url, have_longpoll ? "": "out", pool->rpc_user);
 	}
 	wclrtoeol(statuswin);
 	mvwprintw(statuswin, 5, 0, " Block: %s...  Started: %s  Best share: %s   ", current_hash, blocktime, best_share);
@@ -3553,34 +3553,32 @@ next_submit:
 	}
 
 	if (work->stratum) {
-		struct stratum_share *sshare = calloc(sizeof(struct stratum_share), 1);
 		uint32_t *hash32 = (uint32_t *)work->hash, nonce;
 		char *noncehex;
 		char s[1024];
 
-		memcpy(&sshare->work, work, sizeof(struct work));
-
 		/* Give the stratum share a unique id */
-		mutex_lock(&sshare_lock);
-		sshare->id = swork_id++;
-		HASH_ADD_INT(stratum_shares, id, sshare);
-		mutex_unlock(&sshare_lock);
-
+		swork_id++;
 		nonce = *((uint32_t *)(work->data + 76));
 		noncehex = bin2hex((const unsigned char *)&nonce, 4);
 
 		memset(s, 0, 1024);
 		sprintf(s, "{\"params\": [\"%s\", \"%s\", \"%s\", \"%s\", \"%s\"], \"id\": %d, \"method\": \"mining.submit\"}",
-			pool->rpc_user, work->job_id, work->nonce2, work->ntime, noncehex, sshare->id);
+			pool->rpc_user, work->job_id, work->nonce2, work->ntime, noncehex, swork_id);
 		free(noncehex);
 
 		applog(LOG_DEBUG, "DBG: sending %s submit RPC call: %s", pool->stratum_url, s);
 
-		if (unlikely(!stratum_send(pool, s, strlen(s)))) {
+		if (likely(stratum_send(pool, s, strlen(s)))) {
+			struct stratum_share *sshare = calloc(sizeof(struct stratum_share), 1);
+
+			applog(LOG_DEBUG, "Successfully submitted, adding to stratum_shares db");
+			memcpy(&sshare->work, work, sizeof(struct work));
+
 			mutex_lock(&sshare_lock);
-			HASH_DEL(stratum_shares, sshare);
+			sshare->id = swork_id;
+			HASH_ADD_INT(stratum_shares, id, sshare);
 			mutex_unlock(&sshare_lock);
-			free(sshare);
 		}
 
 		goto out;

+ 11 - 4
util.c

@@ -216,11 +216,10 @@ out:
 	return ptrlen;
 }
 
-int json_rpc_call_sockopt_cb(void __maybe_unused *userdata, curl_socket_t fd,
-			     curlsocktype __maybe_unused purpose)
+static int keep_sockalive(SOCKETTYPE fd)
 {
-	int tcp_keepidle = 120;
-	int tcp_keepintvl = 120;
+	int tcp_keepidle = 60;
+	int tcp_keepintvl = 60;
 
 #ifndef WIN32
 	int keepalive = 1;
@@ -264,6 +263,12 @@ int json_rpc_call_sockopt_cb(void __maybe_unused *userdata, curl_socket_t fd,
 	return 0;
 }
 
+int json_rpc_call_sockopt_cb(void __maybe_unused *userdata, curl_socket_t fd,
+			     curlsocktype __maybe_unused purpose)
+{
+	return keep_sockalive(fd);
+}
+
 static void last_nettime(struct timeval *last)
 {
 	rd_lock(&netacc_lock);
@@ -807,6 +812,7 @@ bool extract_sockaddr(struct pool *pool, char *url)
 	struct addrinfo hints, *res;
 	int url_len, port_len = 0;
 
+	pool->sockaddr_url = url;
 	url_begin = strstr(url, "//");
 	if (!url_begin)
 		url_begin = url;
@@ -1329,6 +1335,7 @@ bool initiate_stratum(struct pool *pool)
 		goto out;
 	}
 	curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, (long *)&pool->sock);
+	keep_sockalive(pool->sock);
 
 	sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": []}", swork_id++);