Browse Source

Clean up the longpoll management to ensure the right paths go to the right pool and display whether we're connected to LP or not in the status line.

nfactor-troky
Con Kolivas 13 years ago
parent
commit
1e77f04481
  1. 33
      main.c
  2. 5
      miner.h
  3. 18
      util.c

33
main.c

@ -172,8 +172,8 @@ static const sha256_func sha256_funcs[] = {
bool opt_debug = false; bool opt_debug = false;
bool opt_protocol = false; bool opt_protocol = false;
bool want_longpoll = true; static bool want_longpoll = true;
bool have_longpoll = false; static bool have_longpoll = false;
bool use_syslog = false; bool use_syslog = false;
static bool opt_quiet = false; static bool opt_quiet = false;
static bool opt_realquiet = false; static bool opt_realquiet = false;
@ -1328,9 +1328,11 @@ static void curses_print_status(int thr_id)
wclrtoeol(statuswin); wclrtoeol(statuswin);
wmove(statuswin, 4, 0); wmove(statuswin, 4, 0);
if (pool_strategy == POOL_LOADBALANCE && total_pools > 1) if (pool_strategy == POOL_LOADBALANCE && total_pools > 1)
wprintw(statuswin, " Connected to multiple pools"); wprintw(statuswin, " Connected to multiple pools with%s LP",
have_longpoll ? "": "out");
else else
wprintw(statuswin, " Connected to %s as user %s", pool->rpc_url, pool->rpc_user); wprintw(statuswin, " Connected to %s with%s LP as user %s",
pool->rpc_url, have_longpoll ? "": "out", pool->rpc_user);
wclrtoeol(statuswin); wclrtoeol(statuswin);
wmove(statuswin, 5, 0); wmove(statuswin, 5, 0);
wprintw(statuswin, " Block: %s... Started: %s", current_hash, blocktime); wprintw(statuswin, " Block: %s... Started: %s", current_hash, blocktime);
@ -1603,7 +1605,7 @@ static bool get_upstream_work(struct work *work, bool lagging)
applog(LOG_DEBUG, "DBG: sending %s get RPC call: %s", pool->rpc_url, rpc_req); applog(LOG_DEBUG, "DBG: sending %s get RPC call: %s", pool->rpc_url, rpc_req);
val = json_rpc_call(curl, pool->rpc_url, pool->rpc_userpass, rpc_req, val = json_rpc_call(curl, pool->rpc_url, pool->rpc_userpass, rpc_req,
want_longpoll, false, &work->rolltime, pool); false, false, &work->rolltime, pool);
if (unlikely(!val)) { if (unlikely(!val)) {
applog(LOG_DEBUG, "Failed json_rpc_call in get_upstream_work"); applog(LOG_DEBUG, "Failed json_rpc_call in get_upstream_work");
goto out; goto out;
@ -2127,6 +2129,7 @@ static void display_pool_summary(struct pool *pool)
mutex_lock(&curses_lock); mutex_lock(&curses_lock);
wlog("Pool: %s\n", pool->rpc_url); wlog("Pool: %s\n", pool->rpc_url);
wlog("%s long-poll support\n", pool->hdr_path ? "Has" : "Does not have");
wlog(" Queued work requests: %d\n", pool->getwork_requested); wlog(" Queued work requests: %d\n", pool->getwork_requested);
wlog(" Share submissions: %d\n", pool->accepted + pool->rejected); wlog(" Share submissions: %d\n", pool->accepted + pool->rejected);
wlog(" Accepted shares: %d\n", pool->accepted); wlog(" Accepted shares: %d\n", pool->accepted);
@ -3726,14 +3729,12 @@ static void *longpoll_thread(void *userdata)
goto out; goto out;
} }
if (opt_debug) tq_pop(mythr->q, NULL);
applog(LOG_DEBUG, "Popping hdr path in longpoll thread"); if (!pool->hdr_path) {
hdr_path = tq_pop(mythr->q, NULL);
if (!hdr_path) {
applog(LOG_WARNING, "No long-poll found on this server"); applog(LOG_WARNING, "No long-poll found on this server");
goto out; goto out;
} }
hdr_path = pool->hdr_path;
/* full URL */ /* full URL */
if (strstr(hdr_path, "://")) { if (strstr(hdr_path, "://")) {
@ -3753,8 +3754,8 @@ static void *longpoll_thread(void *userdata)
sprintf(lp_url, "%s%s%s", pool->rpc_url, need_slash ? "/" : "", copy_start); sprintf(lp_url, "%s%s%s", pool->rpc_url, need_slash ? "/" : "", copy_start);
} }
free(hdr_path);
have_longpoll = true;
applog(LOG_WARNING, "Long-polling activated for %s", lp_url); applog(LOG_WARNING, "Long-polling activated for %s", lp_url);
while (1) { while (1) {
@ -3802,6 +3803,7 @@ static void *longpoll_thread(void *userdata)
} }
out: out:
have_longpoll = false;
free(lp_url); free(lp_url);
tq_freeze(mythr->q); tq_freeze(mythr->q);
if (curl) if (curl)
@ -3827,6 +3829,9 @@ static void start_longpoll(void)
if (unlikely(thr_info_create(thr, NULL, longpoll_thread, thr))) if (unlikely(thr_info_create(thr, NULL, longpoll_thread, thr)))
quit(1, "longpoll thread create failed"); quit(1, "longpoll thread create failed");
pthread_detach(*thr->pth); pthread_detach(*thr->pth);
if (opt_debug)
applog(LOG_DEBUG, "Pushing ping to longpoll thread");
tq_push(thr_info[longpoll_thr_id].q, &ping);
} }
static void restart_longpoll(void) static void restart_longpoll(void)
@ -4598,9 +4603,6 @@ int main (int argc, char *argv[])
if (!thr->q) if (!thr->q)
quit(1, "Failed to tq_new"); quit(1, "Failed to tq_new");
if (want_longpoll)
start_longpoll();
if (opt_n_threads ) { if (opt_n_threads ) {
cpus = calloc(num_processors, sizeof(struct cgpu_info)); cpus = calloc(num_processors, sizeof(struct cgpu_info));
if (unlikely(!cpus)) if (unlikely(!cpus))
@ -4649,6 +4651,9 @@ int main (int argc, char *argv[])
if (!pools_active) if (!pools_active)
quit(0, "No pools active! Exiting."); quit(0, "No pools active! Exiting.");
if (want_longpoll)
start_longpoll();
#ifdef HAVE_OPENCL #ifdef HAVE_OPENCL
/* start GPU mining threads */ /* start GPU mining threads */
for (i = 0; i < nDevs * opt_g_threads; i++) { for (i = 0; i < nDevs * opt_g_threads; i++) {

5
miner.h

@ -261,8 +261,6 @@ timeval_subtract (struct timeval *result, struct timeval *x, struct timeval *y);
extern bool fulltest(const unsigned char *hash, const unsigned char *target); extern bool fulltest(const unsigned char *hash, const unsigned char *target);
extern int opt_scantime; extern int opt_scantime;
extern bool want_longpoll;
extern bool have_longpoll;
struct thread_q; struct thread_q;
struct work_restart { struct work_restart {
@ -305,6 +303,9 @@ struct pool {
bool idle; bool idle;
bool probed; bool probed;
bool enabled; bool enabled;
char *hdr_path;
unsigned int getwork_requested; unsigned int getwork_requested;
unsigned int stale_shares; unsigned int stale_shares;
unsigned int discarded_work; unsigned int discarded_work;

18
util.c

@ -318,7 +318,7 @@ json_t *json_rpc_call(CURL *curl, const char *url,
/* it is assumed that 'curl' is freshly [re]initialized at this pt */ /* it is assumed that 'curl' is freshly [re]initialized at this pt */
if (probe) { if (probe) {
probing = ((want_longpoll && !have_longpoll) || !pool->probed); probing = !pool->probed;
/* Probe for only 15 seconds */ /* Probe for only 15 seconds */
timeout = 15; timeout = 15;
} }
@ -378,21 +378,17 @@ json_t *json_rpc_call(CURL *curl, const char *url,
goto err_out; goto err_out;
} }
if (!have_longpoll && want_longpoll) { if (probing) {
pool->probed = true;
/* If X-Long-Polling was found, activate long polling */ /* If X-Long-Polling was found, activate long polling */
if (hi.lp_path) { if (hi.lp_path)
have_longpoll = true; pool->hdr_path = hi.lp_path;
tq_push(thr_info[longpoll_thr_id].q, hi.lp_path); else
} else pool->hdr_path = NULL;
free(hi.lp_path);
} }
if (probing)
pool->probed = true;
*rolltime = hi.has_rolltime; *rolltime = hi.has_rolltime;
hi.lp_path = NULL;
val = JSON_LOADS(all_data.buf, &err); val = JSON_LOADS(all_data.buf, &err);
if (!val) { if (!val) {
applog(LOG_INFO, "JSON decode failed(%d): %s", err.line, err.text); applog(LOG_INFO, "JSON decode failed(%d): %s", err.line, err.text);

Loading…
Cancel
Save