Commit e15d57d729c8a5738bbedc4e02b956ac8b0dd73b

Con Kolivas 2012-01-22T09:36:21

Implement socks4 proxy support.

diff --git a/README b/README
index d8e0285..e6083a9 100644
--- a/README
+++ b/README
@@ -148,6 +148,7 @@ Options for both config file and command line:
 --sched-start <arg> Set a time of day in HH:MM to start mining (a once off without a stop time)
 --sched-stop <arg>  Set a time of day in HH:MM to stop mining (will quit without a start time)
 --shares <arg>      Quit after mining N shares (default: unlimited)
+--socks-proxy <arg> Set socks4 proxy (host:port)
 --submit-stale      Submit shares even if they would normally be considered stale
 --syslog            Use system log for output messages (default: standard error)
 --text-only|-T      Disable ncurses formatted screen output
diff --git a/main.c b/main.c
index 554993c..423a01e 100644
--- a/main.c
+++ b/main.c
@@ -307,6 +307,7 @@ struct block {
 static struct block *blocks = NULL;
 
 static char *opt_kernel = NULL;
+char *opt_socks_proxy = NULL;
 
 static const char def_conf[] = "cgminer.conf";
 static bool config_loaded = false;
@@ -1700,6 +1701,9 @@ static struct opt_table opt_config_table[] = {
 	OPT_WITH_ARG("--shares",
 		     opt_set_intval, NULL, &opt_shares,
 		     "Quit after mining N shares (default: unlimited)"),
+	OPT_WITH_ARG("--socks-proxy",
+		     opt_set_charp, NULL, &opt_socks_proxy,
+		     "Set socks4 proxy (host:port)"),
 	OPT_WITHOUT_ARG("--submit-stale",
 			opt_set_bool, &opt_submit_stale,
 		        "Submit shares even if they would normally be considered stale"),
@@ -3241,6 +3245,8 @@ static void write_config(FILE *fcfg)
 		fprintf(fcfg, ",\n\"sched-time\" : \"%d:%d\"", schedstart.tm.tm_hour, schedstart.tm.tm_min);
 	if (schedstop.enable)
 		fprintf(fcfg, ",\n\"stop-time\" : \"%d:%d\"", schedstop.tm.tm_hour, schedstop.tm.tm_min);
+	if (opt_socks_proxy && *opt_socks_proxy)
+		fprintf(fcfg, ",\n\"socks-proxy\" : \"%s\"", opt_socks_proxy);
 	for(i = 0; i < nDevs; i++)
 		if (!gpus[i].enabled)
 			break;
diff --git a/miner.h b/miner.h
index 6092b9c..da60ce5 100644
--- a/miner.h
+++ b/miner.h
@@ -412,6 +412,7 @@ extern bool opt_debug;
 extern bool opt_protocol;
 extern bool opt_log_output;
 extern char *opt_kernel_path;
+extern char *opt_socks_proxy;
 extern char *cgminer_path;
 extern bool opt_autofan;
 extern bool opt_autoengine;
diff --git a/util.c b/util.c
index 2314339..86fa2df 100644
--- a/util.c
+++ b/util.c
@@ -345,6 +345,10 @@ 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) {
+		curl_easy_setopt(curl, CURLOPT_PROXY, opt_socks_proxy);
+		curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
+	}
 	if (userpass) {
 		curl_easy_setopt(curl, CURLOPT_USERPWD, userpass);
 		curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);