Browse Source

Clean up protocol debugging output, and other cleanups.

nfactor-troky
Jeff Garzik 14 years ago committed by Jeff Garzik
parent
commit
19b51e3600
  1. 2
      Makefile
  2. 62
      cpu-miner.c

2
Makefile

@ -20,3 +20,5 @@ clean:
$(PROG): $(OBJS) $(PROG): $(OBJS)
gcc $(LDFLAGS) -o $(PROG) $(OBJS) $(LIBS) gcc $(LDFLAGS) -o $(PROG) $(OBJS) $(LIBS)
cpu-miner.o: cpu-miner.c sha256_generic.c

62
cpu-miner.c

@ -28,8 +28,8 @@ enum {
STAT_CTR_INTERVAL = 10000000, STAT_CTR_INTERVAL = 10000000,
}; };
static bool opt_verbose;
static bool opt_debug; static bool opt_debug;
static bool opt_protocol;
static bool program_running = true; static bool program_running = true;
static const bool opt_time = true; static const bool opt_time = true;
static int opt_n_threads = 1; static int opt_n_threads = 1;
@ -41,8 +41,8 @@ static struct argp_option options[] = {
"Number of miner threads" }, "Number of miner threads" },
{ "debug", 'D', NULL, 0, { "debug", 'D', NULL, 0,
"Enable debug output" }, "Enable debug output" },
{ "verbose", 'v', NULL, 0, { "protocol-dump", 'P', NULL, 0,
"Enable verbose output" }, "Verbose dump of protocol-level activities" },
{ } { }
}; };
@ -101,11 +101,6 @@ static size_t all_data_cb(const void *ptr, size_t size, size_t nmemb,
void *newmem; void *newmem;
static const unsigned char zero; static const unsigned char zero;
if (opt_debug)
fprintf(stderr, "DBG(%s): %p, %lu, %lu, %p\n",
__func__, ptr, (unsigned long) size,
(unsigned long) nmemb, user_data);
oldlen = db->len; oldlen = db->len;
newlen = oldlen + len; newlen = oldlen + len;
@ -127,11 +122,6 @@ static size_t upload_data_cb(void *ptr, size_t size, size_t nmemb,
struct upload_buffer *ub = user_data; struct upload_buffer *ub = user_data;
int len = size * nmemb; int len = size * nmemb;
if (opt_debug)
fprintf(stderr, "DBG(%s): %p, %lu, %lu, %p\n",
__func__, ptr, (unsigned long) size,
(unsigned long) nmemb, user_data);
if (len > ub->len) if (len > ub->len)
len = ub->len; len = ub->len;
@ -160,7 +150,7 @@ static json_t *json_rpc_call(const char *url, const char *userpass,
if (!curl) if (!curl)
return NULL; return NULL;
if (opt_verbose) if (opt_protocol)
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_ENCODING, ""); curl_easy_setopt(curl, CURLOPT_ENCODING, "");
@ -176,6 +166,9 @@ static json_t *json_rpc_call(const char *url, const char *userpass,
} }
curl_easy_setopt(curl, CURLOPT_POST, 1); curl_easy_setopt(curl, CURLOPT_POST, 1);
if (opt_protocol)
printf("JSON protocol request:\n%s\n", rpc_req);
upload_data.buf = rpc_req; upload_data.buf = rpc_req;
upload_data.len = strlen(rpc_req); upload_data.len = strlen(rpc_req);
sprintf(len_hdr, "Content-Length: %lu", sprintf(len_hdr, "Content-Length: %lu",
@ -192,16 +185,18 @@ static json_t *json_rpc_call(const char *url, const char *userpass,
if (rc) if (rc)
goto err_out; goto err_out;
if (opt_debug)
printf("====\nSERVER RETURNS:\n%s\n====\n",
(char *) all_data.buf);
val = json_loads(all_data.buf, &err); val = json_loads(all_data.buf, &err);
if (!val) { if (!val) {
fprintf(stderr, "JSON failed(%d): %s\n", err.line, err.text); fprintf(stderr, "JSON failed(%d): %s\n", err.line, err.text);
goto err_out; goto err_out;
} }
if (opt_protocol) {
char *s = json_dumps(val, JSON_INDENT(3));
printf("JSON protocol response:\n%s\n", s);
free(s);
}
databuf_free(&all_data); databuf_free(&all_data);
curl_slist_free_all(headers); curl_slist_free_all(headers);
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
@ -222,7 +217,7 @@ static char *bin2hex(unsigned char *p, size_t len)
return NULL; return NULL;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
sprintf(s + (i * 2), "%02x", p[i]); sprintf(s + (i * 2), "%02x", (unsigned int) p[i]);
return s; return s;
} }
@ -366,15 +361,14 @@ static uint32_t scanhash(unsigned char *midstate, unsigned char *data,
runhash(hash, hash1, init_state); runhash(hash, hash1, init_state);
if (hash32[7] == 0) { if (hash32[7] == 0) {
if (1) { char *hexstr;
char *hexstr;
hexstr = bin2hex(hash, 32);
hexstr = bin2hex(hash, 32); fprintf(stderr,
fprintf(stderr, "DBG: found zeroes in hash:\n%s\n",
"DBG: found zeroes in hash:\n%s\n", hexstr);
hexstr); free(hexstr);
free(hexstr);
}
return n; return n;
} }
@ -456,12 +450,6 @@ static void *miner_thread(void *dummy)
return NULL; return NULL;
} }
if (opt_verbose) {
char *s = json_dumps(val, JSON_INDENT(2));
printf("JSON output:\n%s\n", s);
free(s);
}
/* decode result into work state struct */ /* decode result into work state struct */
work = work_decode(json_object_get(val, "result")); work = work_decode(json_object_get(val, "result"));
if (!work) { if (!work) {
@ -494,12 +482,12 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state)
int v; int v;
switch(key) { switch(key) {
case 'v':
opt_verbose = true;
break;
case 'D': case 'D':
opt_debug = true; opt_debug = true;
break; break;
case 'P':
opt_protocol = true;
break;
case 't': case 't':
v = atoi(arg); v = atoi(arg);
if (v < 1 || v > 9999) /* sanity check */ if (v < 1 || v > 9999) /* sanity check */

Loading…
Cancel
Save