Browse Source

Implement socks4 proxy support.

Con Kolivas 14 years ago
parent
commit
e15d57d729
4 changed files with 12 additions and 0 deletions
  1. 1 0
      README
  2. 6 0
      main.c
  3. 1 0
      miner.h
  4. 4 0
      util.c

+ 1 - 0
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-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)
 --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)
 --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
 --submit-stale      Submit shares even if they would normally be considered stale
 --syslog            Use system log for output messages (default: standard error)
 --syslog            Use system log for output messages (default: standard error)
 --text-only|-T      Disable ncurses formatted screen output
 --text-only|-T      Disable ncurses formatted screen output

+ 6 - 0
main.c

@@ -307,6 +307,7 @@ struct block {
 static struct block *blocks = NULL;
 static struct block *blocks = NULL;
 
 
 static char *opt_kernel = NULL;
 static char *opt_kernel = NULL;
+char *opt_socks_proxy = NULL;
 
 
 static const char def_conf[] = "cgminer.conf";
 static const char def_conf[] = "cgminer.conf";
 static bool config_loaded = false;
 static bool config_loaded = false;
@@ -1700,6 +1701,9 @@ static struct opt_table opt_config_table[] = {
 	OPT_WITH_ARG("--shares",
 	OPT_WITH_ARG("--shares",
 		     opt_set_intval, NULL, &opt_shares,
 		     opt_set_intval, NULL, &opt_shares,
 		     "Quit after mining N shares (default: unlimited)"),
 		     "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_WITHOUT_ARG("--submit-stale",
 			opt_set_bool, &opt_submit_stale,
 			opt_set_bool, &opt_submit_stale,
 		        "Submit shares even if they would normally be considered 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);
 		fprintf(fcfg, ",\n\"sched-time\" : \"%d:%d\"", schedstart.tm.tm_hour, schedstart.tm.tm_min);
 	if (schedstop.enable)
 	if (schedstop.enable)
 		fprintf(fcfg, ",\n\"stop-time\" : \"%d:%d\"", schedstop.tm.tm_hour, schedstop.tm.tm_min);
 		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++)
 	for(i = 0; i < nDevs; i++)
 		if (!gpus[i].enabled)
 		if (!gpus[i].enabled)
 			break;
 			break;

+ 1 - 0
miner.h

@@ -412,6 +412,7 @@ extern bool opt_debug;
 extern bool opt_protocol;
 extern bool opt_protocol;
 extern bool opt_log_output;
 extern bool opt_log_output;
 extern char *opt_kernel_path;
 extern char *opt_kernel_path;
+extern char *opt_socks_proxy;
 extern char *cgminer_path;
 extern char *cgminer_path;
 extern bool opt_autofan;
 extern bool opt_autofan;
 extern bool opt_autoengine;
 extern bool opt_autoengine;

+ 4 - 0
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_HEADERFUNCTION, resp_hdr_cb);
 	curl_easy_setopt(curl, CURLOPT_HEADERDATA, &hi);
 	curl_easy_setopt(curl, CURLOPT_HEADERDATA, &hi);
 	curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_TRY);
 	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) {
 	if (userpass) {
 		curl_easy_setopt(curl, CURLOPT_USERPWD, userpass);
 		curl_easy_setopt(curl, CURLOPT_USERPWD, userpass);
 		curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
 		curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);