Add an option to ignore redirection requests

This commit is contained in:
pooler 2014-04-15 23:11:00 +02:00
parent c46726b4b7
commit 42a002c741
4 changed files with 26 additions and 7 deletions

View file

@ -113,6 +113,7 @@ static const char *algo_names[] = {
bool opt_debug = false;
bool opt_protocol = false;
static bool opt_benchmark = false;
bool opt_redirect = true;
bool want_longpoll = true;
bool have_longpoll = false;
bool want_stratum = true;
@ -182,6 +183,7 @@ Options:\n\
long polling is unavailable, in seconds (default: 5)\n\
--no-longpoll disable X-Long-Polling support\n\
--no-stratum disable X-Stratum support\n\
--no-redirect ignore requests to change the URL of the mining server\n\
-q, --quiet disable per-thread hashmeter output\n\
-D, --debug enable debug output\n\
-P, --protocol-dump verbose dump of protocol-level activities\n"
@ -220,6 +222,7 @@ static struct option const options[] = {
{ "debug", 0, NULL, 'D' },
{ "help", 0, NULL, 'h' },
{ "no-longpoll", 0, NULL, 1003 },
{ "no-redirect", 0, NULL, 1009 },
{ "no-stratum", 0, NULL, 1007 },
{ "pass", 1, NULL, 'p' },
{ "protocol-dump", 0, NULL, 'P' },
@ -1233,6 +1236,9 @@ static void parse_arg (int key, char *arg)
case 1007:
want_stratum = false;
break;
case 1009:
opt_redirect = false;
break;
case 'S':
use_syslog = true;
break;

View file

@ -169,6 +169,7 @@ struct work_restart {
extern bool opt_debug;
extern bool opt_protocol;
extern bool opt_redirect;
extern int opt_timeout;
extern bool want_longpoll;
extern bool have_longpoll;

View file

@ -109,6 +109,9 @@ Print a help message and exit.
\fB\-\-no\-longpoll\fR
Do not use long polling.
.TP
\fB\-\-no\-redirect\fR
Ignore requests from the server to switch to a different URL.
.TP
\fB\-\-no\-stratum\fR
Do not switch to Stratum, even if the server advertises support for it.
.TP

23
util.c
View file

@ -330,7 +330,8 @@ json_t *json_rpc_call(CURL *curl, const char *url,
curl_easy_setopt(curl, CURLOPT_SEEKDATA, &upload_data);
#endif
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_err_str);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
if (opt_redirect)
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, resp_hdr_cb);
curl_easy_setopt(curl, CURLOPT_HEADERDATA, &hi);
@ -1080,6 +1081,7 @@ static bool stratum_set_difficulty(struct stratum_ctx *sctx, json_t *params)
static bool stratum_reconnect(struct stratum_ctx *sctx, json_t *params)
{
json_t *port_val;
char *url;
const char *host;
int port;
@ -1091,13 +1093,20 @@ static bool stratum_reconnect(struct stratum_ctx *sctx, json_t *params)
port = json_integer_value(port_val);
if (!host || !port)
return false;
url = malloc(32 + strlen(host));
sprintf(url, "stratum+tcp://%s:%d", host, port);
if (!opt_redirect) {
applog(LOG_INFO, "Ignoring request to reconnect to %s", url);
free(url);
return true;
}
applog(LOG_NOTICE, "Server requested reconnection to %s", url);
free(sctx->url);
sctx->url = malloc(32 + strlen(host));
sprintf(sctx->url, "stratum+tcp://%s:%d", host, port);
applog(LOG_NOTICE, "Server requested reconnection to %s", sctx->url);
sctx->url = url;
stratum_disconnect(sctx);
return true;