Browse Source

Merge branch 'bfcube_workaround' into bfgminer-3.5.x

Luke Dashjr 11 years ago
parent
commit
e45fa3c991
1 changed files with 14 additions and 8 deletions
  1. 14 8
      driver-getwork.c

+ 14 - 8
driver-getwork.c

@@ -31,28 +31,34 @@
 #include "miner.h"
 
 static
-void getwork_prepare_resp(struct MHD_Response *resp)
+void getwork_prepare_resp(struct MHD_Response *resp, struct MHD_Connection * const conn)
 {
 	httpsrv_prepare_resp(resp);
 	MHD_add_response_header(resp, MHD_HTTP_HEADER_CONTENT_TYPE, "application/json");
 	MHD_add_response_header(resp, "X-Mining-Extensions", "hashesdone");
+#if MHD_VERSION >= 0x00093701
+	const char * const agent = MHD_lookup_connection_value(conn, MHD_HEADER_KIND, "User-Agent");
+	// Block Erupter products can't handle the Connection: close header, so force HTTP/1.0 for them
+	if (!(strcmp(agent, "BE Cube BTC Miner") && strcmp(agent, "Jephis PIC Miner")))
+		MHD_set_response_options(resp, MHD_RF_HTTP_VERSION_1_0_ONLY, MHD_RO_END);
+#endif
 }
 
 static
-struct MHD_Response *getwork_gen_error(int16_t errcode, const char *errmsg, const char *idstr, size_t idstr_sz)
+struct MHD_Response *getwork_gen_error(int16_t errcode, const char *errmsg, const char *idstr, size_t idstr_sz, struct MHD_Connection * const conn)
 {
 	size_t replysz = 0x40 + strlen(errmsg) + idstr_sz;
 	char * const reply = malloc(replysz);
 	replysz = snprintf(reply, replysz, "{\"result\":null,\"error\":{\"code\":%d,\"message\":\"%s\"},\"id\":%s}", errcode, errmsg, idstr ?: "0");
 	struct MHD_Response * const resp = MHD_create_response_from_buffer(replysz, reply, MHD_RESPMEM_MUST_FREE);
-	getwork_prepare_resp(resp);
+	getwork_prepare_resp(resp, conn);
 	return resp;
 }
 
 static
 int getwork_error(struct MHD_Connection *conn, int16_t errcode, const char *errmsg, const char *idstr, size_t idstr_sz)
 {
-	struct MHD_Response * const resp = getwork_gen_error(errcode, errmsg, idstr, idstr_sz);
+	struct MHD_Response * const resp = getwork_gen_error(errcode, errmsg, idstr, idstr_sz, conn);
 	const int ret = MHD_queue_response(conn, 500, resp);
 	MHD_destroy_response(resp);
 	return ret;
@@ -101,7 +107,7 @@ int handle_getwork(struct MHD_Connection *conn, bytes_t *upbuf)
 	user = MHD_basic_auth_get_username_password(conn, NULL);
 	if (!user)
 	{
-		resp = getwork_gen_error(-4096, "Please provide a username", idstr, idstr_sz);
+		resp = getwork_gen_error(-4096, "Please provide a username", idstr, idstr_sz, conn);
 		ret = MHD_queue_basic_auth_fail_response(conn, PACKAGE, resp);
 		goto out;
 	}
@@ -152,7 +158,7 @@ int handle_getwork(struct MHD_Connection *conn, bytes_t *upbuf)
 		sprintf(reply, "{\"error\":null,\"result\":%s,\"id\":%s}",
 		        rejreason ? "false" : "true", idstr);
 		resp = MHD_create_response_from_buffer(replysz, reply, MHD_RESPMEM_MUST_FREE);
-		getwork_prepare_resp(resp);
+		getwork_prepare_resp(resp, conn);
 		MHD_add_response_header(resp, "X-Mining-Identifier", cgpu->proc_repr);
 		if (rejreason)
 			MHD_add_response_header(resp, "X-Reject-Reason", rejreason);
@@ -163,7 +169,7 @@ int handle_getwork(struct MHD_Connection *conn, bytes_t *upbuf)
 	
 	if (cgpu->deven == DEV_DISABLED)
 	{
-		resp = getwork_gen_error(-10, "Virtual device has been disabled", idstr, idstr_sz);
+		resp = getwork_gen_error(-10, "Virtual device has been disabled", idstr, idstr_sz, conn);
 		MHD_add_response_header(resp, "X-Mining-Identifier", cgpu->proc_repr);
 		ret = MHD_queue_response(conn, 500, resp);
 		MHD_destroy_response(resp);
@@ -187,7 +193,7 @@ int handle_getwork(struct MHD_Connection *conn, bytes_t *upbuf)
 		HASH_ADD_KEYPTR(hh, client->work, work->data, 76, work);
 		
 		resp = MHD_create_response_from_buffer(replysz, reply, MHD_RESPMEM_MUST_FREE);
-		getwork_prepare_resp(resp);
+		getwork_prepare_resp(resp, conn);
 		MHD_add_response_header(resp, "X-Mining-Identifier", cgpu->proc_repr);
 		ret = MHD_queue_response(conn, 200, resp);
 		MHD_destroy_response(resp);