Browse Source

Merge branch 'pool_proxy' into bfgminer

Luke Dashjr 13 years ago
parent
commit
460b36c7bb
7 changed files with 73 additions and 4 deletions
  1. 1 0
      API-README
  2. 23 2
      README
  3. 5 0
      api.c
  4. 1 0
      example.conf
  5. 30 1
      miner.c
  6. 3 0
      miner.h
  7. 10 1
      util.c

+ 1 - 0
API-README

@@ -376,6 +376,7 @@ Modified API commands:
  'devs' - add 'Diff1 Work' to all devices
  'gpu|N' - add 'Diff1 Work'
  'pga|N' - add 'Diff1 Work'
+ 'pools' - add 'Proxy'
  'config' - add 'Queue', 'Expiry'
 
 ----------

+ 23 - 2
README

@@ -148,6 +148,7 @@ Options for both config file and command line:
 --no-submit-stale   Don't submit shares if they are detected as stale
 --pass|-p <arg>     Password for bitcoin JSON-RPC server
 --per-device-stats  Force verbose mode and output per-device statistics
+--pool-proxy|-x     Proxy URI to use for connecting to just the previous-defined pool
 --protocol-dump|-P  Verbose dump of protocol-level activities
 --queue|-Q <arg>    Minimum number of work items to have queued (0 - 10) (default: 1)
 --quiet|-q          Disable logging output, display status and errors
@@ -162,7 +163,7 @@ Options for both config file and command line:
 --scrypt            Use the scrypt algorithm for mining (non-bitcoin)
 --sharelog <arg>    Append share log to file
 --shares <arg>      Quit after mining N shares (default: unlimited)
---socks-proxy <arg> Set socks4 proxy (host:port)
+--socks-proxy <arg> Set socks4 proxy (host:port) for all pools without a proxy specified
 --submit-threads    Maximum number of share submission threads (default: 64)
 --syslog            Use system log for output messages (default: standard error)
 --temp-cutoff <arg> Temperature where a device will be automatically disabled, one value or comma separated list (default: 95)
@@ -301,6 +302,26 @@ Add overclocking settings, GPU and fan control with different engine settings fo
 
 bfgminer -o http://pool:port -u username -p password -I 9 --auto-fan --auto-gpu --gpu-engine 750-950,945,700-930,960 --gpu-memclock 300
 
+Single pool with a standard http proxy, regular desktop:
+
+bfgminer -o http://pool:port -x http://proxy:port -u username -p password
+
+Single pool with a socks5 proxy, regular desktop:
+
+bfgminer -o http://pool:port -x socks5://proxy:port -u username -p password
+
+The list of proxy types are:
+ http:    standard http 1.1 proxy
+ socks4:  socks4 proxy
+ socks5:  socks5 proxy
+ socks4a: socks4a proxy
+ socks5h: socks5 proxy using a hostname
+
+Proxy support requires cURL version 7.21.7 or newer.
+
+If you specify the --socks-proxy option to BFGMiner, it will only be applied to all pools
+that don't specify their own proxy setting like above
+
 READ WARNINGS AND DOCUMENTATION BELOW ABOUT OVERCLOCKING
 
 On Linux you virtually always need to export your display settings before
@@ -762,7 +783,7 @@ A: BFGMiner is being packaged with other trojan scripts and some antivirus
 software is falsely accusing bfgminer.exe as being the actual virus, rather
 than whatever it is being packaged with. If you installed BFGMiner yourself,
 then you do not have a virus on your computer. Complain to your antivirus
-software company. They seem to be flagging even source code now from cgminer
+software company. They seem to be flagging even source code now from BFGMiner
 as viruses, even though text source files can't do anything by themself.
 
 Q: Can you modify the display to include more of one thing in the output and

+ 5 - 0
api.c

@@ -1740,6 +1740,11 @@ static void poolstatus(__maybe_unused SOCKETTYPE c, __maybe_unused char *param,
 		root = api_add_escape(root, "User", pool->rpc_user, false);
 		root = api_add_time(root, "Last Share Time", &(pool->last_share_time), false);
 		root = api_add_int(root, "Diff1 Work", &(pool->diff1), false);
+		if (pool->rpc_proxy) {
+			root = api_add_escape(root, "Proxy", pool->rpc_proxy, false);
+		} else {
+			root = api_add_const(root, "Proxy", BLANK, false);
+		}
 
 		if (isjson && (i > 0))
 			strcat(io_buffer, COMMA);

+ 1 - 0
example.conf

@@ -7,6 +7,7 @@
 	},
 	{
 		"url" : "http://url2:8344",
+		"pool-proxy" : "socks5://127.0.0.1:1080",
 		"user" : "user2",
 		"pass" : "pass2"
 	},

+ 30 - 1
miner.c

@@ -420,6 +420,8 @@ static struct pool *add_pool(void)
 	/* Make sure the pool doesn't think we've been idle since time 0 */
 	pool->tv_idle.tv_sec = ~0UL;
 
+	pool->rpc_proxy = NULL;
+
 	pools = realloc(pools, sizeof(struct pool *) * (total_pools + 2));
 	pools[total_pools++] = pool;
 
@@ -694,6 +696,22 @@ static char *set_userpass(const char *arg)
 	return NULL;
 }
 
+static char *set_pool_proxy(const char *arg)
+{
+	struct pool *pool;
+
+	if (!total_pools)
+		return "Usage of --pool-proxy before pools are defined does not make sense";
+
+	if (!our_curl_supports_proxy_uris())
+		return "Your installed cURL library does not support proxy URIs. At least version 7.21.7 is required.";
+
+	pool = pools[total_pools - 1];
+	opt_set_charp(arg, &pool->rpc_proxy);
+
+	return NULL;
+}
+
 static char *enable_debug(bool *flag)
 {
 	*flag = true;
@@ -1039,6 +1057,9 @@ static struct opt_table opt_config_table[] = {
 	OPT_WITHOUT_ARG("--per-device-stats",
 			opt_set_bool, &want_per_device_stats,
 			"Force verbose mode and output per-device statistics"),
+	OPT_WITH_ARG("--pool-proxy|-x",
+		     set_pool_proxy, NULL, NULL,
+		     "Proxy URI to use for connecting to just the previous-defined pool"),
 	OPT_WITHOUT_ARG("--protocol-dump|-P",
 			opt_set_bool, &opt_protocol,
 			"Verbose dump of protocol-level activities"),
@@ -3536,6 +3557,8 @@ void write_config(FILE *fcfg)
 	fputs("{\n\"pools\" : [", fcfg);
 	for(i = 0; i < total_pools; i++) {
 		fprintf(fcfg, "%s\n\t{\n\t\t\"url\" : \"%s\",", i > 0 ? "," : "", json_escape(pools[i]->rpc_url));
+		if (pools[i]->rpc_proxy)
+			fprintf(fcfg, "\n\t\t\"pool-proxy\" : \"%s\",", json_escape(pools[i]->rpc_proxy));
 		fprintf(fcfg, "\n\t\t\"user\" : \"%s\",", json_escape(pools[i]->rpc_user));
 		fprintf(fcfg, "\n\t\t\"pass\" : \"%s\"\n\t}", json_escape(pools[i]->rpc_pass));
 		}
@@ -5556,7 +5579,7 @@ char *curses_input(const char *query)
 }
 #endif
 
-void add_pool_details(bool live, char *url, char *user, char *pass)
+void add_pool_details5(bool live, char *url, char *user, char *pass, char *proxy)
 {
 	struct pool *pool;
 
@@ -5569,6 +5592,7 @@ void add_pool_details(bool live, char *url, char *user, char *pass)
 	if (!pool->rpc_userpass)
 		quit(1, "Failed to malloc userpass");
 	sprintf(pool->rpc_userpass, "%s:%s", pool->rpc_user, pool->rpc_pass);
+	pool->rpc_proxy = proxy;
 
 	/* Test the pool is not idle if we're live running, otherwise
 	 * it will be tested separately */
@@ -5577,6 +5601,11 @@ void add_pool_details(bool live, char *url, char *user, char *pass)
 		pool->idle = true;
 }
 
+void add_pool_details(bool live, char *url, char *user, char *pass)
+{
+	add_pool_details5(live, url, user, pass, NULL);
+}
+
 #ifdef HAVE_CURSES
 static bool input_pool(bool live)
 {

+ 3 - 0
miner.h

@@ -641,6 +641,7 @@ extern const uint32_t sha256_init_state[];
 extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,
 			     const char *rpc_req, bool, bool, int *,
 			     struct pool *pool, bool);
+extern bool our_curl_supports_proxy_uris();
 extern char *bin2hex(const unsigned char *p, size_t len);
 extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
 
@@ -684,6 +685,7 @@ extern void api(int thr_id);
 
 extern struct pool *current_pool(void);
 extern int enabled_pools;
+extern void add_pool_details5(bool live, char *url, char *user, char *pass, char *proxy);
 extern void add_pool_details(bool live, char *url, char *user, char *pass);
 
 #define MAX_GPUDEVICES 16
@@ -825,6 +827,7 @@ struct pool {
 	char *rpc_url;
 	char *rpc_userpass;
 	char *rpc_user, *rpc_pass;
+	char *rpc_proxy;
 
 	pthread_mutex_t pool_lock;
 

+ 10 - 1
util.c

@@ -314,7 +314,9 @@ json_t *json_rpc_call(CURL *curl, const char *url,
 	curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, resp_hdr_cb);
 	curl_easy_setopt(curl, CURLOPT_HEADERDATA, &hi);
 	curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_TRY);
-	if (opt_socks_proxy) {
+	if (pool->rpc_proxy) {
+		curl_easy_setopt(curl, CURLOPT_PROXY, pool->rpc_proxy);
+	} else if (opt_socks_proxy) {
 		curl_easy_setopt(curl, CURLOPT_PROXY, opt_socks_proxy);
 		curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
 	}
@@ -473,6 +475,13 @@ err_out:
 	return NULL;
 }
 
+bool our_curl_supports_proxy_uris()
+{
+	curl_version_info_data *data = curl_version_info(CURLVERSION_NOW);
+	return data->age && data->version_num >= (( 7 <<16)|( 21 <<8)| 7);  // 7.21.7
+}
+
+
 char *bin2hex(const unsigned char *p, size_t len)
 {
 	char *s = malloc((len * 2) + 1);