Skip to content

Commit

Permalink
api: allow -b <ip>, and set bind retry to 20sec
Browse files Browse the repository at this point in the history
before, only -b <ip:port>, <port> or 0 (disable) was allowed

easier to set -b 0.0.0.0 with default port
  • Loading branch information
tpruvot committed Dec 18, 2014
1 parent 6873569 commit fc1653b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 28 deletions.
28 changes: 2 additions & 26 deletions api.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,37 +176,13 @@ static char *getthreads(char *params)
return buffer;
}

/**
* Returns the last 20 scans stats (not implemented)
* optional param thread id (default all)
*/
static char *gethistory(char *params)
{
*buffer = '\0';
#if 0
struct stats_data data[20];
int thr = params ? atoi(params) : -1;
char *p = buffer;
int records = stats_get_history(thr, data, ARRAY_SIZE(data));
for (int i = 0; i < records; i++) {
time_t ts = data[i].tm_stat;
p += sprintf(p, "CPU=%d;KHS=%.2f;DIFF=%.6f;"
"COUNT=%u;FOUND=%u;TS=%u|",
data[i].cpu_id, data[i].hashrate, data[i].difficulty,
data[i].hashcount, data[i].hashfound, (uint32_t)ts);
}
#endif
return buffer;
}

static char *gethelp(char *params);
struct CMDS {
const char *name;
char *(*func)(char *);
} cmds[] = {
{ "summary", getsummary },
{ "threads", getthreads },
//{ "histo", gethistory },
/* keep it the last */
{ "help", gethelp },
};
Expand Down Expand Up @@ -429,8 +405,8 @@ static void api()
break;
else {
if (!opt_quiet || opt_debug)
applog(LOG_WARNING, "API bind to port %d failed - trying again in 15sec", port);
sleep(15);
applog(LOG_WARNING, "API bind to port %d failed - trying again in 20sec", port);
sleep(20);
}
}
else
Expand Down
16 changes: 14 additions & 2 deletions cpu-miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ uint64_t global_hashrate = 0;
double global_diff = 0.0;
int opt_intensity = 0;
uint32_t opt_work_size = 0; /* default */
char *opt_api_allow = "127.0.0.1"; /* 0.0.0.0 for all ips */
char *opt_api_allow = NULL;
int opt_api_listen = 4048; /* 0 to disable */

#ifdef HAVE_GETOPT_LONG
Expand Down Expand Up @@ -1588,6 +1588,9 @@ static void stratum_gen_work(struct stratum_ctx *sctx, struct work *work)
case ALGO_QUBIT:
diff_to_target(work->target, sctx->job.diff / (256.0 * opt_diff_factor));
break;
case ALGO_LYRA2:
diff_to_target(work->target, sctx->job.diff / (128.0 * opt_diff_factor));
break;
default:
diff_to_target(work->target, sctx->job.diff / opt_diff_factor);
}
Expand Down Expand Up @@ -2258,13 +2261,21 @@ static void parse_arg(int key, char *arg)
if (p) {
/* ip:port */
if (p - arg > 0) {
free(opt_api_allow);
opt_api_allow = strdup(arg);
opt_api_allow[p - arg] = '\0';
}
opt_api_listen = atoi(p + 1);
}
else if (arg)
else if (arg && strstr(arg, ".")) {
/* ip only */
free(opt_api_allow);
opt_api_allow = strdup(arg);
}
else if (arg) {
/* port or 0 to disable */
opt_api_listen = atoi(arg);
}
break;
case 'n':
if (opt_algo == ALGO_NEOSCRYPT) {
Expand Down Expand Up @@ -2642,6 +2653,7 @@ int main(int argc, char *argv[]) {

rpc_user = strdup("");
rpc_pass = strdup("");
opt_api_allow = strdup("127.0.0.1"); /* 0.0.0.0 for all ips */

/* parse command line */
parse_cmdline(argc, argv);
Expand Down

0 comments on commit fc1653b

Please sign in to comment.