Browse Source

GWS: Add support for new X-Hashes-Done header to allow devices to more accurately report their work

Luke Dashjr 12 years ago
parent
commit
6af1dd9629
1 changed files with 16 additions and 7 deletions
  1. 16 7
      driver-getwork.c

+ 16 - 7
driver-getwork.c

@@ -38,8 +38,6 @@ struct getwork_client *getwork_clients;
 static
 static
 pthread_mutex_t getwork_clients_mutex;
 pthread_mutex_t getwork_clients_mutex;
 
 
-// TODO: X-Hashes-Done?
-
 static
 static
 void prune_worklog()
 void prune_worklog()
 {
 {
@@ -96,6 +94,7 @@ void getwork_prepare_resp(struct MHD_Response *resp)
 {
 {
 	httpsrv_prepare_resp(resp);
 	httpsrv_prepare_resp(resp);
 	MHD_add_response_header(resp, MHD_HTTP_HEADER_CONTENT_TYPE, "application/json");
 	MHD_add_response_header(resp, MHD_HTTP_HEADER_CONTENT_TYPE, "application/json");
+	MHD_add_response_header(resp, "X-Mining-Extensions", "hashesdone");
 }
 }
 
 
 static
 static
@@ -131,6 +130,7 @@ int handle_getwork(struct MHD_Connection *conn, bytes_t *upbuf)
 	json_error_t jerr;
 	json_error_t jerr;
 	struct work *work;
 	struct work *work;
 	char *reply;
 	char *reply;
+	const char *hashesdone = NULL;
 	int ret;
 	int ret;
 	
 	
 	if (unlikely(!_init))
 	if (unlikely(!_init))
@@ -211,12 +211,13 @@ int handle_getwork(struct MHD_Connection *conn, bytes_t *upbuf)
 	user = NULL;
 	user = NULL;
 	thr = cgpu->thr[0];
 	thr = cgpu->thr[0];
 	
 	
+	hashesdone = MHD_lookup_connection_value(conn, MHD_HEADER_KIND, "X-Hashes-Done");
+	
 	if (submit)
 	if (submit)
 	{
 	{
 		unsigned char hdr[80];
 		unsigned char hdr[80];
 		const char *rejreason;
 		const char *rejreason;
 		uint32_t nonce;
 		uint32_t nonce;
-		struct timeval tv_now, tv_delta;
 		
 		
 		// NOTE: expecting hex2bin to fail since we only parse 80 of the 128
 		// NOTE: expecting hex2bin to fail since we only parse 80 of the 128
 		hex2bin(hdr, submit, 80);
 		hex2bin(hdr, submit, 80);
@@ -237,10 +238,8 @@ int handle_getwork(struct MHD_Connection *conn, bytes_t *upbuf)
 			else
 			else
 				rejreason = NULL;
 				rejreason = NULL;
 			
 			
-			timer_set_now(&tv_now);
-			timersub(&tv_now, &client->tv_hashes_done, &tv_delta);
-			client->tv_hashes_done = tv_now;
-			hashes_done(thr, 0x100000000, &tv_delta, NULL);
+			if (!hashesdone)
+				hashesdone = "0x100000000";
 		}
 		}
 		
 		
 		reply = malloc(36 + idstr_sz);
 		reply = malloc(36 + idstr_sz);
@@ -290,6 +289,16 @@ int handle_getwork(struct MHD_Connection *conn, bytes_t *upbuf)
 	}
 	}
 	
 	
 out:
 out:
+	if (hashesdone)
+	{
+		struct timeval tv_now, tv_delta;
+		long long lld = strtoll(hashesdone, NULL, 0);
+		timer_set_now(&tv_now);
+		timersub(&tv_now, &client->tv_hashes_done, &tv_delta);
+		client->tv_hashes_done = tv_now;
+		hashes_done(thr, lld, &tv_delta, NULL);
+	}
+	
 	free(user);
 	free(user);
 	free(idstr);
 	free(idstr);
 	if (json)
 	if (json)