diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2024-05-26 15:30:02 +0200 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2024-05-26 15:30:02 +0200 |
commit | 81d8f82554260424ea568546ba098ea5cee3ef4b (patch) | |
tree | a8827a7967770596293366ec8d9bd1c719293977 /src/include | |
parent | 48dfc68132cd19013b5a3ce6b170099b988de96e (diff) | |
parent | af21c76e87e701fb88f7b0d535e9758ef832ec39 (diff) | |
download | gnunet-dev/thejackimonster/messenger.tar.gz gnunet-dev/thejackimonster/messenger.zip |
Merge branch 'master' into dev/thejackimonster/messengerdev/thejackimonster/messenger
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat (limited to 'src/include')
30 files changed, 1835 insertions, 2526 deletions
diff --git a/src/include/Makefile.am b/src/include/Makefile.am index 8f39faab6..6942d2d0e 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am | |||
@@ -33,7 +33,6 @@ gnunetinclude_HEADERS = \ | |||
33 | gnunet_container_lib.h \ | 33 | gnunet_container_lib.h \ |
34 | gnunet_conversation_service.h \ | 34 | gnunet_conversation_service.h \ |
35 | gnunet_core_service.h \ | 35 | gnunet_core_service.h \ |
36 | gnunet_core_testing_lib.h \ | ||
37 | gnunet_crypto_lib.h \ | 36 | gnunet_crypto_lib.h \ |
38 | gnunet_curl_lib.h \ | 37 | gnunet_curl_lib.h \ |
39 | gnunet_datacache_lib.h \ | 38 | gnunet_datacache_lib.h \ |
@@ -110,18 +109,17 @@ gnunetinclude_HEADERS = \ | |||
110 | gnunet_sq_lib.h \ | 109 | gnunet_sq_lib.h \ |
111 | gnunet_statistics_service.h \ | 110 | gnunet_statistics_service.h \ |
112 | gnunet_strings_lib.h \ | 111 | gnunet_strings_lib.h \ |
113 | gnunet_testing_barrier.h \ | ||
114 | gnunet_testing_lib.h \ | 112 | gnunet_testing_lib.h \ |
115 | gnunet_testing_plugin.h \ | 113 | gnunet_testing_arm_lib.h \ |
116 | gnunet_testing_ng_lib.h \ | 114 | gnunet_testing_core_lib.h \ |
117 | gnunet_testing_loop_lib.h \ | 115 | gnunet_testing_testbed_lib.h \ |
118 | gnunet_testing_netjail_lib.h \ | 116 | gnunet_testing_transport_lib.h \ |
117 | gnunet_testbed_lib.h \ | ||
119 | gnunet_time_lib.h \ | 118 | gnunet_time_lib.h \ |
120 | gnunet_transport_application_service.h \ | 119 | gnunet_transport_application_service.h \ |
121 | gnunet_transport_communication_service.h \ | 120 | gnunet_transport_communication_service.h \ |
122 | gnunet_transport_monitor_service.h \ | 121 | gnunet_transport_monitor_service.h \ |
123 | gnunet_transport_core_service.h \ | 122 | gnunet_transport_core_service.h \ |
124 | gnunet_transport_testing_ng_lib.h \ | ||
125 | gnunet_tun_lib.h \ | 123 | gnunet_tun_lib.h \ |
126 | gnunet_uri_lib.h \ | 124 | gnunet_uri_lib.h \ |
127 | gnunet_util_lib.h \ | 125 | gnunet_util_lib.h \ |
diff --git a/src/include/gnunet_arm_service.h b/src/include/gnunet_arm_service.h index 639e723c5..ef860bff4 100644 --- a/src/include/gnunet_arm_service.h +++ b/src/include/gnunet_arm_service.h | |||
@@ -244,8 +244,9 @@ struct GNUNET_ARM_Operation; | |||
244 | * #GNUNET_SYSERR if there was an error. | 244 | * #GNUNET_SYSERR if there was an error. |
245 | */ | 245 | */ |
246 | typedef void | 246 | typedef void |
247 | (*GNUNET_ARM_ConnectionStatusCallback) (void *cls, | 247 | (*GNUNET_ARM_ConnectionStatusCallback) ( |
248 | int connected); | 248 | void *cls, |
249 | enum GNUNET_GenericReturnValue connected); | ||
249 | 250 | ||
250 | 251 | ||
251 | /** | 252 | /** |
@@ -259,9 +260,10 @@ typedef void | |||
259 | * @param result result of the operation | 260 | * @param result result of the operation |
260 | */ | 261 | */ |
261 | typedef void | 262 | typedef void |
262 | (*GNUNET_ARM_ResultCallback) (void *cls, | 263 | (*GNUNET_ARM_ResultCallback) ( |
263 | enum GNUNET_ARM_RequestStatus rs, | 264 | void *cls, |
264 | enum GNUNET_ARM_Result result); | 265 | enum GNUNET_ARM_RequestStatus rs, |
266 | enum GNUNET_ARM_Result result); | ||
265 | 267 | ||
266 | 268 | ||
267 | /** | 269 | /** |
@@ -276,10 +278,11 @@ typedef void | |||
276 | * @param list list of services managed by arm | 278 | * @param list list of services managed by arm |
277 | */ | 279 | */ |
278 | typedef void | 280 | typedef void |
279 | (*GNUNET_ARM_ServiceListCallback) (void *cls, | 281 | (*GNUNET_ARM_ServiceListCallback) ( |
280 | enum GNUNET_ARM_RequestStatus rs, | 282 | void *cls, |
281 | unsigned int count, | 283 | enum GNUNET_ARM_RequestStatus rs, |
282 | const struct GNUNET_ARM_ServiceInfo *list); | 284 | unsigned int count, |
285 | const struct GNUNET_ARM_ServiceInfo *list); | ||
283 | 286 | ||
284 | 287 | ||
285 | /** | 288 | /** |
@@ -294,18 +297,20 @@ typedef void | |||
294 | * @return context to use for further ARM operations, NULL on error. | 297 | * @return context to use for further ARM operations, NULL on error. |
295 | */ | 298 | */ |
296 | struct GNUNET_ARM_Handle * | 299 | struct GNUNET_ARM_Handle * |
297 | GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | 300 | GNUNET_ARM_connect ( |
298 | GNUNET_ARM_ConnectionStatusCallback conn_status, | 301 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
299 | void *conn_status_cls); | 302 | GNUNET_ARM_ConnectionStatusCallback conn_status, |
303 | void *conn_status_cls); | ||
300 | 304 | ||
301 | 305 | ||
302 | /** | 306 | /** |
303 | * Disconnect from the ARM service and destroy the handle. | 307 | * Disconnect from the ARM service and destroy the handle. |
304 | * | 308 | * |
305 | * @param h the handle that was being used | 309 | * @param[in] h the handle that was being used |
306 | */ | 310 | */ |
307 | void | 311 | void |
308 | GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h); | 312 | GNUNET_ARM_disconnect ( |
313 | struct GNUNET_ARM_Handle *h); | ||
309 | 314 | ||
310 | 315 | ||
311 | /** | 316 | /** |
@@ -315,7 +320,8 @@ GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h); | |||
315 | * @param op operation to cancel | 320 | * @param op operation to cancel |
316 | */ | 321 | */ |
317 | void | 322 | void |
318 | GNUNET_ARM_operation_cancel (struct GNUNET_ARM_Operation *op); | 323 | GNUNET_ARM_operation_cancel ( |
324 | struct GNUNET_ARM_Operation *op); | ||
319 | 325 | ||
320 | 326 | ||
321 | /** | 327 | /** |
@@ -327,9 +333,10 @@ GNUNET_ARM_operation_cancel (struct GNUNET_ARM_Operation *op); | |||
327 | * @return handle for the operation, NULL on error | 333 | * @return handle for the operation, NULL on error |
328 | */ | 334 | */ |
329 | struct GNUNET_ARM_Operation * | 335 | struct GNUNET_ARM_Operation * |
330 | GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h, | 336 | GNUNET_ARM_request_service_list ( |
331 | GNUNET_ARM_ServiceListCallback cont, | 337 | struct GNUNET_ARM_Handle *h, |
332 | void *cont_cls); | 338 | GNUNET_ARM_ServiceListCallback cont, |
339 | void *cont_cls); | ||
333 | 340 | ||
334 | 341 | ||
335 | /** | 342 | /** |
@@ -347,10 +354,11 @@ GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h, | |||
347 | * @return handle for the operation, NULL on error | 354 | * @return handle for the operation, NULL on error |
348 | */ | 355 | */ |
349 | struct GNUNET_ARM_Operation * | 356 | struct GNUNET_ARM_Operation * |
350 | GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h, | 357 | GNUNET_ARM_request_service_stop ( |
351 | const char *service_name, | 358 | struct GNUNET_ARM_Handle *h, |
352 | GNUNET_ARM_ResultCallback cont, | 359 | const char *service_name, |
353 | void *cont_cls); | 360 | GNUNET_ARM_ResultCallback cont, |
361 | void *cont_cls); | ||
354 | 362 | ||
355 | 363 | ||
356 | /** | 364 | /** |
@@ -364,12 +372,12 @@ GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h, | |||
364 | * @return handle for the operation, NULL on error | 372 | * @return handle for the operation, NULL on error |
365 | */ | 373 | */ |
366 | struct GNUNET_ARM_Operation * | 374 | struct GNUNET_ARM_Operation * |
367 | GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h, | 375 | GNUNET_ARM_request_service_start ( |
368 | const char *service_name, | 376 | struct GNUNET_ARM_Handle *h, |
369 | enum GNUNET_OS_InheritStdioFlags | 377 | const char *service_name, |
370 | std_inheritance, | 378 | enum GNUNET_OS_InheritStdioFlags std_inheritance, |
371 | GNUNET_ARM_ResultCallback cont, | 379 | GNUNET_ARM_ResultCallback cont, |
372 | void *cont_cls); | 380 | void *cont_cls); |
373 | 381 | ||
374 | 382 | ||
375 | /** | 383 | /** |
@@ -386,10 +394,10 @@ struct GNUNET_ARM_MonitorHandle; | |||
386 | * @param status status of the service | 394 | * @param status status of the service |
387 | */ | 395 | */ |
388 | typedef void | 396 | typedef void |
389 | (*GNUNET_ARM_ServiceMonitorCallback) (void *cls, | 397 | (*GNUNET_ARM_ServiceMonitorCallback) ( |
390 | const char *service, | 398 | void *cls, |
391 | enum GNUNET_ARM_ServiceMonitorStatus | 399 | const char *service, |
392 | status); | 400 | enum GNUNET_ARM_ServiceMonitorStatus status); |
393 | 401 | ||
394 | 402 | ||
395 | /** | 403 | /** |
@@ -404,9 +412,10 @@ typedef void | |||
404 | * @return context to use for further ARM monitor operations, NULL on error. | 412 | * @return context to use for further ARM monitor operations, NULL on error. |
405 | */ | 413 | */ |
406 | struct GNUNET_ARM_MonitorHandle * | 414 | struct GNUNET_ARM_MonitorHandle * |
407 | GNUNET_ARM_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | 415 | GNUNET_ARM_monitor_start ( |
408 | GNUNET_ARM_ServiceMonitorCallback cont, | 416 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
409 | void *cont_cls); | 417 | GNUNET_ARM_ServiceMonitorCallback cont, |
418 | void *cont_cls); | ||
410 | 419 | ||
411 | 420 | ||
412 | /** | 421 | /** |
@@ -415,7 +424,8 @@ GNUNET_ARM_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
415 | * @param h the handle that was being used | 424 | * @param h the handle that was being used |
416 | */ | 425 | */ |
417 | void | 426 | void |
418 | GNUNET_ARM_monitor_stop (struct GNUNET_ARM_MonitorHandle *h); | 427 | GNUNET_ARM_monitor_stop ( |
428 | struct GNUNET_ARM_MonitorHandle *h); | ||
419 | 429 | ||
420 | #if 0 /* keep Emacsens' auto-indent happy */ | 430 | #if 0 /* keep Emacsens' auto-indent happy */ |
421 | { | 431 | { |
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h index 9fa3de37d..c5885e7c4 100644 --- a/src/include/gnunet_common.h +++ b/src/include/gnunet_common.h | |||
@@ -55,20 +55,20 @@ | |||
55 | #if defined(__FreeBSD__) | 55 | #if defined(__FreeBSD__) |
56 | 56 | ||
57 | #include <sys/endian.h> | 57 | #include <sys/endian.h> |
58 | #define bswap_32(x) bswap32(x) | 58 | #define bswap_32(x) bswap32 (x) |
59 | #define bswap_64(x) bswap64(x) | 59 | #define bswap_64(x) bswap64 (x) |
60 | 60 | ||
61 | #elif defined(__OpenBSD__) | 61 | #elif defined(__OpenBSD__) |
62 | 62 | ||
63 | #define bswap_32(x) swap32(x) | 63 | #define bswap_32(x) swap32 (x) |
64 | #define bswap_64(x) swap64(x) | 64 | #define bswap_64(x) swap64 (x) |
65 | 65 | ||
66 | #elif defined(__NetBSD__) | 66 | #elif defined(__NetBSD__) |
67 | 67 | ||
68 | #include <machine/bswap.h> | 68 | #include <machine/bswap.h> |
69 | #if defined(__BSWAP_RENAME) && !defined(__bswap_32) | 69 | #if defined(__BSWAP_RENAME) && ! defined(__bswap_32) |
70 | #define bswap_32(x) bswap32(x) | 70 | #define bswap_32(x) bswap32 (x) |
71 | #define bswap_64(x) bswap64(x) | 71 | #define bswap_64(x) bswap64 (x) |
72 | #endif | 72 | #endif |
73 | 73 | ||
74 | #elif defined(__linux__) || defined(GNU) | 74 | #elif defined(__linux__) || defined(GNU) |
@@ -166,15 +166,19 @@ enum GNUNET_GenericReturnValue | |||
166 | #define BYTE_SWAP_16(x) ((((x) & 0x00ff) << 8) | (((x) & 0xff00) >> 8)) | 166 | #define BYTE_SWAP_16(x) ((((x) & 0x00ff) << 8) | (((x) & 0xff00) >> 8)) |
167 | 167 | ||
168 | #define BYTE_SWAP_32(x) \ | 168 | #define BYTE_SWAP_32(x) \ |
169 | ((((x) & 0x000000ffU) << 24) | (((x) & 0x0000ff00U) << 8) \ | 169 | ((((x) & 0x000000ffU) << 24) | (((x) & 0x0000ff00U) << 8) \ |
170 | | (((x) & 0x00ff0000U) >> 8) | (((x) & 0xff000000U) >> 24)) | 170 | | (((x) & 0x00ff0000U) >> 8) | (((x) & 0xff000000U) >> 24)) |
171 | 171 | ||
172 | #define BYTE_SWAP_64(x) \ | 172 | #define BYTE_SWAP_64(x) \ |
173 | ((((x) & 0x00000000000000ffUL) << 56) | (((x) & 0x000000000000ff00UL) << 40) \ | 173 | ((((x) & 0x00000000000000ffUL) << 56) | (((x) & 0x000000000000ff00UL) << \ |
174 | | (((x) & 0x0000000000ff0000UL) << 24) | (((x) & 0x00000000ff000000UL) << 8) \ | 174 | 40) \ |
175 | | (((x) & 0x000000ff00000000UL) >> 8) | (((x) & 0x0000ff0000000000UL) >> 24) \ | 175 | | (((x) & 0x0000000000ff0000UL) << 24) | (((x) & 0x00000000ff000000UL) \ |
176 | | (((x) & 0x00ff000000000000UL) >> 40) | (((x) & 0xff00000000000000UL) >> \ | 176 | << 8) \ |
177 | 56)) | 177 | | (((x) & 0x000000ff00000000UL) >> 8) | (((x) & 0x0000ff0000000000UL) \ |
178 | >> 24) \ | ||
179 | | (((x) & 0x00ff000000000000UL) >> 40) | (((x) & 0xff00000000000000UL) \ | ||
180 | >> \ | ||
181 | 56)) | ||
178 | #endif | 182 | #endif |
179 | 183 | ||
180 | #if __BYTE_ORDER == __LITTLE_ENDIAN | 184 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
@@ -479,7 +483,7 @@ GNUNET_get_log_call_status (int caller_level, | |||
479 | 483 | ||
480 | #endif | 484 | #endif |
481 | 485 | ||
482 | 486 | /* *INDENT-OFF* */ | |
483 | /** | 487 | /** |
484 | * @ingroup logging | 488 | * @ingroup logging |
485 | * Main log function. | 489 | * Main log function. |
@@ -489,13 +493,15 @@ GNUNET_get_log_call_status (int caller_level, | |||
489 | * @param ... arguments for format string | 493 | * @param ... arguments for format string |
490 | */ | 494 | */ |
491 | void | 495 | void |
492 | GNUNET_log_nocheck (enum GNUNET_ErrorType kind, const char *message, ...) | 496 | GNUNET_log_nocheck (enum GNUNET_ErrorType kind, |
497 | const char *message, | ||
498 | ...) | ||
493 | __attribute__ ((format (printf, 2, 3))); | 499 | __attribute__ ((format (printf, 2, 3))); |
494 | 500 | ||
495 | /* from glib */ | 501 | /* from glib */ |
496 | #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) | 502 | #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) |
497 | #define _GNUNET_BOOLEAN_EXPR(expr) \ | 503 | #define _GNUNET_BOOLEAN_EXPR(expr) \ |
498 | __extension__ ({ \ | 504 | __extension__ ({ \ |
499 | int _gnunet_boolean_var_; \ | 505 | int _gnunet_boolean_var_; \ |
500 | if (expr) \ | 506 | if (expr) \ |
501 | _gnunet_boolean_var_ = 1; \ | 507 | _gnunet_boolean_var_ = 1; \ |
@@ -513,6 +519,7 @@ __attribute__ ((format (printf, 2, 3))); | |||
513 | #if ! defined(GNUNET_LOG_CALL_STATUS) | 519 | #if ! defined(GNUNET_LOG_CALL_STATUS) |
514 | #define GNUNET_LOG_CALL_STATUS -1 | 520 | #define GNUNET_LOG_CALL_STATUS -1 |
515 | #endif | 521 | #endif |
522 | /* *INDENT-ON* */ | ||
516 | 523 | ||
517 | 524 | ||
518 | /** | 525 | /** |
@@ -534,56 +541,56 @@ __attribute__ ((format (printf, 3, 4))); | |||
534 | 541 | ||
535 | #if ! defined(GNUNET_CULL_LOGGING) | 542 | #if ! defined(GNUNET_CULL_LOGGING) |
536 | #define GNUNET_log_from(kind, comp, ...) \ | 543 | #define GNUNET_log_from(kind, comp, ...) \ |
537 | do \ | 544 | do \ |
538 | { \ | 545 | { \ |
539 | static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \ | 546 | static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \ |
540 | if ((GNUNET_EXTRA_LOGGING > 0) || \ | 547 | if ((GNUNET_EXTRA_LOGGING > 0) || \ |
541 | ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \ | 548 | ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \ |
542 | { \ | 549 | { \ |
543 | if (GN_UNLIKELY (log_call_enabled == -1)) \ | 550 | if (GN_UNLIKELY (log_call_enabled == -1)) \ |
544 | log_call_enabled = \ | 551 | log_call_enabled = \ |
545 | GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \ | 552 | GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \ |
546 | (comp), \ | 553 | (comp), \ |
547 | __FILE__, \ | 554 | __FILE__, \ |
548 | __FUNCTION__, \ | 555 | __FUNCTION__, \ |
549 | __LINE__); \ | 556 | __LINE__); \ |
550 | if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \ | 557 | if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \ |
551 | { \ | 558 | { \ |
552 | GNUNET_log_skip (-1, GNUNET_NO); \ | 559 | GNUNET_log_skip (-1, GNUNET_NO); \ |
553 | } \ | 560 | } \ |
554 | else \ | 561 | else \ |
555 | { \ | 562 | { \ |
556 | if (GN_UNLIKELY (log_call_enabled)) \ | 563 | if (GN_UNLIKELY (log_call_enabled)) \ |
557 | GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__); \ | 564 | GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__); \ |
558 | } \ | 565 | } \ |
559 | } \ | 566 | } \ |
560 | } while (0) | 567 | } while (0) |
561 | 568 | ||
562 | #define GNUNET_log(kind, ...) \ | 569 | #define GNUNET_log(kind, ...) \ |
563 | do \ | 570 | do \ |
564 | { \ | 571 | { \ |
565 | static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \ | 572 | static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \ |
566 | if ((GNUNET_EXTRA_LOGGING > 0) || \ | 573 | if ((GNUNET_EXTRA_LOGGING > 0) || \ |
567 | ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \ | 574 | ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \ |
568 | { \ | 575 | { \ |
569 | if (GN_UNLIKELY (log_call_enabled == -1)) \ | 576 | if (GN_UNLIKELY (log_call_enabled == -1)) \ |
570 | log_call_enabled = \ | 577 | log_call_enabled = \ |
571 | GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \ | 578 | GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \ |
572 | NULL, \ | 579 | NULL, \ |
573 | __FILE__, \ | 580 | __FILE__, \ |
574 | __FUNCTION__, \ | 581 | __FUNCTION__, \ |
575 | __LINE__); \ | 582 | __LINE__); \ |
576 | if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \ | 583 | if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \ |
577 | { \ | 584 | { \ |
578 | GNUNET_log_skip (-1, GNUNET_NO); \ | 585 | GNUNET_log_skip (-1, GNUNET_NO); \ |
579 | } \ | 586 | } \ |
580 | else \ | 587 | else \ |
581 | { \ | 588 | { \ |
582 | if (GN_UNLIKELY (log_call_enabled)) \ | 589 | if (GN_UNLIKELY (log_call_enabled)) \ |
583 | GNUNET_log_nocheck ((kind), __VA_ARGS__); \ | 590 | GNUNET_log_nocheck ((kind), __VA_ARGS__); \ |
584 | } \ | 591 | } \ |
585 | } \ | 592 | } \ |
586 | } while (0) | 593 | } while (0) |
587 | #else | 594 | #else |
588 | #define GNUNET_log(...) | 595 | #define GNUNET_log(...) |
589 | #define GNUNET_log_from(...) | 596 | #define GNUNET_log_from(...) |
@@ -642,7 +649,7 @@ GNUNET_abort_ (void) GNUNET_NORETURN; | |||
642 | */ | 649 | */ |
643 | const char * | 650 | const char * |
644 | GNUNET_b2s (const void *buf, | 651 | GNUNET_b2s (const void *buf, |
645 | size_t buf_size); | 652 | size_t buf_size); |
646 | 653 | ||
647 | 654 | ||
648 | /** | 655 | /** |
@@ -676,7 +683,9 @@ GNUNET_log_skip (int n, int check_reset); | |||
676 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if logfile could not be opened | 683 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if logfile could not be opened |
677 | */ | 684 | */ |
678 | enum GNUNET_GenericReturnValue | 685 | enum GNUNET_GenericReturnValue |
679 | GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile); | 686 | GNUNET_log_setup (const char *comp, |
687 | const char *loglevel, | ||
688 | const char *logfile); | ||
680 | 689 | ||
681 | 690 | ||
682 | /** | 691 | /** |
@@ -690,7 +699,8 @@ GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile); | |||
690 | * @param logger_cls closure for @a logger | 699 | * @param logger_cls closure for @a logger |
691 | */ | 700 | */ |
692 | void | 701 | void |
693 | GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls); | 702 | GNUNET_logger_add (GNUNET_Logger logger, |
703 | void *logger_cls); | ||
694 | 704 | ||
695 | 705 | ||
696 | /** | 706 | /** |
@@ -701,7 +711,8 @@ GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls); | |||
701 | * @param logger_cls closure for @a logger | 711 | * @param logger_cls closure for @a logger |
702 | */ | 712 | */ |
703 | void | 713 | void |
704 | GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls); | 714 | GNUNET_logger_remove (GNUNET_Logger logger, |
715 | void *logger_cls); | ||
705 | 716 | ||
706 | 717 | ||
707 | /** | 718 | /** |
@@ -916,36 +927,37 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind); | |||
916 | * @ingroup logging | 927 | * @ingroup logging |
917 | * Use this for fatal errors that cannot be handled | 928 | * Use this for fatal errors that cannot be handled |
918 | */ | 929 | */ |
919 | #if __GNUC__ >= 6 || __clang_major__ >= 6 | 930 | #if __GNUC__ >= 6 || __clang_major__ >= 6 |
920 | #define GNUNET_assert(cond) \ | 931 | #define GNUNET_assert(cond) \ |
921 | do \ | 932 | do \ |
922 | { \ | 933 | { \ |
923 | _Pragma("GCC diagnostic push") \ | 934 | _Pragma("GCC diagnostic push") \ |
924 | _Pragma("GCC diagnostic ignored \"-Wtautological-compare\"") \ | 935 | _Pragma("GCC diagnostic ignored \"-Wtautological-compare\"") \ |
925 | if (! (cond)) \ | 936 | if (! (cond)) \ |
926 | { \ | 937 | { \ |
927 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ | 938 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ |
928 | dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \ | 939 | dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \ |
929 | __FILE__, \ | 940 | __FILE__, \ |
930 | __LINE__); \ | 941 | __LINE__); \ |
931 | GNUNET_abort_ (); \ | 942 | GNUNET_abort_ (); \ |
932 | } \ | 943 | } \ |
933 | _Pragma("GCC diagnostic pop") \ | 944 | _Pragma("GCC diagnostic pop") \ |
934 | } while (0) | 945 | } while (0) |
935 | #else | 946 | #else |
936 | /* older GCC/clangs do not support -Wtautological-compare */ | 947 | /* older GCC/clangs do not support -Wtautological-compare */ |
937 | #define GNUNET_assert(cond) \ | 948 | #define GNUNET_assert(cond) \ |
938 | do \ | 949 | do \ |
939 | { \ | 950 | { \ |
940 | if (! (cond)) \ | 951 | if (! (cond)) \ |
941 | { \ | 952 | { \ |
942 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ | 953 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ |
943 | dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \ | 954 | dgettext ("gnunet", \ |
944 | __FILE__, \ | 955 | "Assertion failed at %s:%d. Aborting.\n"), \ |
945 | __LINE__); \ | 956 | __FILE__, \ |
946 | GNUNET_abort_ (); \ | 957 | __LINE__); \ |
947 | } \ | 958 | GNUNET_abort_ (); \ |
948 | } while (0) | 959 | } \ |
960 | } while (0) | ||
949 | #endif | 961 | #endif |
950 | 962 | ||
951 | /** | 963 | /** |
@@ -953,17 +965,18 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind); | |||
953 | * Use this for fatal errors that cannot be handled | 965 | * Use this for fatal errors that cannot be handled |
954 | */ | 966 | */ |
955 | #define GNUNET_assert_at(cond, f, l) \ | 967 | #define GNUNET_assert_at(cond, f, l) \ |
956 | do \ | 968 | do \ |
957 | { \ | 969 | { \ |
958 | if (! (cond)) \ | 970 | if (! (cond)) \ |
959 | { \ | 971 | { \ |
960 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ | 972 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ |
961 | dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \ | 973 | dgettext ("gnunet", \ |
962 | f, \ | 974 | "Assertion failed at %s:%d. Aborting.\n"), \ |
963 | l); \ | 975 | f, \ |
964 | GNUNET_abort_ (); \ | 976 | l); \ |
965 | } \ | 977 | GNUNET_abort_ (); \ |
966 | } while (0) | 978 | } \ |
979 | } while (0) | ||
967 | 980 | ||
968 | 981 | ||
969 | /** | 982 | /** |
@@ -974,18 +987,20 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind); | |||
974 | * @param comp Component string to use for logging | 987 | * @param comp Component string to use for logging |
975 | */ | 988 | */ |
976 | #define GNUNET_assert_from(cond, comp) \ | 989 | #define GNUNET_assert_from(cond, comp) \ |
977 | do \ | 990 | do \ |
978 | { \ | 991 | { \ |
979 | if (! (cond)) \ | 992 | if (! (cond)) \ |
980 | { \ | 993 | { \ |
981 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, \ | 994 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, \ |
982 | comp, \ | 995 | comp, \ |
983 | dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \ | 996 | dgettext ("gnunet", \ |
984 | __FILE__, \ | 997 | "Assertion failed at %s:%d. Aborting.\n") \ |
985 | __LINE__); \ | 998 | , \ |
986 | GNUNET_abort_ (); \ | 999 | __FILE__, \ |
987 | } \ | 1000 | __LINE__); \ |
988 | } while (0) | 1001 | GNUNET_abort_ (); \ |
1002 | } \ | ||
1003 | } while (0) | ||
989 | 1004 | ||
990 | 1005 | ||
991 | #ifdef _Static_assert | 1006 | #ifdef _Static_assert |
@@ -1016,16 +1031,16 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind); | |||
1016 | * not fatal (can be handled) but should not occur. | 1031 | * not fatal (can be handled) but should not occur. |
1017 | */ | 1032 | */ |
1018 | #define GNUNET_break(cond) \ | 1033 | #define GNUNET_break(cond) \ |
1019 | do \ | 1034 | do \ |
1020 | { \ | 1035 | { \ |
1021 | if (! (cond)) \ | 1036 | if (! (cond)) \ |
1022 | { \ | 1037 | { \ |
1023 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ | 1038 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ |
1024 | dgettext ("gnunet", "Assertion failed at %s:%d.\n"), \ | 1039 | dgettext ("gnunet", "Assertion failed at %s:%d.\n"), \ |
1025 | __FILE__, \ | 1040 | __FILE__, \ |
1026 | __LINE__); \ | 1041 | __LINE__); \ |
1027 | } \ | 1042 | } \ |
1028 | } while (0) | 1043 | } while (0) |
1029 | 1044 | ||
1030 | 1045 | ||
1031 | /** | 1046 | /** |
@@ -1038,16 +1053,17 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind); | |||
1038 | * development and testing. "OP == other peer". | 1053 | * development and testing. "OP == other peer". |
1039 | */ | 1054 | */ |
1040 | #define GNUNET_break_op(cond) \ | 1055 | #define GNUNET_break_op(cond) \ |
1041 | do \ | 1056 | do \ |
1042 | { \ | 1057 | { \ |
1043 | if (! (cond)) \ | 1058 | if (! (cond)) \ |
1044 | { \ | 1059 | { \ |
1045 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, \ | 1060 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, \ |
1046 | dgettext ("gnunet", "External protocol violation detected at %s:%d.\n"), \ | 1061 | dgettext ("gnunet", \ |
1047 | __FILE__, \ | 1062 | "External protocol violation detected at %s:%d.\n"), \ |
1048 | __LINE__); \ | 1063 | __FILE__, \ |
1049 | } \ | 1064 | __LINE__); \ |
1050 | } while (0) | 1065 | } \ |
1066 | } while (0) | ||
1051 | 1067 | ||
1052 | 1068 | ||
1053 | /** | 1069 | /** |
@@ -1057,15 +1073,16 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind); | |||
1057 | * by strerror(errno). | 1073 | * by strerror(errno). |
1058 | */ | 1074 | */ |
1059 | #define GNUNET_log_strerror(level, cmd) \ | 1075 | #define GNUNET_log_strerror(level, cmd) \ |
1060 | do \ | 1076 | do \ |
1061 | { \ | 1077 | { \ |
1062 | GNUNET_log (level, \ | 1078 | GNUNET_log (level, \ |
1063 | dgettext ("gnunet", "`%s' failed at %s:%d with error: %s\n"), \ | 1079 | dgettext ("gnunet", \ |
1064 | cmd, \ | 1080 | "`%s' failed at %s:%d with error: %s\n"), \ |
1065 | __FILE__, \ | 1081 | cmd, \ |
1066 | __LINE__, \ | 1082 | __FILE__, \ |
1067 | strerror (errno)); \ | 1083 | __LINE__, \ |
1068 | } while (0) | 1084 | strerror (errno)); \ |
1085 | } while (0) | ||
1069 | 1086 | ||
1070 | 1087 | ||
1071 | /** | 1088 | /** |
@@ -1075,16 +1092,17 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind); | |||
1075 | * by strerror(errno). | 1092 | * by strerror(errno). |
1076 | */ | 1093 | */ |
1077 | #define GNUNET_log_from_strerror(level, component, cmd) \ | 1094 | #define GNUNET_log_from_strerror(level, component, cmd) \ |
1078 | do \ | 1095 | do \ |
1079 | { \ | 1096 | { \ |
1080 | GNUNET_log_from (level, \ | 1097 | GNUNET_log_from (level, \ |
1081 | component, \ | 1098 | component, \ |
1082 | dgettext ("gnunet", "`%s' failed at %s:%d with error: %s\n"), \ | 1099 | dgettext ("gnunet", \ |
1083 | cmd, \ | 1100 | "`%s' failed at %s:%d with error: %s\n"), \ |
1084 | __FILE__, \ | 1101 | cmd, \ |
1085 | __LINE__, \ | 1102 | __FILE__, \ |
1086 | strerror (errno)); \ | 1103 | __LINE__, \ |
1087 | } while (0) | 1104 | strerror (errno)); \ |
1105 | } while (0) | ||
1088 | 1106 | ||
1089 | 1107 | ||
1090 | /** | 1108 | /** |
@@ -1094,16 +1112,17 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind); | |||
1094 | * by strerror(errno). | 1112 | * by strerror(errno). |
1095 | */ | 1113 | */ |
1096 | #define GNUNET_log_strerror_file(level, cmd, filename) \ | 1114 | #define GNUNET_log_strerror_file(level, cmd, filename) \ |
1097 | do \ | 1115 | do \ |
1098 | { \ | 1116 | { \ |
1099 | GNUNET_log (level, \ | 1117 | GNUNET_log (level, \ |
1100 | dgettext ("gnunet", "`%s' failed on file `%s' at %s:%d with error: %s\n"), \ | 1118 | dgettext ("gnunet", \ |
1101 | cmd, \ | 1119 | "`%s' failed on file `%s' at %s:%d with error: %s\n"), \ |
1102 | filename, \ | 1120 | cmd, \ |
1103 | __FILE__, \ | 1121 | filename, \ |
1104 | __LINE__, \ | 1122 | __FILE__, \ |
1105 | strerror (errno)); \ | 1123 | __LINE__, \ |
1106 | } while (0) | 1124 | strerror (errno)); \ |
1125 | } while (0) | ||
1107 | 1126 | ||
1108 | 1127 | ||
1109 | /** | 1128 | /** |
@@ -1113,17 +1132,18 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind); | |||
1113 | * by strerror(errno). | 1132 | * by strerror(errno). |
1114 | */ | 1133 | */ |
1115 | #define GNUNET_log_from_strerror_file(level, component, cmd, filename) \ | 1134 | #define GNUNET_log_from_strerror_file(level, component, cmd, filename) \ |
1116 | do \ | 1135 | do \ |
1117 | { \ | 1136 | { \ |
1118 | GNUNET_log_from (level, \ | 1137 | GNUNET_log_from (level, \ |
1119 | component, \ | 1138 | component, \ |
1120 | dgettext ("gnunet", "`%s' failed on file `%s' at %s:%d with error: %s\n"), \ | 1139 | dgettext ("gnunet", \ |
1121 | cmd, \ | 1140 | "`%s' failed on file `%s' at %s:%d with error: %s\n"), \ |
1122 | filename, \ | 1141 | cmd, \ |
1123 | __FILE__, \ | 1142 | filename, \ |
1124 | __LINE__, \ | 1143 | __FILE__, \ |
1125 | strerror (errno)); \ | 1144 | __LINE__, \ |
1126 | } while (0) | 1145 | strerror (errno)); \ |
1146 | } while (0) | ||
1127 | 1147 | ||
1128 | /* ************************* endianness conversion ****************** */ | 1148 | /* ************************* endianness conversion ****************** */ |
1129 | 1149 | ||
@@ -1216,7 +1236,7 @@ GNUNET_ntoh_double (double d); | |||
1216 | * the first element! | 1236 | * the first element! |
1217 | */ | 1237 | */ |
1218 | #define GNUNET_memcmp(a, b) \ | 1238 | #define GNUNET_memcmp(a, b) \ |
1219 | ({ \ | 1239 | ({ \ |
1220 | const typeof (*b) * _a = (a); \ | 1240 | const typeof (*b) * _a = (a); \ |
1221 | const typeof (*a) * _b = (b); \ | 1241 | const typeof (*a) * _b = (b); \ |
1222 | memcmp (_a, _b, sizeof(*a)); \ | 1242 | memcmp (_a, _b, sizeof(*a)); \ |
@@ -1245,7 +1265,7 @@ GNUNET_memcmp_ct_ (const void *b1, | |||
1245 | * the first element! | 1265 | * the first element! |
1246 | */ | 1266 | */ |
1247 | #define GNUNET_memcmp_priv(a, b) \ | 1267 | #define GNUNET_memcmp_priv(a, b) \ |
1248 | ({ \ | 1268 | ({ \ |
1249 | const typeof (*b) * _a = (a); \ | 1269 | const typeof (*b) * _a = (a); \ |
1250 | const typeof (*a) * _b = (b); \ | 1270 | const typeof (*a) * _b = (b); \ |
1251 | GNUNET_memcmp_ct_ (_a, _b, sizeof(*a)); \ | 1271 | GNUNET_memcmp_ct_ (_a, _b, sizeof(*a)); \ |
@@ -1258,9 +1278,9 @@ GNUNET_memcmp_ct_ (const void *b1, | |||
1258 | * @param a pointer to @a n bytes which should be tested for the | 1278 | * @param a pointer to @a n bytes which should be tested for the |
1259 | * entire memory being zero'ed out. | 1279 | * entire memory being zero'ed out. |
1260 | * @param n number of bytes in @a to be tested | 1280 | * @param n number of bytes in @a to be tested |
1261 | * @return GNUNET_YES if a is zero, GNUNET_NO otherwise | 1281 | * @return true if @a a is zero, false_NO otherwise |
1262 | */ | 1282 | */ |
1263 | enum GNUNET_GenericReturnValue | 1283 | bool |
1264 | GNUNET_is_zero_ (const void *a, | 1284 | GNUNET_is_zero_ (const void *a, |
1265 | size_t n); | 1285 | size_t n); |
1266 | 1286 | ||
@@ -1273,7 +1293,7 @@ GNUNET_is_zero_ (const void *a, | |||
1273 | * @return GNUNET_YES if a is zero, GNUNET_NO otherwise | 1293 | * @return GNUNET_YES if a is zero, GNUNET_NO otherwise |
1274 | */ | 1294 | */ |
1275 | #define GNUNET_is_zero(a) \ | 1295 | #define GNUNET_is_zero(a) \ |
1276 | GNUNET_is_zero_ ((a), sizeof (*(a))) | 1296 | GNUNET_is_zero_ ((a), sizeof (*(a))) |
1277 | 1297 | ||
1278 | 1298 | ||
1279 | /** | 1299 | /** |
@@ -1286,15 +1306,16 @@ GNUNET_is_zero_ (const void *a, | |||
1286 | * @param n number of bytes to copy | 1306 | * @param n number of bytes to copy |
1287 | */ | 1307 | */ |
1288 | #define GNUNET_memcpy(dst, src, n) \ | 1308 | #define GNUNET_memcpy(dst, src, n) \ |
1289 | do \ | 1309 | do \ |
1290 | { \ | 1310 | { \ |
1291 | if (0 != n) \ | 1311 | if (0 != n) \ |
1292 | { \ | 1312 | { \ |
1293 | (void) memcpy (dst, src, n); \ | 1313 | (void) memcpy (dst, src, n); \ |
1294 | } \ | 1314 | } \ |
1295 | } while (0) | 1315 | } while (0) |
1296 | 1316 | ||
1297 | 1317 | ||
1318 | /* *INDENT-OFF* */ | ||
1298 | /** | 1319 | /** |
1299 | * @ingroup memory | 1320 | * @ingroup memory |
1300 | * Allocate a size @a n array with structs or unions of the given @a type. | 1321 | * Allocate a size @a n array with structs or unions of the given @a type. |
@@ -1308,6 +1329,7 @@ GNUNET_is_zero_ (const void *a, | |||
1308 | GNUNET_assert (SIZE_MAX / sizeof (type) >= n); \ | 1329 | GNUNET_assert (SIZE_MAX / sizeof (type) >= n); \ |
1309 | (type *) GNUNET_malloc ((n) * sizeof(type)); \ | 1330 | (type *) GNUNET_malloc ((n) * sizeof(type)); \ |
1310 | }) | 1331 | }) |
1332 | /* *INDENT-ON* */ | ||
1311 | 1333 | ||
1312 | /** | 1334 | /** |
1313 | * @ingroup memory | 1335 | * @ingroup memory |
@@ -1319,7 +1341,7 @@ GNUNET_is_zero_ (const void *a, | |||
1319 | * @param type name of the struct or union, i.e. pass 'struct Foo'. | 1341 | * @param type name of the struct or union, i.e. pass 'struct Foo'. |
1320 | */ | 1342 | */ |
1321 | #define GNUNET_new_array_2d(n, m, type) \ | 1343 | #define GNUNET_new_array_2d(n, m, type) \ |
1322 | (type **) GNUNET_xnew_array_2d_ (n, m, sizeof(type), __FILE__, __LINE__) | 1344 | (type **) GNUNET_xnew_array_2d_ (n, m, sizeof(type), __FILE__, __LINE__) |
1323 | 1345 | ||
1324 | /** | 1346 | /** |
1325 | * @ingroup memory | 1347 | * @ingroup memory |
@@ -1332,7 +1354,8 @@ GNUNET_is_zero_ (const void *a, | |||
1332 | * @param type name of the struct or union, i.e. pass 'struct Foo'. | 1354 | * @param type name of the struct or union, i.e. pass 'struct Foo'. |
1333 | */ | 1355 | */ |
1334 | #define GNUNET_new_array_3d(n, m, o, type) \ | 1356 | #define GNUNET_new_array_3d(n, m, o, type) \ |
1335 | (type ***) GNUNET_xnew_array_3d_ (n, m, o, sizeof(type), __FILE__, __LINE__) | 1357 | (type ***) GNUNET_xnew_array_3d_ (n, m, o, sizeof(type), __FILE__, \ |
1358 | __LINE__) | ||
1336 | 1359 | ||
1337 | /** | 1360 | /** |
1338 | * @ingroup memory | 1361 | * @ingroup memory |
@@ -1364,7 +1387,7 @@ GNUNET_is_zero_ (const void *a, | |||
1364 | * @return pointer to size bytes of memory, NULL if we do not have enough memory | 1387 | * @return pointer to size bytes of memory, NULL if we do not have enough memory |
1365 | */ | 1388 | */ |
1366 | #define GNUNET_malloc_large(size) \ | 1389 | #define GNUNET_malloc_large(size) \ |
1367 | GNUNET_xmalloc_unchecked_ (size, __FILE__, __LINE__) | 1390 | GNUNET_xmalloc_unchecked_ (size, __FILE__, __LINE__) |
1368 | 1391 | ||
1369 | 1392 | ||
1370 | /** | 1393 | /** |
@@ -1377,7 +1400,7 @@ GNUNET_is_zero_ (const void *a, | |||
1377 | * @return pointer to size bytes of memory | 1400 | * @return pointer to size bytes of memory |
1378 | */ | 1401 | */ |
1379 | #define GNUNET_realloc(ptr, size) \ | 1402 | #define GNUNET_realloc(ptr, size) \ |
1380 | GNUNET_xrealloc_ (ptr, size, __FILE__, __LINE__) | 1403 | GNUNET_xrealloc_ (ptr, size, __FILE__, __LINE__) |
1381 | 1404 | ||
1382 | 1405 | ||
1383 | /** | 1406 | /** |
@@ -1404,8 +1427,8 @@ GNUNET_is_zero_ (const void *a, | |||
1404 | * been returned by #GNUNET_strdup, #GNUNET_strndup, #GNUNET_malloc or #GNUNET_array_grow earlier. NULL is allowed. | 1427 | * been returned by #GNUNET_strdup, #GNUNET_strndup, #GNUNET_malloc or #GNUNET_array_grow earlier. NULL is allowed. |
1405 | */ | 1428 | */ |
1406 | #define GNUNET_free(ptr) do { \ | 1429 | #define GNUNET_free(ptr) do { \ |
1407 | GNUNET_xfree_ (ptr, __FILE__, __LINE__); \ | 1430 | GNUNET_xfree_ (ptr, __FILE__, __LINE__); \ |
1408 | ptr = NULL; \ | 1431 | ptr = NULL; \ |
1409 | } while (0) | 1432 | } while (0) |
1410 | 1433 | ||
1411 | 1434 | ||
@@ -1419,6 +1442,7 @@ GNUNET_is_zero_ (const void *a, | |||
1419 | */ | 1442 | */ |
1420 | #define GNUNET_strdup(a) GNUNET_xstrdup_ (a, __FILE__, __LINE__) | 1443 | #define GNUNET_strdup(a) GNUNET_xstrdup_ (a, __FILE__, __LINE__) |
1421 | 1444 | ||
1445 | |||
1422 | /** | 1446 | /** |
1423 | * @ingroup memory | 1447 | * @ingroup memory |
1424 | * Wrapper around #GNUNET_xstrndup_. Makes a partial copy of the string | 1448 | * Wrapper around #GNUNET_xstrndup_. Makes a partial copy of the string |
@@ -1429,7 +1453,7 @@ GNUNET_is_zero_ (const void *a, | |||
1429 | * @return a partial copy of the string including zero-termination | 1453 | * @return a partial copy of the string including zero-termination |
1430 | */ | 1454 | */ |
1431 | #define GNUNET_strndup(a, length) \ | 1455 | #define GNUNET_strndup(a, length) \ |
1432 | GNUNET_xstrndup_ (a, length, __FILE__, __LINE__) | 1456 | GNUNET_xstrndup_ (a, length, __FILE__, __LINE__) |
1433 | 1457 | ||
1434 | /** | 1458 | /** |
1435 | * @ingroup memory | 1459 | * @ingroup memory |
@@ -1467,12 +1491,12 @@ GNUNET_is_zero_ (const void *a, | |||
1467 | * free the vector (then, arr will be NULL afterwards). | 1491 | * free the vector (then, arr will be NULL afterwards). |
1468 | */ | 1492 | */ |
1469 | #define GNUNET_array_grow(arr, size, tsize) \ | 1493 | #define GNUNET_array_grow(arr, size, tsize) \ |
1470 | GNUNET_xgrow_ ((void **) &(arr), \ | 1494 | GNUNET_xgrow_ ((void **) &(arr), \ |
1471 | sizeof((arr)[0]), \ | 1495 | sizeof((arr)[0]), \ |
1472 | &size, \ | 1496 | &size, \ |
1473 | tsize, \ | 1497 | tsize, \ |
1474 | __FILE__, \ | 1498 | __FILE__, \ |
1475 | __LINE__) | 1499 | __LINE__) |
1476 | 1500 | ||
1477 | /** | 1501 | /** |
1478 | * @ingroup memory | 1502 | * @ingroup memory |
@@ -1488,12 +1512,12 @@ GNUNET_is_zero_ (const void *a, | |||
1488 | * @param element the element that will be appended to the array | 1512 | * @param element the element that will be appended to the array |
1489 | */ | 1513 | */ |
1490 | #define GNUNET_array_append(arr, len, element) \ | 1514 | #define GNUNET_array_append(arr, len, element) \ |
1491 | do \ | 1515 | do \ |
1492 | { \ | 1516 | { \ |
1493 | GNUNET_assert ((len) + 1 > (len)); \ | 1517 | GNUNET_assert ((len) + 1 > (len)); \ |
1494 | GNUNET_array_grow (arr, len, len + 1); \ | 1518 | GNUNET_array_grow (arr, len, len + 1); \ |
1495 | (arr) [len - 1] = element; \ | 1519 | (arr) [len - 1] = element; \ |
1496 | } while (0) | 1520 | } while (0) |
1497 | 1521 | ||
1498 | 1522 | ||
1499 | /** | 1523 | /** |
@@ -1520,15 +1544,15 @@ GNUNET_is_zero_ (const void *a, | |||
1520 | 1544 | ||
1521 | */ | 1545 | */ |
1522 | #define GNUNET_array_concatenate(arr1, len1, arr2, len2) \ | 1546 | #define GNUNET_array_concatenate(arr1, len1, arr2, len2) \ |
1523 | do \ | 1547 | do \ |
1524 | { \ | 1548 | { \ |
1525 | const typeof (*arr2) * _a1 = (arr1); \ | 1549 | const typeof (*arr2) * _a1 = (arr1); \ |
1526 | const typeof (*arr1) * _a2 = (arr2); \ | 1550 | const typeof (*arr1) * _a2 = (arr2); \ |
1527 | GNUNET_assert ((len1) + (len2) >= (len1)); \ | 1551 | GNUNET_assert ((len1) + (len2) >= (len1)); \ |
1528 | GNUNET_assert (SIZE_MAX / sizeof (*_a1) >= ((len1) + (len2))); \ | 1552 | GNUNET_assert (SIZE_MAX / sizeof (*_a1) >= ((len1) + (len2))); \ |
1529 | GNUNET_array_grow (arr1, len1, (len1) + (len2)); \ | 1553 | GNUNET_array_grow (arr1, len1, (len1) + (len2)); \ |
1530 | memcpy (&(arr1) [(len1) - (len2)], _a2, (len2) * sizeof (*arr1)); \ | 1554 | memcpy (&(arr1) [(len1) - (len2)], _a2, (len2) * sizeof (*arr1)); \ |
1531 | } while (0) | 1555 | } while (0) |
1532 | 1556 | ||
1533 | 1557 | ||
1534 | /** | 1558 | /** |
@@ -1579,7 +1603,9 @@ __attribute__ ((format (printf, 2, 3))); | |||
1579 | * @return allocated memory, never NULL | 1603 | * @return allocated memory, never NULL |
1580 | */ | 1604 | */ |
1581 | void * | 1605 | void * |
1582 | GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber); | 1606 | GNUNET_xmalloc_ (size_t size, |
1607 | const char *filename, | ||
1608 | int linenumber); | ||
1583 | 1609 | ||
1584 | 1610 | ||
1585 | /** | 1611 | /** |
@@ -1659,7 +1685,9 @@ GNUNET_xmemdup_ (const void *buf, | |||
1659 | * @return pointer to size bytes of memory, NULL if we do not have enough memory | 1685 | * @return pointer to size bytes of memory, NULL if we do not have enough memory |
1660 | */ | 1686 | */ |
1661 | void * | 1687 | void * |
1662 | GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber); | 1688 | GNUNET_xmalloc_unchecked_ (size_t size, |
1689 | const char *filename, | ||
1690 | int linenumber); | ||
1663 | 1691 | ||
1664 | 1692 | ||
1665 | /** | 1693 | /** |
@@ -1667,7 +1695,10 @@ GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber); | |||
1667 | * memory is available. | 1695 | * memory is available. |
1668 | */ | 1696 | */ |
1669 | void * | 1697 | void * |
1670 | GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber); | 1698 | GNUNET_xrealloc_ (void *ptr, |
1699 | size_t n, | ||
1700 | const char *filename, | ||
1701 | int linenumber); | ||
1671 | 1702 | ||
1672 | 1703 | ||
1673 | /** | 1704 | /** |
@@ -1680,7 +1711,9 @@ GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber); | |||
1680 | * @param linenumber line where this call is being made (for debugging) | 1711 | * @param linenumber line where this call is being made (for debugging) |
1681 | */ | 1712 | */ |
1682 | void | 1713 | void |
1683 | GNUNET_xfree_ (void *ptr, const char *filename, int linenumber); | 1714 | GNUNET_xfree_ (void *ptr, |
1715 | const char *filename, | ||
1716 | int linenumber); | ||
1684 | 1717 | ||
1685 | 1718 | ||
1686 | /** | 1719 | /** |
@@ -1691,7 +1724,9 @@ GNUNET_xfree_ (void *ptr, const char *filename, int linenumber); | |||
1691 | * @return the duplicated string | 1724 | * @return the duplicated string |
1692 | */ | 1725 | */ |
1693 | char * | 1726 | char * |
1694 | GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber); | 1727 | GNUNET_xstrdup_ (const char *str, |
1728 | const char *filename, | ||
1729 | int linenumber); | ||
1695 | 1730 | ||
1696 | /** | 1731 | /** |
1697 | * Dup partially a string. Don't call GNUNET_xstrndup_ directly. Use the #GNUNET_strndup macro. | 1732 | * Dup partially a string. Don't call GNUNET_xstrndup_ directly. Use the #GNUNET_strndup macro. |
@@ -1861,6 +1896,8 @@ enum GNUNET_SCHEDULER_Priority | |||
1861 | }; | 1896 | }; |
1862 | 1897 | ||
1863 | 1898 | ||
1899 | /* *INDENT-OFF* */ | ||
1900 | |||
1864 | #if 0 /* keep Emacsens' auto-indent happy */ | 1901 | #if 0 /* keep Emacsens' auto-indent happy */ |
1865 | { | 1902 | { |
1866 | #endif | 1903 | #endif |
@@ -1869,5 +1906,3 @@ enum GNUNET_SCHEDULER_Priority | |||
1869 | #endif | 1906 | #endif |
1870 | 1907 | ||
1871 | #endif /* GNUNET_COMMON_H */ | 1908 | #endif /* GNUNET_COMMON_H */ |
1872 | |||
1873 | /** @} */ /* end of group addition */ | ||
diff --git a/src/include/gnunet_configuration_lib.h b/src/include/gnunet_configuration_lib.h index 3b9be5849..132172516 100644 --- a/src/include/gnunet_configuration_lib.h +++ b/src/include/gnunet_configuration_lib.h | |||
@@ -66,7 +66,8 @@ GNUNET_CONFIGURATION_create (void); | |||
66 | * @return duplicate configuration | 66 | * @return duplicate configuration |
67 | */ | 67 | */ |
68 | struct GNUNET_CONFIGURATION_Handle * | 68 | struct GNUNET_CONFIGURATION_Handle * |
69 | GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg); | 69 | GNUNET_CONFIGURATION_dup ( |
70 | const struct GNUNET_CONFIGURATION_Handle *cfg); | ||
70 | 71 | ||
71 | 72 | ||
72 | /** | 73 | /** |
@@ -75,7 +76,8 @@ GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg); | |||
75 | * @param cfg configuration to destroy | 76 | * @param cfg configuration to destroy |
76 | */ | 77 | */ |
77 | void | 78 | void |
78 | GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg); | 79 | GNUNET_CONFIGURATION_destroy ( |
80 | struct GNUNET_CONFIGURATION_Handle *cfg); | ||
79 | 81 | ||
80 | 82 | ||
81 | /** | 83 | /** |
@@ -88,8 +90,9 @@ GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg); | |||
88 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 90 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
89 | */ | 91 | */ |
90 | enum GNUNET_GenericReturnValue | 92 | enum GNUNET_GenericReturnValue |
91 | GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, | 93 | GNUNET_CONFIGURATION_load ( |
92 | const char *filename); | 94 | struct GNUNET_CONFIGURATION_Handle *cfg, |
95 | const char *filename); | ||
93 | 96 | ||
94 | 97 | ||
95 | /** | 98 | /** |
@@ -101,8 +104,9 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
101 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 104 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
102 | */ | 105 | */ |
103 | enum GNUNET_GenericReturnValue | 106 | enum GNUNET_GenericReturnValue |
104 | GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, | 107 | GNUNET_CONFIGURATION_load_from ( |
105 | const char *defaults_d); | 108 | struct GNUNET_CONFIGURATION_Handle *cfg, |
109 | const char *defaults_d); | ||
106 | 110 | ||
107 | 111 | ||
108 | /** | 112 | /** |
@@ -138,8 +142,9 @@ GNUNET_CONFIGURATION_default_filename (void); | |||
138 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 142 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
139 | */ | 143 | */ |
140 | enum GNUNET_GenericReturnValue | 144 | enum GNUNET_GenericReturnValue |
141 | GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, | 145 | GNUNET_CONFIGURATION_parse ( |
142 | const char *filename); | 146 | struct GNUNET_CONFIGURATION_Handle *cfg, |
147 | const char *filename); | ||
143 | 148 | ||
144 | 149 | ||
145 | /** | 150 | /** |
@@ -151,8 +156,9 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
151 | * present. This memory should be freed by the caller | 156 | * present. This memory should be freed by the caller |
152 | */ | 157 | */ |
153 | char * | 158 | char * |
154 | GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, | 159 | GNUNET_CONFIGURATION_serialize ( |
155 | size_t *size); | 160 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
161 | size_t *size); | ||
156 | 162 | ||
157 | 163 | ||
158 | /** | 164 | /** |
@@ -168,6 +174,7 @@ char * | |||
168 | GNUNET_CONFIGURATION_serialize_diagnostics ( | 174 | GNUNET_CONFIGURATION_serialize_diagnostics ( |
169 | const struct GNUNET_CONFIGURATION_Handle *cfg); | 175 | const struct GNUNET_CONFIGURATION_Handle *cfg); |
170 | 176 | ||
177 | |||
171 | /** | 178 | /** |
172 | * De-serializes configuration | 179 | * De-serializes configuration |
173 | * | 180 | * |
@@ -179,10 +186,11 @@ GNUNET_CONFIGURATION_serialize_diagnostics ( | |||
179 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 186 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
180 | */ | 187 | */ |
181 | enum GNUNET_GenericReturnValue | 188 | enum GNUNET_GenericReturnValue |
182 | GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, | 189 | GNUNET_CONFIGURATION_deserialize ( |
183 | const char *mem, | 190 | struct GNUNET_CONFIGURATION_Handle *cfg, |
184 | size_t size, | 191 | const char *mem, |
185 | const char *source_filename); | 192 | size_t size, |
193 | const char *source_filename); | ||
186 | 194 | ||
187 | 195 | ||
188 | /** | 196 | /** |
@@ -193,8 +201,9 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
193 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 201 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
194 | */ | 202 | */ |
195 | enum GNUNET_GenericReturnValue | 203 | enum GNUNET_GenericReturnValue |
196 | GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, | 204 | GNUNET_CONFIGURATION_write ( |
197 | const char *filename); | 205 | struct GNUNET_CONFIGURATION_Handle *cfg, |
206 | const char *filename); | ||
198 | 207 | ||
199 | 208 | ||
200 | /** | 209 | /** |
@@ -233,7 +242,8 @@ GNUNET_CONFIGURATION_get_diff ( | |||
233 | * @return #GNUNET_NO if clean, #GNUNET_YES if dirty, #GNUNET_SYSERR on error (i.e. last save failed) | 242 | * @return #GNUNET_NO if clean, #GNUNET_YES if dirty, #GNUNET_SYSERR on error (i.e. last save failed) |
234 | */ | 243 | */ |
235 | enum GNUNET_GenericReturnValue | 244 | enum GNUNET_GenericReturnValue |
236 | GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg); | 245 | GNUNET_CONFIGURATION_is_dirty ( |
246 | const struct GNUNET_CONFIGURATION_Handle *cfg); | ||
237 | 247 | ||
238 | 248 | ||
239 | /** | 249 | /** |
@@ -244,8 +254,9 @@ GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg); | |||
244 | * @return status code | 254 | * @return status code |
245 | */ | 255 | */ |
246 | typedef enum GNUNET_GenericReturnValue | 256 | typedef enum GNUNET_GenericReturnValue |
247 | (*GNUNET_CONFIGURATION_Callback)(void *cls, | 257 | (*GNUNET_CONFIGURATION_Callback)( |
248 | const struct GNUNET_CONFIGURATION_Handle *cfg); | 258 | void *cls, |
259 | const struct GNUNET_CONFIGURATION_Handle *cfg); | ||
249 | 260 | ||
250 | 261 | ||
251 | /** | 262 | /** |
@@ -260,9 +271,10 @@ typedef enum GNUNET_GenericReturnValue | |||
260 | * otherwise return value from @a cb. | 271 | * otherwise return value from @a cb. |
261 | */ | 272 | */ |
262 | enum GNUNET_GenericReturnValue | 273 | enum GNUNET_GenericReturnValue |
263 | GNUNET_CONFIGURATION_parse_and_run (const char *filename, | 274 | GNUNET_CONFIGURATION_parse_and_run ( |
264 | GNUNET_CONFIGURATION_Callback cb, | 275 | const char *filename, |
265 | void *cb_cls); | 276 | GNUNET_CONFIGURATION_Callback cb, |
277 | void *cb_cls); | ||
266 | 278 | ||
267 | /** | 279 | /** |
268 | * Enable extra diagnostics. Will produce more log output | 280 | * Enable extra diagnostics. Will produce more log output |
@@ -309,9 +321,10 @@ typedef void | |||
309 | * @param iter_cls closure for @a iter | 321 | * @param iter_cls closure for @a iter |
310 | */ | 322 | */ |
311 | void | 323 | void |
312 | GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, | 324 | GNUNET_CONFIGURATION_iterate ( |
313 | GNUNET_CONFIGURATION_Iterator iter, | 325 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
314 | void *iter_cls); | 326 | GNUNET_CONFIGURATION_Iterator iter, |
327 | void *iter_cls); | ||
315 | 328 | ||
316 | 329 | ||
317 | /** | 330 | /** |
@@ -335,8 +348,9 @@ GNUNET_CONFIGURATION_iterate_sections ( | |||
335 | * @param section name of the section to remove | 348 | * @param section name of the section to remove |
336 | */ | 349 | */ |
337 | void | 350 | void |
338 | GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, | 351 | GNUNET_CONFIGURATION_remove_section ( |
339 | const char *section); | 352 | struct GNUNET_CONFIGURATION_Handle *cfg, |
353 | const char *section); | ||
340 | 354 | ||
341 | 355 | ||
342 | /** | 356 | /** |
@@ -596,10 +610,11 @@ GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
596 | * @param value value to set | 610 | * @param value value to set |
597 | */ | 611 | */ |
598 | void | 612 | void |
599 | GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg, | 613 | GNUNET_CONFIGURATION_set_value_string ( |
600 | const char *section, | 614 | struct GNUNET_CONFIGURATION_Handle *cfg, |
601 | const char *option, | 615 | const char *section, |
602 | const char *value); | 616 | const char *option, |
617 | const char *value); | ||
603 | 618 | ||
604 | 619 | ||
605 | /** | 620 | /** |
@@ -649,10 +664,8 @@ struct GNUNET_CONFIGURATION_ConfigSettings | |||
649 | { | 664 | { |
650 | 665 | ||
651 | /** | 666 | /** |
652 | * Must be set to the API version, i.e. | 667 | * Must be set to the API version, i.e. #GNUNET_UTIL_VERSION. Used to |
653 | * #GNUNET_UTIL_VERSION. Used to detect | 668 | * detect which version of the struct the client is using. |
654 | * which version of the struct the client | ||
655 | * is using. | ||
656 | */ | 669 | */ |
657 | unsigned int api_version; | 670 | unsigned int api_version; |
658 | 671 | ||
@@ -696,7 +709,6 @@ struct GNUNET_CONFIGURATION_ConfigSettings | |||
696 | */ | 709 | */ |
697 | int full; | 710 | int full; |
698 | 711 | ||
699 | |||
700 | /** | 712 | /** |
701 | * Return value from the operation, to be returned | 713 | * Return value from the operation, to be returned |
702 | * from 'main'. | 714 | * from 'main'. |
@@ -714,50 +726,52 @@ struct GNUNET_CONFIGURATION_ConfigSettings | |||
714 | * @param cs configuration settings to initialize | 726 | * @param cs configuration settings to initialize |
715 | */ | 727 | */ |
716 | #define GNUNET_CONFIGURATION_CONFIG_OPTIONS(cs) \ | 728 | #define GNUNET_CONFIGURATION_CONFIG_OPTIONS(cs) \ |
717 | GNUNET_GETOPT_option_flag ( \ | 729 | GNUNET_GETOPT_option_flag ( \ |
718 | 'F', \ | 730 | 'F', \ |
719 | "full", \ | 731 | "full", \ |
720 | gettext_noop ( \ | 732 | gettext_noop ( \ |
721 | "write the full configuration file, including default values"), \ | 733 | "write the full configuration file, including default values"), \ |
722 | &(cs)->full), \ | 734 | &(cs)->full), \ |
723 | GNUNET_GETOPT_option_flag ( \ | 735 | GNUNET_GETOPT_option_flag ( \ |
724 | 'f', \ | 736 | 'f', \ |
725 | "filename", \ | 737 | "filename", \ |
726 | gettext_noop ("interpret option value as a filename (with $-expansion)"), \ | 738 | gettext_noop ( \ |
727 | &(cs)->is_filename), \ | 739 | "interpret option value as a filename (with $-expansion)"), \ |
728 | GNUNET_GETOPT_option_string ('o', \ | 740 | &(cs)->is_filename), \ |
729 | "option", \ | 741 | GNUNET_GETOPT_option_string ('o', \ |
730 | "OPTION", \ | 742 | "option", \ |
731 | gettext_noop ("name of the option to access"), \ | 743 | "OPTION", \ |
732 | &(cs)->option), \ | 744 | gettext_noop ( \ |
733 | GNUNET_GETOPT_option_flag ( \ | 745 | "name of the option to access"), \ |
734 | 'r', \ | 746 | &(cs)->option), \ |
735 | "rewrite", \ | 747 | GNUNET_GETOPT_option_flag ( \ |
736 | gettext_noop ( \ | 748 | 'r', \ |
737 | "rewrite the configuration file, even if nothing changed"), \ | 749 | "rewrite", \ |
738 | &(cs)->rewrite), \ | 750 | gettext_noop ( \ |
739 | GNUNET_GETOPT_option_flag ( \ | 751 | "rewrite the configuration file, even if nothing changed"), \ |
740 | 'd', \ | 752 | &(cs)->rewrite), \ |
741 | "diagnostics", \ | 753 | GNUNET_GETOPT_option_flag ( \ |
742 | gettext_noop ( \ | 754 | 'd', \ |
743 | "output extra diagnostics"), \ | 755 | "diagnostics", \ |
744 | &(cs)->diagnostics), \ | 756 | gettext_noop ( \ |
745 | GNUNET_GETOPT_option_flag ('S', \ | 757 | "output extra diagnostics"), \ |
746 | "list-sections", \ | 758 | &(cs)->diagnostics), \ |
747 | gettext_noop ( \ | 759 | GNUNET_GETOPT_option_flag ('S', \ |
748 | "print available configuration sections"), \ | 760 | "list-sections", \ |
749 | &(cs)->list_sections), \ | 761 | gettext_noop ( \ |
750 | GNUNET_GETOPT_option_string ('s', \ | 762 | "print available configuration sections"), \ |
751 | "section", \ | 763 | &(cs)->list_sections), \ |
752 | "SECTION", \ | 764 | GNUNET_GETOPT_option_string ('s', \ |
753 | gettext_noop ( \ | 765 | "section", \ |
754 | "name of the section to access"), \ | 766 | "SECTION", \ |
755 | &(cs)->section), \ | 767 | gettext_noop ( \ |
756 | GNUNET_GETOPT_option_string ('V', \ | 768 | "name of the section to access"), \ |
757 | "value", \ | 769 | &(cs)->section), \ |
758 | "VALUE", \ | 770 | GNUNET_GETOPT_option_string ('V', \ |
759 | gettext_noop ("value to set"), \ | 771 | "value", \ |
760 | &(cs)->value) | 772 | "VALUE", \ |
773 | gettext_noop ("value to set"), \ | ||
774 | &(cs)->value) | ||
761 | 775 | ||
762 | 776 | ||
763 | /** | 777 | /** |
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index 4580f795d..b74bbcd1e 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h | |||
@@ -973,7 +973,7 @@ GNUNET_CRYPTO_hash_from_string2 (const char *enc, | |||
973 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding | 973 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding |
974 | */ | 974 | */ |
975 | #define GNUNET_CRYPTO_hash_from_string(enc, result) \ | 975 | #define GNUNET_CRYPTO_hash_from_string(enc, result) \ |
976 | GNUNET_CRYPTO_hash_from_string2 (enc, strlen (enc), result) | 976 | GNUNET_CRYPTO_hash_from_string2 (enc, strlen (enc), result) |
977 | 977 | ||
978 | 978 | ||
979 | /** | 979 | /** |
@@ -1736,6 +1736,15 @@ GNUNET_CRYPTO_edx25519_key_clear (struct GNUNET_CRYPTO_Edx25519PrivateKey *pk); | |||
1736 | void | 1736 | void |
1737 | GNUNET_CRYPTO_ecdhe_key_clear (struct GNUNET_CRYPTO_EcdhePrivateKey *pk); | 1737 | GNUNET_CRYPTO_ecdhe_key_clear (struct GNUNET_CRYPTO_EcdhePrivateKey *pk); |
1738 | 1738 | ||
1739 | /** | ||
1740 | * @ingroup crypto | ||
1741 | * Clear memory that was used to store a private key. | ||
1742 | * | ||
1743 | * @param pk location of the key | ||
1744 | */ | ||
1745 | void | ||
1746 | GNUNET_CRYPTO_private_key_clear (struct GNUNET_CRYPTO_PrivateKey *pk); | ||
1747 | |||
1739 | 1748 | ||
1740 | /** | 1749 | /** |
1741 | * @ingroup crypto | 1750 | * @ingroup crypto |
@@ -2215,15 +2224,15 @@ GNUNET_CRYPTO_eddsa_sign_ ( | |||
2215 | * @param[out] sig where to write the signature | 2224 | * @param[out] sig where to write the signature |
2216 | */ | 2225 | */ |
2217 | #define GNUNET_CRYPTO_eddsa_sign(priv,ps,sig) do { \ | 2226 | #define GNUNET_CRYPTO_eddsa_sign(priv,ps,sig) do { \ |
2218 | /* check size is set correctly */ \ | 2227 | /* check size is set correctly */ \ |
2219 | GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*ps)); \ | 2228 | GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*ps)); \ |
2220 | /* check 'ps' begins with the purpose */ \ | 2229 | /* check 'ps' begins with the purpose */ \ |
2221 | GNUNET_static_assert (((void*) (ps)) == \ | 2230 | GNUNET_static_assert (((void*) (ps)) == \ |
2222 | ((void*) &(ps)->purpose)); \ | 2231 | ((void*) &(ps)->purpose)); \ |
2223 | GNUNET_assert (GNUNET_OK == \ | 2232 | GNUNET_assert (GNUNET_OK == \ |
2224 | GNUNET_CRYPTO_eddsa_sign_ (priv, \ | 2233 | GNUNET_CRYPTO_eddsa_sign_ (priv, \ |
2225 | &(ps)->purpose, \ | 2234 | &(ps)->purpose, \ |
2226 | sig)); \ | 2235 | sig)); \ |
2227 | } while (0) | 2236 | } while (0) |
2228 | 2237 | ||
2229 | 2238 | ||
@@ -2277,15 +2286,15 @@ GNUNET_CRYPTO_eddsa_sign_raw ( | |||
2277 | * @param[out] sig where to write the signature | 2286 | * @param[out] sig where to write the signature |
2278 | */ | 2287 | */ |
2279 | #define GNUNET_CRYPTO_ecdsa_sign(priv,ps,sig) do { \ | 2288 | #define GNUNET_CRYPTO_ecdsa_sign(priv,ps,sig) do { \ |
2280 | /* check size is set correctly */ \ | 2289 | /* check size is set correctly */ \ |
2281 | GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \ | 2290 | GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \ |
2282 | /* check 'ps' begins with the purpose */ \ | 2291 | /* check 'ps' begins with the purpose */ \ |
2283 | GNUNET_static_assert (((void*) (ps)) == \ | 2292 | GNUNET_static_assert (((void*) (ps)) == \ |
2284 | ((void*) &(ps)->purpose)); \ | 2293 | ((void*) &(ps)->purpose)); \ |
2285 | GNUNET_assert (GNUNET_OK == \ | 2294 | GNUNET_assert (GNUNET_OK == \ |
2286 | GNUNET_CRYPTO_ecdsa_sign_ (priv, \ | 2295 | GNUNET_CRYPTO_ecdsa_sign_ (priv, \ |
2287 | &(ps)->purpose, \ | 2296 | &(ps)->purpose, \ |
2288 | sig)); \ | 2297 | sig)); \ |
2289 | } while (0) | 2298 | } while (0) |
2290 | 2299 | ||
2291 | /** | 2300 | /** |
@@ -2324,15 +2333,15 @@ GNUNET_CRYPTO_edx25519_sign_ ( | |||
2324 | * @param[out] sig where to write the signature | 2333 | * @param[out] sig where to write the signature |
2325 | */ | 2334 | */ |
2326 | #define GNUNET_CRYPTO_edx25519_sign(priv,ps,sig) do { \ | 2335 | #define GNUNET_CRYPTO_edx25519_sign(priv,ps,sig) do { \ |
2327 | /* check size is set correctly */ \ | 2336 | /* check size is set correctly */ \ |
2328 | GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \ | 2337 | GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \ |
2329 | /* check 'ps' begins with the purpose */ \ | 2338 | /* check 'ps' begins with the purpose */ \ |
2330 | GNUNET_static_assert (((void*) (ps)) == \ | 2339 | GNUNET_static_assert (((void*) (ps)) == \ |
2331 | ((void*) &(ps)->purpose)); \ | 2340 | ((void*) &(ps)->purpose)); \ |
2332 | GNUNET_assert (GNUNET_OK == \ | 2341 | GNUNET_assert (GNUNET_OK == \ |
2333 | GNUNET_CRYPTO_edx25519_sign_ (priv, \ | 2342 | GNUNET_CRYPTO_edx25519_sign_ (priv, \ |
2334 | &(ps)->purpose, \ | 2343 | &(ps)->purpose, \ |
2335 | sig)); \ | 2344 | sig)); \ |
2336 | } while (0) | 2345 | } while (0) |
2337 | 2346 | ||
2338 | 2347 | ||
@@ -2664,90 +2673,97 @@ GNUNET_CRYPTO_edx25519_public_key_derive ( | |||
2664 | size_t seedsize, | 2673 | size_t seedsize, |
2665 | struct GNUNET_CRYPTO_Edx25519PublicKey *result); | 2674 | struct GNUNET_CRYPTO_Edx25519PublicKey *result); |
2666 | 2675 | ||
2667 | /** | ||
2668 | * Note: Included in header for testing purposes. GNUNET_CRYPTO_ecdhe_elligator_decoding will be the correct API for the direct map. | ||
2669 | * TODO: Make static. | ||
2670 | * @ingroup crypto | ||
2671 | * Encodes an element of the underlying finite field, so called representative, of Curve25519 to a point on the curve | ||
2672 | * This transformation is deterministic | ||
2673 | * | ||
2674 | * @param representative element of the finite field | ||
2675 | * @param point destination for the calculated point on the curve | ||
2676 | * @param high_y destination set to "True" if corresponding y-coordinate is > 2 ^ 254 - 10 | ||
2677 | */ | ||
2678 | bool | ||
2679 | GNUNET_CRYPTO_ecdhe_elligator_direct_map (uint8_t *point, bool *high_y, | ||
2680 | uint8_t *representative); | ||
2681 | |||
2682 | 2676 | ||
2683 | /** | 2677 | /** |
2684 | * @ingroup crypto | 2678 | * @ingroup crypto |
2685 | * Clears the most significant bit and second most significant bit to the serialized representaive before applying elligator direct map. | 2679 | * Clears the most significant bit and second most significant bit of the serialized representaive before applying elligator direct map. |
2686 | * | 2680 | * |
2687 | * @param serialized_representative serialized version of an element of Curves25519's finite field | 2681 | * @param representative serialized elligator representative of an element of Curves25519's finite field |
2688 | * @param point destination for the calculated point on the curve | 2682 | * @param point destination for the calculated point on the curve |
2689 | * @param high_y destination set to "True" if corresponding y-coordinate is > 2 ^ 254 - 10 | 2683 | * @param high_y bool pointed to will be set to 'true' if corresponding y-coordinate is > 2 ^ 254 - 10, otherwise 0. Can be set to NULL if not needed. |
2690 | */ | 2684 | */ |
2691 | bool | 2685 | void |
2692 | GNUNET_CRYPTO_ecdhe_elligator_decoding (struct | 2686 | GNUNET_CRYPTO_ecdhe_elligator_decoding ( |
2693 | GNUNET_CRYPTO_EcdhePublicKey *point, | 2687 | struct GNUNET_CRYPTO_EcdhePublicKey *point, |
2694 | bool *high_y, | 2688 | bool *high_y, |
2695 | struct | 2689 | const struct GNUNET_CRYPTO_ElligatorRepresentative *representative); |
2696 | GNUNET_CRYPTO_ElligatorRepresentative * | ||
2697 | seriliazed_representative); | ||
2698 | 2690 | ||
2699 | /** | 2691 | /** |
2700 | * @ingroup crypto | 2692 | * @ingroup crypto |
2701 | * Encodes a point on Curve25519 to a an element of the underlying finite field | 2693 | * Encodes a point on Curve25519 to a an element of the underlying finite field. |
2702 | * This transformation is deterministic | 2694 | * This transformation is deterministic. |
2703 | * | 2695 | * |
2704 | * @param point a point on the curve | 2696 | * @param r storage for the calculated representative |
2697 | * @param pub a point on the curve | ||
2705 | * @param high_y encodes if y-coordinate is > 2 ^254 - 10, which determines the representative value out of two | 2698 | * @param high_y encodes if y-coordinate is > 2 ^254 - 10, which determines the representative value out of two |
2706 | * @param representative destination for the calculated element of the finite field | 2699 | * @return 'true' if the given point can be encoded into a representative. Otherwise 'false' is returned and the content of the representative storage is undefined |
2707 | */ | 2700 | */ |
2708 | bool | 2701 | bool |
2709 | GNUNET_CRYPTO_ecdhe_elligator_inverse_map (uint8_t *representative, const | 2702 | GNUNET_CRYPTO_ecdhe_elligator_encoding ( |
2710 | uint8_t *point, | 2703 | struct GNUNET_CRYPTO_ElligatorRepresentative *r, |
2711 | bool high_y); | 2704 | const struct GNUNET_CRYPTO_EcdhePublicKey *pub, |
2705 | bool high_y); | ||
2712 | 2706 | ||
2713 | 2707 | ||
2714 | /** | 2708 | /** |
2715 | * Initializes the elligator library | ||
2716 | * THis function is thread safe | ||
2717 | */ | ||
2718 | void | ||
2719 | GNUNET_CRYPTO_ecdhe_elligator_initialize (void); | ||
2720 | |||
2721 | /** | ||
2722 | * @ingroup crypto | 2709 | * @ingroup crypto |
2723 | * Generates a valid public key for elligator's inverse map by adding a lower order point to a prime order point. | 2710 | * Generates a valid public key for elligator's inverse map by adding a lower order point to a prime order point. |
2711 | * Following Method 1 in description https://elligator.org/key-exchange section Step 2: Generate a “special” public key. | ||
2724 | * | 2712 | * |
2725 | * @param pub valid public key for elligator inverse map | 2713 | * @param pub valid public key for elligator inverse map |
2726 | * @param pk private key for generating valid public key | 2714 | * @param pk private key for generating valid public key |
2715 | * @return GNUNET_OK on success | ||
2727 | */ | 2716 | */ |
2728 | int | 2717 | enum GNUNET_GenericReturnValue |
2729 | GNUNET_CRYPTO_ecdhe_elligator_generate_public_key (unsigned char | 2718 | GNUNET_CRYPTO_ecdhe_elligator_generate_public_key ( |
2730 | pub[ | 2719 | struct GNUNET_CRYPTO_EcdhePublicKey *pub, |
2731 | crypto_scalarmult_SCALARBYTES | 2720 | struct GNUNET_CRYPTO_EcdhePrivateKey *pk); |
2732 | ], | ||
2733 | struct | ||
2734 | GNUNET_CRYPTO_EcdhePrivateKey | ||
2735 | *pk); | ||
2736 | 2721 | ||
2737 | 2722 | ||
2738 | /** | 2723 | /** |
2739 | * @ingroup crypto | 2724 | * @ingroup crypto |
2740 | * Generates a private key for Curve25519 and the elligator representative of the corresponding public key | 2725 | * Generates a private key for Curve25519 and the elligator representative of the corresponding public key. |
2741 | * | 2726 | * |
2742 | * @param repr representative of the public key | 2727 | * @param repr representative of the public key |
2743 | * @param pk Curve25519 private key | 2728 | * @param pk Curve25519 private key |
2744 | * @return GNUNET_OK if creation successful | ||
2745 | */ | 2729 | */ |
2746 | enum GNUNET_GenericReturnValue | 2730 | void |
2747 | GNUNET_CRYPTO_ecdhe_elligator_key_create ( | 2731 | GNUNET_CRYPTO_ecdhe_elligator_key_create ( |
2748 | struct GNUNET_CRYPTO_ElligatorRepresentative *repr, | 2732 | struct GNUNET_CRYPTO_ElligatorRepresentative *repr, |
2749 | struct GNUNET_CRYPTO_EcdhePrivateKey *pk); | 2733 | struct GNUNET_CRYPTO_EcdhePrivateKey *pk); |
2750 | 2734 | ||
2735 | /** | ||
2736 | * @ingroup crypto | ||
2737 | * Carries out ecdh encapsulation with given public key and the private key from a freshly created ephemeral key pair. | ||
2738 | * Following the terminology in https://eprint.iacr.org/2021/509.pdf. | ||
2739 | * | ||
2740 | * @param pub given edwards curve public key (X) | ||
2741 | * @param r representative of ephemeral public key A to use for the ECDH (direct_map(r)=A=aG) | ||
2742 | * @param key_material where to write the key material H(aX)=H(x(aG)) | ||
2743 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success | ||
2744 | */ | ||
2745 | enum GNUNET_GenericReturnValue | ||
2746 | GNUNET_CRYPTO_eddsa_elligator_kem_encaps ( | ||
2747 | const struct GNUNET_CRYPTO_EddsaPublicKey *pub, | ||
2748 | struct GNUNET_CRYPTO_ElligatorRepresentative *r, | ||
2749 | struct GNUNET_HashCode *key_material); | ||
2750 | |||
2751 | /** | ||
2752 | * @ingroup crypto | ||
2753 | * Carries out ecdh decapsulation with own private key and the representative of the received public key. | ||
2754 | * Following the terminology in https://eprint.iacr.org/2021/509.pdf. | ||
2755 | * | ||
2756 | * @param priv own private key (x) | ||
2757 | * @param r received representative r, from which we can obtain the public key A (direct_map(r)=A=aG) | ||
2758 | * @param key_material where to write the key material H(xA)=H(a(xG)) | ||
2759 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success | ||
2760 | */ | ||
2761 | enum GNUNET_GenericReturnValue | ||
2762 | GNUNET_CRYPTO_eddsa_elligator_kem_decaps ( | ||
2763 | const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, | ||
2764 | const struct GNUNET_CRYPTO_ElligatorRepresentative *r, | ||
2765 | struct GNUNET_HashCode *key_material); | ||
2766 | |||
2751 | 2767 | ||
2752 | /** | 2768 | /** |
2753 | * Output the given MPI value to the given buffer in network | 2769 | * Output the given MPI value to the given buffer in network |
@@ -4232,15 +4248,15 @@ GNUNET_CRYPTO_sign_raw_ ( | |||
4232 | * @param[out] sig where to write the signature | 4248 | * @param[out] sig where to write the signature |
4233 | */ | 4249 | */ |
4234 | #define GNUNET_CRYPTO_sign(priv,ps,sig) do { \ | 4250 | #define GNUNET_CRYPTO_sign(priv,ps,sig) do { \ |
4235 | /* check size is set correctly */ \ | 4251 | /* check size is set correctly */ \ |
4236 | GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \ | 4252 | GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \ |
4237 | /* check 'ps' begins with the purpose */ \ | 4253 | /* check 'ps' begins with the purpose */ \ |
4238 | GNUNET_static_assert (((void*) (ps)) == \ | 4254 | GNUNET_static_assert (((void*) (ps)) == \ |
4239 | ((void*) &(ps)->purpose)); \ | 4255 | ((void*) &(ps)->purpose)); \ |
4240 | GNUNET_assert (GNUNET_OK == \ | 4256 | GNUNET_assert (GNUNET_OK == \ |
4241 | GNUNET_CRYPTO_sign_ (priv, \ | 4257 | GNUNET_CRYPTO_sign_ (priv, \ |
4242 | &(ps)->purpose, \ | 4258 | &(ps)->purpose, \ |
4243 | sig)); \ | 4259 | sig)); \ |
4244 | } while (0) | 4260 | } while (0) |
4245 | 4261 | ||
4246 | 4262 | ||
diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h index 5c271c71f..a05e07ac5 100644 --- a/src/include/gnunet_fs_service.h +++ b/src/include/gnunet_fs_service.h | |||
@@ -525,6 +525,17 @@ GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri); | |||
525 | 525 | ||
526 | 526 | ||
527 | /** | 527 | /** |
528 | * What is the hash of the original file's content | ||
529 | * that this URI refers to? | ||
530 | * | ||
531 | * @param uri the CHK URI to inspect | ||
532 | * @return hash of the file as specified in the CHK URI | ||
533 | */ | ||
534 | const struct GNUNET_HashCode* | ||
535 | GNUNET_FS_uri_chk_get_file_hash (const struct GNUNET_FS_Uri *uri); | ||
536 | |||
537 | |||
538 | /** | ||
528 | * Is this a location URI? | 539 | * Is this a location URI? |
529 | * | 540 | * |
530 | * @param uri the uri to check | 541 | * @param uri the uri to check |
diff --git a/src/include/gnunet_getopt_lib.h b/src/include/gnunet_getopt_lib.h index 390e8c153..91ba362e5 100644 --- a/src/include/gnunet_getopt_lib.h +++ b/src/include/gnunet_getopt_lib.h | |||
@@ -33,7 +33,7 @@ | |||
33 | * @{ | 33 | * @{ |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #if !defined (__GNUNET_UTIL_LIB_H_INSIDE__) | 36 | #if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__) |
37 | #error "Only <gnunet_util_lib.h> can be included directly." | 37 | #error "Only <gnunet_util_lib.h> can be included directly." |
38 | #endif | 38 | #endif |
39 | 39 | ||
@@ -275,12 +275,12 @@ GNUNET_GETOPT_option_base32_fixed_size (char shortName, | |||
275 | argumentHelp, \ | 275 | argumentHelp, \ |
276 | description, \ | 276 | description, \ |
277 | val) \ | 277 | val) \ |
278 | GNUNET_GETOPT_option_base32_fixed_size (shortName, \ | 278 | GNUNET_GETOPT_option_base32_fixed_size (shortName, \ |
279 | name, \ | 279 | name, \ |
280 | argumentHelp, \ | 280 | argumentHelp, \ |
281 | description, \ | 281 | description, \ |
282 | val, \ | 282 | val, \ |
283 | sizeof(*val)) | 283 | sizeof(*val)) |
284 | 284 | ||
285 | 285 | ||
286 | /** | 286 | /** |
@@ -481,9 +481,9 @@ GNUNET_GETOPT_option_exclusive (struct GNUNET_GETOPT_CommandLineOption opt); | |||
481 | * Marker for the end of the list of options. | 481 | * Marker for the end of the list of options. |
482 | */ | 482 | */ |
483 | #define GNUNET_GETOPT_OPTION_END \ | 483 | #define GNUNET_GETOPT_OPTION_END \ |
484 | { \ | 484 | { \ |
485 | '\0', NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL \ | 485 | '\0', NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL \ |
486 | } | 486 | } |
487 | 487 | ||
488 | 488 | ||
489 | /** | 489 | /** |
diff --git a/src/include/gnunet_gns_service.h b/src/include/gnunet_gns_service.h index 1f19e58ac..e7ed2d3c2 100644 --- a/src/include/gnunet_gns_service.h +++ b/src/include/gnunet_gns_service.h | |||
@@ -227,6 +227,16 @@ GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle, | |||
227 | void * | 227 | void * |
228 | GNUNET_GNS_lookup_with_tld_cancel (struct GNUNET_GNS_LookupWithTldRequest *ltr); | 228 | GNUNET_GNS_lookup_with_tld_cancel (struct GNUNET_GNS_LookupWithTldRequest *ltr); |
229 | 229 | ||
230 | /** | ||
231 | * Try to parse the zTLD into a public key. | ||
232 | * | ||
233 | * @param[in] name the name to parse | ||
234 | * @param[out] ztld_key the identity key (must be allocated by caller). Only set of #GNUNET_OK is returned. | ||
235 | * @return GNUNET_OK on success. | ||
236 | */ | ||
237 | enum GNUNET_GenericReturnValue | ||
238 | GNUNET_GNS_parse_ztld (const char *name, | ||
239 | struct GNUNET_CRYPTO_PublicKey *ztld_key); | ||
230 | 240 | ||
231 | #if 0 /* keep Emacsens' auto-indent happy */ | 241 | #if 0 /* keep Emacsens' auto-indent happy */ |
232 | { | 242 | { |
diff --git a/src/include/gnunet_helper_lib.h b/src/include/gnunet_helper_lib.h index c329c4a33..57630c45c 100644 --- a/src/include/gnunet_helper_lib.h +++ b/src/include/gnunet_helper_lib.h | |||
@@ -173,7 +173,7 @@ struct GNUNET_HELPER_SendHandle; | |||
173 | struct GNUNET_HELPER_SendHandle * | 173 | struct GNUNET_HELPER_SendHandle * |
174 | GNUNET_HELPER_send (struct GNUNET_HELPER_Handle *h, | 174 | GNUNET_HELPER_send (struct GNUNET_HELPER_Handle *h, |
175 | const struct GNUNET_MessageHeader *msg, | 175 | const struct GNUNET_MessageHeader *msg, |
176 | int can_drop, | 176 | bool can_drop, |
177 | GNUNET_HELPER_Continuation cont, | 177 | GNUNET_HELPER_Continuation cont, |
178 | void *cont_cls); | 178 | void *cont_cls); |
179 | 179 | ||
diff --git a/src/include/gnunet_json_lib.h b/src/include/gnunet_json_lib.h index 203976b5c..2059e127f 100644 --- a/src/include/gnunet_json_lib.h +++ b/src/include/gnunet_json_lib.h | |||
@@ -430,6 +430,39 @@ GNUNET_JSON_spec_rsa_signature (const char *name, | |||
430 | struct GNUNET_CRYPTO_RsaSignature **sig); | 430 | struct GNUNET_CRYPTO_RsaSignature **sig); |
431 | 431 | ||
432 | 432 | ||
433 | /** | ||
434 | * Specification for parsing a blinded message. | ||
435 | * | ||
436 | * @param name name of the JSON field | ||
437 | * @param sig where to store the blinded message found under @a name | ||
438 | */ | ||
439 | struct GNUNET_JSON_Specification | ||
440 | GNUNET_JSON_spec_blinded_message (const char *name, | ||
441 | struct GNUNET_CRYPTO_BlindedMessage **msg); | ||
442 | |||
443 | |||
444 | /** | ||
445 | * Specification for parsing a blinded signature. | ||
446 | * | ||
447 | * @param name name of the JSON field | ||
448 | * @param sig where to store the blinded signature found under @a name | ||
449 | */ | ||
450 | struct GNUNET_JSON_Specification | ||
451 | GNUNET_JSON_spec_blinded_signature (const char *field, | ||
452 | struct GNUNET_CRYPTO_BlindedSignature **b_sig); | ||
453 | |||
454 | |||
455 | /** | ||
456 | * Specification for parsing a unblinded signature. | ||
457 | * | ||
458 | * @param name name of the JSON field | ||
459 | * @param sig where to store the unblinded signature found under @a name | ||
460 | */ | ||
461 | struct GNUNET_JSON_Specification | ||
462 | GNUNET_JSON_spec_unblinded_signature (const char *field, | ||
463 | struct GNUNET_CRYPTO_UnblindedSignature **ub_sig); | ||
464 | |||
465 | |||
433 | /* ****************** Generic generator interface ******************* */ | 466 | /* ****************** Generic generator interface ******************* */ |
434 | 467 | ||
435 | 468 | ||
@@ -966,6 +999,44 @@ GNUNET_JSON_pack_rsa_signature (const char *name, | |||
966 | const struct GNUNET_CRYPTO_RsaSignature *sig); | 999 | const struct GNUNET_CRYPTO_RsaSignature *sig); |
967 | 1000 | ||
968 | 1001 | ||
1002 | /** | ||
1003 | * Generate packer instruction for a JSON field of type | ||
1004 | * unblinded signature. | ||
1005 | * | ||
1006 | * @param name name of the field to add to the object | ||
1007 | * @param sig unblinded signature | ||
1008 | * @return json pack specification | ||
1009 | */ | ||
1010 | struct GNUNET_JSON_PackSpec | ||
1011 | GNUNET_JSON_pack_unblinded_signature (const char *name, | ||
1012 | const struct GNUNET_CRYPTO_UnblindedSignature *sig); | ||
1013 | |||
1014 | |||
1015 | /** | ||
1016 | * Generate packer instruction for a JSON field of type | ||
1017 | * blinded message. | ||
1018 | * | ||
1019 | * @param name name of the field to add to the object | ||
1020 | * @param msg blinded message | ||
1021 | * @return json pack specification | ||
1022 | */ | ||
1023 | struct GNUNET_JSON_PackSpec | ||
1024 | GNUNET_JSON_pack_blinded_message (const char *name, | ||
1025 | const struct GNUNET_CRYPTO_BlindedMessage *msg); | ||
1026 | |||
1027 | |||
1028 | /** | ||
1029 | * Generate packer instruction for a JSON field of type | ||
1030 | * blinded signature. | ||
1031 | * | ||
1032 | * @param name name of the field to add to the object | ||
1033 | * @param sig blinded signature | ||
1034 | * @return json pack specification | ||
1035 | */ | ||
1036 | struct GNUNET_JSON_PackSpec | ||
1037 | GNUNET_JSON_pack_blinded_sig (const char *name, | ||
1038 | const struct GNUNET_CRYPTO_BlindedSignature *sig); | ||
1039 | |||
969 | #endif | 1040 | #endif |
970 | 1041 | ||
971 | /* end of gnunet_json_lib.h */ | 1042 | /* end of gnunet_json_lib.h */ |
diff --git a/src/include/gnunet_messenger_service.h b/src/include/gnunet_messenger_service.h index 1bc68b87b..3f039f944 100644 --- a/src/include/gnunet_messenger_service.h +++ b/src/include/gnunet_messenger_service.h | |||
@@ -39,21 +39,14 @@ extern "C" { | |||
39 | #endif | 39 | #endif |
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | #include "gnunet_common.h" | ||
43 | #include "gnunet_configuration_lib.h" | ||
44 | #include "gnunet_identity_service.h" | ||
45 | #include "gnunet_reclaim_lib.h" | ||
46 | #include "gnunet_reclaim_service.h" | ||
47 | #include "gnunet_scheduler_lib.h" | ||
48 | #include "gnunet_time_lib.h" | ||
49 | #include "gnunet_util_lib.h" | 42 | #include "gnunet_util_lib.h" |
50 | 43 | ||
51 | /** | 44 | /** |
52 | * Version number of GNUnet Messenger API. | 45 | * Version number of GNUnet Messenger API. |
53 | * | 46 | * |
54 | * Current version of the Messenger: 0.3 | 47 | * Current version of the Messenger: 0.4 |
55 | */ | 48 | */ |
56 | #define GNUNET_MESSENGER_VERSION 0x00000003 | 49 | #define GNUNET_MESSENGER_VERSION 0x00000004 |
57 | 50 | ||
58 | /** | 51 | /** |
59 | * Identifier of GNUnet MESSENGER Service. | 52 | * Identifier of GNUnet MESSENGER Service. |
@@ -91,7 +84,7 @@ struct GNUNET_MESSENGER_RoomEntryRecord | |||
91 | /** | 84 | /** |
92 | * The hash identifying the port of the room. | 85 | * The hash identifying the port of the room. |
93 | */ | 86 | */ |
94 | struct GNUNET_HashCode key; | 87 | struct GNUNET_HashCode key GNUNET_PACKED; |
95 | }; | 88 | }; |
96 | 89 | ||
97 | GNUNET_NETWORK_STRUCT_END | 90 | GNUNET_NETWORK_STRUCT_END |
@@ -536,14 +529,14 @@ struct GNUNET_MESSENGER_MessageConnection | |||
536 | * A ticket message body | 529 | * A ticket message body |
537 | * This allows to exchange ticket identifiers with an audience. | 530 | * This allows to exchange ticket identifiers with an audience. |
538 | * | 531 | * |
539 | * Message-body-size: 32 bytes | 532 | * Message-body-size: 0+ bytes |
540 | */ | 533 | */ |
541 | struct GNUNET_MESSENGER_MessageTicket | 534 | struct GNUNET_MESSENGER_MessageTicket |
542 | { | 535 | { |
543 | /** | 536 | /** |
544 | * The identifier of a RECLAIM ticket. | 537 | * The identifier of a ticket. |
545 | */ | 538 | */ |
546 | struct GNUNET_RECLAIM_Identifier identifier; | 539 | char *identifier; |
547 | }; | 540 | }; |
548 | 541 | ||
549 | /** | 542 | /** |
@@ -1010,22 +1003,6 @@ GNUNET_MESSENGER_iterate_members (struct GNUNET_MESSENGER_Room *room, | |||
1010 | GNUNET_MESSENGER_MemberCallback callback, | 1003 | GNUNET_MESSENGER_MemberCallback callback, |
1011 | void *cls); | 1004 | void *cls); |
1012 | 1005 | ||
1013 | /** | ||
1014 | * Send a <i>ticket</i> into a <i>room</i>. The ticket will automatically be converted | ||
1015 | * into a message to be sent only to its audience as a private message. | ||
1016 | * | ||
1017 | * A ticket can only be sent with this function if its issuer's public key is the one | ||
1018 | * being used by the messenger. The audience's public key is not allowed to be the | ||
1019 | * anonymous public key. The room needs to contain a member using the audience's public | ||
1020 | * key. | ||
1021 | * | ||
1022 | * @param[in,out] room Room handle | ||
1023 | * @param[in] ticket Ticket to send | ||
1024 | */ | ||
1025 | void | ||
1026 | GNUNET_MESSENGER_send_ticket (struct GNUNET_MESSENGER_Room *room, | ||
1027 | const struct GNUNET_RECLAIM_Ticket *ticket); | ||
1028 | |||
1029 | #if 0 /* keep Emacsens' auto-indent happy */ | 1006 | #if 0 /* keep Emacsens' auto-indent happy */ |
1030 | { | 1007 | { |
1031 | #endif | 1008 | #endif |
diff --git a/src/include/gnunet_mq_lib.h b/src/include/gnunet_mq_lib.h index 3eca71f0f..b40693cdb 100644 --- a/src/include/gnunet_mq_lib.h +++ b/src/include/gnunet_mq_lib.h | |||
@@ -19,7 +19,7 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include "gnunet_common.h" | 21 | #include "gnunet_common.h" |
22 | #if !defined (__GNUNET_UTIL_LIB_H_INSIDE__) | 22 | #if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__) |
23 | #error "Only <gnunet_util_lib.h> can be included directly." | 23 | #error "Only <gnunet_util_lib.h> can be included directly." |
24 | #endif | 24 | #endif |
25 | 25 | ||
@@ -61,9 +61,9 @@ | |||
61 | * @return the MQ message | 61 | * @return the MQ message |
62 | */ | 62 | */ |
63 | #define GNUNET_MQ_msg_extra(mvar, esize, type) \ | 63 | #define GNUNET_MQ_msg_extra(mvar, esize, type) \ |
64 | GNUNET_MQ_msg_ (((struct GNUNET_MessageHeader **) &(mvar)), \ | 64 | GNUNET_MQ_msg_ (((struct GNUNET_MessageHeader **) &(mvar)), \ |
65 | (esize) + sizeof *(mvar), \ | 65 | (esize) + sizeof *(mvar), \ |
66 | (type)) | 66 | (type)) |
67 | 67 | ||
68 | /** | 68 | /** |
69 | * Allocate a GNUNET_MQ_Envelope. | 69 | * Allocate a GNUNET_MQ_Envelope. |
@@ -85,7 +85,7 @@ | |||
85 | * @param type type of the message | 85 | * @param type type of the message |
86 | */ | 86 | */ |
87 | #define GNUNET_MQ_msg_header(type) \ | 87 | #define GNUNET_MQ_msg_header(type) \ |
88 | GNUNET_MQ_msg_ (NULL, sizeof(struct GNUNET_MessageHeader), type) | 88 | GNUNET_MQ_msg_ (NULL, sizeof(struct GNUNET_MessageHeader), type) |
89 | 89 | ||
90 | 90 | ||
91 | /** | 91 | /** |
@@ -97,7 +97,8 @@ | |||
97 | * @param type type of the message | 97 | * @param type type of the message |
98 | */ | 98 | */ |
99 | #define GNUNET_MQ_msg_header_extra(mh, esize, type) \ | 99 | #define GNUNET_MQ_msg_header_extra(mh, esize, type) \ |
100 | GNUNET_MQ_msg_ (&mh, (esize) + sizeof(struct GNUNET_MessageHeader), type) | 100 | GNUNET_MQ_msg_ (&mh, (esize) + sizeof(struct GNUNET_MessageHeader), type \ |
101 | ) | ||
101 | 102 | ||
102 | 103 | ||
103 | /** | 104 | /** |
@@ -111,7 +112,7 @@ | |||
111 | * @return a newly allocated 'struct GNUNET_MQ_Envelope *' | 112 | * @return a newly allocated 'struct GNUNET_MQ_Envelope *' |
112 | */ | 113 | */ |
113 | #define GNUNET_MQ_msg_nested_mh(mvar, type, mh) \ | 114 | #define GNUNET_MQ_msg_nested_mh(mvar, type, mh) \ |
114 | ({ \ | 115 | ({ \ |
115 | struct GNUNET_MQ_Envelope *_ev; \ | 116 | struct GNUNET_MQ_Envelope *_ev; \ |
116 | _ev = GNUNET_MQ_msg_nested_mh_ ((struct GNUNET_MessageHeader **) &(mvar), \ | 117 | _ev = GNUNET_MQ_msg_nested_mh_ ((struct GNUNET_MessageHeader **) &(mvar), \ |
117 | sizeof(*(mvar)), \ | 118 | sizeof(*(mvar)), \ |
@@ -131,8 +132,8 @@ | |||
131 | * or NULL if the given message in @a var does not have any space after the message struct | 132 | * or NULL if the given message in @a var does not have any space after the message struct |
132 | */ | 133 | */ |
133 | #define GNUNET_MQ_extract_nested_mh(var) \ | 134 | #define GNUNET_MQ_extract_nested_mh(var) \ |
134 | GNUNET_MQ_extract_nested_mh_ ((struct GNUNET_MessageHeader *) (var), \ | 135 | GNUNET_MQ_extract_nested_mh_ ((struct GNUNET_MessageHeader *) (var), \ |
135 | sizeof(*(var))) | 136 | sizeof(*(var))) |
136 | 137 | ||
137 | 138 | ||
138 | /** | 139 | /** |
@@ -330,7 +331,7 @@ typedef void | |||
330 | * @return #GNUNET_OK if the message is well-formed, | 331 | * @return #GNUNET_OK if the message is well-formed, |
331 | * #GNUNET_SYSERR if not | 332 | * #GNUNET_SYSERR if not |
332 | */ | 333 | */ |
333 | typedef int | 334 | typedef enum GNUNET_GenericReturnValue |
334 | (*GNUNET_MQ_MessageValidationCallback) ( | 335 | (*GNUNET_MQ_MessageValidationCallback) ( |
335 | void *cls, | 336 | void *cls, |
336 | const struct GNUNET_MessageHeader *msg); | 337 | const struct GNUNET_MessageHeader *msg); |
@@ -530,9 +531,9 @@ struct GNUNET_MQ_MessageHandler | |||
530 | * End-marker for the handlers array | 531 | * End-marker for the handlers array |
531 | */ | 532 | */ |
532 | #define GNUNET_MQ_handler_end() \ | 533 | #define GNUNET_MQ_handler_end() \ |
533 | { \ | 534 | { \ |
534 | NULL, NULL, NULL, 0, 0 \ | 535 | NULL, NULL, NULL, 0, 0 \ |
535 | } | 536 | } |
536 | 537 | ||
537 | 538 | ||
538 | /** | 539 | /** |
@@ -564,7 +565,7 @@ struct GNUNET_MQ_MessageHandler | |||
564 | * @param ctx context for the callbacks | 565 | * @param ctx context for the callbacks |
565 | */ | 566 | */ |
566 | #define GNUNET_MQ_hd_fixed_size(name, code, str, ctx) \ | 567 | #define GNUNET_MQ_hd_fixed_size(name, code, str, ctx) \ |
567 | ({ \ | 568 | ({ \ |
568 | void (*_cb)(void *cls, const str *msg) = &handle_ ## name; \ | 569 | void (*_cb)(void *cls, const str *msg) = &handle_ ## name; \ |
569 | ((struct GNUNET_MQ_MessageHandler){ NULL, \ | 570 | ((struct GNUNET_MQ_MessageHandler){ NULL, \ |
570 | (GNUNET_MQ_MessageCallback) _cb, \ | 571 | (GNUNET_MQ_MessageCallback) _cb, \ |
@@ -616,7 +617,7 @@ struct GNUNET_MQ_MessageHandler | |||
616 | * @param ctx context for the callbacks | 617 | * @param ctx context for the callbacks |
617 | */ | 618 | */ |
618 | #define GNUNET_MQ_hd_var_size(name, code, str, ctx) \ | 619 | #define GNUNET_MQ_hd_var_size(name, code, str, ctx) \ |
619 | __extension__ ({ \ | 620 | __extension__ ({ \ |
620 | int (*_mv)(void *cls, const str *msg) = &check_ ## name; \ | 621 | int (*_mv)(void *cls, const str *msg) = &check_ ## name; \ |
621 | void (*_cb)(void *cls, const str *msg) = &handle_ ## name; \ | 622 | void (*_cb)(void *cls, const str *msg) = &handle_ ## name; \ |
622 | ((struct GNUNET_MQ_MessageHandler){ (GNUNET_MQ_MessageValidationCallback) \ | 623 | ((struct GNUNET_MQ_MessageHandler){ (GNUNET_MQ_MessageValidationCallback) \ |
@@ -639,17 +640,17 @@ struct GNUNET_MQ_MessageHandler | |||
639 | * the size, starting with a `struct GNUNET_MessageHeader` | 640 | * the size, starting with a `struct GNUNET_MessageHeader` |
640 | */ | 641 | */ |
641 | #define GNUNET_MQ_check_zero_termination(m) \ | 642 | #define GNUNET_MQ_check_zero_termination(m) \ |
642 | { \ | 643 | { \ |
643 | const char *str = (const char *) &m[1]; \ | 644 | const char *str = (const char *) &m[1]; \ |
644 | const struct GNUNET_MessageHeader *hdr = \ | 645 | const struct GNUNET_MessageHeader *hdr = \ |
645 | (const struct GNUNET_MessageHeader *) m; \ | 646 | (const struct GNUNET_MessageHeader *) m; \ |
646 | uint16_t slen = ntohs (hdr->size) - sizeof(*m); \ | 647 | uint16_t slen = ntohs (hdr->size) - sizeof(*m); \ |
647 | if ((0 == slen) || (memchr (str, 0, slen) != &str[slen - 1])) \ | 648 | if ((0 == slen) || (memchr (str, 0, slen) != &str[slen - 1])) \ |
648 | { \ | 649 | { \ |
649 | GNUNET_break (0); \ | 650 | GNUNET_break (0); \ |
650 | return GNUNET_NO; \ | 651 | return GNUNET_NO; \ |
651 | } \ | 652 | } \ |
652 | } | 653 | } |
653 | 654 | ||
654 | 655 | ||
655 | /** | 656 | /** |
@@ -665,19 +666,19 @@ struct GNUNET_MQ_MessageHandler | |||
665 | * the size, starting with a `struct GNUNET_MessageHeader` | 666 | * the size, starting with a `struct GNUNET_MessageHeader` |
666 | */ | 667 | */ |
667 | #define GNUNET_MQ_check_boxed_message(m) \ | 668 | #define GNUNET_MQ_check_boxed_message(m) \ |
668 | { \ | 669 | { \ |
669 | const struct GNUNET_MessageHeader *inbox = \ | 670 | const struct GNUNET_MessageHeader *inbox = \ |
670 | (const struct GNUNET_MessageHeader *) &m[1]; \ | 671 | (const struct GNUNET_MessageHeader *) &m[1]; \ |
671 | const struct GNUNET_MessageHeader *hdr = \ | 672 | const struct GNUNET_MessageHeader *hdr = \ |
672 | (const struct GNUNET_MessageHeader *) m; \ | 673 | (const struct GNUNET_MessageHeader *) m; \ |
673 | uint16_t slen = ntohs (hdr->size) - sizeof(*m); \ | 674 | uint16_t slen = ntohs (hdr->size) - sizeof(*m); \ |
674 | if ((slen < sizeof(struct GNUNET_MessageHeader)) || \ | 675 | if ((slen < sizeof(struct GNUNET_MessageHeader)) || \ |
675 | (slen != ntohs (inbox->size))) \ | 676 | (slen != ntohs (inbox->size))) \ |
676 | { \ | 677 | { \ |
677 | GNUNET_break (0); \ | 678 | GNUNET_break (0); \ |
678 | return GNUNET_NO; \ | 679 | return GNUNET_NO; \ |
679 | } \ | 680 | } \ |
680 | } | 681 | } |
681 | 682 | ||
682 | 683 | ||
683 | /** | 684 | /** |
diff --git a/src/include/gnunet_nat_service.h b/src/include/gnunet_nat_service.h index f2854a0be..ba9f252a0 100644 --- a/src/include/gnunet_nat_service.h +++ b/src/include/gnunet_nat_service.h | |||
@@ -345,6 +345,19 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
345 | 345 | ||
346 | 346 | ||
347 | /** | 347 | /** |
348 | * Add global address to the list of addresses and notify clients. | ||
349 | * | ||
350 | * @param nh the handle returned by register | ||
351 | * @param addr IP address to add. | ||
352 | * @param address_length number of bytes in @a addr | ||
353 | */ | ||
354 | void | ||
355 | GNUNET_NAT_add_global_address (struct GNUNET_NAT_Handle *nh, | ||
356 | char *addr, | ||
357 | unsigned int address_length); | ||
358 | |||
359 | |||
360 | /** | ||
348 | * Test if the given address is (currently) a plausible IP address for | 361 | * Test if the given address is (currently) a plausible IP address for |
349 | * this peer. Mostly a convenience function so that clients do not | 362 | * this peer. Mostly a convenience function so that clients do not |
350 | * have to explicitly track all IPs that the #GNUNET_NAT_AddressCallback | 363 | * have to explicitly track all IPs that the #GNUNET_NAT_AddressCallback |
diff --git a/src/include/gnunet_pq_lib.h b/src/include/gnunet_pq_lib.h index 3d9c12cb2..7501bee12 100644 --- a/src/include/gnunet_pq_lib.h +++ b/src/include/gnunet_pq_lib.h | |||
@@ -577,7 +577,7 @@ GNUNET_PQ_query_param_uint32 (const uint32_t *x); | |||
577 | 577 | ||
578 | 578 | ||
579 | /** | 579 | /** |
580 | * Generate query parameter for an uint16_t in host byte order. | 580 | * Generate query parameter for an uint64_t in host byte order. |
581 | * | 581 | * |
582 | * @param x pointer to the query parameter to pass | 582 | * @param x pointer to the query parameter to pass |
583 | * @return query parameter to use | 583 | * @return query parameter to use |
@@ -586,6 +586,37 @@ struct GNUNET_PQ_QueryParam | |||
586 | GNUNET_PQ_query_param_uint64 (const uint64_t *x); | 586 | GNUNET_PQ_query_param_uint64 (const uint64_t *x); |
587 | 587 | ||
588 | 588 | ||
589 | /** | ||
590 | * Generate query parameter for an int64_t in host byte order. | ||
591 | * | ||
592 | * @param x pointer to the query parameter to pass | ||
593 | * @return query parameter to use | ||
594 | */ | ||
595 | struct GNUNET_PQ_QueryParam | ||
596 | GNUNET_PQ_query_param_int64 (const int64_t *x); | ||
597 | |||
598 | /** | ||
599 | * Generate query parameter for a blind sign public key. | ||
600 | * Internally, the various attributes of the public key | ||
601 | * will be serialized into on variable-size BLOB. | ||
602 | * | ||
603 | * @param pub pointer to the query parameter to pass | ||
604 | * | ||
605 | */ | ||
606 | struct GNUNET_PQ_QueryParam | ||
607 | GNUNET_PQ_query_param_blind_sign_pub ( | ||
608 | const struct GNUNET_CRYPTO_BlindSignPublicKey *pub); | ||
609 | |||
610 | /** | ||
611 | * Generate query parameter for a blind sign private key of variable size. | ||
612 | * | ||
613 | * @param priv pointer to the query parameter to pass | ||
614 | * | ||
615 | */ | ||
616 | struct GNUNET_PQ_QueryParam | ||
617 | GNUNET_PQ_query_param_blind_sign_priv ( | ||
618 | const struct GNUNET_CRYPTO_BlindSignPrivateKey *priv); | ||
619 | |||
589 | /* ************************* pq_result_helper.c functions ************************ */ | 620 | /* ************************* pq_result_helper.c functions ************************ */ |
590 | 621 | ||
591 | 622 | ||
@@ -895,6 +926,19 @@ struct GNUNET_PQ_ResultSpec | |||
895 | GNUNET_PQ_result_spec_uint64 (const char *name, | 926 | GNUNET_PQ_result_spec_uint64 (const char *name, |
896 | uint64_t *u64); | 927 | uint64_t *u64); |
897 | 928 | ||
929 | |||
930 | /** | ||
931 | * int64_t expected. | ||
932 | * | ||
933 | * @param name name of the field in the table | ||
934 | * @param[out] i64 where to store the result | ||
935 | * @return array entry for the result specification to use | ||
936 | */ | ||
937 | struct GNUNET_PQ_ResultSpec | ||
938 | GNUNET_PQ_result_spec_int64 (const char *name, | ||
939 | int64_t *i64); | ||
940 | |||
941 | |||
898 | /** | 942 | /** |
899 | * array of bool expected. | 943 | * array of bool expected. |
900 | * | 944 | * |
@@ -1081,6 +1125,32 @@ GNUNET_PQ_result_spec_array_string ( | |||
1081 | size_t *num, | 1125 | size_t *num, |
1082 | char **dst); | 1126 | char **dst); |
1083 | 1127 | ||
1128 | |||
1129 | /** | ||
1130 | * Blind sign public key expected. | ||
1131 | * | ||
1132 | * @param name name of the field in the table | ||
1133 | * @param[out] public_key where to store the denomination signature | ||
1134 | * @return array entry for the result specification to use | ||
1135 | */ | ||
1136 | struct GNUNET_PQ_ResultSpec | ||
1137 | GNUNET_PQ_result_spec_blind_sign_pub ( | ||
1138 | const char *name, | ||
1139 | struct GNUNET_CRYPTO_BlindSignPublicKey **public_key); | ||
1140 | |||
1141 | |||
1142 | /** | ||
1143 | * Blind sign private key expected. | ||
1144 | * | ||
1145 | * @param name name of the field in the table | ||
1146 | * @param[out] private_key where to store the denomination signature | ||
1147 | * @return array entry for the result specification to use | ||
1148 | */ | ||
1149 | struct GNUNET_PQ_ResultSpec | ||
1150 | GNUNET_PQ_result_spec_blind_sign_priv ( | ||
1151 | const char *name, | ||
1152 | struct GNUNET_CRYPTO_BlindSignPrivateKey **private_key); | ||
1153 | |||
1084 | /* ************************* pq.c functions ************************ */ | 1154 | /* ************************* pq.c functions ************************ */ |
1085 | 1155 | ||
1086 | /** | 1156 | /** |
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 8638703db..6ab008d16 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -3216,6 +3216,11 @@ extern "C" { | |||
3216 | #define GNUNET_MESSAGE_TYPE_NAT_ADDRESS_CHANGE 1064 | 3216 | #define GNUNET_MESSAGE_TYPE_NAT_ADDRESS_CHANGE 1064 |
3217 | 3217 | ||
3218 | /** | 3218 | /** |
3219 | * Message to ask NAT service to notify all clients about a new global address. | ||
3220 | */ | ||
3221 | #define GNUNET_MESSAGE_TYPE_NAT_ADD_GLOBAL_ADDRESS 1065 | ||
3222 | |||
3223 | /** | ||
3219 | * Message to ask NAT service to request autoconfiguration. | 3224 | * Message to ask NAT service to request autoconfiguration. |
3220 | */ | 3225 | */ |
3221 | #define GNUNET_MESSAGE_TYPE_NAT_AUTO_REQUEST_CFG 1067 | 3226 | #define GNUNET_MESSAGE_TYPE_NAT_AUTO_REQUEST_CFG 1067 |
diff --git a/src/include/gnunet_reclaim_service.h b/src/include/gnunet_reclaim_service.h index a8ab8776e..086c3f021 100644 --- a/src/include/gnunet_reclaim_service.h +++ b/src/include/gnunet_reclaim_service.h | |||
@@ -49,7 +49,7 @@ extern "C" { | |||
49 | /** | 49 | /** |
50 | * Version number of the re:claimID API. | 50 | * Version number of the re:claimID API. |
51 | */ | 51 | */ |
52 | #define GNUNET_RECLAIM_VERSION 0x00000001 | 52 | #define GNUNET_RECLAIM_VERSION 0x00000002 |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Opaque handle to access the service. | 55 | * Opaque handle to access the service. |
@@ -62,6 +62,9 @@ struct GNUNET_RECLAIM_Handle; | |||
62 | */ | 62 | */ |
63 | struct GNUNET_RECLAIM_Operation; | 63 | struct GNUNET_RECLAIM_Operation; |
64 | 64 | ||
65 | #define GNUNET_RECLAIM_TICKET_RP_URI_MAX_LEN 256 | ||
66 | |||
67 | #define GNUNET_RECLAIM_TICKET_RP_URI_URN_PREFIX "urn:gns:" | ||
65 | 68 | ||
66 | /** | 69 | /** |
67 | * The authorization ticket. This ticket is meant to be transferred | 70 | * The authorization ticket. This ticket is meant to be transferred |
@@ -72,19 +75,30 @@ struct GNUNET_RECLAIM_Operation; | |||
72 | struct GNUNET_RECLAIM_Ticket | 75 | struct GNUNET_RECLAIM_Ticket |
73 | { | 76 | { |
74 | /** | 77 | /** |
75 | * The ticket issuer (= the user) | 78 | * The ticket. A GNS name ending in the |
79 | * zTLD for identity. | ||
80 | * Base32(rnd).zTLD(identity) | ||
81 | * 0-terminated string. | ||
76 | */ | 82 | */ |
77 | struct GNUNET_CRYPTO_PublicKey identity; | 83 | char gns_name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH * 2 + 2]; |
78 | 84 | ||
79 | /** | 85 | /** |
80 | * The ticket audience (= relying party) | 86 | * The ticket issuer (= the user) |
81 | */ | 87 | */ |
82 | struct GNUNET_CRYPTO_PublicKey audience; | 88 | //struct GNUNET_CRYPTO_PublicKey identity; |
83 | 89 | ||
84 | /** | 90 | /** |
85 | * The ticket random identifier | 91 | * The ticket random identifier |
86 | */ | 92 | */ |
87 | struct GNUNET_RECLAIM_Identifier rnd; | 93 | //struct GNUNET_RECLAIM_Identifier rnd; |
94 | |||
95 | |||
96 | /** | ||
97 | * Followed by the ticket audience (= relying party) URI. | ||
98 | * 0-terminated string. | ||
99 | * Example: "urn:gns:000G002B4RF1XPBXDPGZA0PT16BHQCS427YQK4NC84KZMK7TK8C2Z5GMK8" | ||
100 | */ | ||
101 | //char rp_uri[GNUNET_RECLAIM_TICKET_RP_URI_MAX_LEN]; | ||
88 | }; | 102 | }; |
89 | 103 | ||
90 | 104 | ||
@@ -95,10 +109,12 @@ struct GNUNET_RECLAIM_Ticket | |||
95 | * | 109 | * |
96 | * @param cls closure | 110 | * @param cls closure |
97 | * @param ticket the ticket | 111 | * @param ticket the ticket |
112 | * @param rp_uri the RP URI of the ticket | ||
98 | */ | 113 | */ |
99 | typedef void (*GNUNET_RECLAIM_TicketCallback) ( | 114 | typedef void (*GNUNET_RECLAIM_TicketCallback) ( |
100 | void *cls, | 115 | void *cls, |
101 | const struct GNUNET_RECLAIM_Ticket *ticket); | 116 | const struct GNUNET_RECLAIM_Ticket *ticket, |
117 | const char* rp_uri); | ||
102 | 118 | ||
103 | /** | 119 | /** |
104 | * Method called when a token has been issued. | 120 | * Method called when a token has been issued. |
@@ -376,7 +392,7 @@ GNUNET_RECLAIM_get_credentials_stop ( | |||
376 | * | 392 | * |
377 | * @param h the identity provider to use | 393 | * @param h the identity provider to use |
378 | * @param iss the issuing identity (= the user) | 394 | * @param iss the issuing identity (= the user) |
379 | * @param rp the subject of the ticket (= the relying party) | 395 | * @param rp_uri the subject of the ticket (= the relying party) see #GNUNET_RECLAIM_Ticket |
380 | * @param attrs the attributes that the relying party is given access to | 396 | * @param attrs the attributes that the relying party is given access to |
381 | * @param cb the callback | 397 | * @param cb the callback |
382 | * @param cb_cls the callback closure | 398 | * @param cb_cls the callback closure |
@@ -386,7 +402,7 @@ struct GNUNET_RECLAIM_Operation * | |||
386 | GNUNET_RECLAIM_ticket_issue ( | 402 | GNUNET_RECLAIM_ticket_issue ( |
387 | struct GNUNET_RECLAIM_Handle *h, | 403 | struct GNUNET_RECLAIM_Handle *h, |
388 | const struct GNUNET_CRYPTO_PrivateKey *iss, | 404 | const struct GNUNET_CRYPTO_PrivateKey *iss, |
389 | const struct GNUNET_CRYPTO_PublicKey *rp, | 405 | const char *rp_uri, |
390 | const struct GNUNET_RECLAIM_AttributeList *attrs, | 406 | const struct GNUNET_RECLAIM_AttributeList *attrs, |
391 | GNUNET_RECLAIM_IssueTicketCallback cb, void *cb_cls); | 407 | GNUNET_RECLAIM_IssueTicketCallback cb, void *cb_cls); |
392 | 408 | ||
@@ -417,9 +433,8 @@ GNUNET_RECLAIM_ticket_revoke ( | |||
417 | * information from the issuer | 433 | * information from the issuer |
418 | * | 434 | * |
419 | * @param h the identity provider to use | 435 | * @param h the identity provider to use |
420 | * @param identity the identity that is the subject of the issued ticket (the | ||
421 | * relying party) | ||
422 | * @param ticket the issued ticket to consume | 436 | * @param ticket the issued ticket to consume |
437 | * @param rp_uri the RP URI | ||
423 | * @param cb the callback to call | 438 | * @param cb the callback to call |
424 | * @param cb_cls the callback closure | 439 | * @param cb_cls the callback closure |
425 | * @return handle to abort the operation | 440 | * @return handle to abort the operation |
@@ -427,8 +442,8 @@ GNUNET_RECLAIM_ticket_revoke ( | |||
427 | struct GNUNET_RECLAIM_Operation * | 442 | struct GNUNET_RECLAIM_Operation * |
428 | GNUNET_RECLAIM_ticket_consume ( | 443 | GNUNET_RECLAIM_ticket_consume ( |
429 | struct GNUNET_RECLAIM_Handle *h, | 444 | struct GNUNET_RECLAIM_Handle *h, |
430 | const struct GNUNET_CRYPTO_PrivateKey *identity, | ||
431 | const struct GNUNET_RECLAIM_Ticket *ticket, | 445 | const struct GNUNET_RECLAIM_Ticket *ticket, |
446 | const char *rp_uri, | ||
432 | GNUNET_RECLAIM_AttributeTicketResult cb, void *cb_cls); | 447 | GNUNET_RECLAIM_AttributeTicketResult cb, void *cb_cls); |
433 | 448 | ||
434 | 449 | ||
@@ -499,44 +514,6 @@ GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h); | |||
499 | void | 514 | void |
500 | GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op); | 515 | GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op); |
501 | 516 | ||
502 | /** | ||
503 | * Get serialized ticket size | ||
504 | * | ||
505 | * @param tkt the ticket | ||
506 | * @return the buffer length requirement for a serialization | ||
507 | */ | ||
508 | size_t | ||
509 | GNUNET_RECLAIM_ticket_serialize_get_size (const struct GNUNET_RECLAIM_Ticket *tkt); | ||
510 | |||
511 | /** | ||
512 | * Deserializes a ticket | ||
513 | * | ||
514 | * @param buffer the buffer to read from | ||
515 | * @param len the length of the buffer | ||
516 | * @param tkt the ticket to write to (must be allocated) | ||
517 | * @param kb_read how many bytes were read from buffer | ||
518 | * @return GNUNET_SYSERR on error | ||
519 | */ | ||
520 | enum GNUNET_GenericReturnValue | ||
521 | GNUNET_RECLAIM_read_ticket_from_buffer (const void *buffer, | ||
522 | size_t len, | ||
523 | struct GNUNET_RECLAIM_Ticket *tkt, | ||
524 | size_t *tb_read); | ||
525 | |||
526 | /** | ||
527 | * Serializes a ticket | ||
528 | * | ||
529 | * @param tkt the ticket to serialize | ||
530 | * @param buffer the buffer to serialize to (must be allocated with sufficient size | ||
531 | * @param len the length of the buffer | ||
532 | * @return the number of written bytes or < 0 on error | ||
533 | */ | ||
534 | ssize_t | ||
535 | GNUNET_RECLAIM_write_ticket_to_buffer (const struct | ||
536 | GNUNET_RECLAIM_Ticket *tkt, | ||
537 | void *buffer, | ||
538 | size_t len); | ||
539 | |||
540 | #if 0 /* keep Emacsens' auto-indent happy */ | 517 | #if 0 /* keep Emacsens' auto-indent happy */ |
541 | { | 518 | { |
542 | #endif | 519 | #endif |
diff --git a/src/include/gnunet_testbed_lib.h b/src/include/gnunet_testbed_lib.h new file mode 100644 index 000000000..e33f31ee1 --- /dev/null +++ b/src/include/gnunet_testbed_lib.h | |||
@@ -0,0 +1,130 @@ | |||
1 | #ifndef GNUNET_TESTBED_LIB_H | ||
2 | #define GNUNET_TESTBED_LIB_H | ||
3 | |||
4 | /** | ||
5 | * FIXME. | ||
6 | */ | ||
7 | struct GNUNET_TESTBED_System; | ||
8 | |||
9 | #define GNUNET_TESTBED_PREFIX "GNUNET_TESTBED_PREFIX" | ||
10 | |||
11 | /** | ||
12 | * Create a system handle. There must only be one system | ||
13 | * handle per operating system. | ||
14 | * | ||
15 | * @param testdir only the directory name without any path. This is used for | ||
16 | * all service homes; the directory will be created in a temporary | ||
17 | * location depending on the underlying OS. This variable will be | ||
18 | * overridden with the value of the environmental variable | ||
19 | * GNUNET_TESTBED_PREFIX, if it exists. | ||
20 | * @param trusted_ip the ip address which will be set as TRUSTED HOST in all | ||
21 | * service configurations generated to allow control connections from | ||
22 | * this ip. This can either be a single ip address or a network address | ||
23 | * in CIDR notation. | ||
24 | * @param hostname the hostname of the system we are using for testing; NULL for | ||
25 | * localhost | ||
26 | * @param lowport lowest port number this system is allowed to allocate (inclusive) | ||
27 | * @param highport highest port number this system is allowed to allocate (exclusive) | ||
28 | * @return handle to this system, NULL on error | ||
29 | */ | ||
30 | struct GNUNET_TESTBED_System * | ||
31 | GNUNET_TESTBED_system_create_with_portrange ( | ||
32 | const char *testdir, | ||
33 | const char *trusted_ip, | ||
34 | const char *hostname, | ||
35 | uint16_t lowport, | ||
36 | uint16_t highport); | ||
37 | |||
38 | |||
39 | /** | ||
40 | * Create a system handle. There must only be one system handle per operating | ||
41 | * system. Uses a default range for allowed ports. Ports are still tested for | ||
42 | * availability. | ||
43 | * | ||
44 | * @param testdir only the directory name without any path. This is used for all | ||
45 | * service homes; the directory will be created in a temporary location | ||
46 | * depending on the underlying OS. This variable will be | ||
47 | * overridden with the value of the environmental variable | ||
48 | * GNUNET_TESTBED_PREFIX, if it exists. | ||
49 | * @param trusted_ip the ip address which will be set as TRUSTED HOST in all | ||
50 | * service configurations generated to allow control connections from | ||
51 | * this ip. This can either be a single ip address or a network address | ||
52 | * in CIDR notation. | ||
53 | * @param hostname the hostname of the system we are using for testing; NULL for | ||
54 | * localhost | ||
55 | * @param shared_services NULL terminated array describing services that are to | ||
56 | * be shared among peers | ||
57 | * @return handle to this system, NULL on error | ||
58 | */ | ||
59 | struct GNUNET_TESTBED_System * | ||
60 | GNUNET_TESTBED_system_create ( | ||
61 | const char *testdir, | ||
62 | const char *trusted_ip, | ||
63 | const char *hostname); | ||
64 | |||
65 | |||
66 | /** | ||
67 | * Free system resources. | ||
68 | * | ||
69 | * @param system system to be freed | ||
70 | * @param remove_paths should the 'testdir' and all subdirectories | ||
71 | * be removed (clean up on shutdown)? | ||
72 | */ | ||
73 | void | ||
74 | GNUNET_TESTBED_system_destroy ( | ||
75 | struct GNUNET_TESTBED_System *system, | ||
76 | bool remove_paths); | ||
77 | |||
78 | |||
79 | /** | ||
80 | * Reserve a TCP or UDP port for a peer. | ||
81 | * | ||
82 | * @param system system to use for reservation tracking | ||
83 | * @return 0 if no free port was available | ||
84 | */ | ||
85 | uint16_t | ||
86 | GNUNET_TESTBED_reserve_port ( | ||
87 | struct GNUNET_TESTBED_System *system); | ||
88 | |||
89 | |||
90 | /** | ||
91 | * Release reservation of a TCP or UDP port for a peer | ||
92 | * (used during #GNUNET_TESTBED_peer_destroy()). | ||
93 | * | ||
94 | * @param system system to use for reservation tracking | ||
95 | * @param port reserved port to release | ||
96 | */ | ||
97 | void | ||
98 | GNUNET_TESTBED_release_port ( | ||
99 | struct GNUNET_TESTBED_System *system, | ||
100 | uint16_t port); | ||
101 | |||
102 | |||
103 | /** | ||
104 | * Create a new configuration using the given configuration as a template; | ||
105 | * ports and paths will be modified to select available ports on the local | ||
106 | * system. The default configuration will be available in PATHS section under | ||
107 | * the option DEFAULTCONFIG after the call. GNUNET_HOME is also set in PATHS | ||
108 | * section to the temporary directory specific to this configuration. If we run | ||
109 | * out of "*port" numbers, return #GNUNET_SYSERR. | ||
110 | * | ||
111 | * This is primarily a helper function used internally | ||
112 | * by 'GNUNET_TESTBED_peer_configure'. | ||
113 | * | ||
114 | * @param system system to use to coordinate resource usage | ||
115 | * @param cfg template configuration to update | ||
116 | * @param ports array with port numbers used in the created configuration. | ||
117 | * Will be updated upon successful return. Can be NULL | ||
118 | * @param nports the size of the `ports' array. Will be updated. | ||
119 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error - the configuration will | ||
120 | * be incomplete and should not be used there upon | ||
121 | */ | ||
122 | enum GNUNET_GenericReturnValue | ||
123 | GNUNET_TESTBED_configuration_create ( | ||
124 | struct GNUNET_TESTBED_System *system, | ||
125 | struct GNUNET_CONFIGURATION_Handle *cfg, | ||
126 | uint16_t **ports, | ||
127 | unsigned int *nports); | ||
128 | |||
129 | |||
130 | #endif | ||
diff --git a/src/include/gnunet_testing_arm_lib.h b/src/include/gnunet_testing_arm_lib.h new file mode 100644 index 000000000..66852b506 --- /dev/null +++ b/src/include/gnunet_testing_arm_lib.h | |||
@@ -0,0 +1,47 @@ | |||
1 | #ifndef GNUNET_TESTING_ARM_LIB_H | ||
2 | #define GNUNET_TESTING_ARM_LIB_H | ||
3 | |||
4 | #include "gnunet_arm_service.h" | ||
5 | |||
6 | /** | ||
7 | * Create command. | ||
8 | * | ||
9 | * @param label name for command. | ||
10 | * @param system_label Label of the cmd to setup a test environment. | ||
11 | * @param cfgname Configuration file name for this peer. | ||
12 | * @return command. | ||
13 | */ | ||
14 | struct GNUNET_TESTING_Command | ||
15 | GNUNET_TESTING_ARM_cmd_start_peer ( | ||
16 | const char *label, | ||
17 | const char *system_label, | ||
18 | const char *cfgname); | ||
19 | |||
20 | |||
21 | /** | ||
22 | * Create command. | ||
23 | * | ||
24 | * @param label name for command. | ||
25 | * @param start_label Label of the cmd to start the peer. | ||
26 | * @return command. | ||
27 | */ | ||
28 | struct GNUNET_TESTING_Command | ||
29 | GNUNET_TESTING_cmd_stop_peer ( | ||
30 | const char *label, | ||
31 | const char *start_label); | ||
32 | |||
33 | |||
34 | /** | ||
35 | * Call #op on all simple traits. | ||
36 | */ | ||
37 | #define GNUNET_TESTING_ARM_SIMPLE_TRAITS(op, prefix) \ | ||
38 | op (prefix, \ | ||
39 | arm_handle, \ | ||
40 | struct GNUNET_ARM_Handle) | ||
41 | |||
42 | |||
43 | GNUNET_TESTING_ARM_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT, | ||
44 | GNUNET_TESTING_ARM) | ||
45 | |||
46 | |||
47 | #endif | ||
diff --git a/src/include/gnunet_testing_barrier.h b/src/include/gnunet_testing_barrier.h deleted file mode 100644 index b0f4e1c03..000000000 --- a/src/include/gnunet_testing_barrier.h +++ /dev/null | |||
@@ -1,122 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2022 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file include/gnunet_testing_barrier.h | ||
23 | * @brief API to manage barriers. | ||
24 | * @author t3sserakt | ||
25 | */ | ||
26 | |||
27 | #ifndef GNUNET_TESTING_BARRIER_LIB_H | ||
28 | #define GNUNET_TESTING_BARRIER_LIB_H | ||
29 | |||
30 | #include "gnunet_testing_plugin.h" | ||
31 | |||
32 | |||
33 | struct GNUNET_TESTING_Barrier; | ||
34 | |||
35 | |||
36 | #define GNUNET_TESTING_BARRIER_MAX 32 | ||
37 | |||
38 | /** | ||
39 | * An entry for a barrier list | ||
40 | * FIXME: why is this in the public API!??! | ||
41 | */ | ||
42 | struct GNUNET_TESTING_BarrierListEntry | ||
43 | { | ||
44 | /* DLL */ | ||
45 | struct GNUNET_TESTING_BarrierListEntry *next; | ||
46 | |||
47 | /* DLL */ | ||
48 | struct GNUNET_TESTING_BarrierListEntry *prev; | ||
49 | |||
50 | /* The barrier name*/ | ||
51 | char *barrier_name; | ||
52 | |||
53 | /** | ||
54 | * Number of commands attached to the barrier. | ||
55 | */ | ||
56 | unsigned int expected_reaches; | ||
57 | }; | ||
58 | |||
59 | /** | ||
60 | * A list to hold barriers provided by plugins | ||
61 | * FIXME: why is this in the public API!??! | ||
62 | */ | ||
63 | struct GNUNET_TESTING_BarrierList | ||
64 | { | ||
65 | /** List head **/ | ||
66 | struct GNUNET_TESTING_BarrierListEntry *head; | ||
67 | |||
68 | /** List tail **/ | ||
69 | struct GNUNET_TESTING_BarrierListEntry *tail; | ||
70 | }; | ||
71 | |||
72 | |||
73 | /** | ||
74 | * Command to create a barrier. | ||
75 | * | ||
76 | * FIXME: high-level it is baffling how we need both the GNUNET_TESTING_Barrier | ||
77 | * and the Command that creates barriers. Conceptually this seems to be | ||
78 | * very much separate. Can we move _Barrier completely into testing as private? | ||
79 | * | ||
80 | * @param label The label of this command. | ||
81 | * @param percentage_to_be_reached If this percentage of processes reached | ||
82 | * this barrier, all processes waiting at | ||
83 | * this barrier can pass it. Must not be | ||
84 | * used together with number_to_be_reached. | ||
85 | * @param number_to_be_reached If this number of processes reached | ||
86 | * this barrier, all processes waiting at | ||
87 | * this barrier can pass it. Must not be | ||
88 | * used together with percentage_to_be_reached. | ||
89 | */ | ||
90 | struct GNUNET_TESTING_Command | ||
91 | GNUNET_TESTING_cmd_barrier_create ( | ||
92 | const char *label, | ||
93 | double percentage_to_be_reached, | ||
94 | unsigned int number_to_be_reached); | ||
95 | |||
96 | |||
97 | /** | ||
98 | * If this command is executed the the process is signaling the master process | ||
99 | * that it reached a barrier. If this command is synchronous it will block. | ||
100 | * | ||
101 | * FIXME: Now this, as it returns a Command, seems to me like it should be | ||
102 | * part of the public API? | ||
103 | * | ||
104 | * @param label name for command. | ||
105 | * @param barrier_label The name of the barrier we waited for and which was reached. | ||
106 | * @param asynchronous_finish If #GNUNET_YES this command will not block. | ||
107 | * @param node_number The global number of the node the cmd runs on. | ||
108 | * @param running_on_master Is this cmd running on the master loop? | ||
109 | * @param write_message Callback to write messages to the master loop. | ||
110 | * @return command. | ||
111 | */ | ||
112 | struct GNUNET_TESTING_Command | ||
113 | GNUNET_TESTING_cmd_barrier_reached ( | ||
114 | const char *label, | ||
115 | const char *barrier_label, | ||
116 | unsigned int asynchronous_finish, /* FIXME: why not a bool? */ | ||
117 | unsigned int node_number, | ||
118 | unsigned int running_on_master, /* FIXME: why not a bool? */ | ||
119 | GNUNET_TESTING_cmd_helper_write_cb write_message); /* FIXME: no 'cls' closure argument!? */ | ||
120 | |||
121 | #endif | ||
122 | /* end of testing_barrier.h */ | ||
diff --git a/src/include/gnunet_core_testing_lib.h b/src/include/gnunet_testing_core_lib.h index bf6f416d9..cf96b395d 100644 --- a/src/include/gnunet_core_testing_lib.h +++ b/src/include/gnunet_testing_core_lib.h | |||
@@ -22,12 +22,12 @@ | |||
22 | * @brief API for cmds working with core sub system provided by libgnunetcoretesting | 22 | * @brief API for cmds working with core sub system provided by libgnunetcoretesting |
23 | * @author t3sserakt | 23 | * @author t3sserakt |
24 | */ | 24 | */ |
25 | #ifndef GNUNET_CORE_TESTING_LIB_H | 25 | #ifndef GNUNET_TESTING_CORE_LIB_H |
26 | #define GNUNET_CORE_TESTING_LIB_H | 26 | #define GNUNET_TESTING_CORE_LIB_H |
27 | 27 | ||
28 | 28 | ||
29 | #include "gnunet_util_lib.h" | 29 | #include "gnunet_util_lib.h" |
30 | #include "gnunet_testing_ng_lib.h" | 30 | #include "gnunet_testing_lib.h" |
31 | 31 | ||
32 | 32 | ||
33 | /** | 33 | /** |
@@ -149,10 +149,11 @@ GNUNET_CORE_cmd_connect_peers ( | |||
149 | * Call #op on all simple traits. | 149 | * Call #op on all simple traits. |
150 | */ | 150 | */ |
151 | #define GNUNET_CORE_TESTING_SIMPLE_TRAITS(op, prefix) \ | 151 | #define GNUNET_CORE_TESTING_SIMPLE_TRAITS(op, prefix) \ |
152 | op (prefix, connect_peer_state, const struct GNUNET_TESTING_ConnectPeersState) | 152 | op (prefix, connect_peer_state, const struct \ |
153 | 153 | GNUNET_TESTING_ConnectPeersState) | |
154 | GNUNET_CORE_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT, GNUNET_CORE_TESTING) | ||
155 | 154 | ||
155 | GNUNET_CORE_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT, | ||
156 | GNUNET_CORE_TESTING) | ||
156 | 157 | ||
157 | 158 | ||
158 | #endif | 159 | #endif |
diff --git a/src/include/gnunet_testing_lib.h b/src/include/gnunet_testing_lib.h index 0d74de8c2..0ee3a68b8 100644 --- a/src/include/gnunet_testing_lib.h +++ b/src/include/gnunet_testing_lib.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2008, 2009, 2012 GNUnet e.V. | 3 | Copyright (C) 2021, 2023, 2024 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -19,445 +19,959 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @addtogroup Testing | 22 | * @brief Central interpreter and command loop for writing an interpreter to test asynchronous systems |
23 | * @{ | 23 | * @author Christian Grothoff <christian@grothoff.org> |
24 | * | 24 | * @author Marcello Stanisci |
25 | * @author Christian Grothoff | 25 | * @author t3sserakt |
26 | * | 26 | */ |
27 | * @file | 27 | #ifndef GNUNET_TESTING_LIB_H |
28 | * Convenience API for writing testcases for GNUnet | 28 | #define GNUNET_TESTING_LIB_H |
29 | |||
30 | #include "gnunet_util_lib.h" | ||
31 | |||
32 | /** | ||
33 | * Maximum length of label in command | ||
34 | */ | ||
35 | #define GNUNET_TESTING_CMD_MAX_LABEL_LENGTH 127 | ||
36 | |||
37 | /* ********************* Helper functions ********************* */ | ||
38 | |||
39 | /** | ||
40 | * Print failing line number and trigger shutdown. Useful | ||
41 | * quite any time after the command "run" method has been called. | ||
42 | * Returns from the current function. | ||
43 | */ | ||
44 | #define GNUNET_TESTING_FAIL(is) \ | ||
45 | do { \ | ||
46 | GNUNET_break (0); \ | ||
47 | GNUNET_TESTING_interpreter_fail (is); \ | ||
48 | return; \ | ||
49 | } while (0) | ||
50 | |||
51 | |||
52 | /** | ||
53 | * Log an error message about a command not having run to completion. | ||
29 | * | 54 | * |
30 | * @defgroup testing Testing library | 55 | * @param is interpreter |
31 | * Library for writing testcases for GNUnet. | 56 | * @param label command label of the incomplete command |
57 | */ | ||
58 | #define GNUNET_TESTING_command_incomplete(is,label) \ | ||
59 | do { \ | ||
60 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ | ||
61 | "Command %s (%s:%u) did not complete (at %s)\n", \ | ||
62 | label, \ | ||
63 | __FILE__, \ | ||
64 | __LINE__, \ | ||
65 | GNUNET_TESTING_interpreter_current_cmd_get_label (is)); \ | ||
66 | } while (0) | ||
67 | |||
68 | |||
69 | /* ******************* Generic interpreter logic ************ */ | ||
70 | |||
71 | /** | ||
72 | * Global state of the interpreter, used by a command | ||
73 | * to access information about other commands. | ||
74 | */ | ||
75 | struct GNUNET_TESTING_Interpreter; | ||
76 | |||
77 | /** | ||
78 | * State each asynchronous command must have in its closure. | ||
79 | */ | ||
80 | struct GNUNET_TESTING_AsyncContext | ||
81 | { | ||
82 | |||
83 | /** | ||
84 | * Interpreter we are part of. Initialized when | ||
85 | * the global interpreter starts. | ||
86 | */ | ||
87 | struct GNUNET_TESTING_Interpreter *is; | ||
88 | |||
89 | /** | ||
90 | * Function to call when async operation is done. | ||
91 | */ | ||
92 | GNUNET_SCHEDULER_TaskCallback notify_finished; | ||
93 | |||
94 | /** | ||
95 | * Closure for @e notify_finished. | ||
96 | */ | ||
97 | void *notify_finished_cls; | ||
98 | |||
99 | /** | ||
100 | * Indication if the command finished (#GNUNET_OK). | ||
101 | * #GNUNET_NO if it did not finish, | ||
102 | * #GNUNET_SYSERR if it failed. | ||
103 | */ | ||
104 | enum GNUNET_GenericReturnValue finished; | ||
105 | |||
106 | /** | ||
107 | * Set to true if interpreter_next() has already been | ||
108 | * called for this command. | ||
109 | */ | ||
110 | bool next_called; | ||
111 | }; | ||
112 | |||
113 | |||
114 | /** | ||
115 | * The asynchronous command of @a ac has failed. | ||
32 | * | 116 | * |
33 | * It can start/stop one or more peers on a system; testing is responsible for | 117 | * @param ac command-specific context |
34 | * managing private keys, ports and paths; it is a low-level library that does | 118 | */ |
35 | * not support higher-level functions such as P2P connection, topology | 119 | void |
36 | * management or distributed testbed maintenance (those are provided by the | 120 | GNUNET_TESTING_async_fail ( |
37 | * [Testbed service](@ref testbed)) | 121 | struct GNUNET_TESTING_AsyncContext *ac); |
122 | |||
123 | |||
124 | /** | ||
125 | * The asynchronous command of @a ac has finished. | ||
38 | * | 126 | * |
39 | * @see [Documentation](https://gnunet.org/writing_testcases) | 127 | * @param ac command-specific context |
128 | */ | ||
129 | void | ||
130 | GNUNET_TESTING_async_finish ( | ||
131 | struct GNUNET_TESTING_AsyncContext *ac); | ||
132 | |||
133 | |||
134 | /** | ||
135 | * Signature of a function used to start executing a command of a test. Runs | ||
136 | * the command. Note that upon return, the interpreter will not automatically | ||
137 | * run the next command if this is an asynchronous command unless the command | ||
138 | * was wrapped in #GNUNET_TESTING_cmd_make_unblocking(), as the command may | ||
139 | * then continue asynchronously in other scheduler tasks. In this case, | ||
140 | * #GNUNET_TESTING_async_finish() must be called to run the next task. | ||
40 | * | 141 | * |
41 | * @{ | 142 | * @param cls closure |
143 | * @param is interpreter running the command | ||
42 | */ | 144 | */ |
145 | typedef void | ||
146 | (*GNUNET_TESTING_CommandRunRoutine)( | ||
147 | void *cls, | ||
148 | struct GNUNET_TESTING_Interpreter *is); | ||
43 | 149 | ||
44 | #ifndef GNUNET_TESTING_LIB_H | ||
45 | #define GNUNET_TESTING_LIB_H | ||
46 | 150 | ||
151 | /** | ||
152 | * Signature of a function used to clean up resources allocated | ||
153 | * by a command. | ||
154 | * | ||
155 | * @param cls closure | ||
156 | */ | ||
157 | typedef void | ||
158 | (*GNUNET_TESTING_CommandCleanupRoutine)(void *cls); | ||
47 | 159 | ||
48 | #include "gnunet_util_lib.h" | ||
49 | #include "gnunet_statistics_service.h" | ||
50 | #include "gnunet_arm_service.h" | ||
51 | 160 | ||
52 | #ifdef __cplusplus | 161 | /** |
53 | extern "C" | 162 | * Signature of a function used to extract traits exposed by a |
54 | { | 163 | * command. |
55 | #if 0 /* keep Emacsens' auto-indent happy */ | 164 | * |
56 | } | 165 | * @param cls closure |
57 | #endif | 166 | * @param[out] ret where to return the trait data |
58 | #endif | 167 | * @param trait name of the trait to return |
168 | * @param index index of the trait (for traits that are indexed) | ||
169 | * @return #GNUNET_OK on success | ||
170 | */ | ||
171 | typedef enum GNUNET_GenericReturnValue | ||
172 | (*GNUNET_TESTING_CommandGetTraits) (void *cls, | ||
173 | const void **ret, | ||
174 | const char *trait, | ||
175 | unsigned int index); | ||
59 | 176 | ||
60 | /** | 177 | /** |
61 | * Size of each hostkey in the hostkey file (in BYTES). | 178 | * Create a new command that may be asynchronous. |
179 | * | ||
180 | * @param cls the closure | ||
181 | * @param label the Label. Maximum length is #GNUNET_TESTING_CMD_MAX_LABEL_LENGTH | ||
182 | * @param run the run routing | ||
183 | * @param cleanup the cleanup function | ||
184 | * @param traits the traits function (optional) | ||
185 | * @param ac the async context, NULL if command is always | ||
186 | * synchronous | ||
187 | * @return the command the function cannot fail | ||
62 | */ | 188 | */ |
63 | #define GNUNET_TESTING_HOSTKEYFILESIZE sizeof(struct \ | 189 | struct GNUNET_TESTING_Command |
64 | GNUNET_CRYPTO_EddsaPrivateKey) | 190 | GNUNET_TESTING_command_new_ac ( |
191 | void *cls, | ||
192 | const char *label, | ||
193 | GNUNET_TESTING_CommandRunRoutine run, | ||
194 | GNUNET_TESTING_CommandCleanupRoutine cleanup, | ||
195 | GNUNET_TESTING_CommandGetTraits traits, | ||
196 | struct GNUNET_TESTING_AsyncContext *ac); | ||
197 | |||
65 | 198 | ||
66 | /** | 199 | /** |
67 | * The environmental variable, if set, that dictates where testing should place | 200 | * Create a new command |
68 | * generated peer configurations | 201 | * |
202 | * @param cls the closure | ||
203 | * @param label the Label. Maximum length is #GNUNET_TESTING_CMD_MAX_LABEL_LENGTH | ||
204 | * @param run the run routing | ||
205 | * @param cleanup the cleanup function | ||
206 | * @param traits the traits function (optional) | ||
207 | * @return the command the function cannot fail | ||
69 | */ | 208 | */ |
70 | #define GNUNET_TESTING_PREFIX "GNUNET_TESTING_PREFIX" | 209 | #define GNUNET_TESTING_command_new(cls,label,run,cleanup,traits) \ |
210 | GNUNET_TESTING_command_new_ac (cls,label,run,cleanup,traits,NULL) | ||
71 | 211 | ||
72 | 212 | ||
73 | /** | 213 | /** |
74 | * Handle for a system on which GNUnet peers are executed; | 214 | * Structure with storage space for a label. |
75 | * a system is used for reserving unique paths and ports. | ||
76 | */ | 215 | */ |
77 | struct GNUNET_TESTING_System; | 216 | struct GNUNET_TESTING_CommandLabel |
217 | { | ||
218 | char value[GNUNET_TESTING_CMD_MAX_LABEL_LENGTH + 1]; | ||
219 | }; | ||
78 | 220 | ||
79 | 221 | ||
80 | /** | 222 | /** |
81 | * Handle for a GNUnet peer controlled by testing. | 223 | * Set @a label to @a value. Asserts that @a value is |
224 | * not longer than #GNUNET_TESTING_CMD_MAX_LABEL_LENGTH. | ||
225 | * | ||
226 | * @param[out] label label to initialize | ||
227 | * @param value value to store into @a label | ||
82 | */ | 228 | */ |
83 | struct GNUNET_TESTING_Peer; | 229 | void |
230 | GNUNET_TESTING_set_label ( | ||
231 | struct GNUNET_TESTING_CommandLabel *label, | ||
232 | const char *value); | ||
84 | 233 | ||
85 | 234 | ||
86 | /** | 235 | /** |
87 | * Specification of a service that is to be shared among peers | 236 | * A command to be run by the interpreter. |
88 | */ | 237 | */ |
89 | struct GNUNET_TESTING_SharedService | 238 | struct GNUNET_TESTING_Command |
90 | { | 239 | { |
240 | |||
241 | /** | ||
242 | * Label for the command. | ||
243 | */ | ||
244 | struct GNUNET_TESTING_CommandLabel label; | ||
245 | |||
246 | /** | ||
247 | * Closure for all commands with command-specific context information. | ||
248 | */ | ||
249 | void *cls; | ||
250 | |||
251 | /** | ||
252 | * Variable name for the command, NULL for none. | ||
253 | */ | ||
254 | const char *name; | ||
255 | |||
256 | /** | ||
257 | * Runs the command. Note that upon return, the interpreter | ||
258 | * will not automatically run the next command, as the command | ||
259 | * may continue asynchronously in other scheduler tasks. Thus, | ||
260 | * the command must ensure to eventually call | ||
261 | * #GNUNET_TESTING_interpreter_next() or | ||
262 | * #GNUNET_TESTING_interpreter_fail(). | ||
263 | * | ||
264 | * If this function creates some asynchronous activity, it should | ||
265 | * initialize @e finish to a function that can be used to wait for | ||
266 | * the asynchronous activity to terminate. | ||
267 | * | ||
268 | * @param cls closure | ||
269 | * @param is interpreter state | ||
270 | */ | ||
271 | GNUNET_TESTING_CommandRunRoutine run; | ||
272 | |||
273 | /** | ||
274 | * Pointer to the asynchronous context in the command's | ||
275 | * closure. Used by the | ||
276 | * #GNUNET_TESTING_async_finish() and | ||
277 | * #GNUNET_TESTING_async_fail() functions. | ||
278 | * | ||
279 | * Must be NULL if a command is synchronous. | ||
280 | */ | ||
281 | struct GNUNET_TESTING_AsyncContext *ac; | ||
282 | |||
91 | /** | 283 | /** |
92 | * The name of the service. | 284 | * Clean up after the command. Run during forced termination |
285 | * (CTRL-C) or test failure or test success. | ||
286 | * | ||
287 | * @param cls closure | ||
93 | */ | 288 | */ |
94 | const char *service; | 289 | GNUNET_TESTING_CommandCleanupRoutine cleanup; |
95 | 290 | ||
96 | /** | 291 | /** |
97 | * The configuration template for the service. Cannot be NULL | 292 | * Extract information from a command that is useful for other |
293 | * commands. Can be NULL if a command has no traits. | ||
294 | * | ||
295 | * @param cls closure | ||
296 | * @param[out] ret result (could be anything) | ||
297 | * @param trait name of the trait | ||
298 | * @param index index number of the object to extract. | ||
299 | * @return #GNUNET_OK on success, | ||
300 | * #GNUNET_NO if no trait was found | ||
98 | */ | 301 | */ |
99 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 302 | GNUNET_TESTING_CommandGetTraits traits; |
100 | 303 | ||
101 | /** | 304 | /** |
102 | * The number of peers which share an instance of the service. 0 for sharing | 305 | * When did the execution of this command start? |
103 | * among all peers | ||
104 | */ | 306 | */ |
105 | unsigned int share; | 307 | struct GNUNET_TIME_Absolute start_time; |
308 | |||
309 | /** | ||
310 | * When did the execution of this command finish? | ||
311 | */ | ||
312 | struct GNUNET_TIME_Absolute finish_time; | ||
313 | |||
314 | /** | ||
315 | * When did we start the last run of this command? Delta to @e finish_time | ||
316 | * gives the latency for the last successful run. Useful in case @e | ||
317 | * num_tries was positive and the command was run multiple times. In that | ||
318 | * case, the @e start_time gives the time when we first tried to run the | ||
319 | * command, so the difference between @e start_time and @e finish_time would | ||
320 | * be the time all of the @e num_tries took, while the delta to @e | ||
321 | * last_req_time is the time the last (successful) execution took. | ||
322 | */ | ||
323 | struct GNUNET_TIME_Absolute last_req_time; | ||
324 | |||
325 | /** | ||
326 | * How often did we try to execute this command? (In case it is a request | ||
327 | * that is repated.) Note that a command must have some built-in retry | ||
328 | * mechanism for this value to be useful. | ||
329 | */ | ||
330 | unsigned int num_tries; | ||
331 | |||
332 | /** | ||
333 | * If "true", the interpreter should not immediately run the next command, | ||
334 | * even if this command did not complete via #GNUNET_TESTING_async_finish(). | ||
335 | * Otherwise, #GNUNET_TESTING_cmd_finish() must be used to ensure that a | ||
336 | * command actually completed. | ||
337 | */ | ||
338 | bool asynchronous_finish; | ||
339 | |||
106 | }; | 340 | }; |
107 | 341 | ||
108 | 342 | ||
109 | /** | 343 | /** |
110 | * Create a system handle. There must only be one system handle per operating | 344 | * Lookup command by label. |
111 | * system. Uses a default range for allowed ports. Ports are still tested for | 345 | * |
112 | * availability. | 346 | * @param is interpreter to lookup command in |
113 | * | 347 | * @param label label of the command to lookup. |
114 | * @param testdir only the directory name without any path. This is used for all | 348 | * @return the command, if it is found, or NULL. |
115 | * service homes; the directory will be created in a temporary location | 349 | */ |
116 | * depending on the underlying OS. This variable will be | 350 | const struct GNUNET_TESTING_Command * |
117 | * overridden with the value of the environmental variable | 351 | GNUNET_TESTING_interpreter_lookup_command ( |
118 | * GNUNET_TESTING_PREFIX, if it exists. | 352 | struct GNUNET_TESTING_Interpreter *is, |
119 | * @param trusted_ip the ip address which will be set as TRUSTED HOST in all | 353 | const char *label); |
120 | * service configurations generated to allow control connections from | 354 | |
121 | * this ip. This can either be a single ip address or a network address | 355 | |
122 | * in CIDR notation. | 356 | /** |
123 | * @param hostname the hostname of the system we are using for testing; NULL for | 357 | * Get command from hash map by variable name. |
124 | * localhost | 358 | * |
125 | * @param shared_services NULL terminated array describing services that are to | 359 | * @param is interpreter state. |
126 | * be shared among peers | 360 | * @param name name of the variable to get command by |
127 | * @return handle to this system, NULL on error | 361 | * @return the command, if it is found, or NULL. |
128 | */ | 362 | */ |
129 | struct GNUNET_TESTING_System * | 363 | const struct GNUNET_TESTING_Command * |
130 | GNUNET_TESTING_system_create (const char *testdir, | 364 | GNUNET_TESTING_interpreter_get_command ( |
131 | const char *trusted_ip, | 365 | struct GNUNET_TESTING_Interpreter *is, |
132 | const char *hostname, | 366 | const char *name); |
133 | const struct GNUNET_TESTING_SharedService * | 367 | |
134 | shared_services); | 368 | |
135 | 369 | /** | |
136 | 370 | * Update the last request time of the current command | |
137 | /** | 371 | * to the current time. |
138 | * Create a system handle. There must only be one system | 372 | * |
139 | * handle per operating system. Use this function directly | 373 | * @param[in,out] is interpreter state where to show |
140 | * if multiple system objects are created for the same host | 374 | * that we are doing something |
141 | * (only really useful when testing --- or to make the port | ||
142 | * range configurable). | ||
143 | * | ||
144 | * @param testdir only the directory name without any path. This is used for | ||
145 | * all service homes; the directory will be created in a temporary | ||
146 | * location depending on the underlying OS. This variable will be | ||
147 | * overridden with the value of the environmental variable | ||
148 | * GNUNET_TESTING_PREFIX, if it exists. | ||
149 | * @param trusted_ip the ip address which will be set as TRUSTED HOST in all | ||
150 | * service configurations generated to allow control connections from | ||
151 | * this ip. This can either be a single ip address or a network address | ||
152 | * in CIDR notation. | ||
153 | * @param hostname the hostname of the system we are using for testing; NULL for | ||
154 | * localhost | ||
155 | * @param shared_services NULL terminated array describing services that are to | ||
156 | * be shared among peers | ||
157 | * @param lowport lowest port number this system is allowed to allocate (inclusive) | ||
158 | * @param highport highest port number this system is allowed to allocate (exclusive) | ||
159 | * @return handle to this system, NULL on error | ||
160 | */ | ||
161 | struct GNUNET_TESTING_System * | ||
162 | GNUNET_TESTING_system_create_with_portrange (const char *testdir, | ||
163 | const char *trusted_ip, | ||
164 | const char *hostname, | ||
165 | const struct | ||
166 | GNUNET_TESTING_SharedService * | ||
167 | shared_services, | ||
168 | uint16_t lowport, | ||
169 | uint16_t highport); | ||
170 | |||
171 | |||
172 | /** | ||
173 | * Free system resources. | ||
174 | * | ||
175 | * @param system system to be freed | ||
176 | * @param remove_paths should the 'testdir' and all subdirectories | ||
177 | * be removed (clean up on shutdown)? | ||
178 | */ | 375 | */ |
179 | void | 376 | void |
180 | GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system, | 377 | GNUNET_TESTING_interpreter_current_cmd_touch ( |
181 | int remove_paths); | 378 | struct GNUNET_TESTING_Interpreter *is); |
182 | 379 | ||
183 | 380 | ||
184 | /** | 381 | /** |
185 | * Testing includes a number of pre-created hostkeys for | 382 | * Increment the 'num_tries' counter for the current command. |
186 | * faster peer startup. This function can be used to | ||
187 | * access the n-th key of those pre-created hostkeys; note | ||
188 | * that these keys are ONLY useful for testing and not | ||
189 | * secure as the private keys are part of the public | ||
190 | * GNUnet source code. | ||
191 | * | 383 | * |
192 | * This is primarily a helper function used internally | 384 | * @param[in,out] is interpreter state where to |
193 | * by #GNUNET_TESTING_peer_configure(). | 385 | * increment the counter |
386 | */ | ||
387 | void | ||
388 | GNUNET_TESTING_interpreter_current_cmd_inc_tries ( | ||
389 | struct GNUNET_TESTING_Interpreter *is); | ||
390 | |||
391 | |||
392 | /** | ||
393 | * Obtain label of the command being now run. | ||
194 | * | 394 | * |
195 | * @param system the testing system handle | 395 | * @param is interpreter state. |
196 | * @param key_number desired pre-created hostkey to obtain | 396 | * @return the label. |
197 | * @param id set to the peer's identity (hash of the public | ||
198 | * key; if NULL, #GNUNET_SYSERR is returned immediately | ||
199 | * @return NULL on error (not enough keys) | ||
200 | */ | 397 | */ |
201 | struct GNUNET_CRYPTO_EddsaPrivateKey * | 398 | const char * |
202 | GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system, | 399 | GNUNET_TESTING_interpreter_current_cmd_get_label ( |
203 | uint32_t key_number, | 400 | struct GNUNET_TESTING_Interpreter *is); |
204 | struct GNUNET_PeerIdentity *id); | ||
205 | 401 | ||
206 | 402 | ||
207 | /** | 403 | /** |
208 | * Reserve a port for a peer. | 404 | * Current command failed, clean up and fail the test case. |
209 | * | 405 | * |
210 | * @param system system to use for reservation tracking | 406 | * @param is interpreter state. |
211 | * @return 0 if no free port was available | ||
212 | */ | 407 | */ |
213 | uint16_t | 408 | void |
214 | GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system); | 409 | GNUNET_TESTING_interpreter_fail ( |
410 | struct GNUNET_TESTING_Interpreter *is); | ||
215 | 411 | ||
216 | 412 | ||
217 | /** | 413 | /** |
218 | * Release reservation of a TCP or UDP port for a peer | 414 | * Skips the current test, the environment is |
219 | * (used during GNUNET_TESTING_peer_destroy). | 415 | * not prepared correctly. |
220 | * | 416 | * |
221 | * @param system system to use for reservation tracking | 417 | * @param is interpreter state. |
222 | * @param port reserved port to release | ||
223 | */ | 418 | */ |
224 | void | 419 | void |
225 | GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system, | 420 | GNUNET_TESTING_interpreter_skip ( |
226 | uint16_t port); | 421 | struct GNUNET_TESTING_Interpreter *is); |
227 | 422 | ||
228 | 423 | ||
229 | /** | 424 | /** |
230 | * Create a new configuration using the given configuration as a template; | 425 | * Callback over commands of an interpreter. |
231 | * ports and paths will be modified to select available ports on the local | ||
232 | * system. The default configuration will be available in PATHS section under | ||
233 | * the option DEFAULTCONFIG after the call. SERVICE_HOME is also set in PATHS | ||
234 | * section to the temporary directory specific to this configuration. If we run | ||
235 | * out of "*port" numbers, return #GNUNET_SYSERR. | ||
236 | * | 426 | * |
237 | * This is primarily a helper function used internally | 427 | * @param cls closure |
238 | * by #GNUNET_TESTING_peer_configure(). | 428 | * @param cmd a command to process |
429 | */ | ||
430 | typedef void | ||
431 | (*GNUNET_TESTING_CommandIterator)( | ||
432 | void *cls, | ||
433 | const struct GNUNET_TESTING_Command *cmd); | ||
434 | |||
435 | |||
436 | /** | ||
437 | * Iterates over all of the top-level commands of an | ||
438 | * interpreter. | ||
239 | * | 439 | * |
240 | * @param system system to use to coordinate resource usage | 440 | * @param[in] is interpreter to iterate over |
241 | * @param cfg template configuration to update | 441 | * @param asc true in execution order, false for reverse execution order |
242 | * @return #GNUNET_OK on success, | 442 | * @param cb function to call on each command |
243 | * #GNUNET_SYSERR on error - the configuration will | 443 | * @param cb_cls closure for cb |
244 | * be incomplete and should not be used there upon | ||
245 | */ | 444 | */ |
246 | int | 445 | void |
247 | GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system, | 446 | GNUNET_TESTING_interpreter_commands_iterate ( |
248 | struct GNUNET_CONFIGURATION_Handle *cfg); | 447 | struct GNUNET_TESTING_Interpreter *is, |
448 | bool asc, | ||
449 | GNUNET_TESTING_CommandIterator cb, | ||
450 | void *cb_cls); | ||
249 | 451 | ||
250 | // FIXME: add dual to 'release' ports again... | 452 | |
453 | /* ************** Fundamental interpreter commands ************ */ | ||
251 | 454 | ||
252 | 455 | ||
253 | /** | 456 | /** |
254 | * Configure a GNUnet peer. GNUnet must be installed on the local | 457 | * Create command array terminator. |
255 | * system and available in the PATH. | ||
256 | * | 458 | * |
257 | * @param system system to use to coordinate resource usage | 459 | * @return a end-command. |
258 | * @param cfg configuration to use; will be UPDATED (to reflect needed | ||
259 | * changes in port numbers and paths) | ||
260 | * @param key_number number of the hostkey to use for the peer | ||
261 | * @param id identifier for the daemon, will be set, can be NULL | ||
262 | * @param emsg set to freshly allocated error message (set to NULL on success), | ||
263 | * can be NULL | ||
264 | * @return handle to the peer, NULL on error | ||
265 | */ | 460 | */ |
266 | struct GNUNET_TESTING_Peer * | 461 | struct GNUNET_TESTING_Command |
267 | GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, | 462 | GNUNET_TESTING_cmd_end (void); |
268 | struct GNUNET_CONFIGURATION_Handle *cfg, | ||
269 | uint32_t key_number, | ||
270 | struct GNUNET_PeerIdentity *id, | ||
271 | char **emsg); | ||
272 | 463 | ||
273 | 464 | ||
274 | /** | 465 | /** |
275 | * Obtain the peer identity from a peer handle. | 466 | * Create a "batch" command. Such command takes a end_CMD-terminated array of |
467 | * CMDs and executed them. Once it hits the end CMD, it passes the control to | ||
468 | * the next top-level CMD, regardless of it being another batch or ordinary | ||
469 | * CMD. | ||
276 | * | 470 | * |
277 | * @param peer peer handle for which we want the peer's identity | 471 | * @param label the command label. |
278 | * @param id identifier for the daemon, will be set | 472 | * @param batch array of CMDs to execute. |
473 | * @return the command. | ||
279 | */ | 474 | */ |
280 | void | 475 | struct GNUNET_TESTING_Command |
281 | GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer, | 476 | GNUNET_TESTING_cmd_batch ( |
282 | struct GNUNET_PeerIdentity *id); | 477 | const char *label, |
478 | struct GNUNET_TESTING_Command *batch); | ||
479 | |||
480 | |||
481 | /** | ||
482 | * Performance counter. | ||
483 | */ | ||
484 | struct GNUNET_TESTING_Timer | ||
485 | { | ||
486 | /** | ||
487 | * For which type of commands. | ||
488 | */ | ||
489 | const char *prefix; | ||
490 | |||
491 | /** | ||
492 | * Total time spend in all commands of this type. | ||
493 | */ | ||
494 | struct GNUNET_TIME_Relative total_duration; | ||
495 | |||
496 | /** | ||
497 | * Total time spend waiting for the *successful* exeuction | ||
498 | * in all commands of this type. | ||
499 | */ | ||
500 | struct GNUNET_TIME_Relative success_latency; | ||
501 | |||
502 | /** | ||
503 | * Number of commands summed up. | ||
504 | */ | ||
505 | unsigned int num_commands; | ||
283 | 506 | ||
507 | /** | ||
508 | * Number of retries summed up. | ||
509 | */ | ||
510 | unsigned int num_retries; | ||
511 | }; | ||
284 | 512 | ||
285 | /** | 513 | /** |
286 | * Start the peer. | 514 | * Obtain performance data from the interpreter. |
287 | * | 515 | * |
288 | * @param peer peer to start | 516 | * @param label command label. |
289 | * @return #GNUNET_OK on success, | 517 | * @param[in,out] timers NULL-prefix terminated array that specifies what commands (by label) to obtain runtimes for |
290 | * #GNUNET_SYSERR on error (i.e. peer already running) | 518 | * @return the command |
291 | */ | 519 | */ |
292 | int | 520 | struct GNUNET_TESTING_Command |
293 | GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer); | 521 | GNUNET_TESTING_cmd_stat ( |
522 | const char *label, | ||
523 | struct GNUNET_TESTING_Timer *timers); | ||
294 | 524 | ||
295 | 525 | ||
296 | /** | 526 | /** |
297 | * Stop the peer. This call is blocking as it kills the peer's main ARM process | 527 | * Set variable to command as side-effect of |
298 | * by sending a SIGTERM and waits on it. For asynchronous shutdown of peer, see | 528 | * running a command. |
299 | * GNUNET_TESTING_peer_stop_async(). | ||
300 | * | 529 | * |
301 | * @param peer peer to stop | 530 | * @param name name of the variable to set |
302 | * @return #GNUNET_OK on success, | 531 | * @param cmd command to set to variable when run |
303 | * #GNUNET_SYSERR on error (i.e. peer not running) | 532 | * @return modified command |
304 | */ | 533 | */ |
305 | int | 534 | struct GNUNET_TESTING_Command |
306 | GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer); | 535 | GNUNET_TESTING_cmd_set_var ( |
536 | const char *name, | ||
537 | struct GNUNET_TESTING_Command cmd); | ||
307 | 538 | ||
308 | 539 | ||
309 | /** | 540 | /** |
310 | * Destroy the peer. Releases resources locked during peer configuration. | 541 | * Command to create a barrier. |
311 | * If the peer is still running, it will be stopped AND a warning will be | ||
312 | * printed (users of the API should stop the peer explicitly first). | ||
313 | * | 542 | * |
314 | * @param peer peer to destroy | 543 | * @param label The label of this command. |
544 | * @param number_to_be_reached If this number of processes reached | ||
545 | * this barrier, all processes waiting at | ||
546 | * this barrier can pass it. | ||
315 | */ | 547 | */ |
316 | void | 548 | struct GNUNET_TESTING_Command |
317 | GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer); | 549 | GNUNET_TESTING_cmd_barrier_create ( |
550 | const char *label, | ||
551 | unsigned int number_to_be_reached); | ||
318 | 552 | ||
319 | 553 | ||
320 | /** | 554 | /** |
321 | * Sends SIGTERM to the peer's main process | 555 | * If this command is executed the the process is signaling the master process |
556 | * that it reached a barrier. If this command is synchronous it will block. | ||
322 | * | 557 | * |
323 | * @param peer the handle to the peer | 558 | * @param label name for command. |
324 | * @return #GNUNET_OK if successful; #GNUNET_SYSERR if the main process is NULL | 559 | * @param barrier_label The name of the barrier we waited for and which was reached. |
325 | * or upon any error while sending SIGTERM | 560 | * @return command. |
326 | */ | 561 | */ |
327 | int | 562 | struct GNUNET_TESTING_Command |
328 | GNUNET_TESTING_peer_kill (struct GNUNET_TESTING_Peer *peer); | 563 | GNUNET_TESTING_cmd_barrier_reached ( |
564 | const char *label, | ||
565 | const char *barrier_label); | ||
566 | |||
329 | 567 | ||
568 | #define GNUNET_TESTING_NETJAIL_START_SCRIPT "netjail_start.sh" | ||
569 | |||
570 | #define GNUNET_TESTING_NETJAIL_STOP_SCRIPT "netjail_stop.sh" | ||
330 | 571 | ||
331 | /** | 572 | /** |
332 | * Waits for a peer to terminate. The peer's main process will also be destroyed. | 573 | * Create command. |
333 | * | 574 | * |
334 | * @param peer the handle to the peer | 575 | * @param label Name for the command. |
335 | * @return #GNUNET_OK if successful; #GNUNET_SYSERR if the main process is NULL | 576 | * @param topology_data topology data |
336 | * or upon any error while waiting | 577 | * @param timeout Before this timeout is reached this cmd MUST finish. |
578 | * @return command. | ||
337 | */ | 579 | */ |
338 | int | 580 | struct GNUNET_TESTING_Command |
339 | GNUNET_TESTING_peer_wait (struct GNUNET_TESTING_Peer *peer); | 581 | GNUNET_TESTING_cmd_netjail_start_helpers ( |
582 | const char *label, | ||
583 | const char *topology_cmd_label, | ||
584 | struct GNUNET_TIME_Relative timeout); | ||
340 | 585 | ||
341 | 586 | ||
342 | /** | 587 | /** |
343 | * Callback to inform whether the peer is running or stopped. | 588 | * This command executes a shell script to setup the netjail environment. |
344 | * | 589 | * |
345 | * @param cls the closure given to GNUNET_TESTING_peer_stop_async() | 590 | * @param label name for command. |
346 | * @param peer the respective peer whose status is being reported | 591 | * @param script which script to run, e.g. #GNUNET_TESTING_NETJAIL_START_SCRIPT |
347 | * @param success #GNUNET_YES if the peer is stopped; #GNUNET_SYSERR upon any | 592 | * @param topology_config Configuration file for the test topology. |
348 | * error | 593 | * @param read_file Flag indicating if the the name of the topology file is send to the helper, or a string with the topology data. |
594 | * @return command. | ||
349 | */ | 595 | */ |
350 | typedef void | 596 | struct GNUNET_TESTING_Command |
351 | (*GNUNET_TESTING_PeerStopCallback) (void *cls, | 597 | GNUNET_TESTING_cmd_netjail_setup ( |
352 | struct GNUNET_TESTING_Peer *peer, | 598 | const char *label, |
353 | int success); | 599 | const char *script, |
600 | const char *topology_cmd_label); | ||
601 | |||
602 | |||
603 | struct GNUNET_TESTING_Command | ||
604 | GNUNET_TESTING_cmd_load_topology_from_file ( | ||
605 | const char *label, | ||
606 | const char *filename); | ||
607 | |||
608 | |||
609 | struct GNUNET_TESTING_Command | ||
610 | GNUNET_TESTING_cmd_load_topology_from_string ( | ||
611 | const char *label, | ||
612 | const char *topology_data); | ||
354 | 613 | ||
355 | 614 | ||
356 | /** | 615 | /** |
357 | * Stop a peer asynchronously using ARM API. Peer's shutdown is signaled | 616 | * Turn asynchronous command into non-blocking command by setting |
358 | * through the GNUNET_TESTING_PeerStopCallback(). | 617 | * asynchronous_finish to true. Modifies (and then returns) @a cmd simply |
618 | * setting the bit. By default, most commands are blocking, and by wrapping | ||
619 | * the command construction in this function a blocking command can be turned | ||
620 | * into an asynchronous command where the interpreter continues after | ||
621 | * initiating the asynchronous action. Does nothing if the command is | ||
622 | * fundamentally synchronous. | ||
359 | * | 623 | * |
360 | * @param peer the peer to stop | 624 | * @param[in,out] cmd command to make non-blocking |
361 | * @param cb the callback to signal peer shutdown | 625 | * @return a finish-command. |
362 | * @param cb_cls closure for the @a cb | ||
363 | * @return #GNUNET_OK upon successfully giving the request to the ARM API (this | ||
364 | * does not mean that the peer is successfully stopped); #GNUNET_SYSERR | ||
365 | * upon any error. | ||
366 | */ | 626 | */ |
367 | int | 627 | struct GNUNET_TESTING_Command |
368 | GNUNET_TESTING_peer_stop_async (struct GNUNET_TESTING_Peer *peer, | 628 | GNUNET_TESTING_cmd_make_unblocking ( |
369 | GNUNET_TESTING_PeerStopCallback cb, | 629 | struct GNUNET_TESTING_Command cmd); |
370 | void *cb_cls); | ||
371 | 630 | ||
372 | 631 | ||
373 | /** | 632 | /** |
374 | * Cancel a previous asynchronous peer stop request. | 633 | * Create (synchronous) command that waits for another command to finish. |
375 | * GNUNET_TESTING_peer_stop_async() should have been called before on the given | 634 | * If @a cmd_ref did not finish after @a timeout, this command will fail |
376 | * peer. It is an error to call this function if the peer stop callback was | 635 | * the test case. |
377 | * already called | ||
378 | * | 636 | * |
379 | * @param peer the peer on which GNUNET_TESTING_peer_stop_async() was called | 637 | * @param finish_label label for this command |
380 | * before. | 638 | * @param cmd_ref reference to a previous command which we should |
639 | * wait for (call `finish()` on) | ||
640 | * @param timeout how long to wait at most for @a cmd_ref to finish | ||
641 | * @return a finish-command. | ||
381 | */ | 642 | */ |
382 | void | 643 | const struct GNUNET_TESTING_Command |
383 | GNUNET_TESTING_peer_stop_async_cancel (struct GNUNET_TESTING_Peer *peer); | 644 | GNUNET_TESTING_cmd_finish ( |
645 | const char *finish_label, | ||
646 | const char *cmd_ref, | ||
647 | struct GNUNET_TIME_Relative timeout); | ||
648 | |||
649 | |||
650 | /** | ||
651 | * Create a "signal" CMD. | ||
652 | * | ||
653 | * @param label command label. | ||
654 | * @param process_label label of a command that has a process trait | ||
655 | * @param signal signal to send to @a process. | ||
656 | * @return the command. | ||
657 | */ | ||
658 | struct GNUNET_TESTING_Command | ||
659 | GNUNET_TESTING_cmd_signal ( | ||
660 | const char *label, | ||
661 | const char *process_label, | ||
662 | int signal); | ||
663 | |||
664 | |||
665 | /** | ||
666 | * Sleep for @a duration. | ||
667 | * | ||
668 | * @param label command label. | ||
669 | * @param duration time to sleep | ||
670 | * @return the command. | ||
671 | */ | ||
672 | struct GNUNET_TESTING_Command | ||
673 | GNUNET_TESTING_cmd_sleep ( | ||
674 | const char *label, | ||
675 | struct GNUNET_TIME_Relative duration); | ||
676 | |||
677 | |||
678 | /** | ||
679 | * Command to execute a command. | ||
680 | * | ||
681 | * @param label Label of the command. | ||
682 | */ | ||
683 | const struct GNUNET_TESTING_Command | ||
684 | GNUNET_TESTING_cmd_exec ( | ||
685 | const char *label, | ||
686 | enum GNUNET_OS_ProcessStatusType expected_type, | ||
687 | unsigned long int expected_exit_code, | ||
688 | char *const script_argv[]); | ||
689 | |||
690 | |||
691 | /** | ||
692 | * Command to execute a command. | ||
693 | * | ||
694 | * @param label Label of the command. | ||
695 | */ | ||
696 | const struct GNUNET_TESTING_Command | ||
697 | GNUNET_TESTING_cmd_exec_va ( | ||
698 | const char *label, | ||
699 | enum GNUNET_OS_ProcessStatusType expected_type, | ||
700 | unsigned long int expected_exit_code, | ||
701 | ...); | ||
384 | 702 | ||
385 | 703 | ||
386 | /** | 704 | /** |
387 | * Signature of the 'main' function for a (single-peer) testcase that | 705 | * Make the instruction pointer point to @a target_label |
388 | * is run using #GNUNET_TESTING_peer_run(). | 706 | * only if @a counter is greater than zero. Note that |
707 | * the command that will be executed next in this case | ||
708 | * is the one AFTER @a target_label, as the command we | ||
709 | * jump to is skipped by the advancing IP after the | ||
710 | * rewind. | ||
711 | * | ||
712 | * @param label command label | ||
713 | * @param target_label label of the new instruction pointer's destination after the jump; | ||
714 | * must be before the current instruction (and the command at the @a target_label itself will not be run, but the one afterwards) | ||
715 | * @param counter counts how many times the rewinding is to happen. | ||
716 | */ | ||
717 | struct GNUNET_TESTING_Command | ||
718 | GNUNET_TESTING_cmd_rewind_ip ( | ||
719 | const char *label, | ||
720 | const char *target_label, | ||
721 | unsigned int counter); | ||
722 | |||
723 | |||
724 | /* ***************** main loop logic ************* */ | ||
725 | |||
726 | /** | ||
727 | * Function called with the final result of the test. | ||
389 | * | 728 | * |
390 | * @param cls closure | 729 | * @param cls closure |
391 | * @param cfg configuration of the peer that was started | 730 | * @param rv #GNUNET_OK if the test passed |
392 | * @param peer identity of the peer that was created | ||
393 | */ | 731 | */ |
394 | typedef void | 732 | typedef void |
395 | (*GNUNET_TESTING_TestMain) (void *cls, | 733 | (*GNUNET_TESTING_ResultCallback)( |
396 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 734 | void *cls, |
397 | struct GNUNET_TESTING_Peer *peer); | 735 | enum GNUNET_GenericReturnValue rv); |
398 | 736 | ||
399 | 737 | ||
400 | /** | 738 | /** |
401 | * Start a single peer and run a test using the testing library. | 739 | * Run the testsuite. Note, CMDs are copied into the interpreter state |
402 | * Starts a peer using the given configuration and then invokes the | 740 | * because they are _usually_ defined into the "run" method that returns after |
403 | * given callback. This function ALSO initializes the scheduler loop | 741 | * having scheduled the test interpreter. |
404 | * and should thus be called directly from "main". The testcase | ||
405 | * should self-terminate by invoking #GNUNET_SCHEDULER_shutdown(). | ||
406 | * | 742 | * |
407 | * @param testdir only the directory name without any path. This is used for | 743 | * @param commands the array of command to execute |
408 | * all service homes; the directory will be created in a temporary | 744 | * @param timeout how long to wait for each command to execute |
409 | * location depending on the underlying OS | 745 | * @param rc function to call with the final result |
410 | * @param cfgfilename name of the configuration file to use; | 746 | * @param rc_cls closure for @a rc |
411 | * use NULL to only run with defaults | 747 | * @return The interpreter. |
412 | * @param tm main function of the testcase | ||
413 | * @param tm_cls closure for @a tm | ||
414 | * @return 0 on success, 1 on error | ||
415 | */ | 748 | */ |
416 | int | 749 | struct GNUNET_TESTING_Interpreter * |
417 | GNUNET_TESTING_peer_run (const char *testdir, | 750 | GNUNET_TESTING_run ( |
418 | const char *cfgfilename, | 751 | const struct GNUNET_TESTING_Command *commands, |
419 | GNUNET_TESTING_TestMain tm, | 752 | struct GNUNET_TIME_Relative timeout, |
420 | void *tm_cls); | 753 | GNUNET_TESTING_ResultCallback rc, |
754 | void *rc_cls); | ||
421 | 755 | ||
422 | 756 | ||
423 | /** | 757 | /** |
424 | * Start a single service (no ARM, except of course if the given | 758 | * Start a GNUnet scheduler event loop and run the testsuite. Return 0 upon |
425 | * service name is 'arm') and run a test using the testing library. | 759 | * success. Expected to be called directly from main(). |
426 | * Starts a service using the given configuration and then invokes the | ||
427 | * given callback. This function ALSO initializes the scheduler loop | ||
428 | * and should thus be called directly from "main". The testcase | ||
429 | * should self-terminate by invoking #GNUNET_SCHEDULER_shutdown(). | ||
430 | * | 760 | * |
431 | * This function is useful if the testcase is for a single service | 761 | * @param commands the list of command to execute |
432 | * and if that service doesn't itself depend on other services. | 762 | * @param timeout how long to wait for each command to execute |
433 | * | 763 | * @return EXIT_SUCCESS on success, EXIT_FAILURE on failure |
434 | * @param testdir only the directory name without any path. This is used for | ||
435 | * all service homes; the directory will be created in a temporary | ||
436 | * location depending on the underlying OS | ||
437 | * @param service_name name of the service to run | ||
438 | * @param cfgfilename name of the configuration file to use; | ||
439 | * use NULL to only run with defaults | ||
440 | * @param tm main function of the testcase | ||
441 | * @param tm_cls closure for @a tm | ||
442 | * @return 0 on success, 1 on error | ||
443 | */ | 764 | */ |
444 | int | 765 | int |
445 | GNUNET_TESTING_service_run (const char *testdir, | 766 | GNUNET_TESTING_main ( |
446 | const char *service_name, | 767 | const struct GNUNET_TESTING_Command *commands, |
447 | const char *cfgfilename, | 768 | struct GNUNET_TIME_Relative timeout); |
448 | GNUNET_TESTING_TestMain tm, | 769 | |
449 | void *tm_cls); | 770 | |
771 | /* ***************** plugin logic ************* */ | ||
772 | |||
773 | |||
774 | /** | ||
775 | * The plugin API every test case plugin has to implement. | ||
776 | */ | ||
777 | struct GNUNET_TESTING_PluginFunctions; | ||
778 | |||
779 | |||
780 | struct GNUNET_TESTING_PluginFunctions * | ||
781 | GNUNET_TESTING_make_plugin ( | ||
782 | const struct GNUNET_TESTING_Command *commands); | ||
783 | |||
784 | #define GNUNET_TESTING_MAKE_PLUGIN(prefix,name,...) \ | ||
785 | void * \ | ||
786 | prefix ## _plugin_ ## name ## _init (void *cls) { \ | ||
787 | const char *my_node_id = cls; (void) my_node_id; \ | ||
788 | struct GNUNET_TESTING_Command commands[] = { \ | ||
789 | __VA_ARGS__, \ | ||
790 | GNUNET_TESTING_cmd_end () \ | ||
791 | }; \ | ||
792 | return GNUNET_TESTING_make_plugin (commands); \ | ||
793 | } \ | ||
794 | void * \ | ||
795 | prefix ## _plugin_ ## name ## _done (void *cls) { \ | ||
796 | struct GNUNET_TESTING_PluginFunctions *api = cls; \ | ||
797 | GNUNET_free (api); \ | ||
798 | return NULL; \ | ||
799 | } | ||
450 | 800 | ||
451 | 801 | ||
452 | #if 0 /* keep Emacsens' auto-indent happy */ | 802 | /* *** Generic trait logic for implementing traits ********* */ |
803 | |||
804 | /** | ||
805 | * A `struct GNUNET_TESTING_Trait` can be used to exchange data between cmds. | ||
806 | * | ||
807 | * Therefor the cmd which like to provide data to other cmds has to implement | ||
808 | * the trait function, where an array of traits is defined with the help of | ||
809 | * the #GNUNET_TESTING_make_trait_ macro. The data can be retrieved with the | ||
810 | * help of the #GNUNET_TESTING_get_trait_ macro. Traits name and type must be | ||
811 | * defined to make use of the macros. | ||
812 | */ | ||
813 | struct GNUNET_TESTING_Trait | ||
453 | { | 814 | { |
454 | #endif | 815 | /** |
455 | #ifdef __cplusplus | 816 | * Index number associated with the trait. This gives the |
456 | } | 817 | * possibility to have _multiple_ traits on offer under the |
457 | #endif | 818 | * same name. |
819 | */ | ||
820 | unsigned int index; | ||
821 | |||
822 | /** | ||
823 | * Trait type, for example "reserve-pub" or "coin-priv". | ||
824 | */ | ||
825 | const char *trait_name; | ||
826 | |||
827 | /** | ||
828 | * Pointer to the piece of data to offer. | ||
829 | */ | ||
830 | const void *ptr; | ||
831 | }; | ||
458 | 832 | ||
459 | #endif | ||
460 | 833 | ||
461 | /** @} */ /* end of group */ | 834 | /** |
835 | * "end" of traits array. Because traits are offered into arrays, this type | ||
836 | * of trait is used to mark the end of such arrays; useful when iterating over | ||
837 | * those. | ||
838 | */ | ||
839 | struct GNUNET_TESTING_Trait | ||
840 | GNUNET_TESTING_trait_end (void); | ||
462 | 841 | ||
463 | /** @} */ /* end of group addition */ | 842 | |
843 | /** | ||
844 | * Obtain value of a trait from a command. | ||
845 | * | ||
846 | * @param traits the array of all the traits. | ||
847 | * @param[out] ret where to store the result. | ||
848 | * @param trait type of the trait to extract. | ||
849 | * @param index index number of the trait to extract. | ||
850 | * @return #GNUNET_OK when the trait is found. | ||
851 | */ | ||
852 | enum GNUNET_GenericReturnValue | ||
853 | GNUNET_TESTING_get_trait ( | ||
854 | const struct GNUNET_TESTING_Trait *traits, | ||
855 | const void **ret, | ||
856 | const char *trait, | ||
857 | unsigned int index); | ||
858 | |||
859 | |||
860 | /** | ||
861 | * Create headers for a trait with name @a name for | ||
862 | * statically allocated data of type @a type. | ||
863 | * | ||
864 | * @param prefix symbol prefix to use | ||
865 | * @param name name of the trait | ||
866 | * @param type data type for the trait | ||
867 | */ | ||
868 | #define GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT(prefix,name,type) \ | ||
869 | enum GNUNET_GenericReturnValue \ | ||
870 | prefix ## _get_trait_ ## name ( \ | ||
871 | const struct GNUNET_TESTING_Command *cmd, \ | ||
872 | type * *ret); \ | ||
873 | struct GNUNET_TESTING_Trait \ | ||
874 | prefix ## _make_trait_ ## name ( \ | ||
875 | type * value); | ||
876 | |||
877 | |||
878 | /** | ||
879 | * Create C implementation for a trait with name @a name for statically | ||
880 | * allocated data of type @a type. | ||
881 | * | ||
882 | * @param prefix symbol prefix to use | ||
883 | * @param name name of the trait | ||
884 | * @param type data type for the trait | ||
885 | */ | ||
886 | #define GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT(prefix,name,type) \ | ||
887 | enum GNUNET_GenericReturnValue \ | ||
888 | prefix ## _get_trait_ ## name ( \ | ||
889 | const struct GNUNET_TESTING_Command *cmd, \ | ||
890 | type * *ret) \ | ||
891 | { \ | ||
892 | if (NULL == cmd->traits) return GNUNET_SYSERR; \ | ||
893 | return cmd->traits (cmd->cls, \ | ||
894 | (const void **) ret, \ | ||
895 | GNUNET_S (name), \ | ||
896 | 0); \ | ||
897 | } \ | ||
898 | struct GNUNET_TESTING_Trait \ | ||
899 | prefix ## _make_trait_ ## name ( \ | ||
900 | type * value) \ | ||
901 | { \ | ||
902 | struct GNUNET_TESTING_Trait ret = { \ | ||
903 | .trait_name = GNUNET_S (name), \ | ||
904 | .ptr = (const void *) value \ | ||
905 | }; \ | ||
906 | return ret; \ | ||
907 | } | ||
908 | |||
909 | |||
910 | /** | ||
911 | * Create headers for a trait with name @a name for | ||
912 | * statically allocated data of type @a type. | ||
913 | * | ||
914 | * @param prefix symbol prefix to use | ||
915 | * @param name name of the trait | ||
916 | * @param type data type for the trait | ||
917 | */ | ||
918 | #define GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT(prefix,name,type) \ | ||
919 | enum GNUNET_GenericReturnValue \ | ||
920 | prefix ## _get_trait_ ## name ( \ | ||
921 | const struct GNUNET_TESTING_Command *cmd, \ | ||
922 | unsigned int index, \ | ||
923 | type * *ret); \ | ||
924 | struct GNUNET_TESTING_Trait \ | ||
925 | prefix ## _make_trait_ ## name ( \ | ||
926 | unsigned int index, \ | ||
927 | type * value); | ||
928 | |||
929 | |||
930 | /** | ||
931 | * Create C implementation for a trait with name @a name for statically | ||
932 | * allocated data of type @a type. | ||
933 | */ | ||
934 | #define GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT(prefix,name,type) \ | ||
935 | enum GNUNET_GenericReturnValue \ | ||
936 | prefix ## _get_trait_ ## name ( \ | ||
937 | const struct GNUNET_TESTING_Command *cmd, \ | ||
938 | unsigned int index, \ | ||
939 | type * *ret) \ | ||
940 | { \ | ||
941 | if (NULL == cmd->traits) return GNUNET_SYSERR; \ | ||
942 | return cmd->traits (cmd->cls, \ | ||
943 | (const void **) ret, \ | ||
944 | GNUNET_S (name), \ | ||
945 | index); \ | ||
946 | } \ | ||
947 | struct GNUNET_TESTING_Trait \ | ||
948 | prefix ## _make_trait_ ## name ( \ | ||
949 | unsigned int index, \ | ||
950 | type * value) \ | ||
951 | { \ | ||
952 | struct GNUNET_TESTING_Trait ret = { \ | ||
953 | .index = index, \ | ||
954 | .trait_name = GNUNET_S (name), \ | ||
955 | .ptr = (const void *) value \ | ||
956 | }; \ | ||
957 | return ret; \ | ||
958 | } | ||
959 | |||
960 | |||
961 | /** | ||
962 | * Call #op on all simple traits needed by testing core logic. | ||
963 | * | ||
964 | * @param op operation to perform | ||
965 | * @param prefix prefix to pass to @e op | ||
966 | */ | ||
967 | #define GNUNET_TESTING_SIMPLE_TRAITS(op,prefix) \ | ||
968 | op (prefix, process, struct GNUNET_OS_Process *) \ | ||
969 | op (prefix, cmd, const struct GNUNET_TESTING_Command) \ | ||
970 | op (prefix, batch_cmds, struct GNUNET_TESTING_Command *) | ||
971 | |||
972 | |||
973 | GNUNET_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT, | ||
974 | GNUNET_TESTING) | ||
975 | |||
976 | |||
977 | #endif | ||
diff --git a/src/include/gnunet_testing_loop_lib.h b/src/include/gnunet_testing_loop_lib.h deleted file mode 100644 index 7e13edfab..000000000 --- a/src/include/gnunet_testing_loop_lib.h +++ /dev/null | |||
@@ -1,697 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2021, 2023 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @brief Central interpreter and command loop for writing an interpreter to test asynchronous systems | ||
23 | * @author Christian Grothoff <christian@grothoff.org> | ||
24 | * @author Marcello Stanisci | ||
25 | * @author t3sserakt | ||
26 | */ | ||
27 | #ifndef GNUNET_TESTING_LOOP_LIB_H | ||
28 | #define GNUNET_TESTING_LOOP_LIB_H | ||
29 | |||
30 | /** | ||
31 | * Maximum length of label in command | ||
32 | */ | ||
33 | #define GNUNET_TESTING_CMD_MAX_LABEL_LENGTH 127 | ||
34 | |||
35 | /* ********************* Helper functions ********************* */ | ||
36 | |||
37 | /** | ||
38 | * Print failing line number and trigger shutdown. Useful | ||
39 | * quite any time after the command "run" method has been called. | ||
40 | */ | ||
41 | #define GNUNET_TESTING_FAIL(is) \ | ||
42 | do \ | ||
43 | { \ | ||
44 | GNUNET_break (0); \ | ||
45 | GNUNET_TESTING_interpreter_fail (is); \ | ||
46 | return; \ | ||
47 | } while (0) | ||
48 | |||
49 | |||
50 | /* ******************* Generic interpreter logic ************ */ | ||
51 | |||
52 | /** | ||
53 | * Global state of the interpreter, used by a command | ||
54 | * to access information about other commands. | ||
55 | */ | ||
56 | struct GNUNET_TESTING_Interpreter; | ||
57 | |||
58 | /** | ||
59 | * State each asynchronous command must have in its closure. | ||
60 | */ | ||
61 | struct GNUNET_TESTING_AsyncContext | ||
62 | { | ||
63 | |||
64 | /** | ||
65 | * Interpreter we are part of. | ||
66 | */ | ||
67 | struct GNUNET_TESTING_Interpreter *is; // FIXME: Why needed? When available? | ||
68 | |||
69 | /** | ||
70 | * Function to call when done. | ||
71 | */ | ||
72 | GNUNET_SCHEDULER_TaskCallback cont; | ||
73 | |||
74 | /** | ||
75 | * Closure for @e cont. | ||
76 | */ | ||
77 | void *cont_cls; | ||
78 | |||
79 | /** | ||
80 | * Indication if the command finished (#GNUNET_OK). | ||
81 | * #GNUNET_NO if it did not finish, | ||
82 | * #GNUNET_SYSERR if it failed. | ||
83 | */ | ||
84 | enum GNUNET_GenericReturnValue finished; | ||
85 | }; | ||
86 | |||
87 | |||
88 | /** | ||
89 | * The asynchronous command of @a ac has failed. | ||
90 | * | ||
91 | * @param ac command-specific context | ||
92 | */ | ||
93 | void | ||
94 | GNUNET_TESTING_async_fail (struct GNUNET_TESTING_AsyncContext *ac); | ||
95 | |||
96 | |||
97 | /** | ||
98 | * The asynchronous command of @a ac has finished. | ||
99 | * | ||
100 | * @param ac command-specific context | ||
101 | */ | ||
102 | void | ||
103 | GNUNET_TESTING_async_finish (struct GNUNET_TESTING_AsyncContext *ac); | ||
104 | |||
105 | |||
106 | /** | ||
107 | * Signature of a function used to start executing a command | ||
108 | * of a test. | ||
109 | * | ||
110 | * @param cls closure | ||
111 | * @param is interpreter running the command | ||
112 | */ | ||
113 | typedef void | ||
114 | (*GNUNET_TESTING_CommandRunRoutine)(void *cls, | ||
115 | struct GNUNET_TESTING_Interpreter *is); | ||
116 | |||
117 | |||
118 | /** | ||
119 | * Signature of a function used to clean up resources allocated | ||
120 | * by a command. | ||
121 | * | ||
122 | * @param cls closure | ||
123 | */ | ||
124 | typedef void | ||
125 | (*GNUNET_TESTING_CommandCleanupRoutine)(void *cls); | ||
126 | |||
127 | |||
128 | /** | ||
129 | * Signature of a function used to extract traits exposed by a | ||
130 | * command. | ||
131 | * | ||
132 | * @param cls closure | ||
133 | * @param[out] ret where to return the trait data | ||
134 | * @param trait name of the trait to return | ||
135 | * @param index index of the trait (for traits that are indexed) | ||
136 | * @return #GNUNET_OK on success | ||
137 | */ | ||
138 | typedef enum GNUNET_GenericReturnValue | ||
139 | (*GNUNET_TESTING_CommandGetTraits) (void *cls, | ||
140 | const void **ret, | ||
141 | const char *trait, | ||
142 | unsigned int index); | ||
143 | |||
144 | /** | ||
145 | * Create a new command | ||
146 | * | ||
147 | * @param cls the closure | ||
148 | * @param label the Label. Maximum length is GNUNET_TESTING_CMD_MAX_LABEL_LENGTH | ||
149 | * @param run the run routing | ||
150 | * @param cleanup the cleanup function | ||
151 | * @param traits the traits function (optional) | ||
152 | * @param the async context | ||
153 | * @return the command the function cannot fail | ||
154 | */ | ||
155 | struct GNUNET_TESTING_Command | ||
156 | GNUNET_TESTING_command_new (void *cls, | ||
157 | const char *label, | ||
158 | GNUNET_TESTING_CommandRunRoutine run, | ||
159 | GNUNET_TESTING_CommandCleanupRoutine cleanup, | ||
160 | GNUNET_TESTING_CommandGetTraits traits, | ||
161 | struct GNUNET_TESTING_AsyncContext *ac); | ||
162 | |||
163 | |||
164 | /** | ||
165 | * Structure with storage space for a label. | ||
166 | */ | ||
167 | struct GNUNET_TESTING_CommandLabel | ||
168 | { | ||
169 | char value[GNUNET_TESTING_CMD_MAX_LABEL_LENGTH + 1]; | ||
170 | }; | ||
171 | |||
172 | |||
173 | /** | ||
174 | * Set @a label to @a value. Asserts that @a value is | ||
175 | * not longer than #GNUNET_TESTING_CMD_MAX_LABEL_LENGTH. | ||
176 | * | ||
177 | * @param[out] label label to initialize | ||
178 | * @param value value to store into @a label | ||
179 | */ | ||
180 | void | ||
181 | GNUNET_TESTING_set_label (struct GNUNET_TESTING_CommandLabel *label, | ||
182 | const char *value); | ||
183 | |||
184 | |||
185 | /** | ||
186 | * A command to be run by the interpreter. | ||
187 | */ | ||
188 | struct GNUNET_TESTING_Command | ||
189 | { | ||
190 | /** | ||
191 | * Closure for all commands with command-specific context information. | ||
192 | */ | ||
193 | void *cls; | ||
194 | |||
195 | /** | ||
196 | * Label for the command. | ||
197 | */ | ||
198 | struct GNUNET_TESTING_CommandLabel label; | ||
199 | |||
200 | /** | ||
201 | * Runs the command. Note that upon return, the interpreter | ||
202 | * will not automatically run the next command, as the command | ||
203 | * may continue asynchronously in other scheduler tasks. Thus, | ||
204 | * the command must ensure to eventually call | ||
205 | * #GNUNET_TESTING_interpreter_next() or | ||
206 | * #GNUNET_TESTING_interpreter_fail(). | ||
207 | * | ||
208 | * If this function creates some asynchronous activity, it should | ||
209 | * initialize @e finish to a function that can be used to wait for | ||
210 | * the asynchronous activity to terminate. | ||
211 | * | ||
212 | * @param cls closure | ||
213 | * @param is interpreter state | ||
214 | */ | ||
215 | GNUNET_TESTING_CommandRunRoutine run; | ||
216 | |||
217 | /** | ||
218 | * Pointer to the asynchronous context in the command's | ||
219 | * closure. Used by the | ||
220 | * #GNUNET_TESTING_async_finish() and | ||
221 | * #GNUNET_TESTING_async_fail() functions. | ||
222 | * | ||
223 | * Must be NULL if a command is synchronous. | ||
224 | */ | ||
225 | struct GNUNET_TESTING_AsyncContext *ac; | ||
226 | |||
227 | /** | ||
228 | * Clean up after the command. Run during forced termination | ||
229 | * (CTRL-C) or test failure or test success. | ||
230 | * | ||
231 | * @param cls closure | ||
232 | */ | ||
233 | GNUNET_TESTING_CommandCleanupRoutine cleanup; | ||
234 | |||
235 | /** | ||
236 | * Extract information from a command that is useful for other | ||
237 | * commands. Can be NULL if a command has no traits. | ||
238 | * | ||
239 | * @param cls closure | ||
240 | * @param[out] ret result (could be anything) | ||
241 | * @param trait name of the trait | ||
242 | * @param index index number of the object to extract. | ||
243 | * @return #GNUNET_OK on success, | ||
244 | * #GNUNET_NO if no trait was found | ||
245 | */ | ||
246 | GNUNET_TESTING_CommandGetTraits traits; | ||
247 | |||
248 | /** | ||
249 | * When did the execution of this command start? | ||
250 | */ | ||
251 | struct GNUNET_TIME_Absolute start_time; | ||
252 | |||
253 | /** | ||
254 | * When did the execution of this command finish? | ||
255 | */ | ||
256 | struct GNUNET_TIME_Absolute finish_time; | ||
257 | |||
258 | /** | ||
259 | * When did we start the last run of this command? Delta to @e finish_time | ||
260 | * gives the latency for the last successful run. Useful in case @e | ||
261 | * num_tries was positive and the command was run multiple times. In that | ||
262 | * case, the @e start_time gives the time when we first tried to run the | ||
263 | * command, so the difference between @e start_time and @e finish_time would | ||
264 | * be the time all of the @e num_tries took, while the delta to @e | ||
265 | * last_req_time is the time the last (successful) execution took. | ||
266 | */ | ||
267 | struct GNUNET_TIME_Absolute last_req_time; | ||
268 | |||
269 | /** | ||
270 | * In case @e asynchronous_finish is true, how long should we wait for this | ||
271 | * command to complete? If @e finish did not complete after this amount of | ||
272 | * time, the interpreter will fail. Should be set generously to ensure | ||
273 | * tests do not fail on slow systems. | ||
274 | */ | ||
275 | struct GNUNET_TIME_Relative default_timeout; | ||
276 | |||
277 | /** | ||
278 | * How often did we try to execute this command? (In case it is a request | ||
279 | * that is repated.) Note that a command must have some built-in retry | ||
280 | * mechanism for this value to be useful. | ||
281 | */ | ||
282 | unsigned int num_tries; | ||
283 | |||
284 | /** | ||
285 | * If "true", the interpreter should not immediately call | ||
286 | * @e finish, even if @e finish is non-NULL. Otherwise, | ||
287 | * #GNUNET_TESTING_cmd_finish() must be used | ||
288 | * to ensure that a command actually completed. | ||
289 | */ | ||
290 | bool asynchronous_finish; | ||
291 | |||
292 | }; | ||
293 | |||
294 | |||
295 | /** | ||
296 | * Lookup command by label. | ||
297 | * Only future commands are looked up. | ||
298 | * | ||
299 | * @param is interpreter to lookup command in | ||
300 | * @param label label of the command to lookup. | ||
301 | * @return the command, if it is found, or NULL. | ||
302 | * @deprecated (still in use in a very odd way) | ||
303 | */ | ||
304 | // FIXME: think harder about whether this is actually needed, likely not. | ||
305 | const struct GNUNET_TESTING_Command * | ||
306 | GNUNET_TESTING_interpreter_lookup_future_command ( | ||
307 | struct GNUNET_TESTING_Interpreter *is, | ||
308 | const char *label); | ||
309 | |||
310 | |||
311 | /** | ||
312 | * Lookup command by label. | ||
313 | * | ||
314 | * @param is interpreter to lookup command in | ||
315 | * @param label label of the command to lookup. | ||
316 | * @return the command, if it is found, or NULL. | ||
317 | */ | ||
318 | const struct GNUNET_TESTING_Command * | ||
319 | GNUNET_TESTING_interpreter_lookup_command ( | ||
320 | struct GNUNET_TESTING_Interpreter *is, | ||
321 | const char *label); | ||
322 | |||
323 | |||
324 | /** | ||
325 | * Lookup command by label. | ||
326 | * All commands, first into the past, then into the future are looked up. | ||
327 | * | ||
328 | * @param is interpreter to lookup command in | ||
329 | * @param label label of the command to lookup. | ||
330 | * @return the command, if it is found, or NULL. | ||
331 | * @deprecated (still in use in a very odd way) | ||
332 | */ | ||
333 | const struct GNUNET_TESTING_Command * | ||
334 | GNUNET_TESTING_interpreter_lookup_command_all ( | ||
335 | struct GNUNET_TESTING_Interpreter *is, | ||
336 | const char *label); | ||
337 | |||
338 | |||
339 | /** | ||
340 | * Current command failed, clean up and fail the test case. | ||
341 | * | ||
342 | * @param is interpreter state. | ||
343 | */ | ||
344 | void | ||
345 | GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is); | ||
346 | |||
347 | |||
348 | /** | ||
349 | * Turn asynchronous command into non-blocking command by setting | ||
350 | * asynchronous_finish to true. Modifies (and then returns) @a cmd simply | ||
351 | * setting the bit. By default, most commands are blocking, and by wrapping | ||
352 | * the command construction in this function a blocking command can be turned | ||
353 | * into an asynchronous command where the interpreter continues after | ||
354 | * initiating the asynchronous action. Does nothing if the command is | ||
355 | * fundamentally synchronous. | ||
356 | * | ||
357 | * @param[in,out] cmd command to make non-blocking | ||
358 | * @return a finish-command. | ||
359 | */ | ||
360 | struct GNUNET_TESTING_Command | ||
361 | GNUNET_TESTING_cmd_make_unblocking (struct GNUNET_TESTING_Command cmd); | ||
362 | |||
363 | |||
364 | /** | ||
365 | * Create (synchronous) command that waits for another command to finish. | ||
366 | * If @a cmd_ref did not finish after @a timeout, this command will fail | ||
367 | * the test case. | ||
368 | * | ||
369 | * @param finish_label label for this command | ||
370 | * @param cmd_ref reference to a previous command which we should | ||
371 | * wait for (call `finish()` on) | ||
372 | * @param timeout how long to wait at most for @a cmd_ref to finish | ||
373 | * @return a finish-command. | ||
374 | */ | ||
375 | const struct GNUNET_TESTING_Command | ||
376 | GNUNET_TESTING_cmd_finish (const char *finish_label, | ||
377 | const char *cmd_ref, | ||
378 | struct GNUNET_TIME_Relative timeout); | ||
379 | |||
380 | |||
381 | /** | ||
382 | * Make the instruction pointer point to @a target_label | ||
383 | * only if @a counter is greater than zero. | ||
384 | * | ||
385 | * @param label command label | ||
386 | * @param target_label label of the new instruction pointer's destination after the jump; | ||
387 | * must be before the current instruction | ||
388 | * @param counter counts how many times the rewinding is to happen. | ||
389 | */ | ||
390 | struct GNUNET_TESTING_Command | ||
391 | GNUNET_TESTING_cmd_rewind_ip (const char *label, | ||
392 | const char *target_label, | ||
393 | unsigned int counter); | ||
394 | |||
395 | |||
396 | /** | ||
397 | * Function called with the final result of the test. | ||
398 | * FIXME: This may want to use a GNUNET_ErrorCode (namespaced, e.g. | ||
399 | * GNUNET_EC_TESTING_*) | ||
400 | * | ||
401 | * @param cls closure | ||
402 | * @param rv #GNUNET_OK if the test passed | ||
403 | */ | ||
404 | typedef void | ||
405 | (*GNUNET_TESTING_ResultCallback)(void *cls, | ||
406 | enum GNUNET_GenericReturnValue rv); | ||
407 | |||
408 | |||
409 | /** | ||
410 | * Run the testsuite. Note, CMDs are copied into | ||
411 | * the interpreter state because they are _usually_ | ||
412 | * defined into the "run" method that returns after | ||
413 | * having scheduled the test interpreter. | ||
414 | * | ||
415 | * @param commands the array of command to execute | ||
416 | * @param timeout how long to wait for each command to execute | ||
417 | * @param rc function to call with the final result | ||
418 | * @param rc_cls closure for @a rc | ||
419 | * @return The interpreter. | ||
420 | */ | ||
421 | struct GNUNET_TESTING_Interpreter * | ||
422 | GNUNET_TESTING_run (const struct GNUNET_TESTING_Command *commands, | ||
423 | struct GNUNET_TIME_Relative timeout, | ||
424 | GNUNET_TESTING_ResultCallback rc, | ||
425 | void *rc_cls); | ||
426 | |||
427 | |||
428 | /** | ||
429 | * Start a GNUnet scheduler event loop and | ||
430 | * run the testsuite. Return 0 upon success. | ||
431 | * Expected to be called directly from main(). | ||
432 | * FIXME: Why is this commands array here not const? | ||
433 | * | ||
434 | * @param commands the list of command to execute | ||
435 | * @param timeout how long to wait for each command to execute | ||
436 | * @return EXIT_SUCCESS on success, EXIT_FAILURE on failure | ||
437 | */ | ||
438 | int | ||
439 | GNUNET_TESTING_main (struct GNUNET_TESTING_Command *commands, | ||
440 | struct GNUNET_TIME_Relative timeout); | ||
441 | |||
442 | |||
443 | |||
444 | /* ************** Fundamental interpreter commands ************ */ | ||
445 | |||
446 | |||
447 | /** | ||
448 | * Create command array terminator. | ||
449 | * | ||
450 | * @return a end-command. | ||
451 | */ | ||
452 | struct GNUNET_TESTING_Command | ||
453 | GNUNET_TESTING_cmd_end (void); | ||
454 | |||
455 | |||
456 | /** | ||
457 | * Create a "batch" command. Such command takes a end_CMD-terminated array of | ||
458 | * CMDs and executed them. Once it hits the end CMD, it passes the control to | ||
459 | * the next top-level CMD, regardless of it being another batch or ordinary | ||
460 | * CMD. | ||
461 | * | ||
462 | * @param label the command label. | ||
463 | * @param batch array of CMDs to execute. | ||
464 | * @return the command. | ||
465 | */ | ||
466 | struct GNUNET_TESTING_Command | ||
467 | GNUNET_TESTING_cmd_batch (const char *label, | ||
468 | struct GNUNET_TESTING_Command *batch); | ||
469 | |||
470 | |||
471 | /** | ||
472 | * Performance counter. | ||
473 | */ | ||
474 | struct GNUNET_TESTING_Timer | ||
475 | { | ||
476 | /** | ||
477 | * For which type of commands. | ||
478 | */ | ||
479 | const char *prefix; | ||
480 | |||
481 | /** | ||
482 | * Total time spend in all commands of this type. | ||
483 | */ | ||
484 | struct GNUNET_TIME_Relative total_duration; | ||
485 | |||
486 | /** | ||
487 | * Total time spend waiting for the *successful* exeuction | ||
488 | * in all commands of this type. | ||
489 | */ | ||
490 | struct GNUNET_TIME_Relative success_latency; | ||
491 | |||
492 | /** | ||
493 | * Number of commands summed up. | ||
494 | */ | ||
495 | unsigned int num_commands; | ||
496 | |||
497 | /** | ||
498 | * Number of retries summed up. | ||
499 | */ | ||
500 | unsigned int num_retries; | ||
501 | }; | ||
502 | |||
503 | /** | ||
504 | * Obtain performance data from the interpreter. | ||
505 | * | ||
506 | * @param[in,out] timers what commands (by label) to obtain runtimes for | ||
507 | * @return the command | ||
508 | */ | ||
509 | struct GNUNET_TESTING_Command | ||
510 | GNUNET_TESTING_cmd_stat (struct GNUNET_TESTING_Timer *timers); | ||
511 | |||
512 | |||
513 | /* *** Generic trait logic for implementing traits ********* */ | ||
514 | |||
515 | /** | ||
516 | * A `struct GNUNET_TESTING_Trait` can be used to exchange data between cmds. | ||
517 | * | ||
518 | * Therefor the cmd which like to provide data to other cmds has to implement | ||
519 | * the trait function, where an array of traits is defined with the help of the | ||
520 | * #GNUNET_TESTING_make_trait_ macro. The data can be retrieved with the help of the | ||
521 | * #GNUNET_TESTING_get_trait_ macro. Traits name and type must be defined to make | ||
522 | * use of the macros. | ||
523 | */ | ||
524 | struct GNUNET_TESTING_Trait | ||
525 | { | ||
526 | /** | ||
527 | * Index number associated with the trait. This gives the | ||
528 | * possibility to have _multiple_ traits on offer under the | ||
529 | * same name. | ||
530 | */ | ||
531 | unsigned int index; | ||
532 | |||
533 | /** | ||
534 | * Trait type, for example "reserve-pub" or "coin-priv". | ||
535 | */ | ||
536 | const char *trait_name; | ||
537 | |||
538 | /** | ||
539 | * Pointer to the piece of data to offer. | ||
540 | */ | ||
541 | const void *ptr; | ||
542 | }; | ||
543 | |||
544 | |||
545 | /** | ||
546 | * "end" of traits array. Because traits are offered into arrays, this type | ||
547 | * of trait is used to mark the end of such arrays; useful when iterating over | ||
548 | * those. | ||
549 | */ | ||
550 | struct GNUNET_TESTING_Trait | ||
551 | GNUNET_TESTING_trait_end (void); | ||
552 | |||
553 | |||
554 | /** | ||
555 | * Obtain value of a trait from a command. | ||
556 | * | ||
557 | * @param traits the array of all the traits. | ||
558 | * @param[out] ret where to store the result. | ||
559 | * @param trait type of the trait to extract. | ||
560 | * @param index index number of the trait to extract. | ||
561 | * @return #GNUNET_OK when the trait is found. | ||
562 | */ | ||
563 | enum GNUNET_GenericReturnValue | ||
564 | GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits, | ||
565 | const void **ret, | ||
566 | const char *trait, | ||
567 | unsigned int index); | ||
568 | |||
569 | |||
570 | |||
571 | /** | ||
572 | * Create headers for a trait with name @a name for | ||
573 | * statically allocated data of type @a type. | ||
574 | * | ||
575 | * @param prefix symbol prefix to use | ||
576 | * @param name name of the trait | ||
577 | * @param type data type for the trait | ||
578 | */ | ||
579 | #define GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT(prefix,name,type) \ | ||
580 | enum GNUNET_GenericReturnValue \ | ||
581 | prefix ## _get_trait_ ## name ( \ | ||
582 | const struct GNUNET_TESTING_Command *cmd, \ | ||
583 | type **ret); \ | ||
584 | struct GNUNET_TESTING_Trait \ | ||
585 | prefix ## _make_trait_ ## name ( \ | ||
586 | type * value); | ||
587 | |||
588 | |||
589 | /** | ||
590 | * Create C implementation for a trait with name @a name for statically | ||
591 | * allocated data of type @a type. | ||
592 | * | ||
593 | * @param prefix symbol prefix to use | ||
594 | * @param name name of the trait | ||
595 | * @param type data type for the trait | ||
596 | */ | ||
597 | #define GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT(prefix,name,type) \ | ||
598 | enum GNUNET_GenericReturnValue \ | ||
599 | prefix ## _get_trait_ ## name ( \ | ||
600 | const struct GNUNET_TESTING_Command *cmd, \ | ||
601 | type * *ret) \ | ||
602 | { \ | ||
603 | if (NULL == cmd->traits) return GNUNET_SYSERR; \ | ||
604 | return cmd->traits (cmd->cls, \ | ||
605 | (const void **) ret, \ | ||
606 | GNUNET_S (name), \ | ||
607 | 0); \ | ||
608 | } \ | ||
609 | struct GNUNET_TESTING_Trait \ | ||
610 | prefix ## _make_trait_ ## name ( \ | ||
611 | type * value) \ | ||
612 | { \ | ||
613 | struct GNUNET_TESTING_Trait ret = { \ | ||
614 | .trait_name = GNUNET_S (name), \ | ||
615 | .ptr = (const void *) value \ | ||
616 | }; \ | ||
617 | return ret; \ | ||
618 | } | ||
619 | |||
620 | |||
621 | /** | ||
622 | * Create headers for a trait with name @a name for | ||
623 | * statically allocated data of type @a type. | ||
624 | * | ||
625 | * @param prefix symbol prefix to use | ||
626 | * @param name name of the trait | ||
627 | * @param type data type for the trait | ||
628 | */ | ||
629 | #define GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT(prefix,name,type) \ | ||
630 | enum GNUNET_GenericReturnValue \ | ||
631 | prefix ## _get_trait_ ## name ( \ | ||
632 | const struct GNUNET_TESTING_Command *cmd, \ | ||
633 | unsigned int index, \ | ||
634 | type **ret); \ | ||
635 | struct GNUNET_TESTING_Trait \ | ||
636 | prefix ## _make_trait_ ## name ( \ | ||
637 | unsigned int index, \ | ||
638 | type *value); | ||
639 | |||
640 | |||
641 | /** | ||
642 | * Create C implementation for a trait with name @a name for statically | ||
643 | * allocated data of type @a type. | ||
644 | */ | ||
645 | #define GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT(prefix,name,type) \ | ||
646 | enum GNUNET_GenericReturnValue \ | ||
647 | prefix ## _get_trait_ ## name ( \ | ||
648 | const struct GNUNET_TESTING_Command *cmd, \ | ||
649 | unsigned int index, \ | ||
650 | type * *ret) \ | ||
651 | { \ | ||
652 | if (NULL == cmd->traits) return GNUNET_SYSERR; \ | ||
653 | return cmd->traits (cmd->cls, \ | ||
654 | (const void **) ret, \ | ||
655 | GNUNET_S (name), \ | ||
656 | index); \ | ||
657 | } \ | ||
658 | struct GNUNET_TESTING_Trait \ | ||
659 | prefix ## _make_trait_ ## name ( \ | ||
660 | unsigned int index, \ | ||
661 | type * value) \ | ||
662 | { \ | ||
663 | struct GNUNET_TESTING_Trait ret = { \ | ||
664 | .index = index, \ | ||
665 | .trait_name = GNUNET_S (name), \ | ||
666 | .ptr = (const void *) value \ | ||
667 | }; \ | ||
668 | return ret; \ | ||
669 | } | ||
670 | |||
671 | |||
672 | /** | ||
673 | * Call #op on all simple traits needed by loop logic. | ||
674 | * | ||
675 | * @param op operation to perform | ||
676 | * @param prefix prefix to pass to @e op | ||
677 | */ | ||
678 | #define GNUNET_TESTING_LOOP_SIMPLE_TRAITS(op,prefix) \ | ||
679 | op (prefix, batch_cmds, struct GNUNET_TESTING_Command *) | ||
680 | |||
681 | |||
682 | GNUNET_TESTING_LOOP_SIMPLE_TRAITS(GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT, GNUNET_TESTING) | ||
683 | |||
684 | |||
685 | /** | ||
686 | * Call #op on all indexed traits needed by loop logic. | ||
687 | * | ||
688 | * @param op operation to perform | ||
689 | * @param prefix prefix to pass to @e op | ||
690 | */ | ||
691 | #define GNUNET_TESTING_LOOP_INDEXED_TRAITS(op,prefix) \ | ||
692 | op (prefix, cmd, const struct GNUNET_TESTING_Command) | ||
693 | |||
694 | GNUNET_TESTING_LOOP_INDEXED_TRAITS (GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT, GNUNET_TESTING) | ||
695 | |||
696 | |||
697 | #endif | ||
diff --git a/src/include/gnunet_testing_netjail_lib.h b/src/include/gnunet_testing_netjail_lib.h deleted file mode 100644 index 843fce0d5..000000000 --- a/src/include/gnunet_testing_netjail_lib.h +++ /dev/null | |||
@@ -1,546 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @brief API for writing an interpreter to test GNUnet components | ||
23 | * @author Christian Grothoff <christian@grothoff.org> | ||
24 | * @author Marcello Stanisci | ||
25 | * @author t3sserakt | ||
26 | */ | ||
27 | #ifndef GNUNET_TESTING_NETJAIL_LIB_H | ||
28 | #define GNUNET_TESTING_NETJAIL_LIB_H | ||
29 | |||
30 | #include "gnunet_testing_ng_lib.h" | ||
31 | #include "gnunet_testing_plugin.h" | ||
32 | |||
33 | |||
34 | /** | ||
35 | * Router of a netjail subnet. | ||
36 | */ | ||
37 | struct GNUNET_TESTING_NetjailRouter | ||
38 | { | ||
39 | /** | ||
40 | * Will tcp be forwarded? | ||
41 | */ | ||
42 | unsigned int tcp_port; | ||
43 | |||
44 | /** | ||
45 | * Will udp be forwarded? | ||
46 | */ | ||
47 | unsigned int udp_port; | ||
48 | }; | ||
49 | |||
50 | |||
51 | /** | ||
52 | * Enum for the different types of nodes. | ||
53 | */ | ||
54 | enum GNUNET_TESTING_NodeType | ||
55 | { | ||
56 | /** | ||
57 | * Node in a subnet. | ||
58 | */ | ||
59 | GNUNET_TESTING_SUBNET_NODE, | ||
60 | |||
61 | /** | ||
62 | * Global known node. | ||
63 | */ | ||
64 | GNUNET_TESTING_GLOBAL_NODE | ||
65 | }; | ||
66 | |||
67 | /** | ||
68 | * Protocol address prefix für a connection between nodes. | ||
69 | */ | ||
70 | struct GNUNET_TESTING_AddressPrefix | ||
71 | { | ||
72 | /** | ||
73 | * Pointer to the previous prefix in the DLL. | ||
74 | */ | ||
75 | struct GNUNET_TESTING_AddressPrefix *prev; | ||
76 | |||
77 | /** | ||
78 | * Pointer to the next prefix in the DLL. | ||
79 | */ | ||
80 | struct GNUNET_TESTING_AddressPrefix *next; | ||
81 | |||
82 | /** | ||
83 | * The address prefix. | ||
84 | */ | ||
85 | char *address_prefix; | ||
86 | }; | ||
87 | |||
88 | |||
89 | /** | ||
90 | * Node in a netjail topology. | ||
91 | */ | ||
92 | struct GNUNET_TESTING_NetjailNode; | ||
93 | |||
94 | /** | ||
95 | * Connection to another node. | ||
96 | */ | ||
97 | struct GNUNET_TESTING_NodeConnection | ||
98 | { | ||
99 | /** | ||
100 | * Pointer to the previous connection in the DLL. | ||
101 | */ | ||
102 | struct GNUNET_TESTING_NodeConnection *prev; | ||
103 | |||
104 | /** | ||
105 | * Pointer to the next connection in the DLL. | ||
106 | */ | ||
107 | struct GNUNET_TESTING_NodeConnection *next; | ||
108 | |||
109 | /** | ||
110 | * The number of the subnet of the node this connection points to. This is 0, | ||
111 | * if the node is a global known node. | ||
112 | */ | ||
113 | unsigned int namespace_n; | ||
114 | |||
115 | /** | ||
116 | * The number of the node this connection points to. | ||
117 | */ | ||
118 | unsigned int node_n; | ||
119 | |||
120 | /** | ||
121 | * The type of the node this connection points to. | ||
122 | */ | ||
123 | enum GNUNET_TESTING_NodeType node_type; | ||
124 | |||
125 | /** | ||
126 | * The node which establish the connection | ||
127 | */ | ||
128 | struct GNUNET_TESTING_NetjailNode *node; | ||
129 | |||
130 | /** | ||
131 | * Head of the DLL with the address prefixes for the protocolls this node is reachable. | ||
132 | */ | ||
133 | struct GNUNET_TESTING_AddressPrefix *address_prefixes_head; | ||
134 | |||
135 | /** | ||
136 | * Tail of the DLL with the address prefixes for the protocolls this node is reachable. | ||
137 | */ | ||
138 | struct GNUNET_TESTING_AddressPrefix *address_prefixes_tail; | ||
139 | }; | ||
140 | |||
141 | /** | ||
142 | * Node in the netjail topology. | ||
143 | */ | ||
144 | struct GNUNET_TESTING_NetjailNode | ||
145 | { | ||
146 | /** | ||
147 | * Head of the DLL with the connections which shall be established to other nodes. | ||
148 | */ | ||
149 | struct GNUNET_TESTING_NodeConnection *node_connections_head; | ||
150 | |||
151 | /** | ||
152 | * Tail of the DLL with the connections which shall be established to other nodes. | ||
153 | */ | ||
154 | struct GNUNET_TESTING_NodeConnection *node_connections_tail; | ||
155 | |||
156 | /** | ||
157 | * Plugin for the test case to be run on this node. | ||
158 | */ | ||
159 | char *plugin; | ||
160 | |||
161 | /** | ||
162 | * Flag indicating if this node is a global known node. | ||
163 | */ | ||
164 | unsigned int is_global; | ||
165 | |||
166 | /** | ||
167 | * The number of the subnet this node is running in. | ||
168 | */ | ||
169 | unsigned int namespace_n; | ||
170 | |||
171 | /** | ||
172 | * The number of this node in the subnet. | ||
173 | */ | ||
174 | unsigned int node_n; | ||
175 | |||
176 | /** | ||
177 | * The overall number of the node in the whole test system. | ||
178 | */ | ||
179 | unsigned int node_number; | ||
180 | |||
181 | /** | ||
182 | * The number of unintentional additional connections this node waits for. This overwrites the global additional_connects value. | ||
183 | */ | ||
184 | unsigned int additional_connects; | ||
185 | |||
186 | /** | ||
187 | * The number of cmds waiting for a specific barrier. | ||
188 | */ | ||
189 | unsigned int expected_reaches; | ||
190 | }; | ||
191 | |||
192 | |||
193 | /** | ||
194 | * Subnet in a topology. | ||
195 | */ | ||
196 | struct GNUNET_TESTING_NetjailNamespace | ||
197 | { | ||
198 | /** | ||
199 | * The number of the subnet. | ||
200 | */ | ||
201 | unsigned int namespace_n; | ||
202 | |||
203 | /** | ||
204 | * Router of the subnet. | ||
205 | */ | ||
206 | struct GNUNET_TESTING_NetjailRouter *router; | ||
207 | |||
208 | /** | ||
209 | * Hash map containing the nodes in this subnet. | ||
210 | */ | ||
211 | struct GNUNET_CONTAINER_MultiShortmap *nodes; | ||
212 | }; | ||
213 | |||
214 | /** | ||
215 | * Toplogy of our netjail setup. | ||
216 | */ | ||
217 | struct GNUNET_TESTING_NetjailTopology | ||
218 | { | ||
219 | |||
220 | /** | ||
221 | * Default plugin for the test case to be run on nodes. | ||
222 | */ | ||
223 | char *plugin; | ||
224 | |||
225 | /** | ||
226 | * Number of subnets. | ||
227 | */ | ||
228 | unsigned int namespaces_n; | ||
229 | |||
230 | /** | ||
231 | * Number of nodes per subnet. | ||
232 | */ | ||
233 | unsigned int nodes_m; | ||
234 | |||
235 | /** | ||
236 | * Number of global known nodes. | ||
237 | */ | ||
238 | unsigned int nodes_x; | ||
239 | |||
240 | /** | ||
241 | * Hash map containing the subnets (for natted nodes) of the topology. | ||
242 | */ | ||
243 | struct GNUNET_CONTAINER_MultiShortmap *map_namespaces; | ||
244 | |||
245 | /** | ||
246 | * Hash map containing the global known nodes which are not natted. | ||
247 | */ | ||
248 | struct GNUNET_CONTAINER_MultiShortmap *map_globals; | ||
249 | |||
250 | /** | ||
251 | * Additional connects we do expect, beside the connects which are configured in the topology. | ||
252 | */ | ||
253 | unsigned int additional_connects; | ||
254 | }; | ||
255 | |||
256 | /** | ||
257 | * Getting the topology from file. | ||
258 | * | ||
259 | * @param filename The name of the topology file. | ||
260 | * @return The GNUNET_TESTING_NetjailTopology | ||
261 | */ | ||
262 | struct GNUNET_TESTING_NetjailTopology * | ||
263 | GNUNET_TESTING_get_topo_from_file (const char *filename); | ||
264 | |||
265 | |||
266 | /** | ||
267 | * FIXME: this could use a "to_string". | ||
268 | * Parse the topology data. | ||
269 | * | ||
270 | * @param data The topology data. | ||
271 | * @return The GNUNET_TESTING_NetjailTopology | ||
272 | */ | ||
273 | struct GNUNET_TESTING_NetjailTopology * | ||
274 | GNUNET_TESTING_get_topo_from_string (const char *data); | ||
275 | |||
276 | |||
277 | /** | ||
278 | * Get the number of unintentional additional connections the node waits for. | ||
279 | * | ||
280 | * @param num The specific node we want the additional connects for. | ||
281 | * @return The number of additional connects | ||
282 | */ | ||
283 | unsigned int | ||
284 | GNUNET_TESTING_get_additional_connects (unsigned int num, | ||
285 | struct GNUNET_TESTING_NetjailTopology * | ||
286 | topology); | ||
287 | |||
288 | /** | ||
289 | * Get a node from the topology. | ||
290 | * | ||
291 | * @param num The specific node we want the connections for. | ||
292 | * @param topology The topology we get the connections from. | ||
293 | * @return The connections of the node. | ||
294 | */ | ||
295 | struct GNUNET_TESTING_NetjailNode * | ||
296 | GNUNET_TESTING_get_node (unsigned int num, | ||
297 | struct GNUNET_TESTING_NetjailTopology *topology); | ||
298 | |||
299 | |||
300 | /** | ||
301 | * Get the connections to other nodes for a specific node. | ||
302 | * | ||
303 | * @param num The specific node we want the connections for. | ||
304 | * @param topology The topology we get the connections from. | ||
305 | * @return The connections of the node. | ||
306 | */ | ||
307 | struct GNUNET_TESTING_NodeConnection * | ||
308 | GNUNET_TESTING_get_connections (unsigned int num, | ||
309 | const struct GNUNET_TESTING_NetjailTopology *topology); | ||
310 | |||
311 | |||
312 | /** | ||
313 | * Get the address for a specific communicator from a connection. | ||
314 | * | ||
315 | * @param connection The connection we like to have the address from. | ||
316 | * @param prefix The communicator protocol prefix. | ||
317 | * @return The address of the communicator. | ||
318 | */ | ||
319 | char * | ||
320 | GNUNET_TESTING_get_address (struct GNUNET_TESTING_NodeConnection *connection, | ||
321 | const char *prefix); | ||
322 | |||
323 | |||
324 | /** | ||
325 | * Deallocate memory of the struct GNUNET_TESTING_NetjailTopology. | ||
326 | * | ||
327 | * @param topology The GNUNET_TESTING_NetjailTopology to be deallocated. | ||
328 | */ | ||
329 | void | ||
330 | GNUNET_TESTING_free_topology (struct GNUNET_TESTING_NetjailTopology *topology); | ||
331 | |||
332 | |||
333 | /** | ||
334 | * Calculate the unique id identifying a node from a given connection. | ||
335 | * | ||
336 | * @param node_connection The connection we calculate the id from. | ||
337 | * @param topology The topology we get all needed information from. | ||
338 | * @return The unique id of the node from the connection. | ||
339 | */ | ||
340 | unsigned int | ||
341 | GNUNET_TESTING_calculate_num (struct | ||
342 | GNUNET_TESTING_NodeConnection *node_connection, | ||
343 | struct GNUNET_TESTING_NetjailTopology *topology); | ||
344 | |||
345 | |||
346 | /** | ||
347 | * Struct with information for callbacks. | ||
348 | * | ||
349 | */ | ||
350 | struct GNUNET_TESTING_BlockState | ||
351 | { | ||
352 | /** | ||
353 | * Context for our asynchronous completion. | ||
354 | */ | ||
355 | struct GNUNET_TESTING_AsyncContext ac; | ||
356 | |||
357 | /** | ||
358 | * The label of this command. | ||
359 | */ | ||
360 | const char *label; | ||
361 | |||
362 | /** | ||
363 | * If this command will block. | ||
364 | */ | ||
365 | unsigned int asynchronous_finish; | ||
366 | }; | ||
367 | |||
368 | /** | ||
369 | * Struct to hold information for callbacks. | ||
370 | * | ||
371 | */ | ||
372 | struct GNUNET_TESTING_LocalPreparedState | ||
373 | { | ||
374 | /** | ||
375 | * Context for our asynchronous completion. | ||
376 | */ | ||
377 | struct GNUNET_TESTING_AsyncContext ac; | ||
378 | |||
379 | /** | ||
380 | * Callback to write messages to the master loop. | ||
381 | * | ||
382 | */ | ||
383 | GNUNET_TESTING_cmd_helper_write_cb write_message; | ||
384 | }; | ||
385 | |||
386 | /** | ||
387 | * This command destroys the ressources allocated for the test system setup. | ||
388 | * | ||
389 | * @param label Name for command. | ||
390 | * @param create_label Label of the cmd which started the test system. | ||
391 | * @param write_message Callback to write messages to the master loop. | ||
392 | * @return command. | ||
393 | */ | ||
394 | struct GNUNET_TESTING_Command | ||
395 | GNUNET_TESTING_cmd_system_destroy (const char *label, | ||
396 | const char *create_label); | ||
397 | |||
398 | /** | ||
399 | * This command is setting up a test environment for a peer to start. | ||
400 | * | ||
401 | * @param label Name for command. | ||
402 | * @param testdir Only the directory name without any path. Temporary | ||
403 | * directory used for all service homes. | ||
404 | */ | ||
405 | struct GNUNET_TESTING_Command | ||
406 | GNUNET_TESTING_cmd_system_create (const char *label, | ||
407 | const char *testdir); | ||
408 | |||
409 | |||
410 | /** | ||
411 | * This command executes a shell script to setup the netjail environment. | ||
412 | * | ||
413 | * @param label name for command. | ||
414 | * @param topology_config Configuration file for the test topology. | ||
415 | * @param read_file Flag indicating if the the name of the topology file is send to the helper, or a string with the topology data. | ||
416 | * @return command. | ||
417 | */ | ||
418 | struct GNUNET_TESTING_Command | ||
419 | GNUNET_TESTING_cmd_netjail_start (const char *label, | ||
420 | char *topology_config, | ||
421 | unsigned int *read_file); | ||
422 | |||
423 | |||
424 | /** | ||
425 | * This command executes a shell script to remove the netjail environment. | ||
426 | * | ||
427 | * @param label name for command. | ||
428 | * @param topology_config Configuration file for the test topology. | ||
429 | * @param read_file Flag indicating if the the name of the topology file is send to the helper, or a string with the topology data. | ||
430 | * @return command. | ||
431 | */ | ||
432 | struct GNUNET_TESTING_Command | ||
433 | GNUNET_TESTING_cmd_netjail_stop (const char *label, | ||
434 | char *topology_config, | ||
435 | unsigned int *read_file); | ||
436 | |||
437 | |||
438 | /** | ||
439 | * This command executes a shell script which starts a helper process. | ||
440 | * This process is running on a netjail node, executing a defined test case. | ||
441 | * | ||
442 | * @param label Name for the command. | ||
443 | * @param topology The complete topology information. | ||
444 | * @param read_file Flag indicating if the the name of the topology file is send to the helper, or a string with the topology data. | ||
445 | * @param topology_data If read_file is GNUNET_NO, topology_data holds the string with the topology. | ||
446 | * @param timeout Before this timeout is reached this cmd MUST finish. | ||
447 | * @return command. | ||
448 | */ | ||
449 | struct GNUNET_TESTING_Command | ||
450 | GNUNET_TESTING_cmd_netjail_start_cmds_helper ( | ||
451 | const char *label, | ||
452 | struct GNUNET_TESTING_NetjailTopology *topology, | ||
453 | unsigned int *read_file, | ||
454 | char *topology_data, | ||
455 | struct GNUNET_TIME_Relative timeout); | ||
456 | |||
457 | |||
458 | /** | ||
459 | * Create command. | ||
460 | * | ||
461 | * @param label name for command. | ||
462 | * @param helper_start_label label of the cmd to start the test system. | ||
463 | * @param topology The complete topology information. | ||
464 | * @return command. | ||
465 | */ | ||
466 | struct GNUNET_TESTING_Command | ||
467 | GNUNET_TESTING_cmd_stop_cmds_helper ( | ||
468 | const char *label, | ||
469 | const char *helper_start_label, | ||
470 | struct GNUNET_TESTING_NetjailTopology *topology); | ||
471 | |||
472 | |||
473 | /** | ||
474 | * This command is used to block the loop, until the command is finished by other commands, | ||
475 | * using a trait to get this commands struct GNUNET_TESTING_AsyncContext. | ||
476 | * | ||
477 | * @param label name for command. | ||
478 | * @return command. | ||
479 | */ | ||
480 | struct GNUNET_TESTING_Command | ||
481 | GNUNET_TESTING_cmd_block_until_external_trigger ( | ||
482 | const char *label); | ||
483 | |||
484 | /** | ||
485 | * DEPRECATED | ||
486 | * This command sends a GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED message to the master loop. | ||
487 | * | ||
488 | * @param label name for command. | ||
489 | * @param write_message Callback to write messages to the master loop. | ||
490 | * @return command. | ||
491 | */ | ||
492 | struct GNUNET_TESTING_Command | ||
493 | GNUNET_TESTING_cmd_send_peer_ready (const char *label, | ||
494 | GNUNET_TESTING_cmd_helper_write_cb write_message); | ||
495 | |||
496 | |||
497 | /** | ||
498 | * This command sends a GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TESTS_PREPARED message to the master loop. | ||
499 | * | ||
500 | * @param label name for command. | ||
501 | * @param write_message Callback to write messages to the master loop. | ||
502 | * @return command. | ||
503 | */ | ||
504 | struct GNUNET_TESTING_Command | ||
505 | GNUNET_TESTING_cmd_local_test_prepared (const char *label, | ||
506 | GNUNET_TESTING_cmd_helper_write_cb | ||
507 | write_message); | ||
508 | |||
509 | |||
510 | /** | ||
511 | * Create command. | ||
512 | * | ||
513 | * @param label name for command. | ||
514 | * @param system_label Label of the cmd to setup a test environment. | ||
515 | * @param no Decimal number representing the last byte of the IP address of this peer. | ||
516 | * @param node_ip The IP address of this node. | ||
517 | * @param cfgname Configuration file name for this peer. | ||
518 | * @param broadcast Flag indicating, if broadcast should be switched on. | ||
519 | * @return command. | ||
520 | */ | ||
521 | struct GNUNET_TESTING_Command | ||
522 | GNUNET_TESTING_cmd_start_peer (const char *label, | ||
523 | const char *system_label, | ||
524 | uint32_t no, | ||
525 | const char *node_ip, | ||
526 | const char *cfgname, | ||
527 | unsigned int broadcast); | ||
528 | |||
529 | |||
530 | /* ***** Netjail trait support ***** */ | ||
531 | |||
532 | |||
533 | /** | ||
534 | * Call #op on all simple traits. | ||
535 | */ | ||
536 | #define GNUNET_TESTING_SIMPLE_NETJAIL_TRAITS(op, prefix) \ | ||
537 | op (prefix, test_system, const struct GNUNET_TESTING_System) \ | ||
538 | op (prefix, async_context, struct GNUNET_TESTING_AsyncContext) \ | ||
539 | op (prefix, helper_handles, const struct GNUNET_HELPER_Handle *) \ | ||
540 | op (prefix, local_prepared_state, const struct GNUNET_TESTING_LocalPreparedState) \ | ||
541 | op (prefix, block_state, struct GNUNET_TESTING_BlockState) | ||
542 | |||
543 | GNUNET_TESTING_SIMPLE_NETJAIL_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT, GNUNET_TESTING) | ||
544 | |||
545 | |||
546 | #endif | ||
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h deleted file mode 100644 index 407f50bb7..000000000 --- a/src/include/gnunet_testing_ng_lib.h +++ /dev/null | |||
@@ -1,115 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2021, 2023 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @brief Meta-header for next-generation testing logic | ||
23 | * @author Christian Grothoff <christian@grothoff.org> | ||
24 | * @author Marcello Stanisci | ||
25 | * @author t3sserakt | ||
26 | */ | ||
27 | #ifndef GNUNET_TESTING_NG_LIB_H | ||
28 | #define GNUNET_TESTING_NG_LIB_H | ||
29 | |||
30 | |||
31 | #include "gnunet_util_lib.h" | ||
32 | |||
33 | /* FIXME: legacy test header, to be removed!! */ | ||
34 | #include "gnunet_testing_lib.h" | ||
35 | |||
36 | #include "gnunet_testing_plugin.h" | ||
37 | #include "gnunet_testing_loop_lib.h" | ||
38 | #include "gnunet_testing_netjail_lib.h" | ||
39 | |||
40 | |||
41 | /** | ||
42 | * Create a "signal" CMD. | ||
43 | * | ||
44 | * @param label command label. | ||
45 | * @param process_label label of a command that has a process trait | ||
46 | * @param signal signal to send to @a process. | ||
47 | * @return the command. | ||
48 | */ | ||
49 | struct GNUNET_TESTING_Command | ||
50 | GNUNET_TESTING_cmd_signal (const char *label, | ||
51 | const char *process_label, | ||
52 | int signal); | ||
53 | |||
54 | |||
55 | /** | ||
56 | * Sleep for @a duration. | ||
57 | * | ||
58 | * @param label command label. | ||
59 | * @param duration time to sleep | ||
60 | * @return the command. | ||
61 | */ | ||
62 | struct GNUNET_TESTING_Command | ||
63 | GNUNET_TESTING_cmd_sleep (const char *label, | ||
64 | struct GNUNET_TIME_Relative duration); | ||
65 | |||
66 | |||
67 | /** | ||
68 | * Command to execute a script synchronously. | ||
69 | * | ||
70 | * FIXME: is this accurate? How is this limited to BASH scripts or even scripts? | ||
71 | * | ||
72 | * @param label Label of the command. | ||
73 | * @param script The name of the script. | ||
74 | * @param script_argv The arguments of the script. | ||
75 | */ | ||
76 | const struct GNUNET_TESTING_Command | ||
77 | GNUNET_TESTING_cmd_exec_bash_script (const char *label, | ||
78 | const char *script, | ||
79 | char *const script_argv[], | ||
80 | // FIXME: wtf are these two args here for!? | ||
81 | int argc, | ||
82 | GNUNET_ChildCompletedCallback cb); | ||
83 | |||
84 | |||
85 | |||
86 | /* ****** Specific traits needed by this component ******* */ | ||
87 | |||
88 | |||
89 | /** | ||
90 | * Call #op on all simple traits. | ||
91 | */ | ||
92 | #define GNUNET_TESTING_SIMPLE_TRAITS(op, prefix) \ | ||
93 | op (prefix, process, struct GNUNET_OS_Process *) | ||
94 | |||
95 | |||
96 | GNUNET_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT, GNUNET_TESTING) | ||
97 | |||
98 | /** | ||
99 | * Call #op on all indexed traits. | ||
100 | */ | ||
101 | #define GNUNET_TESTING_INDEXED_TRAITS(op, prefix) \ | ||
102 | op (prefix, uint32, const uint32_t) \ | ||
103 | op (prefix, uint64, const uint64_t) \ | ||
104 | op (prefix, int64, const int64_t) \ | ||
105 | op (prefix, uint, const unsigned int) \ | ||
106 | op (prefix, string, const char) \ | ||
107 | op (prefix, uuid, const struct GNUNET_Uuid) \ | ||
108 | op (prefix, time, const struct GNUNET_TIME_Absolute) \ | ||
109 | op (prefix, absolute_time, const struct GNUNET_TIME_Absolute) \ | ||
110 | op (prefix, relative_time, const struct GNUNET_TIME_Relative) | ||
111 | |||
112 | GNUNET_TESTING_INDEXED_TRAITS (GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT, GNUNET_TESTING) | ||
113 | |||
114 | |||
115 | #endif | ||
diff --git a/src/include/gnunet_testing_plugin.h b/src/include/gnunet_testing_plugin.h deleted file mode 100644 index b030bc8a8..000000000 --- a/src/include/gnunet_testing_plugin.h +++ /dev/null | |||
@@ -1,145 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * | ||
23 | * @author t3sserakt | ||
24 | * | ||
25 | * Plugin API to start test cases. | ||
26 | * | ||
27 | */ | ||
28 | #ifndef GNUNET_TESTING_PLUGIN_H | ||
29 | #define GNUNET_TESTING_PLUGIN_H | ||
30 | |||
31 | #include "gnunet_common.h" | ||
32 | |||
33 | #ifdef __cplusplus | ||
34 | extern "C" | ||
35 | { | ||
36 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
37 | } | ||
38 | #endif | ||
39 | #endif | ||
40 | |||
41 | |||
42 | /** | ||
43 | * Callback function to write messages from the helper process running on a netjail node to the master process. | ||
44 | * | ||
45 | * @param message The message to write. | ||
46 | * @param msg_length The length of the message. | ||
47 | */ | ||
48 | typedef void | ||
49 | (*GNUNET_TESTING_cmd_helper_write_cb) (struct GNUNET_MessageHeader *message, | ||
50 | size_t msg_length); | ||
51 | |||
52 | /** | ||
53 | * Callback function which writes a message from the helper process running on a netjail node to the master process * signaling that the test case running on the netjail node finished. | ||
54 | */ | ||
55 | typedef void | ||
56 | (*GNUNET_TESTING_cmd_helper_finish_cb) (); | ||
57 | |||
58 | |||
59 | /** | ||
60 | * Function to be implemented for each test case plugin which starts the test case on a netjail node. | ||
61 | * | ||
62 | * @param write_message Callback function to write messages from the helper process running on a | ||
63 | * netjail node to the master process. | ||
64 | * @param router_ip Global address of the network namespace, if the helper process is for a node in a subnet. | ||
65 | * @param node_ip The IP address of the node. | ||
66 | * @param m The number of the node in a network namespace. | ||
67 | * @param n The number of the network namespace. | ||
68 | * @param local_m The number of nodes in a network namespace. | ||
69 | * @param topology_data A file name for the file containing the topology configuration, or a string containing | ||
70 | * the topology configuration. | ||
71 | * @param read_file If read_file is GNUNET_YES this string is the filename for the topology configuration, | ||
72 | * if read_file is GNUNET_NO the string contains the topology configuration. | ||
73 | * @param finish_cb Callback function which writes a message from the helper process running on a netjail | ||
74 | * node to the master process * signaling that the test case running on the netjail node finished. | ||
75 | * @return Returns The struct GNUNET_TESTING_Interpreter of the command loop running on this netjail node. | ||
76 | */ | ||
77 | typedef struct GNUNET_TESTING_Interpreter * | ||
78 | (*GNUNET_TESTING_PLUGIN_StartTestCase) ( | ||
79 | GNUNET_TESTING_cmd_helper_write_cb write_message, | ||
80 | const char *router_ip, | ||
81 | const char *node_ip, | ||
82 | const char *n, | ||
83 | const char *m, | ||
84 | const char *local_m, | ||
85 | const char *topology_data, | ||
86 | unsigned int *read_file, | ||
87 | GNUNET_TESTING_cmd_helper_finish_cb | ||
88 | finish_cb); | ||
89 | |||
90 | /** | ||
91 | * DEPRECATED | ||
92 | * The helper process received a message of type | ||
93 | * GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED. This will finish the blocking command | ||
94 | * GNUNET_TESTING_cmd_block_until_external_trigger which was execute right after the command | ||
95 | * GNUNET_TESTING_cmd_send_peer_ready. | ||
96 | */ | ||
97 | typedef void | ||
98 | (*GNUNET_TESTING_PLUGIN_ALL_PEERS_STARTED) (); | ||
99 | |||
100 | /** | ||
101 | * DEPRECATED | ||
102 | * The helper process received a message of type | ||
103 | * GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED. This will finish the blocking command | ||
104 | * GNUNET_TESTING_cmd_local_test_prepared which was execute right after the command | ||
105 | * GNUNET_TRANSPORT_cmd_connect_peers. | ||
106 | * FIXME: do not use ALL CAPS | ||
107 | */ | ||
108 | typedef void | ||
109 | (*GNUNET_TESTING_PLUGIN_ALL_LOCAL_TESTS_PREPARED) (); | ||
110 | |||
111 | |||
112 | /** | ||
113 | * This function returns a struct GNUNET_TESTING_BarrierList, which is a list of all barriers | ||
114 | * this test case will wait for. | ||
115 | * | ||
116 | * @return A struct GNUNET_TESTING_BarrierList. | ||
117 | * FIXME: do not use ALL CAPS | ||
118 | */ | ||
119 | typedef struct GNUNET_TESTING_BarrierList* | ||
120 | (*GNUNET_TESTING_PLUGIN_GET_WAITING_FOR_BARRIERS) (void); | ||
121 | |||
122 | |||
123 | /** | ||
124 | * The plugin API every test case plugin has to implement. | ||
125 | */ | ||
126 | struct GNUNET_TESTING_PluginFunctions | ||
127 | { | ||
128 | |||
129 | GNUNET_TESTING_PLUGIN_StartTestCase start_testcase; | ||
130 | |||
131 | GNUNET_TESTING_PLUGIN_ALL_PEERS_STARTED all_peers_started; | ||
132 | |||
133 | GNUNET_TESTING_PLUGIN_ALL_LOCAL_TESTS_PREPARED all_local_tests_prepared; | ||
134 | |||
135 | GNUNET_TESTING_PLUGIN_GET_WAITING_FOR_BARRIERS get_waiting_for_barriers; | ||
136 | }; | ||
137 | |||
138 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
139 | { | ||
140 | #endif | ||
141 | #ifdef __cplusplus | ||
142 | } | ||
143 | #endif | ||
144 | |||
145 | #endif | ||
diff --git a/src/include/gnunet_testing_testbed_lib.h b/src/include/gnunet_testing_testbed_lib.h new file mode 100644 index 000000000..872382706 --- /dev/null +++ b/src/include/gnunet_testing_testbed_lib.h | |||
@@ -0,0 +1,42 @@ | |||
1 | #ifndef GNUNET_TESTING_TESTBED_LIB_H | ||
2 | #define GNUNET_TESTING_TESTBED_LIB_H | ||
3 | |||
4 | #include "gnunet_testing_lib.h" | ||
5 | #include "gnunet_testbed_lib.h" | ||
6 | |||
7 | /** | ||
8 | * This command destroys the ressources allocated for the test system setup. | ||
9 | * | ||
10 | * @param label Name for command. | ||
11 | * @param create_label Label of the cmd which started the test system. | ||
12 | * @param write_message Callback to write messages to the master loop. | ||
13 | * @return command. | ||
14 | */ | ||
15 | struct GNUNET_TESTING_Command | ||
16 | GNUNET_TESTBED_cmd_system_destroy (const char *label, | ||
17 | const char *create_label); | ||
18 | |||
19 | /** | ||
20 | * This command is setting up a test environment for a peer to start. | ||
21 | * | ||
22 | * @param label Name for command. | ||
23 | * @param testdir Only the directory name without any path. Temporary | ||
24 | * directory used for all service homes. | ||
25 | */ | ||
26 | struct GNUNET_TESTING_Command | ||
27 | GNUNET_TESTBED_cmd_system_create (const char *label, | ||
28 | const char *testdir); | ||
29 | |||
30 | |||
31 | /** | ||
32 | * Call #op on all simple traits. | ||
33 | */ | ||
34 | #define GNUNET_TESTING_TESTBED_SIMPLE_TRAITS(op, prefix) \ | ||
35 | op (prefix, test_system, struct GNUNET_TESTBED_System) | ||
36 | |||
37 | |||
38 | GNUNET_TESTING_TESTBED_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT, | ||
39 | GNUNET_TESTING_TESTBED) | ||
40 | |||
41 | |||
42 | #endif | ||
diff --git a/src/include/gnunet_transport_testing_ng_lib.h b/src/include/gnunet_testing_transport_lib.h index be904cf4c..db2749661 100644 --- a/src/include/gnunet_transport_testing_ng_lib.h +++ b/src/include/gnunet_testing_transport_lib.h | |||
@@ -27,18 +27,13 @@ | |||
27 | 27 | ||
28 | 28 | ||
29 | #include "gnunet_util_lib.h" | 29 | #include "gnunet_util_lib.h" |
30 | #include "gnunet_testing_ng_lib.h" | 30 | #include "gnunet_testing_lib.h" |
31 | 31 | ||
32 | /** | 32 | /** |
33 | * Application handle; FIXME: what exactly is this? | 33 | * Application handle; FIXME: what exactly is this? |
34 | */ | 34 | */ |
35 | struct GNUNET_TRANSPORT_ApplicationHandle; | 35 | struct GNUNET_TRANSPORT_ApplicationHandle; |
36 | 36 | ||
37 | /** | ||
38 | * FIXME: what is this? | ||
39 | */ | ||
40 | struct GNUNET_TESTING_StartPeerState; | ||
41 | |||
42 | 37 | ||
43 | // FIXME: breaks naming conventions | 38 | // FIXME: breaks naming conventions |
44 | typedef void * | 39 | typedef void * |
@@ -46,7 +41,6 @@ typedef void * | |||
46 | const struct GNUNET_PeerIdentity *peer); | 41 | const struct GNUNET_PeerIdentity *peer); |
47 | 42 | ||
48 | 43 | ||
49 | |||
50 | // FIXME: breaks naming conventions! Needed public? | 44 | // FIXME: breaks naming conventions! Needed public? |
51 | struct GNUNET_TESTING_StartPeerState | 45 | struct GNUNET_TESTING_StartPeerState |
52 | { | 46 | { |
@@ -153,7 +147,6 @@ struct GNUNET_TESTING_StartPeerState | |||
153 | }; | 147 | }; |
154 | 148 | ||
155 | 149 | ||
156 | |||
157 | /** | 150 | /** |
158 | * Create command. | 151 | * Create command. |
159 | * | 152 | * |
@@ -191,21 +184,22 @@ GNUNET_TESTING_get_peer (unsigned int num, | |||
191 | const struct GNUNET_TESTING_System *tl_system); | 184 | const struct GNUNET_TESTING_System *tl_system); |
192 | 185 | ||
193 | 186 | ||
194 | |||
195 | |||
196 | /** | 187 | /** |
197 | * Call #op on all simple traits. | 188 | * Call #op on all simple traits. |
198 | */ | 189 | */ |
199 | #define GNUNET_TRANSPORT_TESTING_SIMPLE_TRAITS(op, prefix) \ | 190 | #define GNUNET_TRANSPORT_TESTING_SIMPLE_TRAITS(op, prefix) \ |
200 | op (prefix, connected_peers_map, const struct GNUNET_CONTAINER_MultiShortmap) \ | 191 | op (prefix, connected_peers_map, const struct \ |
201 | op (prefix, peer_id, const struct GNUNET_PeerIdentity) \ | 192 | GNUNET_CONTAINER_MultiShortmap) \ |
202 | op (prefix, hello_size, const size_t) \ | 193 | op (prefix, peer_id, const struct GNUNET_PeerIdentity) \ |
203 | op (prefix, hello, const char) \ | 194 | op (prefix, hello_size, const size_t) \ |
204 | op (prefix, application_handle, const struct GNUNET_TRANSPORT_ApplicationHandle) \ | 195 | op (prefix, hello, const char) \ |
205 | op (prefix, state, const struct GNUNET_TESTING_StartPeerState) \ | 196 | op (prefix, application_handle, const struct \ |
206 | op (prefix, broadcast, const enum GNUNET_GenericReturnValue) | 197 | GNUNET_TRANSPORT_ApplicationHandle) \ |
207 | 198 | op (prefix, state, const struct GNUNET_TESTING_StartPeerState) \ | |
208 | 199 | op (prefix, broadcast, const enum GNUNET_GenericReturnValue) | |
209 | GNUNET_TRANSPORT_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT, GNUNET_TRANSPORT_TESTING) | 200 | |
201 | |||
202 | GNUNET_TRANSPORT_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT, | ||
203 | GNUNET_TRANSPORT_TESTING) | ||
210 | 204 | ||
211 | #endif | 205 | #endif |
diff --git a/src/include/gnunet_transport_application_service.h b/src/include/gnunet_transport_application_service.h index 66512089a..c093ad96a 100644 --- a/src/include/gnunet_transport_application_service.h +++ b/src/include/gnunet_transport_application_service.h | |||
@@ -36,8 +36,6 @@ | |||
36 | 36 | ||
37 | #include "gnunet_constants.h" | 37 | #include "gnunet_constants.h" |
38 | #include "gnunet_util_lib.h" | 38 | #include "gnunet_util_lib.h" |
39 | #include "gnunet_testing_lib.h" | ||
40 | #include "gnunet_testing_ng_lib.h" | ||
41 | 39 | ||
42 | /** | 40 | /** |
43 | * Handle to the TRANSPORT subsystem for making suggestions about | 41 | * Handle to the TRANSPORT subsystem for making suggestions about |
diff --git a/src/include/gnunet_transport_communication_service.h b/src/include/gnunet_transport_communication_service.h index 92facb0e0..ea947911f 100644 --- a/src/include/gnunet_transport_communication_service.h +++ b/src/include/gnunet_transport_communication_service.h | |||
@@ -74,7 +74,7 @@ extern "C" { | |||
74 | * @param address where to send the message, human-readable | 74 | * @param address where to send the message, human-readable |
75 | * communicator-specific format, 0-terminated, UTF-8 | 75 | * communicator-specific format, 0-terminated, UTF-8 |
76 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the provided address is | 76 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the provided address is |
77 | * invalid | 77 | * invalid, #GNUNET_NO if this address is already (beging) connected to. |
78 | */ | 78 | */ |
79 | typedef int (*GNUNET_TRANSPORT_CommunicatorMqInit) ( | 79 | typedef int (*GNUNET_TRANSPORT_CommunicatorMqInit) ( |
80 | void *cls, | 80 | void *cls, |
diff --git a/src/include/meson.build b/src/include/meson.build index 3127a6a40..51a8009af 100644 --- a/src/include/meson.build +++ b/src/include/meson.build | |||
@@ -104,11 +104,11 @@ install_headers( | |||
104 | 'gnunet_sq_lib.h', | 104 | 'gnunet_sq_lib.h', |
105 | 'gnunet_statistics_service.h', | 105 | 'gnunet_statistics_service.h', |
106 | 'gnunet_strings_lib.h', | 106 | 'gnunet_strings_lib.h', |
107 | 'gnunet_testing_barrier.h', | ||
108 | 'gnunet_testing_lib.h', | 107 | 'gnunet_testing_lib.h', |
109 | 'gnunet_testing_plugin.h', | 108 | 'gnunet_testing_arm_lib.h', |
110 | 'gnunet_testing_ng_lib.h', | 109 | 'gnunet_testing_core_lib.h', |
111 | 'gnunet_testing_netjail_lib.h', | 110 | 'gnunet_testing_testbed_lib.h', |
111 | 'gnunet_testing_transport_lib.h', | ||
112 | 'gnunet_time_lib.h', | 112 | 'gnunet_time_lib.h', |
113 | 'gnunet_transport_application_service.h', | 113 | 'gnunet_transport_application_service.h', |
114 | 'gnunet_transport_communication_service.h', | 114 | 'gnunet_transport_communication_service.h', |