Skip to content
This repository has been archived by the owner on Jan 9, 2021. It is now read-only.

Commit

Permalink
Parse #xnsub at tail of pool url.
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperwang committed Nov 5, 2014
1 parent feb5ada commit 1416777
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cgminer.c
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,7 @@ static char *set_rr(enum pool_strategy *strategy)
* stratum+tcp or by detecting a stratum server response */
bool detect_stratum(struct pool *pool, char *url)
{
check_extranonce_option(pool, url);
if (!extract_sockaddr(url, &pool->sockaddr_url, &pool->stratum_port))
return false;

Expand Down Expand Up @@ -6465,6 +6466,7 @@ static void *longpoll_thread(void *userdata);
static bool stratum_works(struct pool *pool)
{
applog(LOG_INFO, "Testing pool %d stratum %s", pool->pool_no, pool->stratum_url);
check_extranonce_option(pool, pool->stratum_url);
if (!extract_sockaddr(pool->stratum_url, &pool->sockaddr_url, &pool->stratum_port))
return false;

Expand Down
1 change: 1 addition & 0 deletions miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,7 @@ struct pool {

/* Stratum variables */
char *stratum_url;
bool extranonce_subscribe;
char *stratum_port;
SOCKETTYPE sock;
char *sockbuf;
Expand Down
90 changes: 90 additions & 0 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,24 @@ double tdiff(struct timeval *end, struct timeval *start)
return end->tv_sec - start->tv_sec + (end->tv_usec - start->tv_usec) / 1000000.0;
}

void check_extranonce_option(struct pool *pool, char * url)
{
char extra_op[16],*extra_op_loc;
extra_op_loc = strstr(url,"#");
if(extra_op_loc && !pool->extranonce_subscribe)
{
strcpy(extra_op, extra_op_loc);
*extra_op_loc = '\0';
if(!strcmp(extra_op,"#xnsub"))
{
pool->extranonce_subscribe = true;
printf("Extra nonce subscribing enabled.");
return;
}
}
return;
}

bool extract_sockaddr(char *url, char **sockaddr_url, char **sockaddr_port)
{
char *url_begin, *url_end, *ipv6_begin, *ipv6_end, *port_start = NULL;
Expand Down Expand Up @@ -2784,6 +2802,78 @@ void suspend_stratum(struct pool *pool)
mutex_unlock(&pool->stratum_lock);
}

bool extranonce_subscribe(struct pool *pool)
{
bool ret = false, recvd = false, noresume = false, sockd = false;
char s[RBUFSIZE], *sret = NULL, *nonce1, *sessionid;
json_t *val = NULL, *res_val, *err_val;
json_error_t err;
int n2size;

//resend:
// if (!setup_stratum_socket(pool)) {
// sockd = false;
// goto out;
// }
//
// sockd = true;
//
// if (recvd) {
// /* Get rid of any crap lying around if we're resending */
// clear_sock(pool);
// sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": []}", swork_id++);
// } else {
// if (pool->sessionid)
// sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": [\""PACKAGE"/"VERSION"\", \"%s\"]}", swork_id++, pool->sessionid);
// else
// sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": [\""PACKAGE"/"VERSION"\"]}", swork_id++);
// }
sprintf(s,"{\"id\": %d, \"method\": \"mining.extranonce.subscribe\", \"params\": []}", swork_id++);
if (__stratum_send(pool, s, strlen(s)) != SEND_OK) {
applog(LOG_DEBUG, "Failed to send s in extranonce_subscribe");
goto out;
}

if (!socket_full(pool, DEFAULT_SOCKWAIT)) {
applog(LOG_DEBUG, "Timed out waiting for response in extranonce_subscribe");
goto out;
}

sret = recv_line(pool);
if (!sret)
goto out;

recvd = true;

val = JSON_LOADS(sret, &err);
free(sret);
if (!val) {
applog(LOG_INFO, "JSON decode failed(%d): %s", err.line, err.text);
goto out;
}

res_val = json_object_get(val, "result");
err_val = json_object_get(val, "error");

if (!res_val || json_is_null(res_val) ||
(err_val && !json_is_null(err_val))) {
char *ss;

if (err_val)
ss = json_dumps(err_val, JSON_INDENT(3));
else
ss = strdup("(unknown reason)");

applog(LOG_INFO, "JSON-RPC decode failed: %s", ss);

free(ss);

goto out;
}
out:
return ret;
}

bool initiate_stratum(struct pool *pool)
{
bool ret = false, recvd = false, noresume = false, sockd = false;
Expand Down
1 change: 1 addition & 0 deletions util.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ void _recalloc(void **ptr, size_t old, size_t new, const char *file, const char
#define recalloc(ptr, old, new) _recalloc((void *)&(ptr), old, new, __FILE__, __func__, __LINE__)
char *recv_line(struct pool *pool);
bool parse_method(struct pool *pool, char *s);
void check_extranonce_option(struct pool *pool, char * url);
bool extract_sockaddr(char *url, char **sockaddr_url, char **sockaddr_port);
bool auth_stratum(struct pool *pool);
bool initiate_stratum(struct pool *pool);
Expand Down

0 comments on commit 1416777

Please sign in to comment.