diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-12-16 18:56:52 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-12-16 18:56:52 +0000 |
commit | 3307360a2037ca08f56098596ef3f2d6cde0bc9c (patch) | |
tree | 755334f9fc9a7345e0cf4815a691544ea567c38b /src/util/gnunet-scrypt.c | |
parent | b896c07d2a8ab0c6a68423cfcf618fe0189050ee (diff) | |
download | gnunet-3307360a2037ca08f56098596ef3f2d6cde0bc9c.tar.gz gnunet-3307360a2037ca08f56098596ef3f2d6cde0bc9c.zip |
-fix leak
Diffstat (limited to 'src/util/gnunet-scrypt.c')
-rw-r--r-- | src/util/gnunet-scrypt.c | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/src/util/gnunet-scrypt.c b/src/util/gnunet-scrypt.c index cbfcc6917..b6a9969da 100644 --- a/src/util/gnunet-scrypt.c +++ b/src/util/gnunet-scrypt.c | |||
@@ -17,11 +17,9 @@ | |||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | |||
21 | /** | 20 | /** |
22 | * @file util/gnunet-scrypt.c | 21 | * @file util/gnunet-scrypt.c |
23 | * @brief tool to manipulate SCRYPT proofs of work. | 22 | * @brief tool to manipulate SCRYPT proofs of work. |
24 | * largely stolen from gnunet-peerinfo.c and gnunet-service-nse.c | ||
25 | * @author Bart Polot | 23 | * @author Bart Polot |
26 | */ | 24 | */ |
27 | #include "platform.h" | 25 | #include "platform.h" |
@@ -39,12 +37,17 @@ static unsigned long long nse_work_required; | |||
39 | static struct GNUNET_TIME_Relative proof_find_delay; | 37 | static struct GNUNET_TIME_Relative proof_find_delay; |
40 | 38 | ||
41 | static struct GNUNET_CRYPTO_EddsaPublicKey pub; | 39 | static struct GNUNET_CRYPTO_EddsaPublicKey pub; |
42 | uint64_t proof; | ||
43 | GNUNET_SCHEDULER_TaskIdentifier proof_task; | ||
44 | const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
45 | 40 | ||
46 | char *pkfn; | 41 | static uint64_t proof; |
47 | char *pwfn; | 42 | |
43 | static GNUNET_SCHEDULER_TaskIdentifier proof_task; | ||
44 | |||
45 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
46 | |||
47 | static char *pkfn; | ||
48 | |||
49 | static char *pwfn; | ||
50 | |||
48 | 51 | ||
49 | /** | 52 | /** |
50 | * Write our current proof to disk. | 53 | * Write our current proof to disk. |
@@ -82,7 +85,6 @@ pow_hash (const void *buf, | |||
82 | } | 85 | } |
83 | 86 | ||
84 | 87 | ||
85 | |||
86 | /** | 88 | /** |
87 | * Count the leading zeroes in hash. | 89 | * Count the leading zeroes in hash. |
88 | * | 90 | * |
@@ -181,19 +183,23 @@ find_proof (void *cls, | |||
181 | * @param cfg configuration | 183 | * @param cfg configuration |
182 | */ | 184 | */ |
183 | static void | 185 | static void |
184 | run (void *cls, char *const *args, const char *cfgfile, | 186 | run (void *cls, |
187 | char *const *args, | ||
188 | const char *cfgfile, | ||
185 | const struct GNUNET_CONFIGURATION_Handle *config) | 189 | const struct GNUNET_CONFIGURATION_Handle *config) |
186 | { | 190 | { |
187 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; | 191 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; |
192 | char *pids; | ||
188 | 193 | ||
189 | cfg = config; | 194 | cfg = config; |
190 | 195 | ||
191 | /* load proof of work */ | 196 | /* load proof of work */ |
192 | if (NULL == pwfn) | 197 | if (NULL == pwfn) |
193 | { | 198 | { |
194 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", | 199 | if (GNUNET_OK != |
195 | "PROOFFILE", | 200 | GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", |
196 | &pwfn)) | 201 | "PROOFFILE", |
202 | &pwfn)) | ||
197 | { | 203 | { |
198 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 204 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
199 | "NSE", "PROOFFILE"); | 205 | "NSE", "PROOFFILE"); |
@@ -201,9 +207,12 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
201 | return; | 207 | return; |
202 | } | 208 | } |
203 | } | 209 | } |
204 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Proof of Work file: %s\n", pwfn); | 210 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
205 | if (GNUNET_YES != GNUNET_DISK_file_test (pwfn) || | 211 | "Proof of Work file: %s\n", |
206 | sizeof (proof) != GNUNET_DISK_fn_read (pwfn, &proof, sizeof (proof))) | 212 | pwfn); |
213 | if ( (GNUNET_YES != GNUNET_DISK_file_test (pwfn)) || | ||
214 | (sizeof (proof) != | ||
215 | GNUNET_DISK_fn_read (pwfn, &proof, sizeof (proof)))) | ||
207 | proof = 0; | 216 | proof = 0; |
208 | 217 | ||
209 | /* load private key */ | 218 | /* load private key */ |
@@ -228,8 +237,11 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
228 | GNUNET_free (pkfn); | 237 | GNUNET_free (pkfn); |
229 | GNUNET_CRYPTO_eddsa_key_get_public (pk, &pub); | 238 | GNUNET_CRYPTO_eddsa_key_get_public (pk, &pub); |
230 | GNUNET_free (pk); | 239 | GNUNET_free (pk); |
231 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer ID: %s\n", | 240 | pids = GNUNET_CRYPTO_eddsa_public_key_to_string (&pub); |
232 | GNUNET_CRYPTO_eddsa_public_key_to_string (&pub)); | 241 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
242 | "Peer ID: %s\n", | ||
243 | pids); | ||
244 | GNUNET_free (pids); | ||
233 | 245 | ||
234 | /* get target bit amount */ | 246 | /* get target bit amount */ |
235 | if (0 == nse_work_required) | 247 | if (0 == nse_work_required) |
@@ -255,9 +267,12 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
255 | return; | 267 | return; |
256 | } | 268 | } |
257 | } | 269 | } |
258 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Bits: %llu\n", nse_work_required); | 270 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
271 | "Bits: %llu\n", | ||
272 | nse_work_required); | ||
259 | 273 | ||
260 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Delay between tries: %s\n", | 274 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
275 | "Delay between tries: %s\n", | ||
261 | GNUNET_STRINGS_relative_time_to_string (proof_find_delay, 1)); | 276 | GNUNET_STRINGS_relative_time_to_string (proof_find_delay, 1)); |
262 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 277 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, |
263 | &find_proof, NULL); | 278 | &find_proof, NULL); |
@@ -295,7 +310,8 @@ main (int argc, char *const *argv) | |||
295 | return 2; | 310 | return 2; |
296 | 311 | ||
297 | ret = (GNUNET_OK == | 312 | ret = (GNUNET_OK == |
298 | GNUNET_PROGRAM_run (argc, argv, "gnunet-scrypt [OPTIONS] prooffile", | 313 | GNUNET_PROGRAM_run (argc, argv, |
314 | "gnunet-scrypt [OPTIONS] prooffile", | ||
299 | gettext_noop ("Manipulate GNUnet proof of work files"), | 315 | gettext_noop ("Manipulate GNUnet proof of work files"), |
300 | options, &run, NULL)) ? 0 : 1; | 316 | options, &run, NULL)) ? 0 : 1; |
301 | GNUNET_free ((void*) argv); | 317 | GNUNET_free ((void*) argv); |
@@ -303,4 +319,4 @@ main (int argc, char *const *argv) | |||
303 | return ret; | 319 | return ret; |
304 | } | 320 | } |
305 | 321 | ||
306 | /* end of gnunet-ecc.c */ | 322 | /* end of gnunet-scrypt.c */ |