Browse Source

proxy: Replace mess of encoding proxy into pool URI with a --pool-proxy option, and use cURL's builtin proxy URI support

Luke Dashjr 13 years ago
parent
commit
29dabe75f5
7 changed files with 40 additions and 80 deletions
  1. 1 1
      API-README
  2. 4 5
      README
  3. 0 2
      api.c
  4. 1 0
      example.conf
  5. 29 10
      miner.c
  6. 2 3
      miner.h
  7. 3 59
      util.c

+ 1 - 1
API-README

@@ -376,7 +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 Type', 'Proxy'
+ 'pools' - add 'Proxy'
  'config' - add 'Queue', 'Expiry'
 
 ----------

+ 4 - 5
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
@@ -303,22 +304,20 @@ bfgminer -o http://pool:port -u username -p password -I 9 --auto-fan --auto-gpu
 
 Single pool with a standard http proxy, regular desktop:
 
-bfgminer -o "http:proxy:port|http://pool:port" -u username -p password
+bfgminer -o http://pool:port -x http://proxy:port -u username -p password
 
 Single pool with a socks5 proxy, regular desktop:
 
-bfgminer -o "socks5:proxy:port|http://pool:port" -u username -p password
+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
- http0:   http 1.0 proxy
  socks4:  socks4 proxy
  socks5:  socks5 proxy
  socks4a: socks4a proxy
  socks5h: socks5 proxy using a hostname
 
-If you compile BFGMiner with a version of CURL before 7.19.4 then some of the above will
-not be available. All are available since CURL version 7.19.4
+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

+ 0 - 2
api.c

@@ -1741,10 +1741,8 @@ static void poolstatus(__maybe_unused SOCKETTYPE c, __maybe_unused char *param,
 		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_const(root, "Proxy Type", proxytype(pool->rpc_proxytype), false);
 			root = api_add_escape(root, "Proxy", pool->rpc_proxy, false);
 		} else {
-			root = api_add_const(root, "Proxy Type", BLANK, false);
 			root = api_add_const(root, "Proxy", BLANK, false);
 		}
 

+ 1 - 0
example.conf

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

+ 29 - 10
miner.c

@@ -635,8 +635,6 @@ static char *set_url(char *arg)
 		add_pool();
 	pool = pools[total_urls - 1];
 
-	arg = get_proxy(arg, pool);
-
 	opt_set_charp(arg, &pool->rpc_url);
 	if (strncmp(arg, "http://", 7) &&
 	    strncmp(arg, "https://", 8)) {
@@ -698,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;
@@ -1043,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"),
@@ -3539,11 +3556,9 @@ void write_config(FILE *fcfg)
 	/* Write pool values */
 	fputs("{\n\"pools\" : [", fcfg);
 	for(i = 0; i < total_pools; i++) {
-		fprintf(fcfg, "%s\n\t{\n\t\t\"url\" : \"%s%s%s%s\",", i > 0 ? "," : "",
-			pools[i]->rpc_proxy ? json_escape((char *)proxytype(pools[i]->rpc_proxytype)) : "",
-			pools[i]->rpc_proxy ? json_escape(pools[i]->rpc_proxy) : "",
-			pools[i]->rpc_proxy ? "|" : "",
-			json_escape(pools[i]->rpc_url));
+		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));
 		}
@@ -5564,14 +5579,12 @@ 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;
 
 	pool = add_pool();
 
-	url = get_proxy(url, pool);
-
 	pool->rpc_url = url;
 	pool->rpc_user = user;
 	pool->rpc_pass = pass;
@@ -5579,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 */
@@ -5587,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)
 {

+ 2 - 3
miner.h

@@ -641,8 +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 const char *proxytype(curl_proxytype proxytype);
-extern char *get_proxy(char *url, struct pool *pool);
+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);
 
@@ -686,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
@@ -827,7 +827,6 @@ struct pool {
 	char *rpc_url;
 	char *rpc_userpass;
 	char *rpc_user, *rpc_pass;
-	curl_proxytype rpc_proxytype;
 	char *rpc_proxy;
 
 	pthread_mutex_t pool_lock;

+ 3 - 59
util.c

@@ -316,7 +316,6 @@ json_t *json_rpc_call(CURL *curl, const char *url,
 	curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_TRY);
 	if (pool->rpc_proxy) {
 		curl_easy_setopt(curl, CURLOPT_PROXY, pool->rpc_proxy);
-		curl_easy_setopt(curl, CURLOPT_PROXYTYPE, pool->rpc_proxytype);
 	} else if (opt_socks_proxy) {
 		curl_easy_setopt(curl, CURLOPT_PROXY, opt_socks_proxy);
 		curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
@@ -476,65 +475,10 @@ err_out:
 	return NULL;
 }
 
-#if (LIBCURL_VERSION_MAJOR == 7 && LIBCURL_VERSION_MINOR >= 10) || (LIBCURL_VERSION_MAJOR > 7)
-static struct {
-	const char *name;
-	curl_proxytype proxytype;
-} proxynames[] = {
-	{ "http:",	CURLPROXY_HTTP },
-#if (LIBCURL_VERSION_MAJOR > 7) || (LIBCURL_VERSION_MINOR > 19) || (LIBCURL_VERSION_MINOR == 19 && LIBCURL_VERSION_PATCH >= 4)
-	{ "http0:",	CURLPROXY_HTTP_1_0 },
-#endif
-#if (LIBCURL_VERSION_MAJOR > 7) || (LIBCURL_VERSION_MINOR > 15) || (LIBCURL_VERSION_MINOR == 15 && LIBCURL_VERSION_PATCH >= 2)
-	{ "socks4:",	CURLPROXY_SOCKS4 },
-#endif
-	{ "socks5:",	CURLPROXY_SOCKS5 },
-#if (LIBCURL_VERSION_MAJOR > 7) || (LIBCURL_VERSION_MINOR >= 18)
-	{ "socks4a:",	CURLPROXY_SOCKS4A },
-	{ "socks5h:",	CURLPROXY_SOCKS5_HOSTNAME },
-#endif
-};
-#endif
-
-const char *proxytype(curl_proxytype proxytype)
-{
-	int i;
-
-	for (i = 0; proxynames[i].name; i++)
-		if (proxynames[i].proxytype == proxytype)
-			return proxynames[i].name;
-
-	return "invalid";
-}
-
-char *get_proxy(char *url, struct pool *pool)
+bool our_curl_supports_proxy_uris()
 {
-	pool->rpc_proxy = NULL;
-
-#if (LIBCURL_VERSION_MAJOR == 7 && LIBCURL_VERSION_MINOR >= 10) || (LIBCURL_VERSION_MAJOR > 7)
-	char *split;
-	int plen, len, i;
-
-	for (i = 0; proxynames[i].name; i++) {
-		plen = strlen(proxynames[i].name);
-		if (strncmp(url, proxynames[i].name, plen) == 0) {
-			if (!(split = strchr(url, '|')))
-				return url;
-
-			*split = '\0';
-			len = split - url;
-			pool->rpc_proxy = malloc(1 + len - plen);
-			if (!(pool->rpc_proxy))
-				quit(1, "Failed to malloc rpc_proxy");
-
-			strcpy(pool->rpc_proxy, url + plen);
-			pool->rpc_proxytype = proxynames[i].proxytype;
-			url = split + 1;
-			break;
-		}
-	}
-#endif
-	return url;
+	curl_version_info_data *data = curl_version_info(CURLVERSION_NOW);
+	return data->age && data->version_num >= (( 7 <<16)|( 21 <<8)| 7);  // 7.21.7
 }