diff options
author | Anna Wimbauer <anna.wimbauer@gmx.de> | 2020-04-27 09:28:53 +0200 |
---|---|---|
committer | Anna Wimbauer <anna.wimbauer@gmx.de> | 2020-04-27 09:28:53 +0200 |
commit | e5bc04c4a1499a472f3b6f0bd41c275a8537071f (patch) | |
tree | 29fa88bb7336ac5c148f3c6304304a2b904f02c5 /src | |
parent | 9a91e41070e368e929e7534c047c8360e60d1901 (diff) | |
parent | 91fd7860cba14c27d52850f91b17060790855145 (diff) | |
download | gnunet-e5bc04c4a1499a472f3b6f0bd41c275a8537071f.tar.gz gnunet-e5bc04c4a1499a472f3b6f0bd41c275a8537071f.zip |
Merge branch 'master' of ssh://gnunet.org/gnunet
Diffstat (limited to 'src')
103 files changed, 983 insertions, 483 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index e1d73ab01..16df77fb4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
@@ -28,6 +28,7 @@ if HAVE_MHD | |||
28 | JSON_DIR = json | 28 | JSON_DIR = json |
29 | endif | 29 | endif |
30 | endif | 30 | endif |
31 | if HAVE_MHD | ||
31 | if HAVE_LIBGNURL | 32 | if HAVE_LIBGNURL |
32 | CURL_DIR = curl | 33 | CURL_DIR = curl |
33 | else | 34 | else |
@@ -35,6 +36,7 @@ if HAVE_LIBCURL | |||
35 | CURL_DIR = curl | 36 | CURL_DIR = curl |
36 | endif | 37 | endif |
37 | endif | 38 | endif |
39 | endif | ||
38 | 40 | ||
39 | if BUILD_PULSE_HELPERS | 41 | if BUILD_PULSE_HELPERS |
40 | CONVERSATION_DIR = conversation | 42 | CONVERSATION_DIR = conversation |
diff --git a/src/abd/gnunet-abd.c b/src/abd/gnunet-abd.c index a5d32c3dd..eb3e29e23 100644 --- a/src/abd/gnunet-abd.c +++ b/src/abd/gnunet-abd.c | |||
@@ -1074,7 +1074,7 @@ main (int argc, char *const *argv) | |||
1074 | &run, | 1074 | &run, |
1075 | NULL)) | 1075 | NULL)) |
1076 | ret = 1; | 1076 | ret = 1; |
1077 | GNUNET_free ((void *) argv); | 1077 | GNUNET_free_nz ((void *) argv); |
1078 | return ret; | 1078 | return ret; |
1079 | } | 1079 | } |
1080 | 1080 | ||
diff --git a/src/arm/gnunet-arm.c b/src/arm/gnunet-arm.c index 3b4e770b0..ea3a012ab 100644 --- a/src/arm/gnunet-arm.c +++ b/src/arm/gnunet-arm.c | |||
@@ -1054,10 +1054,10 @@ main (int argc, char *const *argv) | |||
1054 | &run, | 1054 | &run, |
1055 | NULL))) | 1055 | NULL))) |
1056 | { | 1056 | { |
1057 | GNUNET_free ((void *) argv); | 1057 | GNUNET_free_nz ((void *) argv); |
1058 | return ret; | 1058 | return ret; |
1059 | } | 1059 | } |
1060 | GNUNET_free ((void *) argv); | 1060 | GNUNET_free_nz ((void *) argv); |
1061 | return lret; | 1061 | return lret; |
1062 | } | 1062 | } |
1063 | 1063 | ||
diff --git a/src/ats-tool/gnunet-ats.c b/src/ats-tool/gnunet-ats.c index 16636e505..947ed7798 100644 --- a/src/ats-tool/gnunet-ats.c +++ b/src/ats-tool/gnunet-ats.c | |||
@@ -980,7 +980,7 @@ main (int argc, char *const *argv) | |||
980 | NULL); | 980 | NULL); |
981 | GNUNET_free_non_null (opt_pid_str); | 981 | GNUNET_free_non_null (opt_pid_str); |
982 | GNUNET_free_non_null (opt_type_str); | 982 | GNUNET_free_non_null (opt_type_str); |
983 | GNUNET_free ((void *) argv); | 983 | GNUNET_free_nz ((void *) argv); |
984 | 984 | ||
985 | if (GNUNET_OK == res) | 985 | if (GNUNET_OK == res) |
986 | return ret; | 986 | return ret; |
diff --git a/src/auction/gnunet-auction-create.c b/src/auction/gnunet-auction-create.c index 79106d8e8..93947b89c 100644 --- a/src/auction/gnunet-auction-create.c +++ b/src/auction/gnunet-auction-create.c | |||
@@ -214,6 +214,6 @@ main (int argc, char *const *argv) | |||
214 | options, | 214 | options, |
215 | &run, | 215 | &run, |
216 | NULL)) ? ret : 1; | 216 | NULL)) ? ret : 1; |
217 | GNUNET_free ((void *) argv); | 217 | GNUNET_free_nz ((void *) argv); |
218 | return ret; | 218 | return ret; |
219 | } | 219 | } |
diff --git a/src/auction/gnunet-auction-info.c b/src/auction/gnunet-auction-info.c index f20565835..dded45ce6 100644 --- a/src/auction/gnunet-auction-info.c +++ b/src/auction/gnunet-auction-info.c | |||
@@ -78,7 +78,7 @@ main (int argc, char *const *argv) | |||
78 | options, | 78 | options, |
79 | &run, | 79 | &run, |
80 | NULL)) ? ret : 1; | 80 | NULL)) ? ret : 1; |
81 | GNUNET_free ((void *) argv); | 81 | GNUNET_free_nz ((void *) argv); |
82 | return ret; | 82 | return ret; |
83 | } | 83 | } |
84 | 84 | ||
diff --git a/src/auction/gnunet-auction-join.c b/src/auction/gnunet-auction-join.c index f20565835..dded45ce6 100644 --- a/src/auction/gnunet-auction-join.c +++ b/src/auction/gnunet-auction-join.c | |||
@@ -78,7 +78,7 @@ main (int argc, char *const *argv) | |||
78 | options, | 78 | options, |
79 | &run, | 79 | &run, |
80 | NULL)) ? ret : 1; | 80 | NULL)) ? ret : 1; |
81 | GNUNET_free ((void *) argv); | 81 | GNUNET_free_nz ((void *) argv); |
82 | return ret; | 82 | return ret; |
83 | } | 83 | } |
84 | 84 | ||
diff --git a/src/cadet/gnunet-cadet.c b/src/cadet/gnunet-cadet.c index f3ccd9883..9b7538ae7 100644 --- a/src/cadet/gnunet-cadet.c +++ b/src/cadet/gnunet-cadet.c | |||
@@ -840,7 +840,7 @@ main (int argc, char *const *argv) | |||
840 | &run, | 840 | &run, |
841 | NULL); | 841 | NULL); |
842 | 842 | ||
843 | GNUNET_free ((void *) argv); | 843 | GNUNET_free_nz ((void *) argv); |
844 | 844 | ||
845 | if (GNUNET_OK == res) | 845 | if (GNUNET_OK == res) |
846 | return 0; | 846 | return 0; |
diff --git a/src/conversation/gnunet-conversation-test.c b/src/conversation/gnunet-conversation-test.c index 2e6772d92..9f8e54033 100644 --- a/src/conversation/gnunet-conversation-test.c +++ b/src/conversation/gnunet-conversation-test.c | |||
@@ -257,7 +257,7 @@ main (int argc, | |||
257 | options, | 257 | options, |
258 | &run, | 258 | &run, |
259 | NULL)) ? ret : 1; | 259 | NULL)) ? ret : 1; |
260 | GNUNET_free ((void *) argv); | 260 | GNUNET_free_nz ((void *) argv); |
261 | return ret; | 261 | return ret; |
262 | } | 262 | } |
263 | 263 | ||
diff --git a/src/conversation/gnunet-conversation.c b/src/conversation/gnunet-conversation.c index 6c0a6e42f..b908cd82c 100644 --- a/src/conversation/gnunet-conversation.c +++ b/src/conversation/gnunet-conversation.c | |||
@@ -1219,7 +1219,7 @@ main (int argc, char *const *argv) | |||
1219 | options, | 1219 | options, |
1220 | &run, | 1220 | &run, |
1221 | NULL); | 1221 | NULL); |
1222 | GNUNET_free ((void *) argv); | 1222 | GNUNET_free_nz ((void *) argv); |
1223 | if (NULL != cfg) | 1223 | if (NULL != cfg) |
1224 | { | 1224 | { |
1225 | GNUNET_CONFIGURATION_destroy (cfg); | 1225 | GNUNET_CONFIGURATION_destroy (cfg); |
diff --git a/src/core/gnunet-core.c b/src/core/gnunet-core.c index 90777a7a8..d90c8e1f5 100644 --- a/src/core/gnunet-core.c +++ b/src/core/gnunet-core.c | |||
@@ -198,7 +198,7 @@ main (int argc, char *const *argv) | |||
198 | &run, | 198 | &run, |
199 | NULL); | 199 | NULL); |
200 | 200 | ||
201 | GNUNET_free ((void *) argv); | 201 | GNUNET_free_nz ((void *) argv); |
202 | if (GNUNET_OK == res) | 202 | if (GNUNET_OK == res) |
203 | return 0; | 203 | return 0; |
204 | return 1; | 204 | return 1; |
diff --git a/src/curl/Makefile.am b/src/curl/Makefile.am index ed5819dee..c6b350bc7 100644 --- a/src/curl/Makefile.am +++ b/src/curl/Makefile.am | |||
@@ -32,7 +32,7 @@ libgnunetcurl_la_LIBADD = \ | |||
32 | $(LIB_GNURL) \ | 32 | $(LIB_GNURL) \ |
33 | $(XLIB) | 33 | $(XLIB) |
34 | libgnunetcurl_la_CPPFLAGS = \ | 34 | libgnunetcurl_la_CPPFLAGS = \ |
35 | $(CPP_GNURL) $(AM_CPPFLAGS) | 35 | $(CPP_GNURL) $(AM_CPPFLAGS) $(MHD_CFLAGS) |
36 | 36 | ||
37 | #check_PROGRAMS = \ | 37 | #check_PROGRAMS = \ |
38 | # test_curl | 38 | # test_curl |
diff --git a/src/curl/curl.c b/src/curl/curl.c index da486ecc1..b7452330f 100644 --- a/src/curl/curl.c +++ b/src/curl/curl.c | |||
@@ -25,6 +25,7 @@ | |||
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include <jansson.h> | 27 | #include <jansson.h> |
28 | #include <microhttpd.h> | ||
28 | #include "gnunet_curl_lib.h" | 29 | #include "gnunet_curl_lib.h" |
29 | 30 | ||
30 | #if ENABLE_BENCHMARK | 31 | #if ENABLE_BENCHMARK |
@@ -181,7 +182,8 @@ struct GNUNET_CURL_Context | |||
181 | * @return library context | 182 | * @return library context |
182 | */ | 183 | */ |
183 | struct GNUNET_CURL_Context * | 184 | struct GNUNET_CURL_Context * |
184 | GNUNET_CURL_init (GNUNET_CURL_RescheduleCallback cb, void *cb_cls) | 185 | GNUNET_CURL_init (GNUNET_CURL_RescheduleCallback cb, |
186 | void *cb_cls) | ||
185 | { | 187 | { |
186 | struct GNUNET_CURL_Context *ctx; | 188 | struct GNUNET_CURL_Context *ctx; |
187 | CURLM *multi; | 189 | CURLM *multi; |
@@ -263,7 +265,10 @@ GNUNET_CURL_is_valid_scope_id (const char *scope_id) | |||
263 | * @return number of bytes processed from @a bufptr | 265 | * @return number of bytes processed from @a bufptr |
264 | */ | 266 | */ |
265 | static size_t | 267 | static size_t |
266 | download_cb (char *bufptr, size_t size, size_t nitems, void *cls) | 268 | download_cb (char *bufptr, |
269 | size_t size, | ||
270 | size_t nitems, | ||
271 | void *cls) | ||
267 | { | 272 | { |
268 | struct GNUNET_CURL_DownloadBuffer *db = cls; | 273 | struct GNUNET_CURL_DownloadBuffer *db = cls; |
269 | size_t msize; | 274 | size_t msize; |
@@ -376,7 +381,9 @@ setup_job (CURL *eh, | |||
376 | } | 381 | } |
377 | job->easy_handle = eh; | 382 | job->easy_handle = eh; |
378 | job->ctx = ctx; | 383 | job->ctx = ctx; |
379 | GNUNET_CONTAINER_DLL_insert (ctx->jobs_head, ctx->jobs_tail, job); | 384 | GNUNET_CONTAINER_DLL_insert (ctx->jobs_head, |
385 | ctx->jobs_tail, | ||
386 | job); | ||
380 | return job; | 387 | return job; |
381 | } | 388 | } |
382 | 389 | ||
@@ -497,7 +504,11 @@ GNUNET_CURL_job_add (struct GNUNET_CURL_Context *ctx, | |||
497 | curl_slist_append (NULL, "Content-Type: application/json"))); | 504 | curl_slist_append (NULL, "Content-Type: application/json"))); |
498 | } | 505 | } |
499 | 506 | ||
500 | job = GNUNET_CURL_job_add2 (ctx, eh, job_headers, jcc, jcc_cls); | 507 | job = GNUNET_CURL_job_add2 (ctx, |
508 | eh, | ||
509 | job_headers, | ||
510 | jcc, | ||
511 | jcc_cls); | ||
501 | curl_slist_free_all (job_headers); | 512 | curl_slist_free_all (job_headers); |
502 | return job; | 513 | return job; |
503 | } | 514 | } |
@@ -526,6 +537,40 @@ GNUNET_CURL_job_cancel (struct GNUNET_CURL_Job *job) | |||
526 | 537 | ||
527 | 538 | ||
528 | /** | 539 | /** |
540 | * Test if the given content type @a ct is JSON | ||
541 | * | ||
542 | * @param ct a content type, i.e. "application/json; charset=UTF-8" | ||
543 | * @return true if @a ct denotes JSON | ||
544 | */ | ||
545 | static bool | ||
546 | is_json (const char *ct) | ||
547 | { | ||
548 | const char *semi; | ||
549 | |||
550 | /* check for "application/json" exact match */ | ||
551 | if (0 == strcasecmp (ct, | ||
552 | "application/json")) | ||
553 | return true; | ||
554 | /* check for "application/json;[ANYTHING]" */ | ||
555 | semi = strchr (ct, | ||
556 | ';'); | ||
557 | /* also allow "application/json [ANYTHING]" (note the space!) */ | ||
558 | if (NULL == semi) | ||
559 | semi = strchr (ct, | ||
560 | ' '); | ||
561 | if (NULL == semi) | ||
562 | return false; /* no delimiter we accept, forget it */ | ||
563 | if (semi - ct != strlen ("application/json")) | ||
564 | return false; /* delimiter past desired length, forget it */ | ||
565 | if (0 == strncasecmp (ct, | ||
566 | "application/json", | ||
567 | strlen ("application/json"))) | ||
568 | return true; /* OK */ | ||
569 | return false; | ||
570 | } | ||
571 | |||
572 | |||
573 | /** | ||
529 | * Obtain information about the final result about the | 574 | * Obtain information about the final result about the |
530 | * HTTP download. If the download was successful, parses | 575 | * HTTP download. If the download was successful, parses |
531 | * the JSON in the @a db and returns it. Also returns | 576 | * the JSON in the @a db and returns it. Also returns |
@@ -562,8 +607,7 @@ GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db, | |||
562 | CURLINFO_CONTENT_TYPE, | 607 | CURLINFO_CONTENT_TYPE, |
563 | &ct)) || | 608 | &ct)) || |
564 | (NULL == ct) || | 609 | (NULL == ct) || |
565 | (0 != strcasecmp (ct, | 610 | (! is_json (ct))) |
566 | "application/json"))) | ||
567 | { | 611 | { |
568 | /* No content type or explicitly not JSON, refuse to parse | 612 | /* No content type or explicitly not JSON, refuse to parse |
569 | (but keep response code) */ | 613 | (but keep response code) */ |
@@ -583,6 +627,8 @@ GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db, | |||
583 | (const char *) db->buf); | 627 | (const char *) db->buf); |
584 | return NULL; | 628 | return NULL; |
585 | } | 629 | } |
630 | if (MHD_HTTP_NO_CONTENT == *response_code) | ||
631 | return NULL; | ||
586 | json = NULL; | 632 | json = NULL; |
587 | if (0 == db->eno) | 633 | if (0 == db->eno) |
588 | { | 634 | { |
diff --git a/src/datastore/gnunet-datastore.c b/src/datastore/gnunet-datastore.c index 54d087bc4..5901cce54 100644 --- a/src/datastore/gnunet-datastore.c +++ b/src/datastore/gnunet-datastore.c | |||
@@ -500,7 +500,7 @@ main (int argc, char *const *argv) | |||
500 | &run, | 500 | &run, |
501 | NULL)) | 501 | NULL)) |
502 | ret = 1; | 502 | ret = 1; |
503 | GNUNET_free ((void *) argv); | 503 | GNUNET_free_nz ((void *) argv); |
504 | return ret; | 504 | return ret; |
505 | } | 505 | } |
506 | 506 | ||
diff --git a/src/dns/gnunet-dns-monitor.c b/src/dns/gnunet-dns-monitor.c index 7be792fc5..f6c0d0660 100644 --- a/src/dns/gnunet-dns-monitor.c +++ b/src/dns/gnunet-dns-monitor.c | |||
@@ -387,7 +387,7 @@ main (int argc, char *const *argv) | |||
387 | gettext_noop | 387 | gettext_noop |
388 | ("Monitor DNS queries."), options, | 388 | ("Monitor DNS queries."), options, |
389 | &run, NULL)) ? ret : 1; | 389 | &run, NULL)) ? ret : 1; |
390 | GNUNET_free ((void *) argv); | 390 | GNUNET_free_nz ((void *) argv); |
391 | return ret; | 391 | return ret; |
392 | } | 392 | } |
393 | 393 | ||
diff --git a/src/dns/gnunet-dns-redirector.c b/src/dns/gnunet-dns-redirector.c index f7051f70b..606864c8a 100644 --- a/src/dns/gnunet-dns-redirector.c +++ b/src/dns/gnunet-dns-redirector.c | |||
@@ -260,7 +260,7 @@ main (int argc, char *const *argv) | |||
260 | ("Change DNS replies to point elsewhere."), | 260 | ("Change DNS replies to point elsewhere."), |
261 | options, | 261 | options, |
262 | &run, NULL)) ? ret : 1; | 262 | &run, NULL)) ? ret : 1; |
263 | GNUNET_free ((void *) argv); | 263 | GNUNET_free_nz ((void *) argv); |
264 | return ret; | 264 | return ret; |
265 | } | 265 | } |
266 | 266 | ||
diff --git a/src/fs/gnunet-auto-share.c b/src/fs/gnunet-auto-share.c index 53c64ab04..13bc908e8 100644 --- a/src/fs/gnunet-auto-share.c +++ b/src/fs/gnunet-auto-share.c | |||
@@ -775,7 +775,7 @@ main (int argc, char *const *argv) | |||
775 | sigpipe = NULL; | 775 | sigpipe = NULL; |
776 | GNUNET_free_non_null (cfg_filename); | 776 | GNUNET_free_non_null (cfg_filename); |
777 | cfg_filename = NULL; | 777 | cfg_filename = NULL; |
778 | GNUNET_free ((void *) argv); | 778 | GNUNET_free_nz ((void *) argv); |
779 | return ok; | 779 | return ok; |
780 | } | 780 | } |
781 | 781 | ||
diff --git a/src/fs/gnunet-directory.c b/src/fs/gnunet-directory.c index 58950bceb..10a09f73b 100644 --- a/src/fs/gnunet-directory.c +++ b/src/fs/gnunet-directory.c | |||
@@ -203,7 +203,7 @@ main (int argc, char *const *argv) | |||
203 | NULL)) | 203 | NULL)) |
204 | ? ret | 204 | ? ret |
205 | : 1; | 205 | : 1; |
206 | GNUNET_free ((void *) argv); | 206 | GNUNET_free_nz ((void *) argv); |
207 | return ret; | 207 | return ret; |
208 | } | 208 | } |
209 | 209 | ||
diff --git a/src/fs/gnunet-download.c b/src/fs/gnunet-download.c index 63bb02958..eebf8e993 100644 --- a/src/fs/gnunet-download.c +++ b/src/fs/gnunet-download.c | |||
@@ -376,7 +376,7 @@ main (int argc, char *const *argv) | |||
376 | NULL)) | 376 | NULL)) |
377 | ? ret | 377 | ? ret |
378 | : 1; | 378 | : 1; |
379 | GNUNET_free ((void *) argv); | 379 | GNUNET_free_nz ((void *) argv); |
380 | return ret; | 380 | return ret; |
381 | } | 381 | } |
382 | 382 | ||
diff --git a/src/fs/gnunet-fs-profiler.c b/src/fs/gnunet-fs-profiler.c index fe86cf21f..62da46834 100644 --- a/src/fs/gnunet-fs-profiler.c +++ b/src/fs/gnunet-fs-profiler.c | |||
@@ -237,7 +237,7 @@ main (int argc, char *const *argv) | |||
237 | "run a testbed to measure file-sharing performance"), | 237 | "run a testbed to measure file-sharing performance"), |
238 | options, &run, | 238 | options, &run, |
239 | NULL)) ? ret : 1; | 239 | NULL)) ? ret : 1; |
240 | GNUNET_free ((void *) argv); | 240 | GNUNET_free_nz ((void *) argv); |
241 | return ret; | 241 | return ret; |
242 | } | 242 | } |
243 | 243 | ||
diff --git a/src/fs/gnunet-fs.c b/src/fs/gnunet-fs.c index 35d410d37..70a0034a0 100644 --- a/src/fs/gnunet-fs.c +++ b/src/fs/gnunet-fs.c | |||
@@ -144,7 +144,7 @@ main (int argc, char *const *argv) | |||
144 | NULL)) | 144 | NULL)) |
145 | ? ret | 145 | ? ret |
146 | : 1; | 146 | : 1; |
147 | GNUNET_free ((void *) argv); | 147 | GNUNET_free_nz ((void *) argv); |
148 | return ret; | 148 | return ret; |
149 | } | 149 | } |
150 | 150 | ||
diff --git a/src/fs/gnunet-publish.c b/src/fs/gnunet-publish.c index ac310b785..b10e6163c 100644 --- a/src/fs/gnunet-publish.c +++ b/src/fs/gnunet-publish.c | |||
@@ -992,7 +992,7 @@ main (int argc, char *const *argv) | |||
992 | NULL)) | 992 | NULL)) |
993 | ? ret | 993 | ? ret |
994 | : 1; | 994 | : 1; |
995 | GNUNET_free ((void *) argv); | 995 | GNUNET_free_nz ((void *) argv); |
996 | return ret; | 996 | return ret; |
997 | } | 997 | } |
998 | 998 | ||
diff --git a/src/fs/gnunet-search.c b/src/fs/gnunet-search.c index e0b9a31fd..098633379 100644 --- a/src/fs/gnunet-search.c +++ b/src/fs/gnunet-search.c | |||
@@ -371,7 +371,7 @@ main (int argc, char *const *argv) | |||
371 | NULL)) | 371 | NULL)) |
372 | ? ret | 372 | ? ret |
373 | : 1; | 373 | : 1; |
374 | GNUNET_free ((void *) argv); | 374 | GNUNET_free_nz ((void *) argv); |
375 | return ret; | 375 | return ret; |
376 | } | 376 | } |
377 | 377 | ||
diff --git a/src/fs/gnunet-unindex.c b/src/fs/gnunet-unindex.c index bf32de812..afc547127 100644 --- a/src/fs/gnunet-unindex.c +++ b/src/fs/gnunet-unindex.c | |||
@@ -197,7 +197,7 @@ main (int argc, char *const *argv) | |||
197 | NULL)) | 197 | NULL)) |
198 | ? ret | 198 | ? ret |
199 | : 1; | 199 | : 1; |
200 | GNUNET_free ((void *) argv); | 200 | GNUNET_free_nz ((void *) argv); |
201 | return ret; | 201 | return ret; |
202 | } | 202 | } |
203 | 203 | ||
diff --git a/src/gns/gnunet-bcd.c b/src/gns/gnunet-bcd.c index 6ceff4a9a..f71f477ef 100644 --- a/src/gns/gnunet-bcd.c +++ b/src/gns/gnunet-bcd.c | |||
@@ -525,7 +525,7 @@ main (int argc, char *const *argv) | |||
525 | NULL)) | 525 | NULL)) |
526 | ? 0 | 526 | ? 0 |
527 | : 1; | 527 | : 1; |
528 | GNUNET_free ((void *) argv); | 528 | GNUNET_free_nz ((void *) argv); |
529 | return ret; | 529 | return ret; |
530 | } | 530 | } |
531 | 531 | ||
diff --git a/src/gns/gnunet-dns2gns.c b/src/gns/gnunet-dns2gns.c index 8ec1f1cdb..eb9996b36 100644 --- a/src/gns/gnunet-dns2gns.c +++ b/src/gns/gnunet-dns2gns.c | |||
@@ -775,7 +775,7 @@ main (int argc, | |||
775 | _ ("GNUnet DNS-to-GNS proxy (a DNS server)"), | 775 | _ ("GNUnet DNS-to-GNS proxy (a DNS server)"), |
776 | options, | 776 | options, |
777 | &run, NULL)) ? 0 : 1; | 777 | &run, NULL)) ? 0 : 1; |
778 | GNUNET_free ((void *) argv); | 778 | GNUNET_free_nz ((void *) argv); |
779 | return ret; | 779 | return ret; |
780 | } | 780 | } |
781 | 781 | ||
diff --git a/src/gns/gnunet-gns-benchmark.c b/src/gns/gnunet-gns-benchmark.c index 0dcff7566..b36a83f21 100644 --- a/src/gns/gnunet-gns-benchmark.c +++ b/src/gns/gnunet-gns-benchmark.c | |||
@@ -610,7 +610,7 @@ main (int argc, | |||
610 | &run, | 610 | &run, |
611 | NULL)) | 611 | NULL)) |
612 | ret = 1; | 612 | ret = 1; |
613 | GNUNET_free ((void *) argv); | 613 | GNUNET_free_nz ((void *) argv); |
614 | return ret; | 614 | return ret; |
615 | } | 615 | } |
616 | 616 | ||
diff --git a/src/gns/gnunet-gns-import.c b/src/gns/gnunet-gns-import.c index 0c104ee0d..2c7c56411 100644 --- a/src/gns/gnunet-gns-import.c +++ b/src/gns/gnunet-gns-import.c | |||
@@ -486,7 +486,7 @@ main (int argc, char *const *argv) | |||
486 | "This program will import some GNS authorities into your GNS namestore."), | 486 | "This program will import some GNS authorities into your GNS namestore."), |
487 | options, | 487 | options, |
488 | &run, NULL); | 488 | &run, NULL); |
489 | GNUNET_free ((void *) argv); | 489 | GNUNET_free_nz ((void *) argv); |
490 | return GNUNET_OK == r ? ret : 1; | 490 | return GNUNET_OK == r ? ret : 1; |
491 | } | 491 | } |
492 | 492 | ||
diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c index d52761ef8..eb1d4f23f 100644 --- a/src/gns/gnunet-gns.c +++ b/src/gns/gnunet-gns.c | |||
@@ -376,7 +376,7 @@ main (int argc, char *const *argv) | |||
376 | options, | 376 | options, |
377 | &run, | 377 | &run, |
378 | NULL); | 378 | NULL); |
379 | GNUNET_free ((void *) argv); | 379 | GNUNET_free_nz ((void *) argv); |
380 | if (GNUNET_OK != ret) | 380 | if (GNUNET_OK != ret) |
381 | return 1; | 381 | return 1; |
382 | return global_ret; | 382 | return global_ret; |
diff --git a/src/gnsrecord/perf_gnsrecord_crypto.c b/src/gnsrecord/perf_gnsrecord_crypto.c index b2614eb77..eb4633f75 100644 --- a/src/gnsrecord/perf_gnsrecord_crypto.c +++ b/src/gnsrecord/perf_gnsrecord_crypto.c | |||
@@ -107,7 +107,7 @@ run (void *cls, | |||
107 | GNUNET_YES), | 107 | GNUNET_YES), |
108 | ROUNDS); | 108 | ROUNDS); |
109 | for (unsigned int i = 0; i < RECORDS; i++) | 109 | for (unsigned int i = 0; i < RECORDS; i++) |
110 | GNUNET_free ((void *) s_rd[i].data); | 110 | GNUNET_free_nz ((void *) s_rd[i].data); |
111 | GNUNET_free (s_rd); | 111 | GNUNET_free (s_rd); |
112 | } | 112 | } |
113 | 113 | ||
diff --git a/src/gnsrecord/test_gnsrecord_serialization.c b/src/gnsrecord/test_gnsrecord_serialization.c index 22d9f8396..d268cb7f3 100644 --- a/src/gnsrecord/test_gnsrecord_serialization.c +++ b/src/gnsrecord/test_gnsrecord_serialization.c | |||
@@ -132,7 +132,7 @@ run (void *cls, | |||
132 | 132 | ||
133 | for (c = 0; c < rd_count; c++) | 133 | for (c = 0; c < rd_count; c++) |
134 | { | 134 | { |
135 | GNUNET_free ((void *) src[c].data); | 135 | GNUNET_free_nz ((void *) src[c].data); |
136 | } | 136 | } |
137 | } | 137 | } |
138 | 138 | ||
diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c index ca77545cd..704c796b4 100644 --- a/src/hostlist/gnunet-daemon-hostlist.c +++ b/src/hostlist/gnunet-daemon-hostlist.c | |||
@@ -409,7 +409,7 @@ main (int argc, char *const *argv) | |||
409 | _ ("GNUnet hostlist server and client"), | 409 | _ ("GNUnet hostlist server and client"), |
410 | options, | 410 | options, |
411 | &run, NULL)) ? 0 : 1; | 411 | &run, NULL)) ? 0 : 1; |
412 | GNUNET_free ((void *) argv); | 412 | GNUNET_free_nz ((void *) argv); |
413 | return ret; | 413 | return ret; |
414 | } | 414 | } |
415 | 415 | ||
diff --git a/src/identity/gnunet-identity.c b/src/identity/gnunet-identity.c index 1350376d9..8445a0ee5 100644 --- a/src/identity/gnunet-identity.c +++ b/src/identity/gnunet-identity.c | |||
@@ -439,7 +439,7 @@ main (int argc, char *const *argv) | |||
439 | options, | 439 | options, |
440 | &run, | 440 | &run, |
441 | NULL); | 441 | NULL); |
442 | GNUNET_free ((void *) argv); | 442 | GNUNET_free_nz ((void *) argv); |
443 | 443 | ||
444 | if (GNUNET_OK != res) | 444 | if (GNUNET_OK != res) |
445 | return 3; | 445 | return 3; |
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h index 78aeb3de7..033a68894 100644 --- a/src/include/gnunet_common.h +++ b/src/include/gnunet_common.h | |||
@@ -1209,7 +1209,10 @@ GNUNET_is_zero_ (const void *a, | |||
1209 | * @param n number of elements in the array | 1209 | * @param n number of elements in the array |
1210 | * @param type name of the struct or union, i.e. pass 'struct Foo'. | 1210 | * @param type name of the struct or union, i.e. pass 'struct Foo'. |
1211 | */ | 1211 | */ |
1212 | #define GNUNET_new_array(n, type) (type *) GNUNET_malloc ((n) * sizeof(type)) | 1212 | #define GNUNET_new_array(n, type) ({ \ |
1213 | GNUNET_assert (SIZE_MAX / sizeof (type) >= n); \ | ||
1214 | (type *) GNUNET_malloc ((n) * sizeof(type)); \ | ||
1215 | }) | ||
1213 | 1216 | ||
1214 | /** | 1217 | /** |
1215 | * @ingroup memory | 1218 | * @ingroup memory |
@@ -1284,23 +1287,23 @@ GNUNET_is_zero_ (const void *a, | |||
1284 | * @ingroup memory | 1287 | * @ingroup memory |
1285 | * Wrapper around free. Frees the memory referred to by ptr. | 1288 | * Wrapper around free. Frees the memory referred to by ptr. |
1286 | * Note that it is generally better to free memory that was | 1289 | * Note that it is generally better to free memory that was |
1287 | * allocated with #GNUNET_array_grow using #GNUNET_array_grow(mem, size, 0) instead of #GNUNET_free. | 1290 | * allocated with #GNUNET_array_grow using #GNUNET_array_grow(mem, size, 0) instead of #GNUNET_free_nz. |
1288 | * | 1291 | * |
1289 | * @param ptr location where to free the memory. ptr must have | 1292 | * @param ptr location where to free the memory. ptr must have |
1290 | * been returned by #GNUNET_strdup, #GNUNET_strndup, #GNUNET_malloc or #GNUNET_array_grow earlier. | 1293 | * been returned by #GNUNET_strdup, #GNUNET_strndup, #GNUNET_malloc or #GNUNET_array_grow earlier. |
1291 | */ | 1294 | */ |
1292 | #define GNUNET_free(ptr) GNUNET_xfree_ (ptr, __FILE__, __LINE__) | 1295 | #define GNUNET_free_nz(ptr) GNUNET_xfree_ (ptr, __FILE__, __LINE__) |
1293 | 1296 | ||
1294 | /** | 1297 | /** |
1295 | * @ingroup memory | 1298 | * @ingroup memory |
1296 | * Wrapper around free. Frees the memory referred to by ptr and sets ptr to NULL. | 1299 | * Wrapper around free. Frees the memory referred to by ptr and sets ptr to NULL. |
1297 | * Note that it is generally better to free memory that was | 1300 | * Note that it is generally better to free memory that was |
1298 | * allocated with #GNUNET_array_grow using #GNUNET_array_grow(mem, size, 0) instead of #GNUNET_freez. | 1301 | * allocated with #GNUNET_array_grow using #GNUNET_array_grow(mem, size, 0) instead of #GNUNET_free. |
1299 | * | 1302 | * |
1300 | * @param ptr location where to free the memory. ptr must have | 1303 | * @param ptr location where to free the memory. ptr must have |
1301 | * been returned by #GNUNET_strdup, #GNUNET_strndup, #GNUNET_malloc or #GNUNET_array_grow earlier. | 1304 | * been returned by #GNUNET_strdup, #GNUNET_strndup, #GNUNET_malloc or #GNUNET_array_grow earlier. |
1302 | */ | 1305 | */ |
1303 | #define GNUNET_freez(ptr) do { \ | 1306 | #define GNUNET_free(ptr) do { \ |
1304 | GNUNET_xfree_ (ptr, __FILE__, __LINE__); \ | 1307 | GNUNET_xfree_ (ptr, __FILE__, __LINE__); \ |
1305 | ptr = NULL; \ | 1308 | ptr = NULL; \ |
1306 | } while (0) | 1309 | } while (0) |
@@ -1389,22 +1392,58 @@ GNUNET_is_zero_ (const void *a, | |||
1389 | 1392 | ||
1390 | /** | 1393 | /** |
1391 | * @ingroup memory | 1394 | * @ingroup memory |
1392 | * Append an element to a list (growing the list by one). | 1395 | * Append an element to an array (growing the array by one). |
1393 | * | 1396 | * |
1394 | * @param arr base-pointer of the vector, may be NULL if size is 0; | 1397 | * @param arr base-pointer of the vector, may be NULL if @a len is 0; |
1395 | * will be updated to reflect the new address. The TYPE of | 1398 | * will be updated to reflect the new address. The TYPE of |
1396 | * arr is important since size is the number of elements and | 1399 | * arr is important since size is the number of elements and |
1397 | * not the size in bytes | 1400 | * not the size in bytes |
1398 | * @param size the number of elements in the existing vector (number | 1401 | * @param len the number of elements in the existing vector (number |
1399 | * of elements to copy over), will be updated with the new | 1402 | * of elements to copy over), will be updated with the new |
1400 | * array size | 1403 | * array length |
1401 | * @param element the element that will be appended to the array | 1404 | * @param element the element that will be appended to the array |
1402 | */ | 1405 | */ |
1403 | #define GNUNET_array_append(arr, size, element) \ | 1406 | #define GNUNET_array_append(arr, len, element) \ |
1407 | do \ | ||
1408 | { \ | ||
1409 | GNUNET_assert ((len) + 1 > (len)); \ | ||
1410 | GNUNET_array_grow (arr, len, len + 1); \ | ||
1411 | (arr) [len - 1] = element; \ | ||
1412 | } while (0) | ||
1413 | |||
1414 | |||
1415 | /** | ||
1416 | * @ingroup memory | ||
1417 | * Append @a arr2 to @a arr1 (growing @a arr1 | ||
1418 | * as needed). The @a arr2 array is left unchanged. Naturally | ||
1419 | * this function performs a shallow copy. Both arrays must have | ||
1420 | * the same type for their elements. | ||
1421 | * | ||
1422 | * @param arr1 base-pointer of the vector, may be NULL if @a len is 0; | ||
1423 | * will be updated to reflect the new address. The TYPE of | ||
1424 | * arr is important since size is the number of elements and | ||
1425 | * not the size in bytes | ||
1426 | * @param len1 the number of elements in the existing vector (number | ||
1427 | * of elements to copy over), will be updated with the new | ||
1428 | * array size | ||
1429 | * @param arr2 base-pointer a second array to concatenate, may be NULL if @a len2 is 0; | ||
1430 | * will be updated to reflect the new address. The TYPE of | ||
1431 | * arr is important since size is the number of elements and | ||
1432 | * not the size in bytes | ||
1433 | * @param len the number of elements in the existing vector (number | ||
1434 | * of elements to copy over), will be updated with the new | ||
1435 | * array size | ||
1436 | |||
1437 | */ | ||
1438 | #define GNUNET_array_concatenate(arr1, len1, arr2, len2) \ | ||
1404 | do \ | 1439 | do \ |
1405 | { \ | 1440 | { \ |
1406 | GNUNET_array_grow (arr, size, size + 1); \ | 1441 | const typeof (*arr2) * _a1 = (arr1); \ |
1407 | (arr) [size - 1] = element; \ | 1442 | const typeof (*arr1) * _a2 = (arr2); \ |
1443 | GNUNET_assert ((len1) + (len2) >= (len1)); \ | ||
1444 | GNUNET_assert (SIZE_MAX / sizeof (*_a1) >= ((len1) + (len2))); \ | ||
1445 | GNUNET_array_grow (arr1, len1, (len1) + (len2)); \ | ||
1446 | memcpy (&(arr1) [(len1) - (len2)], _a2, (len2) * sizeof (*arr1)); \ | ||
1408 | } while (0) | 1447 | } while (0) |
1409 | 1448 | ||
1410 | /** | 1449 | /** |
diff --git a/src/include/gnunet_json_lib.h b/src/include/gnunet_json_lib.h index f6cabd589..27996f18d 100644 --- a/src/include/gnunet_json_lib.h +++ b/src/include/gnunet_json_lib.h | |||
@@ -219,6 +219,17 @@ GNUNET_JSON_spec_json (const char *name, json_t **jsonp); | |||
219 | 219 | ||
220 | 220 | ||
221 | /** | 221 | /** |
222 | * boolean. | ||
223 | * | ||
224 | * @param name name of the JSON field | ||
225 | * @param[out] b where to store the boolean found under @a name | ||
226 | */ | ||
227 | struct GNUNET_JSON_Specification | ||
228 | GNUNET_JSON_spec_bool (const char *name, | ||
229 | bool *b); | ||
230 | |||
231 | |||
232 | /** | ||
222 | * 8-bit integer. | 233 | * 8-bit integer. |
223 | * | 234 | * |
224 | * @param name name of the JSON field | 235 | * @param name name of the JSON field |
diff --git a/src/include/gnunet_revocation_service.h b/src/include/gnunet_revocation_service.h index 7222cedc1..9a8918b43 100644 --- a/src/include/gnunet_revocation_service.h +++ b/src/include/gnunet_revocation_service.h | |||
@@ -51,6 +51,73 @@ extern "C" | |||
51 | #define GNUNET_REVOCATION_VERSION 0x00000000 | 51 | #define GNUNET_REVOCATION_VERSION 0x00000000 |
52 | 52 | ||
53 | /** | 53 | /** |
54 | * The proof-of-work narrowing factor. | ||
55 | * The number of PoWs that are calculates as part of revocation. | ||
56 | */ | ||
57 | #define POW_COUNT 32 | ||
58 | |||
59 | |||
60 | GNUNET_NETWORK_STRUCT_BEGIN | ||
61 | |||
62 | struct GNUNET_REVOCATION_Pow | ||
63 | { | ||
64 | /** | ||
65 | * The timestamp of the revocation | ||
66 | */ | ||
67 | struct GNUNET_TIME_AbsoluteNBO timestamp; | ||
68 | |||
69 | /** | ||
70 | * The TTL of this revocation (purely informational) | ||
71 | */ | ||
72 | struct GNUNET_TIME_RelativeNBO ttl; | ||
73 | |||
74 | /** | ||
75 | * The PoWs | ||
76 | */ | ||
77 | uint64_t pow[POW_COUNT] GNUNET_PACKED; | ||
78 | |||
79 | /** | ||
80 | * The signature | ||
81 | */ | ||
82 | struct GNUNET_CRYPTO_EcdsaSignature signature; | ||
83 | |||
84 | /** | ||
85 | * The revoked public key | ||
86 | */ | ||
87 | struct GNUNET_CRYPTO_EcdsaPublicKey key; | ||
88 | }; | ||
89 | |||
90 | |||
91 | /** | ||
92 | * The signature object we use for the PoW | ||
93 | */ | ||
94 | struct GNUNET_REVOCATION_SignaturePurpose | ||
95 | { | ||
96 | /** | ||
97 | * The signature purpose | ||
98 | */ | ||
99 | struct GNUNET_CRYPTO_EccSignaturePurpose purpose; | ||
100 | |||
101 | /** | ||
102 | * The revoked public key | ||
103 | */ | ||
104 | struct GNUNET_CRYPTO_EcdsaPublicKey key; | ||
105 | |||
106 | /** | ||
107 | * The timestamp of the revocation | ||
108 | */ | ||
109 | struct GNUNET_TIME_AbsoluteNBO timestamp; | ||
110 | }; | ||
111 | |||
112 | GNUNET_NETWORK_STRUCT_END | ||
113 | |||
114 | |||
115 | /** | ||
116 | * Handle to a running proof-of-work calculation. | ||
117 | */ | ||
118 | struct GNUNET_REVOCATION_PowCalculationHandle; | ||
119 | |||
120 | /** | ||
54 | * Handle for the key revocation query. | 121 | * Handle for the key revocation query. |
55 | */ | 122 | */ |
56 | struct GNUNET_REVOCATION_Query; | 123 | struct GNUNET_REVOCATION_Query; |
@@ -65,7 +132,8 @@ struct GNUNET_REVOCATION_Query; | |||
65 | * | 132 | * |
66 | */ | 133 | */ |
67 | typedef void (*GNUNET_REVOCATION_Callback) (void *cls, | 134 | typedef void (*GNUNET_REVOCATION_Callback) (void *cls, |
68 | int is_valid); | 135 | enum GNUNET_GenericReturnValue |
136 | is_valid); | ||
69 | 137 | ||
70 | 138 | ||
71 | /** | 139 | /** |
@@ -102,12 +170,9 @@ struct GNUNET_REVOCATION_Handle; | |||
102 | * Perform key revocation. | 170 | * Perform key revocation. |
103 | * | 171 | * |
104 | * @param cfg the configuration to use | 172 | * @param cfg the configuration to use |
105 | * @param key public key of the key to revoke | ||
106 | * @param sig signature to use on the revocation (should have been | ||
107 | * created using #GNUNET_REVOCATION_sign_revocation). | ||
108 | * @param pow proof of work to use (should have been created by | 173 | * @param pow proof of work to use (should have been created by |
109 | * iteratively calling #GNUNET_REVOCATION_check_pow) | 174 | * iteratively calling #GNUNET_REVOCATION_pow_round) |
110 | * @param func funtion to call with the result of the check | 175 | * @param func function to call with the result of the check |
111 | * (called with `is_valid` being #GNUNET_NO if | 176 | * (called with `is_valid` being #GNUNET_NO if |
112 | * the revocation worked). | 177 | * the revocation worked). |
113 | * @param func_cls closure to pass to @a func | 178 | * @param func_cls closure to pass to @a func |
@@ -115,9 +180,7 @@ struct GNUNET_REVOCATION_Handle; | |||
115 | */ | 180 | */ |
116 | struct GNUNET_REVOCATION_Handle * | 181 | struct GNUNET_REVOCATION_Handle * |
117 | GNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg, | 182 | GNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg, |
118 | const struct GNUNET_CRYPTO_EcdsaPublicKey *key, | 183 | const struct GNUNET_REVOCATION_Pow *pow, |
119 | const struct GNUNET_CRYPTO_EcdsaSignature *sig, | ||
120 | uint64_t pow, | ||
121 | GNUNET_REVOCATION_Callback func, void *func_cls); | 184 | GNUNET_REVOCATION_Callback func, void *func_cls); |
122 | 185 | ||
123 | 186 | ||
@@ -131,31 +194,64 @@ GNUNET_REVOCATION_revoke_cancel (struct GNUNET_REVOCATION_Handle *h); | |||
131 | 194 | ||
132 | 195 | ||
133 | /** | 196 | /** |
134 | * Check if the given proof-of-work value | 197 | * Check if the given proof-of-work is valid. |
135 | * would be acceptable for revoking the given key. | ||
136 | * | 198 | * |
137 | * @param key key to check for | 199 | * @param pow proof of work |
138 | * @param pow proof of work value | ||
139 | * @param matching_bits how many bits must match (configuration) | 200 | * @param matching_bits how many bits must match (configuration) |
201 | * @param epoch_duration length of single epoch in configuration | ||
140 | * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not | 202 | * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not |
141 | */ | 203 | */ |
142 | int | 204 | enum GNUNET_GenericReturnValue |
143 | GNUNET_REVOCATION_check_pow (const struct GNUNET_CRYPTO_EcdsaPublicKey *key, | 205 | GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_Pow *pow, |
144 | uint64_t pow, | 206 | unsigned int matching_bits, |
145 | unsigned int matching_bits); | 207 | struct GNUNET_TIME_Relative epoch_duration); |
146 | 208 | ||
147 | 209 | ||
148 | /** | 210 | /** |
149 | * Create a revocation signature. | 211 | * Initializes a fresh PoW computation. |
150 | * | 212 | * |
151 | * @param key private key of the key to revoke | 213 | * @param key the key to calculate the PoW for. |
152 | * @param sig where to write the revocation signature | 214 | * @param pow the pow object to work with in the calculation. |
153 | */ | 215 | */ |
154 | void | 216 | void |
155 | GNUNET_REVOCATION_sign_revocation (const struct | 217 | GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, |
156 | GNUNET_CRYPTO_EcdsaPrivateKey *key, | 218 | struct GNUNET_REVOCATION_Pow *pow); |
157 | struct GNUNET_CRYPTO_EcdsaSignature *sig); | 219 | |
220 | |||
221 | /** | ||
222 | * Starts a proof-of-work calculation given the pow object as well as | ||
223 | * target epochs and difficulty. | ||
224 | * | ||
225 | * @param pow the PoW to based calculations on. | ||
226 | * @param epochs the number of epochs for which the PoW must be valid. | ||
227 | * @param difficulty the base difficulty of the PoW. | ||
228 | * @return a handle for use in PoW rounds | ||
229 | */ | ||
230 | struct GNUNET_REVOCATION_PowCalculationHandle* | ||
231 | GNUNET_REVOCATION_pow_start (struct GNUNET_REVOCATION_Pow *pow, | ||
232 | int epochs, | ||
233 | unsigned int difficulty); | ||
234 | |||
158 | 235 | ||
236 | /** | ||
237 | * Calculate a single round in the key revocation PoW. | ||
238 | * | ||
239 | * @param pc handle to the PoW, initially called with NULL. | ||
240 | * @return GNUNET_YES if the @a pow is acceptable, GNUNET_NO if not | ||
241 | */ | ||
242 | enum GNUNET_GenericReturnValue | ||
243 | GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc); | ||
244 | |||
245 | |||
246 | /** | ||
247 | * Stop a PoW calculation | ||
248 | * | ||
249 | * @param pc the calculation to clean up | ||
250 | * @return #GNUNET_YES if pow valid, #GNUNET_NO if pow was set but is not | ||
251 | * valid | ||
252 | */ | ||
253 | void | ||
254 | GNUNET_REVOCATION_pow_stop (struct GNUNET_REVOCATION_PowCalculationHandle *pc); | ||
159 | 255 | ||
160 | #if 0 /* keep Emacsens' auto-indent happy */ | 256 | #if 0 /* keep Emacsens' auto-indent happy */ |
161 | { | 257 | { |
diff --git a/src/json/Makefile.am b/src/json/Makefile.am index 5968a3596..9cd80851c 100644 --- a/src/json/Makefile.am +++ b/src/json/Makefile.am | |||
@@ -37,6 +37,7 @@ TESTS = \ | |||
37 | 37 | ||
38 | test_json_SOURCES = \ | 38 | test_json_SOURCES = \ |
39 | test_json.c | 39 | test_json.c |
40 | test_json_CFLAGS = $(MHD_CFLAGS) $(AM_CFLAGS) | ||
40 | test_json_LDADD = \ | 41 | test_json_LDADD = \ |
41 | libgnunetjson.la \ | 42 | libgnunetjson.la \ |
42 | $(top_builddir)/src/util/libgnunetutil.la \ | 43 | $(top_builddir)/src/util/libgnunetutil.la \ |
diff --git a/src/json/json_gnsrecord.c b/src/json/json_gnsrecord.c index bfbdd96ee..37f0c03da 100644 --- a/src/json/json_gnsrecord.c +++ b/src/json/json_gnsrecord.c | |||
@@ -50,10 +50,10 @@ cleanup_recordinfo (struct GnsRecordInfo *gnsrecord_info) | |||
50 | { | 50 | { |
51 | if (NULL != *(gnsrecord_info->rd)) | 51 | if (NULL != *(gnsrecord_info->rd)) |
52 | { | 52 | { |
53 | for (int i = 0; i < *(gnsrecord_info->rd_count); i++) | 53 | for (unsigned int i = 0; i < *(gnsrecord_info->rd_count); i++) |
54 | { | 54 | { |
55 | if (NULL != (*(gnsrecord_info->rd))[i].data) | 55 | if (NULL != (*(gnsrecord_info->rd))[i].data) |
56 | GNUNET_free ((char *) (*(gnsrecord_info->rd))[i].data); | 56 | GNUNET_free_nz ((char *) (*(gnsrecord_info->rd))[i].data); |
57 | } | 57 | } |
58 | GNUNET_free (*(gnsrecord_info->rd)); | 58 | GNUNET_free (*(gnsrecord_info->rd)); |
59 | *(gnsrecord_info->rd) = NULL; | 59 | *(gnsrecord_info->rd) = NULL; |
diff --git a/src/json/json_helper.c b/src/json/json_helper.c index 74a92ce9f..02bd6bfab 100644 --- a/src/json/json_helper.c +++ b/src/json/json_helper.c | |||
@@ -327,6 +327,60 @@ GNUNET_JSON_spec_json (const char *name, | |||
327 | 327 | ||
328 | 328 | ||
329 | /** | 329 | /** |
330 | * Parse given JSON object to a bool. | ||
331 | * | ||
332 | * @param cls closure, NULL | ||
333 | * @param root the json object representing data | ||
334 | * @param[out] spec where to write the data | ||
335 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | ||
336 | */ | ||
337 | static int | ||
338 | parse_bool (void *cls, | ||
339 | json_t *root, | ||
340 | struct GNUNET_JSON_Specification *spec) | ||
341 | { | ||
342 | bool *b = spec->ptr; | ||
343 | |||
344 | if (json_true () == root) | ||
345 | { | ||
346 | *b = true; | ||
347 | return GNUNET_OK; | ||
348 | } | ||
349 | if (json_false () == root) | ||
350 | { | ||
351 | *b = false; | ||
352 | return GNUNET_OK; | ||
353 | } | ||
354 | GNUNET_break_op (0); | ||
355 | return GNUNET_SYSERR; | ||
356 | } | ||
357 | |||
358 | |||
359 | /** | ||
360 | * boolean. | ||
361 | * | ||
362 | * @param name name of the JSON field | ||
363 | * @param[out] b where to store the boolean found under @a name | ||
364 | */ | ||
365 | struct GNUNET_JSON_Specification | ||
366 | GNUNET_JSON_spec_bool (const char *name, | ||
367 | bool *b) | ||
368 | { | ||
369 | struct GNUNET_JSON_Specification ret = { | ||
370 | .parser = &parse_bool, | ||
371 | .cleaner = NULL, | ||
372 | .cls = NULL, | ||
373 | .field = name, | ||
374 | .ptr = b, | ||
375 | .ptr_size = sizeof(bool), | ||
376 | .size_ptr = NULL | ||
377 | }; | ||
378 | |||
379 | return ret; | ||
380 | } | ||
381 | |||
382 | |||
383 | /** | ||
330 | * Parse given JSON object to a uint8_t. | 384 | * Parse given JSON object to a uint8_t. |
331 | * | 385 | * |
332 | * @param cls closure, NULL | 386 | * @param cls closure, NULL |
diff --git a/src/json/test_json_mhd.c b/src/json/test_json_mhd.c index 5ab1b63ca..642715f25 100644 --- a/src/json/test_json_mhd.c +++ b/src/json/test_json_mhd.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_json_lib.h" | 28 | #include "gnunet_json_lib.h" |
29 | #include "gnunet_curl_lib.h" | 29 | #include "gnunet_curl_lib.h" |
30 | #include "gnunet_mhd_compat.h" | ||
30 | #include <zlib.h> | 31 | #include <zlib.h> |
31 | 32 | ||
32 | #define MAX_SIZE 1024 * 1024 | 33 | #define MAX_SIZE 1024 * 1024 |
@@ -36,7 +37,7 @@ static json_t *bigj; | |||
36 | static int global_ret; | 37 | static int global_ret; |
37 | 38 | ||
38 | 39 | ||
39 | static int | 40 | static MHD_RESULT |
40 | access_handler_cb (void *cls, | 41 | access_handler_cb (void *cls, |
41 | struct MHD_Connection *connection, | 42 | struct MHD_Connection *connection, |
42 | const char *url, | 43 | const char *url, |
diff --git a/src/namecache/gnunet-namecache.c b/src/namecache/gnunet-namecache.c index 15a0c96ee..2e3c733e6 100644 --- a/src/namecache/gnunet-namecache.c +++ b/src/namecache/gnunet-namecache.c | |||
@@ -235,10 +235,10 @@ main (int argc, char *const *argv) | |||
235 | &run, | 235 | &run, |
236 | NULL)) | 236 | NULL)) |
237 | { | 237 | { |
238 | GNUNET_free ((void *) argv); | 238 | GNUNET_free_nz ((void *) argv); |
239 | return 1; | 239 | return 1; |
240 | } | 240 | } |
241 | GNUNET_free ((void *) argv); | 241 | GNUNET_free_nz ((void *) argv); |
242 | return ret; | 242 | return ret; |
243 | } | 243 | } |
244 | 244 | ||
diff --git a/src/namecache/test_namecache_api_cache_block.c b/src/namecache/test_namecache_api_cache_block.c index 9b150c9d9..12b72d93b 100644 --- a/src/namecache/test_namecache_api_cache_block.c +++ b/src/namecache/test_namecache_api_cache_block.c | |||
@@ -39,7 +39,7 @@ static struct GNUNET_NAMECACHE_Handle *nsh; | |||
39 | 39 | ||
40 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 40 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
41 | 41 | ||
42 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 42 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; |
43 | 43 | ||
44 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 44 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; |
45 | 45 | ||
@@ -56,11 +56,6 @@ cleanup () | |||
56 | GNUNET_NAMECACHE_disconnect (nsh); | 56 | GNUNET_NAMECACHE_disconnect (nsh); |
57 | nsh = NULL; | 57 | nsh = NULL; |
58 | } | 58 | } |
59 | if (NULL != privkey) | ||
60 | { | ||
61 | GNUNET_free (privkey); | ||
62 | privkey = NULL; | ||
63 | } | ||
64 | GNUNET_SCHEDULER_shutdown (); | 59 | GNUNET_SCHEDULER_shutdown (); |
65 | } | 60 | } |
66 | 61 | ||
@@ -188,10 +183,12 @@ run (void *cls, | |||
188 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | 183 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); |
189 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", | 184 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", |
190 | hostkey_file); | 185 | hostkey_file); |
191 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file); | 186 | GNUNET_assert (GNUNET_SYSERR != |
187 | GNUNET_CRYPTO_ecdsa_key_from_file (hostkey_file, | ||
188 | GNUNET_YES, | ||
189 | &privkey)); | ||
192 | GNUNET_free (hostkey_file); | 190 | GNUNET_free (hostkey_file); |
193 | GNUNET_assert (privkey != NULL); | 191 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, &pubkey); |
194 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); | ||
195 | 192 | ||
196 | 193 | ||
197 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 10000000000; | 194 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 10000000000; |
@@ -200,7 +197,7 @@ run (void *cls, | |||
200 | rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); | 197 | rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); |
201 | rd.flags = 0; | 198 | rd.flags = 0; |
202 | memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN); | 199 | memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN); |
203 | block = GNUNET_GNSRECORD_block_create (privkey, | 200 | block = GNUNET_GNSRECORD_block_create (&privkey, |
204 | GNUNET_TIME_UNIT_FOREVER_ABS, | 201 | GNUNET_TIME_UNIT_FOREVER_ABS, |
205 | name, &rd, 1); | 202 | name, &rd, 1); |
206 | if (NULL == block) | 203 | if (NULL == block) |
@@ -232,7 +229,7 @@ run (void *cls, | |||
232 | _ ("Namecache cannot cache no block\n")); | 229 | _ ("Namecache cannot cache no block\n")); |
233 | } | 230 | } |
234 | GNUNET_free (block); | 231 | GNUNET_free (block); |
235 | GNUNET_free ((void *) rd.data); | 232 | GNUNET_free_nz ((void *) rd.data); |
236 | } | 233 | } |
237 | 234 | ||
238 | 235 | ||
diff --git a/src/namestore/gnunet-namestore-fcfsd.c b/src/namestore/gnunet-namestore-fcfsd.c index 67fc5bdf4..34641d22e 100644 --- a/src/namestore/gnunet-namestore-fcfsd.c +++ b/src/namestore/gnunet-namestore-fcfsd.c | |||
@@ -1210,7 +1210,7 @@ main (int argc, | |||
1210 | "GNU Name System First Come First Serve name registration service"), | 1210 | "GNU Name System First Come First Serve name registration service"), |
1211 | options, | 1211 | options, |
1212 | &run, NULL)) ? 0 : 1; | 1212 | &run, NULL)) ? 0 : 1; |
1213 | GNUNET_free ((void *) argv); | 1213 | GNUNET_free_nz ((void *) argv); |
1214 | GNUNET_CRYPTO_ecdsa_key_clear (&fcfs_zone_pkey); | 1214 | GNUNET_CRYPTO_ecdsa_key_clear (&fcfs_zone_pkey); |
1215 | return ret; | 1215 | return ret; |
1216 | } | 1216 | } |
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index 25dfda59b..508566a49 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c | |||
@@ -1688,11 +1688,11 @@ main (int argc, char *const *argv) | |||
1688 | &run, | 1688 | &run, |
1689 | NULL))) | 1689 | NULL))) |
1690 | { | 1690 | { |
1691 | GNUNET_free ((void *) argv); | 1691 | GNUNET_free_nz ((void *) argv); |
1692 | GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey); | 1692 | GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey); |
1693 | return lret; | 1693 | return lret; |
1694 | } | 1694 | } |
1695 | GNUNET_free ((void *) argv); | 1695 | GNUNET_free_nz ((void *) argv); |
1696 | GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey); | 1696 | GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey); |
1697 | return ret; | 1697 | return ret; |
1698 | } | 1698 | } |
diff --git a/src/namestore/gnunet-zoneimport.c b/src/namestore/gnunet-zoneimport.c index eca02bdc3..5b4e41475 100644 --- a/src/namestore/gnunet-zoneimport.c +++ b/src/namestore/gnunet-zoneimport.c | |||
@@ -1866,7 +1866,7 @@ main (int argc, char *const *argv) | |||
1866 | &run, | 1866 | &run, |
1867 | NULL))) | 1867 | NULL))) |
1868 | return ret; | 1868 | return ret; |
1869 | GNUNET_free ((void *) argv); | 1869 | GNUNET_free_nz ((void *) argv); |
1870 | fprintf (stderr, | 1870 | fprintf (stderr, |
1871 | "Rejected %u names, had %u cached, did %u lookups, stored %u record sets\n" | 1871 | "Rejected %u names, had %u cached, did %u lookups, stored %u record sets\n" |
1872 | "Found %u records, %u lookups failed, %u/%u pending on shutdown\n", | 1872 | "Found %u records, %u lookups failed, %u/%u pending on shutdown\n", |
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c index d2a93a286..c0bf4b048 100644 --- a/src/namestore/plugin_rest_namestore.c +++ b/src/namestore/plugin_rest_namestore.c | |||
@@ -267,7 +267,7 @@ cleanup_handle (void *cls) | |||
267 | for (int i = 0; i < handle->rd_count; i++) | 267 | for (int i = 0; i < handle->rd_count; i++) |
268 | { | 268 | { |
269 | if (NULL != handle->rd[i].data) | 269 | if (NULL != handle->rd[i].data) |
270 | GNUNET_free ((void *) handle->rd[i].data); | 270 | GNUNET_free_nz ((void *) handle->rd[i].data); |
271 | } | 271 | } |
272 | GNUNET_free (handle->rd); | 272 | GNUNET_free (handle->rd); |
273 | } | 273 | } |
diff --git a/src/namestore/test_namestore_api_lookup_private.c b/src/namestore/test_namestore_api_lookup_private.c index 98fdb1b43..d0ad726cc 100644 --- a/src/namestore/test_namestore_api_lookup_private.c +++ b/src/namestore/test_namestore_api_lookup_private.c | |||
@@ -212,7 +212,7 @@ run (void *cls, | |||
212 | _ ("Namestore cannot store no block\n")); | 212 | _ ("Namestore cannot store no block\n")); |
213 | } | 213 | } |
214 | 214 | ||
215 | GNUNET_free ((void *) rd.data); | 215 | GNUNET_free_nz ((void *) rd.data); |
216 | } | 216 | } |
217 | 217 | ||
218 | 218 | ||
diff --git a/src/namestore/test_namestore_api_lookup_public.c b/src/namestore/test_namestore_api_lookup_public.c index 83a5a78f6..039c7cbf6 100644 --- a/src/namestore/test_namestore_api_lookup_public.c +++ b/src/namestore/test_namestore_api_lookup_public.c | |||
@@ -221,7 +221,7 @@ run (void *cls, | |||
221 | _ ("Namestore cannot store no block\n")); | 221 | _ ("Namestore cannot store no block\n")); |
222 | } | 222 | } |
223 | 223 | ||
224 | GNUNET_free ((void *) rd.data); | 224 | GNUNET_free_nz ((void *) rd.data); |
225 | } | 225 | } |
226 | 226 | ||
227 | 227 | ||
diff --git a/src/namestore/test_namestore_api_lookup_shadow.c b/src/namestore/test_namestore_api_lookup_shadow.c index 08c428731..d399d903a 100644 --- a/src/namestore/test_namestore_api_lookup_shadow.c +++ b/src/namestore/test_namestore_api_lookup_shadow.c | |||
@@ -254,7 +254,7 @@ run (void *cls, | |||
254 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 254 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
255 | _ ("Namestore cannot store no block\n")); | 255 | _ ("Namestore cannot store no block\n")); |
256 | } | 256 | } |
257 | GNUNET_free ((void *) rd.data); | 257 | GNUNET_free_nz ((void *) rd.data); |
258 | } | 258 | } |
259 | 259 | ||
260 | 260 | ||
diff --git a/src/namestore/test_namestore_api_lookup_shadow_filter.c b/src/namestore/test_namestore_api_lookup_shadow_filter.c index 634a6a3c4..40dbeb90f 100644 --- a/src/namestore/test_namestore_api_lookup_shadow_filter.c +++ b/src/namestore/test_namestore_api_lookup_shadow_filter.c | |||
@@ -336,8 +336,8 @@ run (void *cls, | |||
336 | _ ("Namestore cannot store no block\n")); | 336 | _ ("Namestore cannot store no block\n")); |
337 | } | 337 | } |
338 | 338 | ||
339 | GNUNET_free ((void *) records[0].data); | 339 | GNUNET_free_nz ((void *) records[0].data); |
340 | GNUNET_free ((void *) records[1].data); | 340 | GNUNET_free_nz ((void *) records[1].data); |
341 | } | 341 | } |
342 | 342 | ||
343 | 343 | ||
diff --git a/src/namestore/test_namestore_api_monitoring.c b/src/namestore/test_namestore_api_monitoring.c index d26492517..cc00adf44 100644 --- a/src/namestore/test_namestore_api_monitoring.c +++ b/src/namestore/test_namestore_api_monitoring.c | |||
@@ -94,17 +94,17 @@ do_shutdown () | |||
94 | 94 | ||
95 | if (s_rd_1 != NULL) | 95 | if (s_rd_1 != NULL) |
96 | { | 96 | { |
97 | GNUNET_free ((void *) s_rd_1->data); | 97 | GNUNET_free_nz ((void *) s_rd_1->data); |
98 | GNUNET_free (s_rd_1); | 98 | GNUNET_free (s_rd_1); |
99 | } | 99 | } |
100 | if (s_rd_2 != NULL) | 100 | if (s_rd_2 != NULL) |
101 | { | 101 | { |
102 | GNUNET_free ((void *) s_rd_2->data); | 102 | GNUNET_free_nz ((void *) s_rd_2->data); |
103 | GNUNET_free (s_rd_2); | 103 | GNUNET_free (s_rd_2); |
104 | } | 104 | } |
105 | if (s_rd_3 != NULL) | 105 | if (s_rd_3 != NULL) |
106 | { | 106 | { |
107 | GNUNET_free ((void *) s_rd_3->data); | 107 | GNUNET_free_nz ((void *) s_rd_3->data); |
108 | GNUNET_free (s_rd_3); | 108 | GNUNET_free (s_rd_3); |
109 | } | 109 | } |
110 | } | 110 | } |
diff --git a/src/namestore/test_namestore_api_monitoring_existing.c b/src/namestore/test_namestore_api_monitoring_existing.c index 040a63f91..728fcc25e 100644 --- a/src/namestore/test_namestore_api_monitoring_existing.c +++ b/src/namestore/test_namestore_api_monitoring_existing.c | |||
@@ -111,17 +111,17 @@ end (void *cls) | |||
111 | } | 111 | } |
112 | if (NULL != s_rd_1) | 112 | if (NULL != s_rd_1) |
113 | { | 113 | { |
114 | GNUNET_free ((void *) s_rd_1->data); | 114 | GNUNET_free_nz ((void *) s_rd_1->data); |
115 | GNUNET_free (s_rd_1); | 115 | GNUNET_free (s_rd_1); |
116 | } | 116 | } |
117 | if (NULL != s_rd_2) | 117 | if (NULL != s_rd_2) |
118 | { | 118 | { |
119 | GNUNET_free ((void *) s_rd_2->data); | 119 | GNUNET_free_nz ((void *) s_rd_2->data); |
120 | GNUNET_free (s_rd_2); | 120 | GNUNET_free (s_rd_2); |
121 | } | 121 | } |
122 | if (NULL != s_rd_3) | 122 | if (NULL != s_rd_3) |
123 | { | 123 | { |
124 | GNUNET_free ((void *) s_rd_3->data); | 124 | GNUNET_free_nz ((void *) s_rd_3->data); |
125 | GNUNET_free (s_rd_3); | 125 | GNUNET_free (s_rd_3); |
126 | } | 126 | } |
127 | } | 127 | } |
diff --git a/src/namestore/test_namestore_api_remove.c b/src/namestore/test_namestore_api_remove.c index 3f0c4c123..e575821e8 100644 --- a/src/namestore/test_namestore_api_remove.c +++ b/src/namestore/test_namestore_api_remove.c | |||
@@ -187,7 +187,7 @@ run (void *cls, | |||
187 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 187 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
188 | _ ("Namestore cannot store no block\n")); | 188 | _ ("Namestore cannot store no block\n")); |
189 | } | 189 | } |
190 | GNUNET_free ((void *) rd.data); | 190 | GNUNET_free_nz ((void *) rd.data); |
191 | } | 191 | } |
192 | 192 | ||
193 | 193 | ||
diff --git a/src/namestore/test_namestore_api_store.c b/src/namestore/test_namestore_api_store.c index ab211aeae..9223b56a3 100644 --- a/src/namestore/test_namestore_api_store.c +++ b/src/namestore/test_namestore_api_store.c | |||
@@ -138,7 +138,7 @@ run (void *cls, | |||
138 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 138 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
139 | _ ("Namestore cannot store no block\n")); | 139 | _ ("Namestore cannot store no block\n")); |
140 | } | 140 | } |
141 | GNUNET_free ((void *) rd.data); | 141 | GNUNET_free_nz ((void *) rd.data); |
142 | } | 142 | } |
143 | 143 | ||
144 | 144 | ||
diff --git a/src/namestore/test_namestore_api_store_update.c b/src/namestore/test_namestore_api_store_update.c index 65dbdbd8c..7a5a69a6c 100644 --- a/src/namestore/test_namestore_api_store_update.c +++ b/src/namestore/test_namestore_api_store_update.c | |||
@@ -274,7 +274,7 @@ run (void *cls, | |||
274 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 274 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
275 | _ ("Namestore cannot store no block\n")); | 275 | _ ("Namestore cannot store no block\n")); |
276 | } | 276 | } |
277 | GNUNET_free ((void *) rd.data); | 277 | GNUNET_free_nz ((void *) rd.data); |
278 | } | 278 | } |
279 | 279 | ||
280 | 280 | ||
diff --git a/src/namestore/test_namestore_api_zone_iteration.c b/src/namestore/test_namestore_api_zone_iteration.c index d69b7cc62..a363ee28d 100644 --- a/src/namestore/test_namestore_api_zone_iteration.c +++ b/src/namestore/test_namestore_api_zone_iteration.c | |||
@@ -37,9 +37,9 @@ static struct GNUNET_NAMESTORE_Handle *nsh; | |||
37 | 37 | ||
38 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 38 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
39 | 39 | ||
40 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 40 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; |
41 | 41 | ||
42 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey2; | 42 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey2; |
43 | 43 | ||
44 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; | 44 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; |
45 | 45 | ||
@@ -88,32 +88,22 @@ end (void *cls) | |||
88 | GNUNET_SCHEDULER_cancel (endbadly_task); | 88 | GNUNET_SCHEDULER_cancel (endbadly_task); |
89 | endbadly_task = NULL; | 89 | endbadly_task = NULL; |
90 | } | 90 | } |
91 | if (NULL != privkey) | ||
92 | { | ||
93 | GNUNET_free (privkey); | ||
94 | privkey = NULL; | ||
95 | } | ||
96 | if (NULL != privkey2) | ||
97 | { | ||
98 | GNUNET_free (privkey2); | ||
99 | privkey2 = NULL; | ||
100 | } | ||
101 | GNUNET_free_non_null (s_name_1); | 91 | GNUNET_free_non_null (s_name_1); |
102 | GNUNET_free_non_null (s_name_2); | 92 | GNUNET_free_non_null (s_name_2); |
103 | GNUNET_free_non_null (s_name_3); | 93 | GNUNET_free_non_null (s_name_3); |
104 | if (NULL != s_rd_1) | 94 | if (NULL != s_rd_1) |
105 | { | 95 | { |
106 | GNUNET_free ((void *) s_rd_1->data); | 96 | GNUNET_free_nz ((void *) s_rd_1->data); |
107 | GNUNET_free (s_rd_1); | 97 | GNUNET_free (s_rd_1); |
108 | } | 98 | } |
109 | if (NULL != s_rd_2) | 99 | if (NULL != s_rd_2) |
110 | { | 100 | { |
111 | GNUNET_free ((void *) s_rd_2->data); | 101 | GNUNET_free_nz ((void *) s_rd_2->data); |
112 | GNUNET_free (s_rd_2); | 102 | GNUNET_free (s_rd_2); |
113 | } | 103 | } |
114 | if (NULL != s_rd_3) | 104 | if (NULL != s_rd_3) |
115 | { | 105 | { |
116 | GNUNET_free ((void *) s_rd_3->data); | 106 | GNUNET_free_nz ((void *) s_rd_3->data); |
117 | GNUNET_free (s_rd_3); | 107 | GNUNET_free (s_rd_3); |
118 | } | 108 | } |
119 | if (NULL != nsh) | 109 | if (NULL != nsh) |
@@ -161,7 +151,7 @@ zone_proc (void *cls, | |||
161 | 151 | ||
162 | GNUNET_assert (NULL != zone); | 152 | GNUNET_assert (NULL != zone); |
163 | if (0 == GNUNET_memcmp (zone, | 153 | if (0 == GNUNET_memcmp (zone, |
164 | privkey)) | 154 | &privkey)) |
165 | { | 155 | { |
166 | if (0 == strcmp (label, s_name_1)) | 156 | if (0 == strcmp (label, s_name_1)) |
167 | { | 157 | { |
@@ -207,7 +197,7 @@ zone_proc (void *cls, | |||
207 | } | 197 | } |
208 | } | 198 | } |
209 | else if (0 == GNUNET_memcmp (zone, | 199 | else if (0 == GNUNET_memcmp (zone, |
210 | privkey2)) | 200 | &privkey2)) |
211 | { | 201 | { |
212 | if (0 == strcmp (label, s_name_3)) | 202 | if (0 == strcmp (label, s_name_3)) |
213 | { | 203 | { |
@@ -382,9 +372,11 @@ empty_zone_end (void *cls) | |||
382 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 372 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
383 | "Using zonekey file `%s' \n", | 373 | "Using zonekey file `%s' \n", |
384 | hostkey_file); | 374 | hostkey_file); |
385 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file); | 375 | GNUNET_assert (GNUNET_SYSERR != |
376 | GNUNET_CRYPTO_ecdsa_key_from_file (hostkey_file, | ||
377 | GNUNET_YES, | ||
378 | &privkey)); | ||
386 | GNUNET_free (hostkey_file); | 379 | GNUNET_free (hostkey_file); |
387 | GNUNET_assert (privkey != NULL); | ||
388 | 380 | ||
389 | GNUNET_asprintf (&hostkey_file, | 381 | GNUNET_asprintf (&hostkey_file, |
390 | "zonefiles%s%s", | 382 | "zonefiles%s%s", |
@@ -393,16 +385,18 @@ empty_zone_end (void *cls) | |||
393 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 385 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
394 | "Using zonekey file `%s' \n", | 386 | "Using zonekey file `%s' \n", |
395 | hostkey_file); | 387 | hostkey_file); |
396 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file); | 388 | GNUNET_assert (GNUNET_SYSERR != |
389 | GNUNET_CRYPTO_ecdsa_key_from_file (hostkey_file, | ||
390 | GNUNET_YES, | ||
391 | &privkey2)); | ||
397 | GNUNET_free (hostkey_file); | 392 | GNUNET_free (hostkey_file); |
398 | GNUNET_assert (privkey2 != NULL); | ||
399 | 393 | ||
400 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); | 394 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); |
401 | 395 | ||
402 | GNUNET_asprintf (&s_name_1, "dummy1"); | 396 | GNUNET_asprintf (&s_name_1, "dummy1"); |
403 | s_rd_1 = create_record (1); | 397 | s_rd_1 = create_record (1); |
404 | GNUNET_NAMESTORE_records_store (nsh, | 398 | GNUNET_NAMESTORE_records_store (nsh, |
405 | privkey, | 399 | &privkey, |
406 | s_name_1, | 400 | s_name_1, |
407 | 1, s_rd_1, | 401 | 1, s_rd_1, |
408 | &put_cont, | 402 | &put_cont, |
@@ -412,7 +406,7 @@ empty_zone_end (void *cls) | |||
412 | GNUNET_asprintf (&s_name_2, "dummy2"); | 406 | GNUNET_asprintf (&s_name_2, "dummy2"); |
413 | s_rd_2 = create_record (1); | 407 | s_rd_2 = create_record (1); |
414 | GNUNET_NAMESTORE_records_store (nsh, | 408 | GNUNET_NAMESTORE_records_store (nsh, |
415 | privkey, | 409 | &privkey, |
416 | s_name_2, | 410 | s_name_2, |
417 | 1, s_rd_2, | 411 | 1, s_rd_2, |
418 | &put_cont, | 412 | &put_cont, |
@@ -423,7 +417,7 @@ empty_zone_end (void *cls) | |||
423 | GNUNET_asprintf (&s_name_3, "dummy3"); | 417 | GNUNET_asprintf (&s_name_3, "dummy3"); |
424 | s_rd_3 = create_record (1); | 418 | s_rd_3 = create_record (1); |
425 | GNUNET_NAMESTORE_records_store (nsh, | 419 | GNUNET_NAMESTORE_records_store (nsh, |
426 | privkey2, | 420 | &privkey2, |
427 | s_name_3, | 421 | s_name_3, |
428 | 1, | 422 | 1, |
429 | s_rd_3, | 423 | s_rd_3, |
diff --git a/src/namestore/test_namestore_api_zone_iteration_nick.c b/src/namestore/test_namestore_api_zone_iteration_nick.c index f5ffe3899..b0c4c8211 100644 --- a/src/namestore/test_namestore_api_zone_iteration_nick.c +++ b/src/namestore/test_namestore_api_zone_iteration_nick.c | |||
@@ -87,17 +87,17 @@ end (void *cls) | |||
87 | 87 | ||
88 | if (s_rd_1 != NULL) | 88 | if (s_rd_1 != NULL) |
89 | { | 89 | { |
90 | GNUNET_free ((void *) s_rd_1->data); | 90 | GNUNET_free_nz ((void *) s_rd_1->data); |
91 | GNUNET_free (s_rd_1); | 91 | GNUNET_free (s_rd_1); |
92 | } | 92 | } |
93 | if (s_rd_2 != NULL) | 93 | if (s_rd_2 != NULL) |
94 | { | 94 | { |
95 | GNUNET_free ((void *) s_rd_2->data); | 95 | GNUNET_free_nz ((void *) s_rd_2->data); |
96 | GNUNET_free (s_rd_2); | 96 | GNUNET_free (s_rd_2); |
97 | } | 97 | } |
98 | if (s_rd_3 != NULL) | 98 | if (s_rd_3 != NULL) |
99 | { | 99 | { |
100 | GNUNET_free ((void *) s_rd_3->data); | 100 | GNUNET_free_nz ((void *) s_rd_3->data); |
101 | GNUNET_free (s_rd_3); | 101 | GNUNET_free (s_rd_3); |
102 | } | 102 | } |
103 | } | 103 | } |
diff --git a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c index 97093cb71..0534da001 100644 --- a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c +++ b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c | |||
@@ -93,17 +93,17 @@ end (void *cls) | |||
93 | GNUNET_free_non_null (s_name_3); | 93 | GNUNET_free_non_null (s_name_3); |
94 | if (s_rd_1 != NULL) | 94 | if (s_rd_1 != NULL) |
95 | { | 95 | { |
96 | GNUNET_free ((void *) s_rd_1->data); | 96 | GNUNET_free_nz ((void *) s_rd_1->data); |
97 | GNUNET_free (s_rd_1); | 97 | GNUNET_free (s_rd_1); |
98 | } | 98 | } |
99 | if (s_rd_2 != NULL) | 99 | if (s_rd_2 != NULL) |
100 | { | 100 | { |
101 | GNUNET_free ((void *) s_rd_2->data); | 101 | GNUNET_free_nz ((void *) s_rd_2->data); |
102 | GNUNET_free (s_rd_2); | 102 | GNUNET_free (s_rd_2); |
103 | } | 103 | } |
104 | if (s_rd_3 != NULL) | 104 | if (s_rd_3 != NULL) |
105 | { | 105 | { |
106 | GNUNET_free ((void *) s_rd_3->data); | 106 | GNUNET_free_nz ((void *) s_rd_3->data); |
107 | GNUNET_free (s_rd_3); | 107 | GNUNET_free (s_rd_3); |
108 | } | 108 | } |
109 | if (nsh != NULL) | 109 | if (nsh != NULL) |
diff --git a/src/namestore/test_namestore_api_zone_iteration_stop.c b/src/namestore/test_namestore_api_zone_iteration_stop.c index 81fb4de7e..b71a8789c 100644 --- a/src/namestore/test_namestore_api_zone_iteration_stop.c +++ b/src/namestore/test_namestore_api_zone_iteration_stop.c | |||
@@ -34,9 +34,9 @@ | |||
34 | 34 | ||
35 | static struct GNUNET_NAMESTORE_Handle *nsh; | 35 | static struct GNUNET_NAMESTORE_Handle *nsh; |
36 | 36 | ||
37 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 37 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; |
38 | 38 | ||
39 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey2; | 39 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey2; |
40 | 40 | ||
41 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; | 41 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; |
42 | 42 | ||
@@ -80,29 +80,19 @@ end (void *cls) | |||
80 | GNUNET_free_non_null (s_name_3); | 80 | GNUNET_free_non_null (s_name_3); |
81 | if (s_rd_1 != NULL) | 81 | if (s_rd_1 != NULL) |
82 | { | 82 | { |
83 | GNUNET_free ((void *) s_rd_1->data); | 83 | GNUNET_free_nz ((void *) s_rd_1->data); |
84 | GNUNET_free (s_rd_1); | 84 | GNUNET_free (s_rd_1); |
85 | } | 85 | } |
86 | if (s_rd_2 != NULL) | 86 | if (s_rd_2 != NULL) |
87 | { | 87 | { |
88 | GNUNET_free ((void *) s_rd_2->data); | 88 | GNUNET_free_nz ((void *) s_rd_2->data); |
89 | GNUNET_free (s_rd_2); | 89 | GNUNET_free (s_rd_2); |
90 | } | 90 | } |
91 | if (s_rd_3 != NULL) | 91 | if (s_rd_3 != NULL) |
92 | { | 92 | { |
93 | GNUNET_free ((void *) s_rd_3->data); | 93 | GNUNET_free_nz ((void *) s_rd_3->data); |
94 | GNUNET_free (s_rd_3); | 94 | GNUNET_free (s_rd_3); |
95 | } | 95 | } |
96 | if (privkey != NULL) | ||
97 | { | ||
98 | GNUNET_free (privkey); | ||
99 | privkey = NULL; | ||
100 | } | ||
101 | if (privkey2 != NULL) | ||
102 | { | ||
103 | GNUNET_free (privkey2); | ||
104 | privkey2 = NULL; | ||
105 | } | ||
106 | } | 96 | } |
107 | 97 | ||
108 | 98 | ||
@@ -130,7 +120,7 @@ zone_proc (void *cls, | |||
130 | int failed = GNUNET_NO; | 120 | int failed = GNUNET_NO; |
131 | 121 | ||
132 | GNUNET_assert (NULL != zone); | 122 | GNUNET_assert (NULL != zone); |
133 | if (0 == GNUNET_memcmp (zone, privkey)) | 123 | if (0 == GNUNET_memcmp (zone, &privkey)) |
134 | { | 124 | { |
135 | if (0 == strcmp (label, s_name_1)) | 125 | if (0 == strcmp (label, s_name_1)) |
136 | { | 126 | { |
@@ -175,7 +165,7 @@ zone_proc (void *cls, | |||
175 | GNUNET_break (0); | 165 | GNUNET_break (0); |
176 | } | 166 | } |
177 | } | 167 | } |
178 | else if (0 == GNUNET_memcmp (zone, privkey2)) | 168 | else if (0 == GNUNET_memcmp (zone, &privkey2)) |
179 | { | 169 | { |
180 | if (0 == strcmp (label, s_name_3)) | 170 | if (0 == strcmp (label, s_name_3)) |
181 | { | 171 | { |
@@ -368,10 +358,11 @@ empty_zone_proc_end (void *cls) | |||
368 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 358 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
369 | "Using zonekey file `%s' \n", | 359 | "Using zonekey file `%s' \n", |
370 | hostkey_file); | 360 | hostkey_file); |
371 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file); | 361 | GNUNET_assert (GNUNET_SYSERR |
362 | != GNUNET_CRYPTO_ecdsa_key_from_file (hostkey_file, | ||
363 | GNUNET_YES, | ||
364 | &privkey)); | ||
372 | GNUNET_free (hostkey_file); | 365 | GNUNET_free (hostkey_file); |
373 | GNUNET_assert (privkey != NULL); | ||
374 | |||
375 | GNUNET_asprintf (&hostkey_file, | 366 | GNUNET_asprintf (&hostkey_file, |
376 | "zonefiles%s%s", | 367 | "zonefiles%s%s", |
377 | DIR_SEPARATOR_STR, | 368 | DIR_SEPARATOR_STR, |
@@ -379,17 +370,19 @@ empty_zone_proc_end (void *cls) | |||
379 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 370 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
380 | "Using zonekey file `%s'\n", | 371 | "Using zonekey file `%s'\n", |
381 | hostkey_file); | 372 | hostkey_file); |
382 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file); | 373 | GNUNET_assert (GNUNET_SYSERR != |
374 | GNUNET_CRYPTO_ecdsa_key_from_file (hostkey_file, | ||
375 | GNUNET_YES, | ||
376 | &privkey2)); | ||
383 | GNUNET_free (hostkey_file); | 377 | GNUNET_free (hostkey_file); |
384 | GNUNET_assert (privkey2 != NULL); | ||
385 | |||
386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 378 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
387 | "Created record 1\n"); | 379 | "Created record 1\n"); |
388 | 380 | ||
389 | GNUNET_asprintf (&s_name_1, | 381 | GNUNET_asprintf (&s_name_1, |
390 | "dummy1"); | 382 | "dummy1"); |
391 | s_rd_1 = create_record (1); | 383 | s_rd_1 = create_record (1); |
392 | GNUNET_NAMESTORE_records_store (nsh, privkey, s_name_1, | 384 | GNUNET_NAMESTORE_records_store (nsh, |
385 | &privkey, s_name_1, | ||
393 | 1, s_rd_1, &put_cont, NULL); | 386 | 1, s_rd_1, &put_cont, NULL); |
394 | 387 | ||
395 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 388 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -398,7 +391,7 @@ empty_zone_proc_end (void *cls) | |||
398 | "dummy2"); | 391 | "dummy2"); |
399 | s_rd_2 = create_record (1); | 392 | s_rd_2 = create_record (1); |
400 | GNUNET_NAMESTORE_records_store (nsh, | 393 | GNUNET_NAMESTORE_records_store (nsh, |
401 | privkey, | 394 | &privkey, |
402 | s_name_2, | 395 | s_name_2, |
403 | 1, | 396 | 1, |
404 | s_rd_2, | 397 | s_rd_2, |
@@ -411,7 +404,7 @@ empty_zone_proc_end (void *cls) | |||
411 | GNUNET_asprintf (&s_name_3, "dummy3"); | 404 | GNUNET_asprintf (&s_name_3, "dummy3"); |
412 | s_rd_3 = create_record (1); | 405 | s_rd_3 = create_record (1); |
413 | GNUNET_NAMESTORE_records_store (nsh, | 406 | GNUNET_NAMESTORE_records_store (nsh, |
414 | privkey2, | 407 | &privkey2, |
415 | s_name_3, | 408 | s_name_3, |
416 | 1, | 409 | 1, |
417 | s_rd_3, | 410 | s_rd_3, |
diff --git a/src/nat-auto/gnunet-nat-auto.c b/src/nat-auto/gnunet-nat-auto.c index d40f4ef32..95a7ced9e 100644 --- a/src/nat-auto/gnunet-nat-auto.c +++ b/src/nat-auto/gnunet-nat-auto.c | |||
@@ -359,7 +359,7 @@ main (int argc, char *const argv[]) | |||
359 | { | 359 | { |
360 | global_ret = 1; | 360 | global_ret = 1; |
361 | } | 361 | } |
362 | GNUNET_free ((void *) argv); | 362 | GNUNET_free_nz ((void *) argv); |
363 | return global_ret; | 363 | return global_ret; |
364 | } | 364 | } |
365 | 365 | ||
diff --git a/src/nat/gnunet-nat.c b/src/nat/gnunet-nat.c index 857ce5093..5012d6455 100644 --- a/src/nat/gnunet-nat.c +++ b/src/nat/gnunet-nat.c | |||
@@ -468,7 +468,7 @@ main (int argc, char *const argv[]) | |||
468 | { | 468 | { |
469 | global_ret = 1; | 469 | global_ret = 1; |
470 | } | 470 | } |
471 | GNUNET_free ((void *) argv); | 471 | GNUNET_free_nz ((void *) argv); |
472 | return global_ret; | 472 | return global_ret; |
473 | } | 473 | } |
474 | 474 | ||
diff --git a/src/peerinfo-tool/gnunet-peerinfo.c b/src/peerinfo-tool/gnunet-peerinfo.c index 4d4c4de33..df6c169b5 100644 --- a/src/peerinfo-tool/gnunet-peerinfo.c +++ b/src/peerinfo-tool/gnunet-peerinfo.c | |||
@@ -855,7 +855,7 @@ main (int argc, char *const *argv) | |||
855 | NULL)) | 855 | NULL)) |
856 | ? 0 | 856 | ? 0 |
857 | : 1; | 857 | : 1; |
858 | GNUNET_free ((void *) argv); | 858 | GNUNET_free_nz ((void *) argv); |
859 | return ret; | 859 | return ret; |
860 | } | 860 | } |
861 | 861 | ||
diff --git a/src/peerinfo-tool/plugin_rest_peerinfo.c b/src/peerinfo-tool/plugin_rest_peerinfo.c index 14559a8cf..6e156569a 100644 --- a/src/peerinfo-tool/plugin_rest_peerinfo.c +++ b/src/peerinfo-tool/plugin_rest_peerinfo.c | |||
@@ -272,7 +272,7 @@ cleanup_handle (void *cls) | |||
272 | if (NULL != handle->emsg) | 272 | if (NULL != handle->emsg) |
273 | GNUNET_free (handle->emsg); | 273 | GNUNET_free (handle->emsg); |
274 | if (NULL != handle->address) | 274 | if (NULL != handle->address) |
275 | GNUNET_free ((char *) handle->address); | 275 | GNUNET_free_nz ((char *) handle->address); |
276 | if (NULL != handle->expiration_str) | 276 | if (NULL != handle->expiration_str) |
277 | GNUNET_free (handle->expiration_str); | 277 | GNUNET_free (handle->expiration_str); |
278 | if (NULL != handle->pubkey) | 278 | if (NULL != handle->pubkey) |
diff --git a/src/pt/gnunet-daemon-pt.c b/src/pt/gnunet-daemon-pt.c index f8765818b..bcc913bd2 100644 --- a/src/pt/gnunet-daemon-pt.c +++ b/src/pt/gnunet-daemon-pt.c | |||
@@ -1317,7 +1317,7 @@ main (int argc, | |||
1317 | NULL)) | 1317 | NULL)) |
1318 | ? 0 | 1318 | ? 0 |
1319 | : 1; | 1319 | : 1; |
1320 | GNUNET_free ((void *) argv); | 1320 | GNUNET_free_nz ((void *) argv); |
1321 | return ret; | 1321 | return ret; |
1322 | } | 1322 | } |
1323 | 1323 | ||
diff --git a/src/pt/test_gns_vpn.c b/src/pt/test_gns_vpn.c index 9bf497b16..69afca789 100644 --- a/src/pt/test_gns_vpn.c +++ b/src/pt/test_gns_vpn.c | |||
@@ -45,6 +45,7 @@ | |||
45 | #include "gnunet_gnsrecord_lib.h" | 45 | #include "gnunet_gnsrecord_lib.h" |
46 | #include "gnunet_gns_service.h" | 46 | #include "gnunet_gns_service.h" |
47 | #include "gnunet_testing_lib.h" | 47 | #include "gnunet_testing_lib.h" |
48 | #include "gnunet_mhd_compat.h" | ||
48 | 49 | ||
49 | #define PORT 8080 | 50 | #define PORT 8080 |
50 | #define TEST_DOMAIN "www.gnu" | 51 | #define TEST_DOMAIN "www.gnu" |
@@ -121,7 +122,7 @@ copy_buffer (void *ptr, | |||
121 | } | 122 | } |
122 | 123 | ||
123 | 124 | ||
124 | static int | 125 | static MHD_RESULT |
125 | mhd_ahc (void *cls, | 126 | mhd_ahc (void *cls, |
126 | struct MHD_Connection *connection, | 127 | struct MHD_Connection *connection, |
127 | const char *url, | 128 | const char *url, |
@@ -611,7 +612,7 @@ identity_cb (void *cls, | |||
611 | 1, &rd, | 612 | 1, &rd, |
612 | &commence_testing, | 613 | &commence_testing, |
613 | NULL); | 614 | NULL); |
614 | GNUNET_free ((void **) rd.data); | 615 | GNUNET_free_nz ((void **) rd.data); |
615 | GNUNET_free (rd_string); | 616 | GNUNET_free (rd_string); |
616 | } | 617 | } |
617 | 618 | ||
diff --git a/src/pt/test_gnunet_vpn.c b/src/pt/test_gnunet_vpn.c index 42fd52c38..cb9bb61fe 100644 --- a/src/pt/test_gnunet_vpn.c +++ b/src/pt/test_gnunet_vpn.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <microhttpd.h> | 29 | #include <microhttpd.h> |
30 | #include "gnunet_vpn_service.h" | 30 | #include "gnunet_vpn_service.h" |
31 | #include "gnunet_testing_lib.h" | 31 | #include "gnunet_testing_lib.h" |
32 | #include "gnunet_mhd_compat.h" | ||
32 | 33 | ||
33 | #define PORT 48080 | 34 | #define PORT 48080 |
34 | 35 | ||
@@ -96,7 +97,7 @@ copy_buffer (void *ptr, size_t size, size_t nmemb, void *ctx) | |||
96 | } | 97 | } |
97 | 98 | ||
98 | 99 | ||
99 | static int | 100 | static MHD_RESULT |
100 | mhd_ahc (void *cls, | 101 | mhd_ahc (void *cls, |
101 | struct MHD_Connection *connection, | 102 | struct MHD_Connection *connection, |
102 | const char *url, | 103 | const char *url, |
diff --git a/src/regex/gnunet-daemon-regexprofiler.c b/src/regex/gnunet-daemon-regexprofiler.c index eda58fdd2..d94b5ae46 100644 --- a/src/regex/gnunet-daemon-regexprofiler.c +++ b/src/regex/gnunet-daemon-regexprofiler.c | |||
@@ -118,7 +118,7 @@ shutdown_task (void *cls) | |||
118 | } | 118 | } |
119 | if (NULL != reannounce_task) | 119 | if (NULL != reannounce_task) |
120 | { | 120 | { |
121 | GNUNET_free (GNUNET_SCHEDULER_cancel (reannounce_task)); | 121 | GNUNET_free_nz (GNUNET_SCHEDULER_cancel (reannounce_task)); |
122 | reannounce_task = NULL; | 122 | reannounce_task = NULL; |
123 | } | 123 | } |
124 | if (NULL != dht_handle) | 124 | if (NULL != dht_handle) |
diff --git a/src/revocation/gnunet-revocation.c b/src/revocation/gnunet-revocation.c index f5aa2d17e..8b7cf33c6 100644 --- a/src/revocation/gnunet-revocation.c +++ b/src/revocation/gnunet-revocation.c | |||
@@ -28,6 +28,10 @@ | |||
28 | #include "gnunet_revocation_service.h" | 28 | #include "gnunet_revocation_service.h" |
29 | #include "gnunet_identity_service.h" | 29 | #include "gnunet_identity_service.h" |
30 | 30 | ||
31 | /** | ||
32 | * Pow passes | ||
33 | */ | ||
34 | static unsigned int pow_passes = 1; | ||
31 | 35 | ||
32 | /** | 36 | /** |
33 | * Final status code. | 37 | * Final status code. |
@@ -55,6 +59,11 @@ static char *revoke_ego; | |||
55 | static char *test_ego; | 59 | static char *test_ego; |
56 | 60 | ||
57 | /** | 61 | /** |
62 | * -e option. | ||
63 | */ | ||
64 | static unsigned int epochs = 1; | ||
65 | |||
66 | /** | ||
58 | * Handle for revocation query. | 67 | * Handle for revocation query. |
59 | */ | 68 | */ |
60 | static struct GNUNET_REVOCATION_Query *q; | 69 | static struct GNUNET_REVOCATION_Query *q; |
@@ -80,10 +89,19 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
80 | static unsigned long long matching_bits; | 89 | static unsigned long long matching_bits; |
81 | 90 | ||
82 | /** | 91 | /** |
92 | * Epoch length | ||
93 | */ | ||
94 | static struct GNUNET_TIME_Relative epoch_duration; | ||
95 | |||
96 | /** | ||
83 | * Task used for proof-of-work calculation. | 97 | * Task used for proof-of-work calculation. |
84 | */ | 98 | */ |
85 | static struct GNUNET_SCHEDULER_Task *pow_task; | 99 | static struct GNUNET_SCHEDULER_Task *pow_task; |
86 | 100 | ||
101 | /** | ||
102 | * Proof-of-work object | ||
103 | */ | ||
104 | static struct GNUNET_REVOCATION_Pow proof_of_work; | ||
87 | 105 | ||
88 | /** | 106 | /** |
89 | * Function run if the user aborts with CTRL-C. | 107 | * Function run if the user aborts with CTRL-C. |
@@ -93,6 +111,7 @@ static struct GNUNET_SCHEDULER_Task *pow_task; | |||
93 | static void | 111 | static void |
94 | do_shutdown (void *cls) | 112 | do_shutdown (void *cls) |
95 | { | 113 | { |
114 | fprintf (stderr, "%s", _ ("Shutting down...\n")); | ||
96 | if (NULL != el) | 115 | if (NULL != el) |
97 | { | 116 | { |
98 | GNUNET_IDENTITY_ego_lookup_cancel (el); | 117 | GNUNET_IDENTITY_ego_lookup_cancel (el); |
@@ -188,37 +207,13 @@ print_revocation_result (void *cls, int is_valid) | |||
188 | 207 | ||
189 | 208 | ||
190 | /** | 209 | /** |
191 | * Data needed to perform a revocation. | ||
192 | */ | ||
193 | struct RevocationData | ||
194 | { | ||
195 | /** | ||
196 | * Public key. | ||
197 | */ | ||
198 | struct GNUNET_CRYPTO_EcdsaPublicKey key; | ||
199 | |||
200 | /** | ||
201 | * Revocation signature data. | ||
202 | */ | ||
203 | struct GNUNET_CRYPTO_EcdsaSignature sig; | ||
204 | |||
205 | /** | ||
206 | * Proof of work (in NBO). | ||
207 | */ | ||
208 | uint64_t pow GNUNET_PACKED; | ||
209 | }; | ||
210 | |||
211 | |||
212 | /** | ||
213 | * Perform the revocation. | 210 | * Perform the revocation. |
214 | */ | 211 | */ |
215 | static void | 212 | static void |
216 | perform_revocation (const struct RevocationData *rd) | 213 | perform_revocation () |
217 | { | 214 | { |
218 | h = GNUNET_REVOCATION_revoke (cfg, | 215 | h = GNUNET_REVOCATION_revoke (cfg, |
219 | &rd->key, | 216 | &proof_of_work, |
220 | &rd->sig, | ||
221 | rd->pow, | ||
222 | &print_revocation_result, | 217 | &print_revocation_result, |
223 | NULL); | 218 | NULL); |
224 | } | 219 | } |
@@ -231,13 +226,13 @@ perform_revocation (const struct RevocationData *rd) | |||
231 | * @param rd data to sync | 226 | * @param rd data to sync |
232 | */ | 227 | */ |
233 | static void | 228 | static void |
234 | sync_rd (const struct RevocationData *rd) | 229 | sync_pow () |
235 | { | 230 | { |
236 | if ((NULL != filename) && | 231 | if ((NULL != filename) && |
237 | (sizeof(struct RevocationData) == | 232 | (sizeof(struct GNUNET_REVOCATION_Pow) != |
238 | GNUNET_DISK_fn_write (filename, | 233 | GNUNET_DISK_fn_write (filename, |
239 | &rd, | 234 | &proof_of_work, |
240 | sizeof(rd), | 235 | sizeof(struct GNUNET_REVOCATION_Pow), |
241 | GNUNET_DISK_PERM_USER_READ | 236 | GNUNET_DISK_PERM_USER_READ |
242 | | GNUNET_DISK_PERM_USER_WRITE))) | 237 | | GNUNET_DISK_PERM_USER_WRITE))) |
243 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); | 238 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); |
@@ -252,15 +247,16 @@ sync_rd (const struct RevocationData *rd) | |||
252 | static void | 247 | static void |
253 | calculate_pow_shutdown (void *cls) | 248 | calculate_pow_shutdown (void *cls) |
254 | { | 249 | { |
255 | struct RevocationData *rd = cls; | 250 | struct GNUNET_REVOCATION_PowCalculationHandle *ph = cls; |
256 | 251 | fprintf (stderr, "%s", _ ("Cancelling calculation.\n")); | |
252 | sync_pow (); | ||
257 | if (NULL != pow_task) | 253 | if (NULL != pow_task) |
258 | { | 254 | { |
259 | GNUNET_SCHEDULER_cancel (pow_task); | 255 | GNUNET_SCHEDULER_cancel (pow_task); |
260 | pow_task = NULL; | 256 | pow_task = NULL; |
261 | } | 257 | } |
262 | sync_rd (rd); | 258 | if (NULL != ph) |
263 | GNUNET_free (rd); | 259 | GNUNET_REVOCATION_pow_stop (ph); |
264 | } | 260 | } |
265 | 261 | ||
266 | 262 | ||
@@ -272,38 +268,26 @@ calculate_pow_shutdown (void *cls) | |||
272 | static void | 268 | static void |
273 | calculate_pow (void *cls) | 269 | calculate_pow (void *cls) |
274 | { | 270 | { |
275 | struct RevocationData *rd = cls; | 271 | struct GNUNET_REVOCATION_PowCalculationHandle *ph = cls; |
276 | 272 | ||
277 | /* store temporary results */ | 273 | /* store temporary results */ |
278 | pow_task = NULL; | 274 | pow_task = NULL; |
279 | if (0 == (rd->pow % 128)) | 275 | if (0 == (pow_passes % 128)) |
280 | sync_rd (rd); | 276 | sync_pow (); |
281 | /* display progress estimate */ | ||
282 | if ((0 == ((1 << matching_bits) / 100 / 50)) || | ||
283 | (0 == (rd->pow % ((1 << matching_bits) / 100 / 50)))) | ||
284 | fprintf (stderr, "%s", "."); | ||
285 | if ((0 != rd->pow) && ((0 == ((1 << matching_bits) / 100)) || | ||
286 | (0 == (rd->pow % ((1 << matching_bits) / 100))))) | ||
287 | fprintf (stderr, | ||
288 | " - @ %3u%% (estimate)\n", | ||
289 | (unsigned int) (rd->pow * 100) / (1 << matching_bits)); | ||
290 | /* actually do POW calculation */ | 277 | /* actually do POW calculation */ |
291 | rd->pow++; | 278 | if (GNUNET_OK == GNUNET_REVOCATION_pow_round (ph)) |
292 | if (GNUNET_OK == GNUNET_REVOCATION_check_pow (&rd->key, | ||
293 | rd->pow, | ||
294 | (unsigned int) matching_bits)) | ||
295 | { | 279 | { |
296 | if ((NULL != filename) && | 280 | if ((NULL != filename) && |
297 | (sizeof(struct RevocationData) != | 281 | (sizeof(struct GNUNET_REVOCATION_Pow) != |
298 | GNUNET_DISK_fn_write (filename, | 282 | GNUNET_DISK_fn_write (filename, |
299 | rd, | 283 | &proof_of_work, |
300 | sizeof(struct RevocationData), | 284 | sizeof(struct GNUNET_REVOCATION_Pow), |
301 | GNUNET_DISK_PERM_USER_READ | 285 | GNUNET_DISK_PERM_USER_READ |
302 | | GNUNET_DISK_PERM_USER_WRITE))) | 286 | | GNUNET_DISK_PERM_USER_WRITE))) |
303 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); | 287 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); |
304 | if (perform) | 288 | if (perform) |
305 | { | 289 | { |
306 | perform_revocation (rd); | 290 | perform_revocation (); |
307 | } | 291 | } |
308 | else | 292 | else |
309 | { | 293 | { |
@@ -316,7 +300,19 @@ calculate_pow (void *cls) | |||
316 | } | 300 | } |
317 | return; | 301 | return; |
318 | } | 302 | } |
319 | pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, rd); | 303 | pow_passes++; |
304 | /** | ||
305 | * Otherwise CTRL-C does not work | ||
306 | */ | ||
307 | if (0 == pow_passes % 128) | ||
308 | pow_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, | ||
309 | &calculate_pow, | ||
310 | ph); | ||
311 | else | ||
312 | pow_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, | ||
313 | &calculate_pow, | ||
314 | ph); | ||
315 | |||
320 | } | 316 | } |
321 | 317 | ||
322 | 318 | ||
@@ -329,8 +325,9 @@ calculate_pow (void *cls) | |||
329 | static void | 325 | static void |
330 | ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego) | 326 | ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego) |
331 | { | 327 | { |
332 | struct RevocationData *rd; | ||
333 | struct GNUNET_CRYPTO_EcdsaPublicKey key; | 328 | struct GNUNET_CRYPTO_EcdsaPublicKey key; |
329 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | ||
330 | struct GNUNET_REVOCATION_PowCalculationHandle *ph = NULL; | ||
334 | 331 | ||
335 | el = NULL; | 332 | el = NULL; |
336 | if (NULL == ego) | 333 | if (NULL == ego) |
@@ -340,44 +337,55 @@ ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego) | |||
340 | return; | 337 | return; |
341 | } | 338 | } |
342 | GNUNET_IDENTITY_ego_get_public_key (ego, &key); | 339 | GNUNET_IDENTITY_ego_get_public_key (ego, &key); |
343 | rd = GNUNET_new (struct RevocationData); | 340 | privkey = GNUNET_IDENTITY_ego_get_private_key (ego); |
341 | memset (&proof_of_work, 0, sizeof (proof_of_work)); | ||
344 | if ((NULL != filename) && (GNUNET_YES == GNUNET_DISK_file_test (filename)) && | 342 | if ((NULL != filename) && (GNUNET_YES == GNUNET_DISK_file_test (filename)) && |
345 | (sizeof(struct RevocationData) == | 343 | (sizeof(proof_of_work) == |
346 | GNUNET_DISK_fn_read (filename, rd, sizeof(struct RevocationData)))) | 344 | GNUNET_DISK_fn_read (filename, &proof_of_work, sizeof(proof_of_work)))) |
347 | { | 345 | { |
348 | if (0 != GNUNET_memcmp (&rd->key, &key)) | 346 | if (0 != GNUNET_memcmp (&proof_of_work.key, &key)) |
349 | { | 347 | { |
350 | fprintf (stderr, | 348 | fprintf (stderr, |
351 | _ ("Error: revocation certificate in `%s' is not for `%s'\n"), | 349 | _ ("Error: revocation certificate in `%s' is not for `%s'\n"), |
352 | filename, | 350 | filename, |
353 | revoke_ego); | 351 | revoke_ego); |
354 | GNUNET_free (rd); | ||
355 | return; | 352 | return; |
356 | } | 353 | } |
357 | } | 354 | if (GNUNET_YES == |
358 | else | 355 | GNUNET_REVOCATION_check_pow (&proof_of_work, |
359 | { | 356 | (unsigned int) matching_bits, |
360 | GNUNET_REVOCATION_sign_revocation (GNUNET_IDENTITY_ego_get_private_key ( | 357 | epoch_duration)) |
361 | ego), | 358 | { |
362 | &rd->sig); | 359 | fprintf (stderr, "%s", _ ("Revocation certificate ready\n")); |
363 | rd->key = key; | 360 | if (perform) |
364 | } | 361 | perform_revocation (); |
365 | if (GNUNET_YES == | 362 | else |
366 | GNUNET_REVOCATION_check_pow (&key, rd->pow, (unsigned int) matching_bits)) | 363 | GNUNET_SCHEDULER_shutdown (); |
367 | { | 364 | return; |
368 | fprintf (stderr, "%s", _ ("Revocation certificate ready\n")); | 365 | } |
369 | if (perform) | 366 | /** |
370 | perform_revocation (rd); | 367 | * Certificate not yet ready |
371 | else | 368 | */ |
372 | GNUNET_SCHEDULER_shutdown (); | 369 | fprintf (stderr, |
373 | GNUNET_free (rd); | 370 | "%s", |
374 | return; | 371 | _ ("Continuing calculation where left off...\n")); |
372 | ph = GNUNET_REVOCATION_pow_start (&proof_of_work, | ||
373 | epochs, | ||
374 | matching_bits); | ||
375 | } | 375 | } |
376 | fprintf (stderr, | 376 | fprintf (stderr, |
377 | "%s", | 377 | "%s", |
378 | _ ("Revocation certificate not ready, calculating proof of work\n")); | 378 | _ ("Revocation certificate not ready, calculating proof of work\n")); |
379 | pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, rd); | 379 | if (NULL == ph) |
380 | GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, rd); | 380 | { |
381 | GNUNET_REVOCATION_pow_init (privkey, | ||
382 | &proof_of_work); | ||
383 | ph = GNUNET_REVOCATION_pow_start (&proof_of_work, | ||
384 | epochs, /* Epochs */ | ||
385 | matching_bits); | ||
386 | } | ||
387 | pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, ph); | ||
388 | GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, ph); | ||
381 | } | 389 | } |
382 | 390 | ||
383 | 391 | ||
@@ -396,7 +404,6 @@ run (void *cls, | |||
396 | const struct GNUNET_CONFIGURATION_Handle *c) | 404 | const struct GNUNET_CONFIGURATION_Handle *c) |
397 | { | 405 | { |
398 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; | 406 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; |
399 | struct RevocationData rd; | ||
400 | 407 | ||
401 | cfg = c; | 408 | cfg = c; |
402 | if (NULL != test_ego) | 409 | if (NULL != test_ego) |
@@ -429,6 +436,17 @@ run (void *cls, | |||
429 | "WORKBITS"); | 436 | "WORKBITS"); |
430 | return; | 437 | return; |
431 | } | 438 | } |
439 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, | ||
440 | "REVOCATION", | ||
441 | "EPOCH_DURATION", | ||
442 | &epoch_duration)) | ||
443 | { | ||
444 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | ||
445 | "REVOCATION", | ||
446 | "EPOCH_DURATION"); | ||
447 | return; | ||
448 | } | ||
449 | |||
432 | if (NULL != revoke_ego) | 450 | if (NULL != revoke_ego) |
433 | { | 451 | { |
434 | if (! perform && (NULL == filename)) | 452 | if (! perform && (NULL == filename)) |
@@ -445,7 +463,9 @@ run (void *cls, | |||
445 | } | 463 | } |
446 | if ((NULL != filename) && (perform)) | 464 | if ((NULL != filename) && (perform)) |
447 | { | 465 | { |
448 | if (sizeof(rd) != GNUNET_DISK_fn_read (filename, &rd, sizeof(rd))) | 466 | if (sizeof(proof_of_work) != GNUNET_DISK_fn_read (filename, |
467 | &proof_of_work, | ||
468 | sizeof(proof_of_work))) | ||
449 | { | 469 | { |
450 | fprintf (stderr, | 470 | fprintf (stderr, |
451 | _ ("Failed to read revocation certificate from `%s'\n"), | 471 | _ ("Failed to read revocation certificate from `%s'\n"), |
@@ -454,18 +474,20 @@ run (void *cls, | |||
454 | } | 474 | } |
455 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 475 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); |
456 | if (GNUNET_YES != | 476 | if (GNUNET_YES != |
457 | GNUNET_REVOCATION_check_pow (&rd.key, | 477 | GNUNET_REVOCATION_check_pow (&proof_of_work, |
458 | rd.pow, | 478 | (unsigned int) matching_bits, |
459 | (unsigned int) matching_bits)) | 479 | epoch_duration)) |
460 | { | 480 | { |
461 | struct RevocationData *cp = GNUNET_new (struct RevocationData); | 481 | struct GNUNET_REVOCATION_PowCalculationHandle *ph; |
482 | ph = GNUNET_REVOCATION_pow_start (&proof_of_work, | ||
483 | epochs, /* Epochs */ | ||
484 | matching_bits); | ||
462 | 485 | ||
463 | *cp = rd; | 486 | pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, ph); |
464 | pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, cp); | 487 | GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, ph); |
465 | GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, cp); | ||
466 | return; | 488 | return; |
467 | } | 489 | } |
468 | perform_revocation (&rd); | 490 | perform_revocation (); |
469 | return; | 491 | return; |
470 | } | 492 | } |
471 | fprintf (stderr, "%s", _ ("No action specified. Nothing to do.\n")); | 493 | fprintf (stderr, "%s", _ ("No action specified. Nothing to do.\n")); |
@@ -511,6 +533,12 @@ main (int argc, char *const *argv) | |||
511 | gettext_noop ( | 533 | gettext_noop ( |
512 | "test if the public key KEY has been revoked"), | 534 | "test if the public key KEY has been revoked"), |
513 | &test_ego), | 535 | &test_ego), |
536 | GNUNET_GETOPT_option_uint ('e', | ||
537 | "epochs", | ||
538 | "EPOCHS", | ||
539 | gettext_noop ( | ||
540 | "number of epochs to calculate for"), | ||
541 | &epochs), | ||
514 | 542 | ||
515 | GNUNET_GETOPT_OPTION_END | 543 | GNUNET_GETOPT_OPTION_END |
516 | }; | 544 | }; |
@@ -527,7 +555,7 @@ main (int argc, char *const *argv) | |||
527 | NULL)) | 555 | NULL)) |
528 | ? ret | 556 | ? ret |
529 | : 1; | 557 | : 1; |
530 | GNUNET_free ((void *) argv); | 558 | GNUNET_free_nz ((void *) argv); |
531 | return ret; | 559 | return ret; |
532 | } | 560 | } |
533 | 561 | ||
diff --git a/src/revocation/gnunet-service-revocation.c b/src/revocation/gnunet-service-revocation.c index 3e811cd9a..3c08e8452 100644 --- a/src/revocation/gnunet-service-revocation.c +++ b/src/revocation/gnunet-service-revocation.c | |||
@@ -129,6 +129,11 @@ static struct GNUNET_SET_ListenHandle *revocation_union_listen_handle; | |||
129 | static unsigned long long revocation_work_required; | 129 | static unsigned long long revocation_work_required; |
130 | 130 | ||
131 | /** | 131 | /** |
132 | * Length of an expiration expoch | ||
133 | */ | ||
134 | static struct GNUNET_TIME_Relative epoch_duration; | ||
135 | |||
136 | /** | ||
132 | * Our application ID for set union operations. Must be the | 137 | * Our application ID for set union operations. Must be the |
133 | * same for all (compatible) peers. | 138 | * same for all (compatible) peers. |
134 | */ | 139 | */ |
@@ -167,25 +172,15 @@ new_peer_entry (const struct GNUNET_PeerIdentity *peer) | |||
167 | static int | 172 | static int |
168 | verify_revoke_message (const struct RevokeMessage *rm) | 173 | verify_revoke_message (const struct RevokeMessage *rm) |
169 | { | 174 | { |
170 | if (GNUNET_YES != | 175 | if (GNUNET_YES != GNUNET_REVOCATION_check_pow (&rm->proof_of_work, |
171 | GNUNET_REVOCATION_check_pow (&rm->public_key, | 176 | (unsigned int) revocation_work_required, |
172 | rm->proof_of_work, | 177 | epoch_duration)) |
173 | (unsigned int) revocation_work_required)) | ||
174 | { | 178 | { |
175 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 179 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
176 | "Proof of work invalid!\n"); | 180 | "Proof of work invalid!\n"); |
177 | GNUNET_break_op (0); | 181 | GNUNET_break_op (0); |
178 | return GNUNET_NO; | 182 | return GNUNET_NO; |
179 | } | 183 | } |
180 | if (GNUNET_OK != | ||
181 | GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_REVOCATION, | ||
182 | &rm->purpose, | ||
183 | &rm->signature, | ||
184 | &rm->public_key)) | ||
185 | { | ||
186 | GNUNET_break_op (0); | ||
187 | return GNUNET_NO; | ||
188 | } | ||
189 | return GNUNET_YES; | 184 | return GNUNET_YES; |
190 | } | 185 | } |
191 | 186 | ||
@@ -308,7 +303,7 @@ publicize_rm (const struct RevokeMessage *rm) | |||
308 | struct GNUNET_HashCode hc; | 303 | struct GNUNET_HashCode hc; |
309 | struct GNUNET_SET_Element e; | 304 | struct GNUNET_SET_Element e; |
310 | 305 | ||
311 | GNUNET_CRYPTO_hash (&rm->public_key, | 306 | GNUNET_CRYPTO_hash (&rm->proof_of_work.key, |
312 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), | 307 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), |
313 | &hc); | 308 | &hc); |
314 | if (GNUNET_YES == | 309 | if (GNUNET_YES == |
@@ -848,6 +843,20 @@ run (void *cls, | |||
848 | GNUNET_free (fn); | 843 | GNUNET_free (fn); |
849 | return; | 844 | return; |
850 | } | 845 | } |
846 | if (GNUNET_OK != | ||
847 | GNUNET_CONFIGURATION_get_value_time (cfg, | ||
848 | "REVOCATION", | ||
849 | "EPOCH_DURATION", | ||
850 | &epoch_duration)) | ||
851 | { | ||
852 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | ||
853 | "REVOCATION", | ||
854 | "EPOCH_DURATION"); | ||
855 | GNUNET_SCHEDULER_shutdown (); | ||
856 | GNUNET_free (fn); | ||
857 | return; | ||
858 | } | ||
859 | |||
851 | revocation_set = GNUNET_SET_create (cfg, | 860 | revocation_set = GNUNET_SET_create (cfg, |
852 | GNUNET_SET_OPERATION_UNION); | 861 | GNUNET_SET_OPERATION_UNION); |
853 | revocation_union_listen_handle | 862 | revocation_union_listen_handle |
@@ -893,7 +902,7 @@ run (void *cls, | |||
893 | return; | 902 | return; |
894 | } | 903 | } |
895 | GNUNET_break (0 == ntohl (rm->reserved)); | 904 | GNUNET_break (0 == ntohl (rm->reserved)); |
896 | GNUNET_CRYPTO_hash (&rm->public_key, | 905 | GNUNET_CRYPTO_hash (&rm->proof_of_work.key, |
897 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), | 906 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), |
898 | &hc); | 907 | &hc); |
899 | GNUNET_break (GNUNET_OK == | 908 | GNUNET_break (GNUNET_OK == |
diff --git a/src/revocation/plugin_block_revocation.c b/src/revocation/plugin_block_revocation.c index 8d16b8781..291c56f70 100644 --- a/src/revocation/plugin_block_revocation.c +++ b/src/revocation/plugin_block_revocation.c | |||
@@ -52,6 +52,7 @@ | |||
52 | struct InternalContext | 52 | struct InternalContext |
53 | { | 53 | { |
54 | unsigned int matching_bits; | 54 | unsigned int matching_bits; |
55 | struct GNUNET_TIME_Relative epoch_duration; | ||
55 | }; | 56 | }; |
56 | 57 | ||
57 | 58 | ||
@@ -142,24 +143,15 @@ block_plugin_revocation_evaluate (void *cls, | |||
142 | GNUNET_break_op (0); | 143 | GNUNET_break_op (0); |
143 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 144 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
144 | } | 145 | } |
145 | if (GNUNET_YES != | 146 | if (0 >= |
146 | GNUNET_REVOCATION_check_pow (&rm->public_key, | 147 | GNUNET_REVOCATION_check_pow (&rm->proof_of_work, |
147 | rm->proof_of_work, | 148 | ic->matching_bits, |
148 | ic->matching_bits)) | 149 | ic->epoch_duration)) |
149 | { | 150 | { |
150 | GNUNET_break_op (0); | 151 | GNUNET_break_op (0); |
151 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 152 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
152 | } | 153 | } |
153 | if (GNUNET_OK != | 154 | GNUNET_CRYPTO_hash (&rm->proof_of_work.key, |
154 | GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_REVOCATION, | ||
155 | &rm->purpose, | ||
156 | &rm->signature, | ||
157 | &rm->public_key)) | ||
158 | { | ||
159 | GNUNET_break_op (0); | ||
160 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
161 | } | ||
162 | GNUNET_CRYPTO_hash (&rm->public_key, | ||
163 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), | 155 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), |
164 | &chash); | 156 | &chash); |
165 | if (GNUNET_YES == | 157 | if (GNUNET_YES == |
@@ -195,7 +187,7 @@ block_plugin_revocation_get_key (void *cls, | |||
195 | GNUNET_break_op (0); | 187 | GNUNET_break_op (0); |
196 | return GNUNET_SYSERR; | 188 | return GNUNET_SYSERR; |
197 | } | 189 | } |
198 | GNUNET_CRYPTO_hash (&rm->public_key, | 190 | GNUNET_CRYPTO_hash (&rm->proof_of_work.key, |
199 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), | 191 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), |
200 | key); | 192 | key); |
201 | return GNUNET_OK; | 193 | return GNUNET_OK; |
@@ -218,6 +210,7 @@ libgnunet_plugin_block_revocation_init (void *cls) | |||
218 | struct GNUNET_BLOCK_PluginFunctions *api; | 210 | struct GNUNET_BLOCK_PluginFunctions *api; |
219 | struct InternalContext *ic; | 211 | struct InternalContext *ic; |
220 | unsigned long long matching_bits; | 212 | unsigned long long matching_bits; |
213 | struct GNUNET_TIME_Relative epoch_duration; | ||
221 | 214 | ||
222 | if (GNUNET_OK != | 215 | if (GNUNET_OK != |
223 | GNUNET_CONFIGURATION_get_value_number (cfg, | 216 | GNUNET_CONFIGURATION_get_value_number (cfg, |
@@ -225,6 +218,12 @@ libgnunet_plugin_block_revocation_init (void *cls) | |||
225 | "WORKBITS", | 218 | "WORKBITS", |
226 | &matching_bits)) | 219 | &matching_bits)) |
227 | return NULL; | 220 | return NULL; |
221 | if (GNUNET_OK != | ||
222 | GNUNET_CONFIGURATION_get_value_time (cfg, | ||
223 | "REVOCATION", | ||
224 | "EPOCH_DURATION", | ||
225 | &epoch_duration)) | ||
226 | return NULL; | ||
228 | 227 | ||
229 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 228 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
230 | api->evaluate = &block_plugin_revocation_evaluate; | 229 | api->evaluate = &block_plugin_revocation_evaluate; |
@@ -233,6 +232,7 @@ libgnunet_plugin_block_revocation_init (void *cls) | |||
233 | api->types = types; | 232 | api->types = types; |
234 | ic = GNUNET_new (struct InternalContext); | 233 | ic = GNUNET_new (struct InternalContext); |
235 | ic->matching_bits = (unsigned int) matching_bits; | 234 | ic->matching_bits = (unsigned int) matching_bits; |
235 | ic->epoch_duration = epoch_duration; | ||
236 | api->cls = ic; | 236 | api->cls = ic; |
237 | return api; | 237 | return api; |
238 | } | 238 | } |
diff --git a/src/revocation/revocation.conf.in b/src/revocation/revocation.conf.in index 5ad41cd49..346168785 100644 --- a/src/revocation/revocation.conf.in +++ b/src/revocation/revocation.conf.in | |||
@@ -14,5 +14,6 @@ UNIX_MATCH_GID = YES | |||
14 | # (using only a single-core) with SCRYPT. | 14 | # (using only a single-core) with SCRYPT. |
15 | # DO NOT CHANGE THIS VALUE, doing so will break the protocol! | 15 | # DO NOT CHANGE THIS VALUE, doing so will break the protocol! |
16 | WORKBITS = 25 | 16 | WORKBITS = 25 |
17 | EPOCH_DURATION = 356 d | ||
17 | 18 | ||
18 | DATABASE = $GNUNET_DATA_HOME/revocation.dat | 19 | DATABASE = $GNUNET_DATA_HOME/revocation.dat |
diff --git a/src/revocation/revocation.h b/src/revocation/revocation.h index b6e7a07ec..868c2b853 100644 --- a/src/revocation/revocation.h +++ b/src/revocation/revocation.h | |||
@@ -27,6 +27,7 @@ | |||
27 | #define REVOCATION_H | 27 | #define REVOCATION_H |
28 | 28 | ||
29 | #include "gnunet_util_lib.h" | 29 | #include "gnunet_util_lib.h" |
30 | #include "gnunet_revocation_service.h" | ||
30 | 31 | ||
31 | GNUNET_NETWORK_STRUCT_BEGIN | 32 | GNUNET_NETWORK_STRUCT_BEGIN |
32 | 33 | ||
@@ -91,23 +92,7 @@ struct RevokeMessage | |||
91 | /** | 92 | /** |
92 | * Number that causes a hash collision with the @e public_key. | 93 | * Number that causes a hash collision with the @e public_key. |
93 | */ | 94 | */ |
94 | uint64_t proof_of_work GNUNET_PACKED; | 95 | struct GNUNET_REVOCATION_Pow proof_of_work; |
95 | |||
96 | /** | ||
97 | * Signature confirming revocation. | ||
98 | */ | ||
99 | struct GNUNET_CRYPTO_EcdsaSignature signature; | ||
100 | |||
101 | /** | ||
102 | * Must have purpose #GNUNET_SIGNATURE_PURPOSE_REVOCATION, | ||
103 | * size expands over the public key. (@deprecated) | ||
104 | */ | ||
105 | struct GNUNET_CRYPTO_EccSignaturePurpose purpose; | ||
106 | |||
107 | /** | ||
108 | * Key to revoke. | ||
109 | */ | ||
110 | struct GNUNET_CRYPTO_EcdsaPublicKey public_key; | ||
111 | }; | 96 | }; |
112 | 97 | ||
113 | 98 | ||
diff --git a/src/revocation/revocation_api.c b/src/revocation/revocation_api.c index 4755d4816..18a312ab8 100644 --- a/src/revocation/revocation_api.c +++ b/src/revocation/revocation_api.c | |||
@@ -27,8 +27,7 @@ | |||
27 | #include "gnunet_signatures.h" | 27 | #include "gnunet_signatures.h" |
28 | #include "gnunet_protocols.h" | 28 | #include "gnunet_protocols.h" |
29 | #include "revocation.h" | 29 | #include "revocation.h" |
30 | #include <gcrypt.h> | 30 | #include <inttypes.h> |
31 | |||
32 | 31 | ||
33 | /** | 32 | /** |
34 | * Handle for the key revocation query. | 33 | * Handle for the key revocation query. |
@@ -53,6 +52,58 @@ struct GNUNET_REVOCATION_Query | |||
53 | 52 | ||
54 | 53 | ||
55 | /** | 54 | /** |
55 | * Helper struct that holds a found pow nonce | ||
56 | * and the corresponding number of leading zeroes. | ||
57 | */ | ||
58 | struct BestPow | ||
59 | { | ||
60 | /** | ||
61 | * PoW nonce | ||
62 | */ | ||
63 | uint64_t pow; | ||
64 | |||
65 | /** | ||
66 | * Corresponding zero bits in hash | ||
67 | */ | ||
68 | unsigned int bits; | ||
69 | }; | ||
70 | |||
71 | |||
72 | /** | ||
73 | * The handle to a PoW calculation. | ||
74 | * Used in iterative PoW rounds. | ||
75 | */ | ||
76 | struct GNUNET_REVOCATION_PowCalculationHandle | ||
77 | { | ||
78 | /** | ||
79 | * Current set of found PoWs | ||
80 | */ | ||
81 | struct BestPow best[POW_COUNT]; | ||
82 | |||
83 | /** | ||
84 | * The final PoW result data structure. | ||
85 | */ | ||
86 | struct GNUNET_REVOCATION_Pow *pow; | ||
87 | |||
88 | /** | ||
89 | * The current nonce to try | ||
90 | */ | ||
91 | uint64_t current_pow; | ||
92 | |||
93 | /** | ||
94 | * Epochs how long the PoW should be valid. | ||
95 | * This is added on top of the difficulty in the PoW. | ||
96 | */ | ||
97 | unsigned int epochs; | ||
98 | |||
99 | /** | ||
100 | * The difficulty (leading zeros) to achieve. | ||
101 | */ | ||
102 | unsigned int difficulty; | ||
103 | |||
104 | }; | ||
105 | |||
106 | /** | ||
56 | * Generic error handler, called with the appropriate | 107 | * Generic error handler, called with the appropriate |
57 | * error code and the same closure specified at the creation of | 108 | * error code and the same closure specified at the creation of |
58 | * the message queue. | 109 | * the message queue. |
@@ -235,6 +286,7 @@ handle_revocation_response (void *cls, | |||
235 | * @param key public key of the key to revoke | 286 | * @param key public key of the key to revoke |
236 | * @param sig signature to use on the revocation (should have been | 287 | * @param sig signature to use on the revocation (should have been |
237 | * created using #GNUNET_REVOCATION_sign_revocation). | 288 | * created using #GNUNET_REVOCATION_sign_revocation). |
289 | * @param ts revocation timestamp | ||
238 | * @param pow proof of work to use (should have been created by | 290 | * @param pow proof of work to use (should have been created by |
239 | * iteratively calling #GNUNET_REVOCATION_check_pow) | 291 | * iteratively calling #GNUNET_REVOCATION_check_pow) |
240 | * @param func funtion to call with the result of the check | 292 | * @param func funtion to call with the result of the check |
@@ -245,9 +297,7 @@ handle_revocation_response (void *cls, | |||
245 | */ | 297 | */ |
246 | struct GNUNET_REVOCATION_Handle * | 298 | struct GNUNET_REVOCATION_Handle * |
247 | GNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg, | 299 | GNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg, |
248 | const struct GNUNET_CRYPTO_EcdsaPublicKey *key, | 300 | const struct GNUNET_REVOCATION_Pow *pow, |
249 | const struct GNUNET_CRYPTO_EcdsaSignature *sig, | ||
250 | uint64_t pow, | ||
251 | GNUNET_REVOCATION_Callback func, | 301 | GNUNET_REVOCATION_Callback func, |
252 | void *func_cls) | 302 | void *func_cls) |
253 | { | 303 | { |
@@ -261,23 +311,39 @@ GNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
261 | GNUNET_MQ_handler_end () | 311 | GNUNET_MQ_handler_end () |
262 | }; | 312 | }; |
263 | unsigned long long matching_bits; | 313 | unsigned long long matching_bits; |
314 | struct GNUNET_TIME_Relative epoch_duration; | ||
264 | struct RevokeMessage *rm; | 315 | struct RevokeMessage *rm; |
265 | struct GNUNET_MQ_Envelope *env; | 316 | struct GNUNET_MQ_Envelope *env; |
266 | 317 | ||
267 | if ((GNUNET_OK == | 318 | if ((GNUNET_OK != |
268 | GNUNET_CONFIGURATION_get_value_number (cfg, | 319 | GNUNET_CONFIGURATION_get_value_number (cfg, |
269 | "REVOCATION", | 320 | "REVOCATION", |
270 | "WORKBITS", | 321 | "WORKBITS", |
271 | &matching_bits)) && | 322 | &matching_bits))) |
272 | (GNUNET_YES != | 323 | { |
273 | GNUNET_REVOCATION_check_pow (key, | 324 | GNUNET_break (0); |
274 | pow, | 325 | GNUNET_free (h); |
275 | (unsigned int) matching_bits))) | 326 | return NULL; |
327 | } | ||
328 | if ((GNUNET_OK != | ||
329 | GNUNET_CONFIGURATION_get_value_time (cfg, | ||
330 | "REVOCATION", | ||
331 | "EPOCH_DURATION", | ||
332 | &epoch_duration))) | ||
276 | { | 333 | { |
277 | GNUNET_break (0); | 334 | GNUNET_break (0); |
278 | GNUNET_free (h); | 335 | GNUNET_free (h); |
279 | return NULL; | 336 | return NULL; |
280 | } | 337 | } |
338 | if (GNUNET_YES != GNUNET_REVOCATION_check_pow (pow, | ||
339 | (unsigned int) matching_bits, | ||
340 | epoch_duration)) | ||
341 | { | ||
342 | GNUNET_break (0); | ||
343 | GNUNET_free (h); | ||
344 | return NULL; | ||
345 | } | ||
346 | |||
281 | 347 | ||
282 | h->mq = GNUNET_CLIENT_connect (cfg, | 348 | h->mq = GNUNET_CLIENT_connect (cfg, |
283 | "revocation", | 349 | "revocation", |
@@ -294,12 +360,7 @@ GNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
294 | env = GNUNET_MQ_msg (rm, | 360 | env = GNUNET_MQ_msg (rm, |
295 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE); | 361 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE); |
296 | rm->reserved = htonl (0); | 362 | rm->reserved = htonl (0); |
297 | rm->proof_of_work = pow; | 363 | rm->proof_of_work = *pow; |
298 | rm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION); | ||
299 | rm->purpose.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) | ||
300 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); | ||
301 | rm->public_key = *key; | ||
302 | rm->signature = *sig; | ||
303 | GNUNET_MQ_send (h->mq, | 364 | GNUNET_MQ_send (h->mq, |
304 | env); | 365 | env); |
305 | return h; | 366 | return h; |
@@ -342,56 +403,263 @@ count_leading_zeroes (const struct GNUNET_HashCode *hash) | |||
342 | 403 | ||
343 | 404 | ||
344 | /** | 405 | /** |
345 | * Check if the given proof-of-work value | 406 | * Calculate the average zeros in the pows. |
346 | * would be acceptable for revoking the given key. | ||
347 | * | 407 | * |
348 | * @param key key to check for | 408 | * @param ph the PowHandle |
349 | * @param pow proof of work value | 409 | * @return the average number of zeroes. |
410 | */ | ||
411 | static unsigned int | ||
412 | calculate_score (const struct GNUNET_REVOCATION_PowCalculationHandle *ph) | ||
413 | { | ||
414 | double sum = 0.0; | ||
415 | for (unsigned int j = 0; j<POW_COUNT; j++) | ||
416 | sum += ph->best[j].bits; | ||
417 | double avg = sum / POW_COUNT; | ||
418 | return avg; | ||
419 | } | ||
420 | |||
421 | |||
422 | /** | ||
423 | * Check if the given proof-of-work is valid. | ||
424 | * | ||
425 | * @param pow proof of work | ||
350 | * @param matching_bits how many bits must match (configuration) | 426 | * @param matching_bits how many bits must match (configuration) |
427 | * @param epoch_duration length of single epoch in configuration | ||
428 | * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not | ||
429 | */ | ||
430 | enum GNUNET_GenericReturnValue | ||
431 | GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_Pow *pow, | ||
432 | unsigned int difficulty, | ||
433 | struct GNUNET_TIME_Relative epoch_duration) | ||
434 | { | ||
435 | char buf[sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) | ||
436 | + sizeof (struct GNUNET_TIME_AbsoluteNBO) | ||
437 | + sizeof (uint64_t)] GNUNET_ALIGN; | ||
438 | struct GNUNET_REVOCATION_SignaturePurpose spurp; | ||
439 | struct GNUNET_HashCode result; | ||
440 | struct GNUNET_TIME_Absolute ts; | ||
441 | struct GNUNET_TIME_Absolute exp; | ||
442 | struct GNUNET_TIME_Relative ttl; | ||
443 | struct GNUNET_TIME_Relative buffer; | ||
444 | unsigned int score = 0; | ||
445 | unsigned int tmp_score = 0; | ||
446 | unsigned int epochs; | ||
447 | uint64_t pow_val; | ||
448 | |||
449 | /** | ||
450 | * Check if signature valid | ||
451 | */ | ||
452 | spurp.key = pow->key; | ||
453 | spurp.timestamp = pow->timestamp; | ||
454 | spurp.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION); | ||
455 | spurp.purpose.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) | ||
456 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) | ||
457 | + sizeof (struct GNUNET_TIME_AbsoluteNBO)); | ||
458 | if (GNUNET_OK != | ||
459 | GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_REVOCATION, | ||
460 | &spurp.purpose, | ||
461 | &pow->signature, | ||
462 | &pow->key)) | ||
463 | { | ||
464 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
465 | "Proof of work signature invalid!\n"); | ||
466 | return GNUNET_NO; | ||
467 | } | ||
468 | |||
469 | /** | ||
470 | * First, check if any duplicates are in the PoW set | ||
471 | */ | ||
472 | for (unsigned int i = 0; i < POW_COUNT; i++) | ||
473 | { | ||
474 | for (unsigned int j = i + 1; j < POW_COUNT; j++) | ||
475 | { | ||
476 | if (pow->pow[i] == pow->pow[j]) | ||
477 | return GNUNET_NO; | ||
478 | } | ||
479 | } | ||
480 | GNUNET_memcpy (&buf[sizeof(uint64_t)], | ||
481 | &pow->timestamp, | ||
482 | sizeof (uint64_t)); | ||
483 | GNUNET_memcpy (&buf[sizeof(uint64_t) * 2], | ||
484 | &pow->key, | ||
485 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); | ||
486 | for (unsigned int i = 0; i < POW_COUNT; i++) | ||
487 | { | ||
488 | pow_val = GNUNET_ntohll (pow->pow[i]); | ||
489 | GNUNET_memcpy (buf, &pow_val, sizeof(uint64_t)); | ||
490 | GNUNET_CRYPTO_pow_hash ("gnunet-revocation-proof-of-work", | ||
491 | buf, | ||
492 | sizeof(buf), | ||
493 | &result); | ||
494 | tmp_score = count_leading_zeroes (&result); | ||
495 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
496 | "Score %u with %" PRIu64 " (#%u)\n", | ||
497 | tmp_score, pow_val, i); | ||
498 | score += tmp_score; | ||
499 | |||
500 | } | ||
501 | score = score / POW_COUNT; | ||
502 | if (score < difficulty) | ||
503 | return GNUNET_NO; | ||
504 | epochs = score - difficulty; | ||
505 | |||
506 | /** | ||
507 | * Check expiration | ||
508 | */ | ||
509 | ts = GNUNET_TIME_absolute_ntoh (pow->timestamp); | ||
510 | ttl = GNUNET_TIME_relative_multiply (epoch_duration, | ||
511 | epochs); | ||
512 | /** | ||
513 | * Extend by 10% for unsynchronized clocks | ||
514 | */ | ||
515 | buffer = GNUNET_TIME_relative_divide (epoch_duration, | ||
516 | 10); | ||
517 | exp = GNUNET_TIME_absolute_add (ts, ttl); | ||
518 | exp = GNUNET_TIME_absolute_add (exp, | ||
519 | buffer); | ||
520 | |||
521 | if (0 != GNUNET_TIME_absolute_get_remaining (ts).rel_value_us) | ||
522 | return GNUNET_NO; /* Not yet valid. */ | ||
523 | /* Revert to actual start time */ | ||
524 | ts = GNUNET_TIME_absolute_add (ts, | ||
525 | buffer); | ||
526 | |||
527 | if (0 == GNUNET_TIME_absolute_get_remaining (exp).rel_value_us) | ||
528 | return GNUNET_NO; /* expired */ | ||
529 | return GNUNET_YES; | ||
530 | } | ||
531 | |||
532 | |||
533 | /** | ||
534 | * Initializes a fresh PoW computation. | ||
535 | * | ||
536 | * @param key the key to calculate the PoW for. | ||
537 | * @param[out] pow starting point for PoW calculation (not yet valid) | ||
538 | */ | ||
539 | void | ||
540 | GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | ||
541 | struct GNUNET_REVOCATION_Pow *pow) | ||
542 | { | ||
543 | struct GNUNET_TIME_Absolute ts = GNUNET_TIME_absolute_get (); | ||
544 | struct GNUNET_REVOCATION_SignaturePurpose rp; | ||
545 | |||
546 | /** | ||
547 | * Predate the validity period to prevent rejections due to | ||
548 | * unsynchronized clocks | ||
549 | */ | ||
550 | ts = GNUNET_TIME_absolute_subtract (ts, | ||
551 | GNUNET_TIME_UNIT_WEEKS); | ||
552 | |||
553 | pow->timestamp = GNUNET_TIME_absolute_hton (ts); | ||
554 | rp.timestamp = pow->timestamp; | ||
555 | rp.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION); | ||
556 | rp.purpose.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) | ||
557 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) | ||
558 | + sizeof (struct GNUNET_TIME_AbsoluteNBO)); | ||
559 | GNUNET_CRYPTO_ecdsa_key_get_public (key, &pow->key); | ||
560 | rp.key = pow->key; | ||
561 | GNUNET_assert (GNUNET_OK == | ||
562 | GNUNET_CRYPTO_ecdsa_sign_ (key, | ||
563 | &rp.purpose, | ||
564 | &pow->signature)); | ||
565 | } | ||
566 | |||
567 | |||
568 | /** | ||
569 | * Starts a proof-of-work calculation given the pow object as well as | ||
570 | * target epochs and difficulty. | ||
571 | * | ||
572 | * @param pow the PoW to based calculations on. | ||
573 | * @param epochs the number of epochs for which the PoW must be valid. | ||
574 | * @param difficulty the base difficulty of the PoW. | ||
575 | * @return a handle for use in PoW rounds | ||
576 | */ | ||
577 | struct GNUNET_REVOCATION_PowCalculationHandle* | ||
578 | GNUNET_REVOCATION_pow_start (struct GNUNET_REVOCATION_Pow *pow, | ||
579 | int epochs, | ||
580 | unsigned int difficulty) | ||
581 | { | ||
582 | struct GNUNET_REVOCATION_PowCalculationHandle *pc; | ||
583 | |||
584 | pc = GNUNET_new (struct GNUNET_REVOCATION_PowCalculationHandle); | ||
585 | pc->pow = pow; | ||
586 | pc->current_pow = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
587 | UINT64_MAX); | ||
588 | pc->difficulty = difficulty; | ||
589 | pc->epochs = epochs; | ||
590 | return pc; | ||
591 | } | ||
592 | |||
593 | |||
594 | /** | ||
595 | * Calculate a key revocation valid for broadcasting for a number | ||
596 | * of epochs. | ||
597 | * | ||
598 | * @param pc handle to the PoW, initially called with NULL. | ||
599 | * @param epochs number of epochs for which the revocation must be valid. | ||
600 | * @param pow current pow value to try | ||
601 | * @param difficulty current base difficulty to achieve | ||
351 | * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not | 602 | * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not |
352 | */ | 603 | */ |
353 | int | 604 | enum GNUNET_GenericReturnValue |
354 | GNUNET_REVOCATION_check_pow (const struct GNUNET_CRYPTO_EcdsaPublicKey *key, | 605 | GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc) |
355 | uint64_t pow, | ||
356 | unsigned int matching_bits) | ||
357 | { | 606 | { |
358 | char buf[sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) | 607 | char buf[sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) |
359 | + sizeof(pow)] GNUNET_ALIGN; | 608 | + sizeof (uint64_t) |
609 | + sizeof (uint64_t)] GNUNET_ALIGN; | ||
360 | struct GNUNET_HashCode result; | 610 | struct GNUNET_HashCode result; |
611 | unsigned int zeros; | ||
612 | |||
613 | pc->current_pow++; | ||
361 | 614 | ||
362 | GNUNET_memcpy (buf, &pow, sizeof(pow)); | 615 | /** |
363 | GNUNET_memcpy (&buf[sizeof(pow)], key, | 616 | * Do not try duplicates |
617 | */ | ||
618 | for (unsigned int i = 0; i < POW_COUNT; i++) | ||
619 | if (pc->current_pow == pc->best[i].pow) | ||
620 | return GNUNET_NO; | ||
621 | |||
622 | GNUNET_memcpy (buf, &pc->current_pow, sizeof(uint64_t)); | ||
623 | GNUNET_memcpy (&buf[sizeof(uint64_t)], | ||
624 | &pc->pow->timestamp, | ||
625 | sizeof (uint64_t)); | ||
626 | GNUNET_memcpy (&buf[sizeof(uint64_t) * 2], | ||
627 | &pc->pow->key, | ||
364 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); | 628 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); |
365 | GNUNET_CRYPTO_pow_hash ("gnunet-revocation-proof-of-work", | 629 | GNUNET_CRYPTO_pow_hash ("gnunet-revocation-proof-of-work", |
366 | buf, | 630 | buf, |
367 | sizeof(buf), | 631 | sizeof(buf), |
368 | &result); | 632 | &result); |
369 | return (count_leading_zeroes (&result) >= | 633 | zeros = count_leading_zeroes (&result); |
370 | matching_bits) ? GNUNET_YES : GNUNET_NO; | 634 | for (unsigned int i = 0; i < POW_COUNT; i++) |
635 | { | ||
636 | if (pc->best[i].bits < zeros) | ||
637 | { | ||
638 | pc->best[i].bits = zeros; | ||
639 | pc->best[i].pow = pc->current_pow; | ||
640 | pc->pow->pow[i] = GNUNET_htonll (pc->current_pow); | ||
641 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
642 | "New best score %u with %" PRIu64 " (#%u)\n", | ||
643 | zeros, pc->current_pow, i); | ||
644 | break; | ||
645 | } | ||
646 | } | ||
647 | return calculate_score (pc) >= pc->difficulty + pc->epochs ? GNUNET_YES : | ||
648 | GNUNET_NO; | ||
371 | } | 649 | } |
372 | 650 | ||
373 | 651 | ||
374 | /** | 652 | /** |
375 | * Create a revocation signature. | 653 | * Stop a PoW calculation |
376 | * | 654 | * |
377 | * @param key private key of the key to revoke | 655 | * @param pc the calculation to clean up |
378 | * @param sig where to write the revocation signature | 656 | * @return #GNUNET_YES if pow valid, #GNUNET_NO if pow was set but is not |
657 | * valid | ||
379 | */ | 658 | */ |
380 | void | 659 | void |
381 | GNUNET_REVOCATION_sign_revocation (const struct | 660 | GNUNET_REVOCATION_pow_stop (struct GNUNET_REVOCATION_PowCalculationHandle *pc) |
382 | GNUNET_CRYPTO_EcdsaPrivateKey *key, | ||
383 | struct GNUNET_CRYPTO_EcdsaSignature *sig) | ||
384 | { | 661 | { |
385 | struct RevokeMessage rm; | 662 | GNUNET_free (pc); |
386 | |||
387 | rm.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION); | ||
388 | rm.purpose.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) | ||
389 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); | ||
390 | GNUNET_CRYPTO_ecdsa_key_get_public (key, &rm.public_key); | ||
391 | GNUNET_assert (GNUNET_OK == | ||
392 | GNUNET_CRYPTO_ecdsa_sign_ (key, | ||
393 | &rm.purpose, | ||
394 | sig)); | ||
395 | } | 663 | } |
396 | 664 | ||
397 | 665 | ||
diff --git a/src/revocation/test_revocation.c b/src/revocation/test_revocation.c index 012bac09e..f193d5f6c 100644 --- a/src/revocation/test_revocation.c +++ b/src/revocation/test_revocation.c | |||
@@ -45,7 +45,7 @@ struct TestPeer | |||
45 | struct GNUNET_IDENTITY_EgoLookup *ego_lookup; | 45 | struct GNUNET_IDENTITY_EgoLookup *ego_lookup; |
46 | struct GNUNET_REVOCATION_Handle *revok_handle; | 46 | struct GNUNET_REVOCATION_Handle *revok_handle; |
47 | struct GNUNET_CORE_Handle *ch; | 47 | struct GNUNET_CORE_Handle *ch; |
48 | uint64_t pow; | 48 | struct GNUNET_REVOCATION_PowCalculationHandle *pow; |
49 | }; | 49 | }; |
50 | 50 | ||
51 | static struct TestPeer testpeers[2]; | 51 | static struct TestPeer testpeers[2]; |
@@ -131,7 +131,7 @@ check_revocation (void *cls) | |||
131 | 131 | ||
132 | 132 | ||
133 | static void | 133 | static void |
134 | revocation_cb (void *cls, int is_valid) | 134 | revocation_cb (void *cls, enum GNUNET_GenericReturnValue is_valid) |
135 | { | 135 | { |
136 | testpeers[1].revok_handle = NULL; | 136 | testpeers[1].revok_handle = NULL; |
137 | if (GNUNET_NO == is_valid) | 137 | if (GNUNET_NO == is_valid) |
@@ -141,11 +141,14 @@ revocation_cb (void *cls, int is_valid) | |||
141 | } | 141 | } |
142 | } | 142 | } |
143 | 143 | ||
144 | struct GNUNET_REVOCATION_Pow proof_of_work; | ||
145 | |||
144 | 146 | ||
145 | static void | 147 | static void |
146 | ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego) | 148 | ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego) |
147 | { | 149 | { |
148 | static int completed = 0; | 150 | static int completed = 0; |
151 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | ||
149 | 152 | ||
150 | if ((NULL != ego) && (cls == &testpeers[0])) | 153 | if ((NULL != ego) && (cls == &testpeers[0])) |
151 | { | 154 | { |
@@ -159,17 +162,20 @@ ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego) | |||
159 | testpeers[1].ego_lookup = NULL; | 162 | testpeers[1].ego_lookup = NULL; |
160 | testpeers[1].privkey = GNUNET_IDENTITY_ego_get_private_key (ego); | 163 | testpeers[1].privkey = GNUNET_IDENTITY_ego_get_private_key (ego); |
161 | GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[1].pubkey); | 164 | GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[1].pubkey); |
162 | GNUNET_REVOCATION_sign_revocation (testpeers[1].privkey, &testpeers[1].sig); | ||
163 | |||
164 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Calculating proof of work...\n"); | 165 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Calculating proof of work...\n"); |
165 | testpeers[1].pow = 0; | 166 | privkey = GNUNET_IDENTITY_ego_get_private_key (ego); |
167 | memset (&proof_of_work, 0, sizeof (proof_of_work)); | ||
168 | GNUNET_REVOCATION_pow_init (privkey, | ||
169 | &proof_of_work); | ||
170 | testpeers[1].pow = GNUNET_REVOCATION_pow_start (&proof_of_work, | ||
171 | 1, | ||
172 | 5); | ||
166 | int res = | 173 | int res = |
167 | GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey, testpeers[1].pow, 5); | 174 | GNUNET_REVOCATION_pow_round (testpeers[1].pow); |
168 | while (GNUNET_OK != res) | 175 | while (GNUNET_OK != res) |
169 | { | 176 | { |
170 | testpeers[1].pow++; | ||
171 | res = | 177 | res = |
172 | GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey, testpeers[1].pow, 5); | 178 | GNUNET_REVOCATION_pow_round (testpeers[1].pow); |
173 | } | 179 | } |
174 | fprintf (stderr, "Done calculating proof of work\n"); | 180 | fprintf (stderr, "Done calculating proof of work\n"); |
175 | completed++; | 181 | completed++; |
@@ -178,11 +184,10 @@ ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego) | |||
178 | { | 184 | { |
179 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Egos retrieved\n"); | 185 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Egos retrieved\n"); |
180 | testpeers[1].revok_handle = GNUNET_REVOCATION_revoke (testpeers[1].cfg, | 186 | testpeers[1].revok_handle = GNUNET_REVOCATION_revoke (testpeers[1].cfg, |
181 | &testpeers[1].pubkey, | 187 | &proof_of_work, |
182 | &testpeers[1].sig, | ||
183 | testpeers[1].pow, | ||
184 | &revocation_cb, | 188 | &revocation_cb, |
185 | NULL); | 189 | NULL); |
190 | GNUNET_REVOCATION_pow_stop (testpeers[1].pow); | ||
186 | } | 191 | } |
187 | } | 192 | } |
188 | 193 | ||
diff --git a/src/revocation/test_revocation.conf b/src/revocation/test_revocation.conf index 3b04150c1..66e2cdcc9 100644 --- a/src/revocation/test_revocation.conf +++ b/src/revocation/test_revocation.conf | |||
@@ -7,6 +7,7 @@ SERVICEHOME=$GNUNET_TMP/test-revocation-service | |||
7 | [revocation] | 7 | [revocation] |
8 | WORKBITS = 3 | 8 | WORKBITS = 3 |
9 | IMMEDIATE_START = YES | 9 | IMMEDIATE_START = YES |
10 | EPOCH_DURATION = 365 d | ||
10 | 11 | ||
11 | [identity] | 12 | [identity] |
12 | # Directory where we store information about our egos | 13 | # Directory where we store information about our egos |
diff --git a/src/statistics/gnunet-statistics.c b/src/statistics/gnunet-statistics.c index 47bdbf2c1..63afde877 100644 --- a/src/statistics/gnunet-statistics.c +++ b/src/statistics/gnunet-statistics.c | |||
@@ -881,7 +881,7 @@ main (int argc, char *const *argv) | |||
881 | num_nodes, | 881 | num_nodes, |
882 | 0); | 882 | 0); |
883 | GNUNET_free_non_null (remote_host); | 883 | GNUNET_free_non_null (remote_host); |
884 | GNUNET_free ((void *) argv); | 884 | GNUNET_free_nz ((void *) argv); |
885 | return ret; | 885 | return ret; |
886 | } | 886 | } |
887 | 887 | ||
diff --git a/src/template/gnunet-template.c b/src/template/gnunet-template.c index b33cbcc64..5e250bbdf 100644 --- a/src/template/gnunet-template.c +++ b/src/template/gnunet-template.c | |||
@@ -78,7 +78,7 @@ main (int argc, char *const *argv) | |||
78 | NULL)) | 78 | NULL)) |
79 | ? ret | 79 | ? ret |
80 | : 1; | 80 | : 1; |
81 | GNUNET_free ((void *) argv); | 81 | GNUNET_free_nz ((void *) argv); |
82 | return ret; | 82 | return ret; |
83 | } | 83 | } |
84 | 84 | ||
diff --git a/src/testbed/gnunet-daemon-latency-logger.c b/src/testbed/gnunet-daemon-latency-logger.c index 0af718a63..c13750db7 100644 --- a/src/testbed/gnunet-daemon-latency-logger.c +++ b/src/testbed/gnunet-daemon-latency-logger.c | |||
@@ -317,6 +317,6 @@ main (int argc, char *const *argv) | |||
317 | _ ( | 317 | _ ( |
318 | "Daemon to log latency values of connections to neighbours"), | 318 | "Daemon to log latency values of connections to neighbours"), |
319 | options, &run, NULL)) ? 0 : 1; | 319 | options, &run, NULL)) ? 0 : 1; |
320 | GNUNET_free ((void *) argv); | 320 | GNUNET_free_nz ((void *) argv); |
321 | return ret; | 321 | return ret; |
322 | } | 322 | } |
diff --git a/src/testbed/gnunet-daemon-testbed-blacklist.c b/src/testbed/gnunet-daemon-testbed-blacklist.c index 070583941..c82f8075f 100644 --- a/src/testbed/gnunet-daemon-testbed-blacklist.c +++ b/src/testbed/gnunet-daemon-testbed-blacklist.c | |||
@@ -249,6 +249,6 @@ main (int argc, char *const *argv) | |||
249 | _ ( | 249 | _ ( |
250 | "Daemon to restrict incoming transport layer connections during testbed deployments"), | 250 | "Daemon to restrict incoming transport layer connections during testbed deployments"), |
251 | options, &run, NULL)) ? 0 : 1; | 251 | options, &run, NULL)) ? 0 : 1; |
252 | GNUNET_free ((void *) argv); | 252 | GNUNET_free_nz ((void *) argv); |
253 | return ret; | 253 | return ret; |
254 | } | 254 | } |
diff --git a/src/testbed/gnunet-daemon-testbed-underlay.c b/src/testbed/gnunet-daemon-testbed-underlay.c index 09dfee5a6..2bff7cdd4 100644 --- a/src/testbed/gnunet-daemon-testbed-underlay.c +++ b/src/testbed/gnunet-daemon-testbed-underlay.c | |||
@@ -476,6 +476,6 @@ main (int argc, char *const *argv) | |||
476 | ( | 476 | ( |
477 | "Daemon to restrict underlay network in testbed deployments"), | 477 | "Daemon to restrict underlay network in testbed deployments"), |
478 | options, &run, NULL)) ? 0 : 1; | 478 | options, &run, NULL)) ? 0 : 1; |
479 | GNUNET_free ((void *) argv); | 479 | GNUNET_free_nz ((void *) argv); |
480 | return ret; | 480 | return ret; |
481 | } | 481 | } |
diff --git a/src/testbed/gnunet-testbed-profiler.c b/src/testbed/gnunet-testbed-profiler.c index cfc6367fe..90813c8e5 100644 --- a/src/testbed/gnunet-testbed-profiler.c +++ b/src/testbed/gnunet-testbed-profiler.c | |||
@@ -318,7 +318,7 @@ main (int argc, char *const *argv) | |||
318 | ret = | 318 | ret = |
319 | GNUNET_PROGRAM_run (argc, argv, "gnunet-testbed-profiler", binaryHelp, | 319 | GNUNET_PROGRAM_run (argc, argv, "gnunet-testbed-profiler", binaryHelp, |
320 | options, &run, NULL); | 320 | options, &run, NULL); |
321 | GNUNET_free ((void *) argv); | 321 | GNUNET_free_nz ((void *) argv); |
322 | if (GNUNET_OK != ret) | 322 | if (GNUNET_OK != ret) |
323 | return ret; | 323 | return ret; |
324 | if (GNUNET_OK != result) | 324 | if (GNUNET_OK != result) |
diff --git a/src/testing/gnunet-testing.c b/src/testing/gnunet-testing.c index b850d6b13..a9e5042b2 100644 --- a/src/testing/gnunet-testing.c +++ b/src/testing/gnunet-testing.c | |||
@@ -436,7 +436,7 @@ main (int argc, char *const *argv) | |||
436 | GNUNET_YES)) | 436 | GNUNET_YES)) |
437 | ? ret | 437 | ? ret |
438 | : 1; | 438 | : 1; |
439 | GNUNET_free ((void *) argv); | 439 | GNUNET_free_nz ((void *) argv); |
440 | return ret; | 440 | return ret; |
441 | } | 441 | } |
442 | 442 | ||
diff --git a/src/testing/testing.c b/src/testing/testing.c index 3e447e1ff..23bc40d7e 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c | |||
@@ -1343,7 +1343,7 @@ GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer, | |||
1343 | return; | 1343 | return; |
1344 | } | 1344 | } |
1345 | peer->id = GNUNET_new (struct GNUNET_PeerIdentity); | 1345 | peer->id = GNUNET_new (struct GNUNET_PeerIdentity); |
1346 | GNUNET_free ( | 1346 | GNUNET_free_nz ( |
1347 | GNUNET_TESTING_hostkey_get (peer->system, peer->key_number, peer->id)); | 1347 | GNUNET_TESTING_hostkey_get (peer->system, peer->key_number, peer->id)); |
1348 | GNUNET_memcpy (id, peer->id, sizeof(struct GNUNET_PeerIdentity)); | 1348 | GNUNET_memcpy (id, peer->id, sizeof(struct GNUNET_PeerIdentity)); |
1349 | } | 1349 | } |
diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c index 261d825ea..c6f600df1 100644 --- a/src/topology/gnunet-daemon-topology.c +++ b/src/topology/gnunet-daemon-topology.c | |||
@@ -1130,7 +1130,7 @@ main (int argc, char *const *argv) | |||
1130 | NULL)) | 1130 | NULL)) |
1131 | ? 0 | 1131 | ? 0 |
1132 | : 1; | 1132 | : 1; |
1133 | GNUNET_free ((void *) argv); | 1133 | GNUNET_free_nz ((void *) argv); |
1134 | return ret; | 1134 | return ret; |
1135 | } | 1135 | } |
1136 | 1136 | ||
diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c index 82ee309a5..bbfacbffd 100644 --- a/src/transport/gnunet-communicator-tcp.c +++ b/src/transport/gnunet-communicator-tcp.c | |||
@@ -2285,7 +2285,7 @@ main (int argc, char *const *argv) | |||
2285 | NULL)) | 2285 | NULL)) |
2286 | ? 0 | 2286 | ? 0 |
2287 | : 1; | 2287 | : 1; |
2288 | GNUNET_free ((void *) argv); | 2288 | GNUNET_free_nz ((void *) argv); |
2289 | return ret; | 2289 | return ret; |
2290 | } | 2290 | } |
2291 | 2291 | ||
diff --git a/src/transport/gnunet-communicator-udp.c b/src/transport/gnunet-communicator-udp.c index e0b14f669..72e84567a 100644 --- a/src/transport/gnunet-communicator-udp.c +++ b/src/transport/gnunet-communicator-udp.c | |||
@@ -2791,7 +2791,7 @@ main (int argc, char *const *argv) | |||
2791 | NULL)) | 2791 | NULL)) |
2792 | ? 0 | 2792 | ? 0 |
2793 | : 1; | 2793 | : 1; |
2794 | GNUNET_free ((void *) argv); | 2794 | GNUNET_free_nz ((void *) argv); |
2795 | return ret; | 2795 | return ret; |
2796 | } | 2796 | } |
2797 | 2797 | ||
diff --git a/src/transport/gnunet-communicator-unix.c b/src/transport/gnunet-communicator-unix.c index 7d7f18a9c..31d2e4ed3 100644 --- a/src/transport/gnunet-communicator-unix.c +++ b/src/transport/gnunet-communicator-unix.c | |||
@@ -1135,7 +1135,7 @@ main (int argc, char *const *argv) | |||
1135 | NULL)) | 1135 | NULL)) |
1136 | ? 0 | 1136 | ? 0 |
1137 | : 1; | 1137 | : 1; |
1138 | GNUNET_free ((void *) argv); | 1138 | GNUNET_free_nz ((void *) argv); |
1139 | return ret; | 1139 | return ret; |
1140 | } | 1140 | } |
1141 | 1141 | ||
diff --git a/src/transport/gnunet-transport-profiler.c b/src/transport/gnunet-transport-profiler.c index 6c13cf059..81678fa20 100644 --- a/src/transport/gnunet-transport-profiler.c +++ b/src/transport/gnunet-transport-profiler.c | |||
@@ -615,7 +615,7 @@ main (int argc, char *const *argv) | |||
615 | options, | 615 | options, |
616 | &run, | 616 | &run, |
617 | NULL); | 617 | NULL); |
618 | GNUNET_free ((void *) argv); | 618 | GNUNET_free_nz ((void *) argv); |
619 | if (GNUNET_OK == res) | 619 | if (GNUNET_OK == res) |
620 | return ret; | 620 | return ret; |
621 | return 1; | 621 | return 1; |
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c index 5a437b660..35da5ec10 100644 --- a/src/transport/gnunet-transport.c +++ b/src/transport/gnunet-transport.c | |||
@@ -1427,7 +1427,7 @@ main (int argc, char *const *argv) | |||
1427 | options, | 1427 | options, |
1428 | &run, | 1428 | &run, |
1429 | NULL); | 1429 | NULL); |
1430 | GNUNET_free ((void *) argv); | 1430 | GNUNET_free_nz ((void *) argv); |
1431 | if (GNUNET_OK == res) | 1431 | if (GNUNET_OK == res) |
1432 | return ret; | 1432 | return ret; |
1433 | return 1; | 1433 | return 1; |
diff --git a/src/transport/tcp_service_legacy.c b/src/transport/tcp_service_legacy.c index f207863f9..fb4e9c3c9 100644 --- a/src/transport/tcp_service_legacy.c +++ b/src/transport/tcp_service_legacy.c | |||
@@ -1474,7 +1474,7 @@ shutdown: | |||
1474 | i = 0; | 1474 | i = 0; |
1475 | if (NULL != sctx.addrs) | 1475 | if (NULL != sctx.addrs) |
1476 | while (NULL != sctx.addrs[i]) | 1476 | while (NULL != sctx.addrs[i]) |
1477 | GNUNET_free (sctx.addrs[i++]); | 1477 | GNUNET_free_nz (sctx.addrs[i++]); |
1478 | GNUNET_free_non_null (sctx.addrs); | 1478 | GNUNET_free_non_null (sctx.addrs); |
1479 | GNUNET_free_non_null (sctx.addrlens); | 1479 | GNUNET_free_non_null (sctx.addrlens); |
1480 | GNUNET_free_non_null (logfile); | 1480 | GNUNET_free_non_null (logfile); |
@@ -1631,7 +1631,7 @@ LEGACY_SERVICE_stop (struct LEGACY_SERVICE_Context *sctx) | |||
1631 | { | 1631 | { |
1632 | i = 0; | 1632 | i = 0; |
1633 | while (NULL != sctx->addrs[i]) | 1633 | while (NULL != sctx->addrs[i]) |
1634 | GNUNET_free (sctx->addrs[i++]); | 1634 | GNUNET_free_nz (sctx->addrs[i++]); |
1635 | GNUNET_free (sctx->addrs); | 1635 | GNUNET_free (sctx->addrs); |
1636 | } | 1636 | } |
1637 | GNUNET_free_non_null (sctx->addrlens); | 1637 | GNUNET_free_non_null (sctx->addrlens); |
diff --git a/src/transport/test_plugin_transport.c b/src/transport/test_plugin_transport.c index 10e07dae5..04687d845 100644 --- a/src/transport/test_plugin_transport.c +++ b/src/transport/test_plugin_transport.c | |||
@@ -49,7 +49,7 @@ static struct GNUNET_PeerIdentity my_identity; | |||
49 | /** | 49 | /** |
50 | * Our private key. | 50 | * Our private key. |
51 | */ | 51 | */ |
52 | static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key; | 52 | static struct GNUNET_CRYPTO_EddsaPrivateKey my_private_key; |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Our configuration. | 55 | * Our configuration. |
@@ -647,16 +647,20 @@ run (void *cls, | |||
647 | } | 647 | } |
648 | 648 | ||
649 | max_connect_per_transport = (uint32_t) tneigh; | 649 | max_connect_per_transport = (uint32_t) tneigh; |
650 | my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile); | 650 | if (GNUNET_SYSERR == |
651 | GNUNET_free (keyfile); | 651 | GNUNET_CRYPTO_eddsa_key_from_file (keyfile, |
652 | if (NULL == my_private_key) | 652 | GNUNET_YES, |
653 | &my_private_key)) | ||
653 | { | 654 | { |
655 | GNUNET_free (keyfile); | ||
654 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 656 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
655 | "Could not access hostkey. Exiting.\n"); | 657 | "Could not access hostkey. Exiting.\n"); |
656 | end_badly_now (); | 658 | end_badly_now (); |
657 | return; | 659 | return; |
658 | } | 660 | } |
659 | GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key); | 661 | GNUNET_free (keyfile); |
662 | GNUNET_CRYPTO_eddsa_key_get_public (&my_private_key, | ||
663 | &my_identity.public_key); | ||
660 | 664 | ||
661 | hello = GNUNET_HELLO_create (&my_identity.public_key, NULL, NULL, GNUNET_NO); | 665 | hello = GNUNET_HELLO_create (&my_identity.public_key, NULL, NULL, GNUNET_NO); |
662 | 666 | ||
diff --git a/src/util/Makefile.am b/src/util/Makefile.am index ae72abb44..fed0dad79 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am | |||
@@ -133,6 +133,7 @@ libgnunetutil_la_LIBADD = \ | |||
133 | $(LIBIDN) $(LIBIDN2) \ | 133 | $(LIBIDN) $(LIBIDN2) \ |
134 | $(Z_LIBS) \ | 134 | $(Z_LIBS) \ |
135 | -lunistring \ | 135 | -lunistring \ |
136 | -largon2 \ | ||
136 | $(XLIB) \ | 137 | $(XLIB) \ |
137 | $(PTHREAD) | 138 | $(PTHREAD) |
138 | 139 | ||
diff --git a/src/util/buffer.c b/src/util/buffer.c index 8efb3e284..dabf630c7 100644 --- a/src/util/buffer.c +++ b/src/util/buffer.c | |||
@@ -56,6 +56,8 @@ GNUNET_buffer_ensure_remaining (struct GNUNET_Buffer *buf, | |||
56 | { | 56 | { |
57 | size_t new_capacity = buf->position + n; | 57 | size_t new_capacity = buf->position + n; |
58 | 58 | ||
59 | /* guard against overflow */ | ||
60 | GNUNET_assert (new_capacity >= buf->position); | ||
59 | if (new_capacity <= buf->capacity) | 61 | if (new_capacity <= buf->capacity) |
60 | return; | 62 | return; |
61 | /* warn if calculation of expected size was wrong */ | 63 | /* warn if calculation of expected size was wrong */ |
diff --git a/src/util/crypto_pow.c b/src/util/crypto_pow.c index 9b20ab345..35511a130 100644 --- a/src/util/crypto_pow.c +++ b/src/util/crypto_pow.c | |||
@@ -25,7 +25,7 @@ | |||
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_crypto_lib.h" | 27 | #include "gnunet_crypto_lib.h" |
28 | #include <gcrypt.h> | 28 | #include <argon2.h> |
29 | 29 | ||
30 | /** | 30 | /** |
31 | * Calculate the 'proof-of-work' hash (an expensive hash). | 31 | * Calculate the 'proof-of-work' hash (an expensive hash). |
@@ -43,81 +43,17 @@ GNUNET_CRYPTO_pow_hash (const char *salt, | |||
43 | size_t buf_len, | 43 | size_t buf_len, |
44 | struct GNUNET_HashCode *result) | 44 | struct GNUNET_HashCode *result) |
45 | { | 45 | { |
46 | #ifdef LSD001 | 46 | GNUNET_break (ARGON2_OK == argon2d_hash_raw (3, /* iterations */ |
47 | char twofish_iv[128 / 8]; //128 bit IV | 47 | 1024, /* memory (1 MiB) */ |
48 | char twofish_key[256 / 8]; //256 bit Key | 48 | 1, /* threads */ |
49 | char rbuf[buf_len]; | 49 | buf, |
50 | int rc; | 50 | buf_len, |
51 | gcry_cipher_hd_t handle; | 51 | salt, |
52 | strlen (salt), | ||
53 | result, | ||
54 | sizeof (struct | ||
55 | GNUNET_HashCode))); | ||
52 | 56 | ||
53 | GNUNET_break (0 == gcry_kdf_derive (buf, | ||
54 | buf_len, | ||
55 | GCRY_KDF_SCRYPT, | ||
56 | 1 /* subalgo */, | ||
57 | salt, | ||
58 | strlen (salt), | ||
59 | 2 /* iterations; keep cost of individual op small */, | ||
60 | sizeof(twofish_key), | ||
61 | &twofish_key)); | ||
62 | |||
63 | GNUNET_CRYPTO_kdf (twofish_iv, | ||
64 | sizeof (twofish_iv), | ||
65 | "gnunet-proof-of-work-iv", | ||
66 | strlen ("gnunet-proof-of-work-iv"), | ||
67 | twofish_key, | ||
68 | sizeof(twofish_key), | ||
69 | salt, | ||
70 | strlen (salt), | ||
71 | NULL, 0); | ||
72 | GNUNET_assert (0 == | ||
73 | gcry_cipher_open (&handle, GCRY_CIPHER_TWOFISH, | ||
74 | GCRY_CIPHER_MODE_CFB, 0)); | ||
75 | rc = gcry_cipher_setkey (handle, | ||
76 | twofish_key, | ||
77 | sizeof(twofish_key)); | ||
78 | GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); | ||
79 | rc = gcry_cipher_setiv (handle, | ||
80 | twofish_iv, | ||
81 | sizeof(twofish_iv)); | ||
82 | GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); | ||
83 | GNUNET_assert (0 == gcry_cipher_encrypt (handle, &rbuf, buf_len, buf, buf_len)); | ||
84 | gcry_cipher_close (handle); | ||
85 | #else | ||
86 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; | ||
87 | struct GNUNET_CRYPTO_SymmetricSessionKey skey; | ||
88 | char rbuf[buf_len]; | ||
89 | |||
90 | GNUNET_break (0 == gcry_kdf_derive (buf, | ||
91 | buf_len, | ||
92 | GCRY_KDF_SCRYPT, | ||
93 | 1 /* subalgo */, | ||
94 | salt, | ||
95 | strlen (salt), | ||
96 | 2 /* iterations; keep cost of individual op small */, | ||
97 | sizeof(skey), | ||
98 | &skey)); | ||
99 | GNUNET_CRYPTO_symmetric_derive_iv (&iv, | ||
100 | &skey, | ||
101 | "gnunet-proof-of-work-iv", | ||
102 | strlen ("gnunet-proof-of-work-iv"), | ||
103 | salt, | ||
104 | strlen (salt), | ||
105 | NULL, 0); | ||
106 | GNUNET_CRYPTO_symmetric_encrypt (buf, | ||
107 | buf_len, | ||
108 | &skey, | ||
109 | &iv, | ||
110 | &rbuf); | ||
111 | #endif | ||
112 | GNUNET_break (0 == gcry_kdf_derive (rbuf, | ||
113 | buf_len, | ||
114 | GCRY_KDF_SCRYPT, | ||
115 | 1 /* subalgo */, | ||
116 | salt, | ||
117 | strlen (salt), | ||
118 | 2 /* iterations; keep cost of individual op small */, | ||
119 | sizeof(struct GNUNET_HashCode), | ||
120 | result)); | ||
121 | } | 57 | } |
122 | 58 | ||
123 | 59 | ||
diff --git a/src/util/gnunet-config.c b/src/util/gnunet-config.c index f101e8b61..5883c1497 100644 --- a/src/util/gnunet-config.c +++ b/src/util/gnunet-config.c | |||
@@ -331,7 +331,7 @@ main (int argc, char *const *argv) | |||
331 | options, | 331 | options, |
332 | &run, | 332 | &run, |
333 | NULL); | 333 | NULL); |
334 | GNUNET_free ((void *) argv); | 334 | GNUNET_free_nz ((void *) argv); |
335 | if (GNUNET_OK == ret) | 335 | if (GNUNET_OK == ret) |
336 | return global_ret; | 336 | return global_ret; |
337 | return ret; | 337 | return ret; |
diff --git a/src/util/gnunet-ecc.c b/src/util/gnunet-ecc.c index 764a507b6..8e30ac416 100644 --- a/src/util/gnunet-ecc.c +++ b/src/util/gnunet-ecc.c | |||
@@ -501,7 +501,7 @@ main (int argc, char *const *argv) | |||
501 | NULL)) | 501 | NULL)) |
502 | ? 0 | 502 | ? 0 |
503 | : 1; | 503 | : 1; |
504 | GNUNET_free ((void *) argv); | 504 | GNUNET_free_nz ((void *) argv); |
505 | return ret; | 505 | return ret; |
506 | } | 506 | } |
507 | 507 | ||
diff --git a/src/util/gnunet-resolver.c b/src/util/gnunet-resolver.c index 6a602c64e..8a6c7fbe9 100644 --- a/src/util/gnunet-resolver.c +++ b/src/util/gnunet-resolver.c | |||
@@ -171,14 +171,18 @@ main (int argc, char *const *argv) | |||
171 | }; | 171 | }; |
172 | int ret; | 172 | int ret; |
173 | 173 | ||
174 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 174 | if (GNUNET_OK != |
175 | GNUNET_STRINGS_get_utf8_args (argc, argv, | ||
176 | &argc, &argv)) | ||
175 | return 2; | 177 | return 2; |
176 | 178 | ||
177 | ret = (GNUNET_OK == | 179 | ret = (GNUNET_OK == |
178 | GNUNET_PROGRAM_run (argc, argv, "gnunet-resolver [hostname]", | 180 | GNUNET_PROGRAM_run (argc, argv, |
181 | "gnunet-resolver [hostname]", | ||
179 | gettext_noop ("Use build-in GNUnet stub resolver"), | 182 | gettext_noop ("Use build-in GNUnet stub resolver"), |
180 | options, &run, NULL)) ? 0 : 1; | 183 | options, |
181 | GNUNET_free ((void *) argv); | 184 | &run, NULL)) ? 0 : 1; |
185 | GNUNET_free_nz ((void *) argv); | ||
182 | return ret; | 186 | return ret; |
183 | } | 187 | } |
184 | 188 | ||
diff --git a/src/util/gnunet-scrypt.c b/src/util/gnunet-scrypt.c index 8c46136b9..70ba48d82 100644 --- a/src/util/gnunet-scrypt.c +++ b/src/util/gnunet-scrypt.c | |||
@@ -322,7 +322,7 @@ main (int argc, char *const *argv) | |||
322 | NULL)) | 322 | NULL)) |
323 | ? 0 | 323 | ? 0 |
324 | : 1; | 324 | : 1; |
325 | GNUNET_free ((void *) argv); | 325 | GNUNET_free_nz ((void *) argv); |
326 | GNUNET_free_non_null (pwfn); | 326 | GNUNET_free_non_null (pwfn); |
327 | return ret; | 327 | return ret; |
328 | } | 328 | } |
diff --git a/src/util/gnunet-uri.c b/src/util/gnunet-uri.c index 84100ff56..48c46ee49 100644 --- a/src/util/gnunet-uri.c +++ b/src/util/gnunet-uri.c | |||
@@ -184,7 +184,7 @@ main (int argc, char *const *argv) | |||
184 | shc_chld = NULL; | 184 | shc_chld = NULL; |
185 | GNUNET_DISK_pipe_close (sigpipe); | 185 | GNUNET_DISK_pipe_close (sigpipe); |
186 | sigpipe = NULL; | 186 | sigpipe = NULL; |
187 | GNUNET_free ((void *) argv); | 187 | GNUNET_free_nz ((void *) argv); |
188 | return ((GNUNET_OK == ret) && (0 == exit_code)) ? 0 : 1; | 188 | return ((GNUNET_OK == ret) && (0 == exit_code)) ? 0 : 1; |
189 | } | 189 | } |
190 | 190 | ||
diff --git a/src/util/os_priority.c b/src/util/os_priority.c index 36f0d8e30..5799d893b 100644 --- a/src/util/os_priority.c +++ b/src/util/os_priority.c | |||
@@ -875,7 +875,7 @@ GNUNET_OS_start_process_s (int pipe_control, | |||
875 | binary_path, | 875 | binary_path, |
876 | argv); | 876 | argv); |
877 | while (argv_size > 0) | 877 | while (argv_size > 0) |
878 | GNUNET_free (argv[--argv_size]); | 878 | GNUNET_free_nz (argv[--argv_size]); |
879 | GNUNET_free (argv); | 879 | GNUNET_free (argv); |
880 | return proc; | 880 | return proc; |
881 | } | 881 | } |
diff --git a/src/util/scheduler.c b/src/util/scheduler.c index 45a6b61e5..93393bd7c 100644 --- a/src/util/scheduler.c +++ b/src/util/scheduler.c | |||
@@ -584,28 +584,26 @@ dump_backtrace (struct GNUNET_SCHEDULER_Task *t) | |||
584 | static void | 584 | static void |
585 | destroy_task (struct GNUNET_SCHEDULER_Task *t) | 585 | destroy_task (struct GNUNET_SCHEDULER_Task *t) |
586 | { | 586 | { |
587 | unsigned int i; | ||
588 | |||
589 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 587 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
590 | "destroying task %p\n", | 588 | "destroying task %p\n", |
591 | t); | 589 | t); |
592 | 590 | ||
593 | if (GNUNET_YES == t->own_handles) | 591 | if (GNUNET_YES == t->own_handles) |
594 | { | 592 | { |
595 | for (i = 0; i != t->fds_len; ++i) | 593 | for (unsigned int i = 0; i != t->fds_len; ++i) |
596 | { | 594 | { |
597 | const struct GNUNET_NETWORK_Handle *fd = t->fds[i].fd; | 595 | const struct GNUNET_NETWORK_Handle *fd = t->fds[i].fd; |
598 | const struct GNUNET_DISK_FileHandle *fh = t->fds[i].fh; | 596 | const struct GNUNET_DISK_FileHandle *fh = t->fds[i].fh; |
599 | if (fd) | 597 | if (fd) |
600 | { | 598 | { |
601 | GNUNET_NETWORK_socket_free_memory_only_ ((struct | 599 | GNUNET_NETWORK_socket_free_memory_only_ ( |
602 | GNUNET_NETWORK_Handle *) fd); | 600 | (struct GNUNET_NETWORK_Handle *) fd); |
603 | } | 601 | } |
604 | if (fh) | 602 | if (fh) |
605 | { | 603 | { |
606 | // FIXME: on WIN32 this is not enough! A function | 604 | // FIXME: on WIN32 this is not enough! A function |
607 | // GNUNET_DISK_file_free_memory_only would be nice | 605 | // GNUNET_DISK_file_free_memory_only would be nice |
608 | GNUNET_free ((void *) fh); | 606 | GNUNET_free_nz ((void *) fh); |
609 | } | 607 | } |
610 | } | 608 | } |
611 | } | 609 | } |
diff --git a/src/util/test_common_allocation.c b/src/util/test_common_allocation.c index e2fc29e82..a24af7124 100644 --- a/src/util/test_common_allocation.c +++ b/src/util/test_common_allocation.c | |||
@@ -27,7 +27,7 @@ | |||
27 | 27 | ||
28 | 28 | ||
29 | static int | 29 | static int |
30 | check () | 30 | check (void) |
31 | { | 31 | { |
32 | #define MAX_TESTVAL 1024 | 32 | #define MAX_TESTVAL 1024 |
33 | char *ptrs[MAX_TESTVAL]; | 33 | char *ptrs[MAX_TESTVAL]; |
@@ -134,6 +134,28 @@ check () | |||
134 | } | 134 | } |
135 | 135 | ||
136 | 136 | ||
137 | static int | ||
138 | check2 (void) | ||
139 | { | ||
140 | char *a1 = NULL; | ||
141 | unsigned int a1_len = 0; | ||
142 | const char *a2 = "test"; | ||
143 | |||
144 | GNUNET_array_append (a1, | ||
145 | a1_len, | ||
146 | 'x'); | ||
147 | GNUNET_array_concatenate (a1, | ||
148 | a1_len, | ||
149 | a2, | ||
150 | 4); | ||
151 | GNUNET_assert (0 == strncmp ("xtest", | ||
152 | a1, | ||
153 | 5)); | ||
154 | GNUNET_assert (5 == a1_len); | ||
155 | return 0; | ||
156 | } | ||
157 | |||
158 | |||
137 | int | 159 | int |
138 | main (int argc, char *argv[]) | 160 | main (int argc, char *argv[]) |
139 | { | 161 | { |
@@ -142,7 +164,7 @@ main (int argc, char *argv[]) | |||
142 | GNUNET_log_setup ("test-common-allocation", | 164 | GNUNET_log_setup ("test-common-allocation", |
143 | "WARNING", | 165 | "WARNING", |
144 | NULL); | 166 | NULL); |
145 | ret = check (); | 167 | ret = check () | check2 (); |
146 | if (ret != 0) | 168 | if (ret != 0) |
147 | fprintf (stderr, | 169 | fprintf (stderr, |
148 | "ERROR %d.\n", | 170 | "ERROR %d.\n", |
diff --git a/src/vpn/gnunet-vpn.c b/src/vpn/gnunet-vpn.c index 6dcd227c7..a7f7fc30c 100644 --- a/src/vpn/gnunet-vpn.c +++ b/src/vpn/gnunet-vpn.c | |||
@@ -357,7 +357,7 @@ main (int argc, char *const *argv) | |||
357 | NULL)) | 357 | NULL)) |
358 | ? ret | 358 | ? ret |
359 | : 1; | 359 | : 1; |
360 | GNUNET_free ((void *) argv); | 360 | GNUNET_free_nz ((void *) argv); |
361 | return ret; | 361 | return ret; |
362 | } | 362 | } |
363 | 363 | ||