Clean up protocol debugging output, and other cleanups.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
diff --git a/Makefile b/Makefile
index 81a2076..b004836 100644
--- a/Makefile
+++ b/Makefile
@@ -20,3 +20,5 @@ clean:
$(PROG): $(OBJS)
gcc $(LDFLAGS) -o $(PROG) $(OBJS) $(LIBS)
+cpu-miner.o: cpu-miner.c sha256_generic.c
+
diff --git a/cpu-miner.c b/cpu-miner.c
index f1c7e7b..f93df64 100644
--- a/cpu-miner.c
+++ b/cpu-miner.c
@@ -28,8 +28,8 @@ enum {
STAT_CTR_INTERVAL = 10000000,
};
-static bool opt_verbose;
static bool opt_debug;
+static bool opt_protocol;
static bool program_running = true;
static const bool opt_time = true;
static int opt_n_threads = 1;
@@ -41,8 +41,8 @@ static struct argp_option options[] = {
"Number of miner threads" },
{ "debug", 'D', NULL, 0,
"Enable debug output" },
- { "verbose", 'v', NULL, 0,
- "Enable verbose output" },
+ { "protocol-dump", 'P', NULL, 0,
+ "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;
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;
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;
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)
len = ub->len;
@@ -160,7 +150,7 @@ static json_t *json_rpc_call(const char *url, const char *userpass,
if (!curl)
return NULL;
- if (opt_verbose)
+ if (opt_protocol)
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
curl_easy_setopt(curl, CURLOPT_URL, url);
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);
+ if (opt_protocol)
+ printf("JSON protocol request:\n%s\n", rpc_req);
+
upload_data.buf = rpc_req;
upload_data.len = strlen(rpc_req);
sprintf(len_hdr, "Content-Length: %lu",
@@ -192,16 +185,18 @@ static json_t *json_rpc_call(const char *url, const char *userpass,
if (rc)
goto err_out;
- if (opt_debug)
- printf("====\nSERVER RETURNS:\n%s\n====\n",
- (char *) all_data.buf);
-
val = json_loads(all_data.buf, &err);
if (!val) {
fprintf(stderr, "JSON failed(%d): %s\n", err.line, err.text);
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);
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
@@ -222,7 +217,7 @@ static char *bin2hex(unsigned char *p, size_t len)
return NULL;
for (i = 0; i < len; i++)
- sprintf(s + (i * 2), "%02x", p[i]);
+ sprintf(s + (i * 2), "%02x", (unsigned int) p[i]);
return s;
}
@@ -366,15 +361,14 @@ static uint32_t scanhash(unsigned char *midstate, unsigned char *data,
runhash(hash, hash1, init_state);
if (hash32[7] == 0) {
- if (1) {
- char *hexstr;
-
- hexstr = bin2hex(hash, 32);
- fprintf(stderr,
- "DBG: found zeroes in hash:\n%s\n",
- hexstr);
- free(hexstr);
- }
+ char *hexstr;
+
+ hexstr = bin2hex(hash, 32);
+ fprintf(stderr,
+ "DBG: found zeroes in hash:\n%s\n",
+ hexstr);
+ free(hexstr);
+
return n;
}
@@ -456,12 +450,6 @@ static void *miner_thread(void *dummy)
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 */
work = work_decode(json_object_get(val, "result"));
if (!work) {
@@ -494,12 +482,12 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state)
int v;
switch(key) {
- case 'v':
- opt_verbose = true;
- break;
case 'D':
opt_debug = true;
break;
+ case 'P':
+ opt_protocol = true;
+ break;
case 't':
v = atoi(arg);
if (v < 1 || v > 9999) /* sanity check */