diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-05-22 12:42:58 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-05-22 12:42:58 +0000 |
commit | 7b636c9e74039f14b25e70d1050432d9782efef9 (patch) | |
tree | 123c283ba01ca97ff885628c5bf62e8109e30cc3 /src/regex | |
parent | 157f7872646546aa956e36b3c3629eed00013f45 (diff) | |
download | gnunet-7b636c9e74039f14b25e70d1050432d9782efef9.tar.gz gnunet-7b636c9e74039f14b25e70d1050432d9782efef9.zip |
-improving testcase
Diffstat (limited to 'src/regex')
-rw-r--r-- | src/regex/regex_internal_dht.c | 66 | ||||
-rw-r--r-- | src/regex/test_regex_integration.c | 36 |
2 files changed, 63 insertions, 39 deletions
diff --git a/src/regex/regex_internal_dht.c b/src/regex/regex_internal_dht.c index 7b93fddca..7fa15ba45 100644 --- a/src/regex/regex_internal_dht.c +++ b/src/regex/regex_internal_dht.c | |||
@@ -122,7 +122,7 @@ regex_iterator (void *cls, | |||
122 | ab.expiration_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_DHT_MAX_EXPIRATION)); | 122 | ab.expiration_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_DHT_MAX_EXPIRATION)); |
123 | ab.key = *key; | 123 | ab.key = *key; |
124 | GNUNET_CRYPTO_eddsa_key_get_public (h->priv, | 124 | GNUNET_CRYPTO_eddsa_key_get_public (h->priv, |
125 | &ab.peer.public_key); | 125 | &ab.peer.public_key); |
126 | GNUNET_assert (GNUNET_OK == | 126 | GNUNET_assert (GNUNET_OK == |
127 | GNUNET_CRYPTO_eddsa_sign (h->priv, | 127 | GNUNET_CRYPTO_eddsa_sign (h->priv, |
128 | &ab.purpose, | 128 | &ab.purpose, |
@@ -263,7 +263,7 @@ struct RegexSearchContext | |||
263 | 263 | ||
264 | 264 | ||
265 | /** | 265 | /** |
266 | * Type of values in 'dht_get_results'. | 266 | * Type of values in #dht_get_results(). |
267 | */ | 267 | */ |
268 | struct Result | 268 | struct Result |
269 | { | 269 | { |
@@ -393,7 +393,7 @@ dht_get_string_accept_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
393 | 393 | ||
394 | 394 | ||
395 | /** | 395 | /** |
396 | * Find a path to a peer that offers a regex servcie compatible | 396 | * Find a path to a peer that offers a regex service compatible |
397 | * with a given string. | 397 | * with a given string. |
398 | * | 398 | * |
399 | * @param key The key of the accepting state. | 399 | * @param key The key of the accepting state. |
@@ -406,8 +406,9 @@ regex_find_path (const struct GNUNET_HashCode *key, | |||
406 | struct GNUNET_DHT_GetHandle *get_h; | 406 | struct GNUNET_DHT_GetHandle *get_h; |
407 | 407 | ||
408 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 408 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
409 | "regex finds path for %s\n", | 409 | "Accept state found, now searching for paths to %s\n", |
410 | GNUNET_h2s (key)); | 410 | GNUNET_h2s (key), |
411 | (unsigned int) ctx->position); | ||
411 | get_h = GNUNET_DHT_get_start (ctx->info->dht, /* handle */ | 412 | get_h = GNUNET_DHT_get_start (ctx->info->dht, /* handle */ |
412 | GNUNET_BLOCK_TYPE_REGEX_ACCEPT, /* type */ | 413 | GNUNET_BLOCK_TYPE_REGEX_ACCEPT, /* type */ |
413 | key, /* key to search */ | 414 | key, /* key to search */ |
@@ -432,9 +433,9 @@ regex_find_path (const struct GNUNET_HashCode *key, | |||
432 | * @param exp when will this value expire | 433 | * @param exp when will this value expire |
433 | * @param key key of the result | 434 | * @param key key of the result |
434 | * @param get_path path of the get request (not used) | 435 | * @param get_path path of the get request (not used) |
435 | * @param get_path_length lenght of get_path (not used) | 436 | * @param get_path_length length of @a get_path (not used) |
436 | * @param put_path path of the put request (not used) | 437 | * @param put_path path of the put request (not used) |
437 | * @param put_path_length length of the put_path (not used) | 438 | * @param put_path_length length of the @a put_path (not used) |
438 | * @param type type of the result | 439 | * @param type type of the result |
439 | * @param size number of bytes in data | 440 | * @param size number of bytes in data |
440 | * @param data pointer to the result data | 441 | * @param data pointer to the result data |
@@ -492,7 +493,7 @@ dht_get_string_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
492 | * @param cls Closure (current context)- | 493 | * @param cls Closure (current context)- |
493 | * @param key Current key code (key for cached block). | 494 | * @param key Current key code (key for cached block). |
494 | * @param value Value in the hash map (cached RegexBlock). | 495 | * @param value Value in the hash map (cached RegexBlock). |
495 | * @return GNUNET_YES: we should always continue to iterate. | 496 | * @return #GNUNET_YES: we should always continue to iterate. |
496 | */ | 497 | */ |
497 | static int | 498 | static int |
498 | regex_result_iterator (void *cls, | 499 | regex_result_iterator (void *cls, |
@@ -533,8 +534,7 @@ regex_result_iterator (void *cls, | |||
533 | * @param token Token that follows to next state. | 534 | * @param token Token that follows to next state. |
534 | * @param len Lenght of token. | 535 | * @param len Lenght of token. |
535 | * @param key Hash of next state. | 536 | * @param key Hash of next state. |
536 | * | 537 | * @return #GNUNET_YES if should keep iterating, #GNUNET_NO otherwise. |
537 | * @return GNUNET_YES if should keep iterating, GNUNET_NO otherwise. | ||
538 | */ | 538 | */ |
539 | static int | 539 | static int |
540 | regex_edge_iterator (void *cls, | 540 | regex_edge_iterator (void *cls, |
@@ -636,9 +636,11 @@ regex_next_edge (const struct RegexBlock *block, | |||
636 | GNUNET_STATISTICS_update (info->stats, "# regex nodes traversed", | 636 | GNUNET_STATISTICS_update (info->stats, "# regex nodes traversed", |
637 | 1, GNUNET_NO); | 637 | 1, GNUNET_NO); |
638 | 638 | ||
639 | LOG (GNUNET_ERROR_TYPE_INFO, | 639 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
640 | "looking for %s\n", | 640 | "Following edges at %s for offset %u in `%s'\n", |
641 | GNUNET_h2s (hash)); | 641 | GNUNET_h2s (hash), |
642 | (unsigned int) ctx->position, | ||
643 | info->description); | ||
642 | rest = &new_ctx->info->description[new_ctx->position]; | 644 | rest = &new_ctx->info->description[new_ctx->position]; |
643 | get_h = | 645 | get_h = |
644 | GNUNET_DHT_get_start (info->dht, /* handle */ | 646 | GNUNET_DHT_get_start (info->dht, /* handle */ |
@@ -663,7 +665,7 @@ regex_next_edge (const struct RegexBlock *block, | |||
663 | 665 | ||
664 | /** | 666 | /** |
665 | * Search for a peer offering a regex matching certain string in the DHT. | 667 | * Search for a peer offering a regex matching certain string in the DHT. |
666 | * The search runs until REGEX_INTERNAL_search_cancel is called, even if results | 668 | * The search runs until #REGEX_INTERNAL_search_cancel() is called, even if results |
667 | * are returned. | 669 | * are returned. |
668 | * | 670 | * |
669 | * @param dht An existing and valid DHT service handle. | 671 | * @param dht An existing and valid DHT service handle. |
@@ -671,16 +673,15 @@ regex_next_edge (const struct RegexBlock *block, | |||
671 | * @param callback Callback for found peers. | 673 | * @param callback Callback for found peers. |
672 | * @param callback_cls Closure for @c callback. | 674 | * @param callback_cls Closure for @c callback. |
673 | * @param stats Optional statistics handle to report usage. Can be NULL. | 675 | * @param stats Optional statistics handle to report usage. Can be NULL. |
674 | * | ||
675 | * @return Handle to stop search and free resources. | 676 | * @return Handle to stop search and free resources. |
676 | * Must be freed by calling REGEX_INTERNAL_search_cancel. | 677 | * Must be freed by calling #REGEX_INTERNAL_search_cancel(). |
677 | */ | 678 | */ |
678 | struct REGEX_INTERNAL_Search * | 679 | struct REGEX_INTERNAL_Search * |
679 | REGEX_INTERNAL_search (struct GNUNET_DHT_Handle *dht, | 680 | REGEX_INTERNAL_search (struct GNUNET_DHT_Handle *dht, |
680 | const char *string, | 681 | const char *string, |
681 | REGEX_INTERNAL_Found callback, | 682 | REGEX_INTERNAL_Found callback, |
682 | void *callback_cls, | 683 | void *callback_cls, |
683 | struct GNUNET_STATISTICS_Handle *stats) | 684 | struct GNUNET_STATISTICS_Handle *stats) |
684 | { | 685 | { |
685 | struct REGEX_INTERNAL_Search *h; | 686 | struct REGEX_INTERNAL_Search *h; |
686 | struct GNUNET_DHT_GetHandle *get_h; | 687 | struct GNUNET_DHT_GetHandle *get_h; |
@@ -690,7 +691,6 @@ REGEX_INTERNAL_search (struct GNUNET_DHT_Handle *dht, | |||
690 | size_t len; | 691 | size_t len; |
691 | 692 | ||
692 | /* Initialize handle */ | 693 | /* Initialize handle */ |
693 | LOG (GNUNET_ERROR_TYPE_INFO, "REGEX_INTERNAL_search: %s\n", string); | ||
694 | GNUNET_assert (NULL != dht); | 694 | GNUNET_assert (NULL != dht); |
695 | GNUNET_assert (NULL != callback); | 695 | GNUNET_assert (NULL != callback); |
696 | h = GNUNET_new (struct REGEX_INTERNAL_Search); | 696 | h = GNUNET_new (struct REGEX_INTERNAL_Search); |
@@ -706,17 +706,17 @@ REGEX_INTERNAL_search (struct GNUNET_DHT_Handle *dht, | |||
706 | len = strlen (string); | 706 | len = strlen (string); |
707 | size = REGEX_INTERNAL_get_first_key (string, len, &key); | 707 | size = REGEX_INTERNAL_get_first_key (string, len, &key); |
708 | LOG (GNUNET_ERROR_TYPE_INFO, | 708 | LOG (GNUNET_ERROR_TYPE_INFO, |
709 | " initial key for %s: %s (%.*s)\n", | 709 | "Initial key for `%s' is %s (based on `%.*s')\n", |
710 | string, GNUNET_h2s (&key), size, string); | 710 | string, |
711 | GNUNET_h2s (&key), | ||
712 | size, | ||
713 | string); | ||
711 | ctx = GNUNET_new (struct RegexSearchContext); | 714 | ctx = GNUNET_new (struct RegexSearchContext); |
712 | ctx->position = size; | 715 | ctx->position = size; |
713 | ctx->info = h; | 716 | ctx->info = h; |
714 | GNUNET_array_append (h->contexts, h->n_contexts, ctx); | 717 | GNUNET_array_append (h->contexts, |
715 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 718 | h->n_contexts, |
716 | "consumed %u bits out of %u, now looking for %s\n", | 719 | ctx); |
717 | size, len, | ||
718 | GNUNET_h2s (&key)); | ||
719 | |||
720 | /* Start search in DHT */ | 720 | /* Start search in DHT */ |
721 | get_h = GNUNET_DHT_get_start (h->dht, /* handle */ | 721 | get_h = GNUNET_DHT_get_start (h->dht, /* handle */ |
722 | GNUNET_BLOCK_TYPE_REGEX, /* type */ | 722 | GNUNET_BLOCK_TYPE_REGEX, /* type */ |
@@ -747,8 +747,8 @@ REGEX_INTERNAL_search (struct GNUNET_DHT_Handle *dht, | |||
747 | * @param cls Closure (unused). | 747 | * @param cls Closure (unused). |
748 | * @param key Current key code (unused). | 748 | * @param key Current key code (unused). |
749 | * @param value Value in the hash map (get handle). | 749 | * @param value Value in the hash map (get handle). |
750 | * @return GNUNET_YES if we should continue to iterate, | 750 | * @return #GNUNET_YES if we should continue to iterate, |
751 | * GNUNET_NO if not. | 751 | * #GNUNET_NO if not. |
752 | */ | 752 | */ |
753 | static int | 753 | static int |
754 | regex_cancel_dht_get (void *cls, | 754 | regex_cancel_dht_get (void *cls, |
@@ -769,8 +769,8 @@ regex_cancel_dht_get (void *cls, | |||
769 | * @param cls Closure (unused). | 769 | * @param cls Closure (unused). |
770 | * @param key Current key code (unused). | 770 | * @param key Current key code (unused). |
771 | * @param value CadetRegexBlock in the hash map. | 771 | * @param value CadetRegexBlock in the hash map. |
772 | * @return GNUNET_YES if we should continue to iterate, | 772 | * @return #GNUNET_YES if we should continue to iterate, |
773 | * GNUNET_NO if not. | 773 | * #GNUNET_NO if not. |
774 | */ | 774 | */ |
775 | static int | 775 | static int |
776 | regex_free_result (void *cls, | 776 | regex_free_result (void *cls, |
diff --git a/src/regex/test_regex_integration.c b/src/regex/test_regex_integration.c index 734b1c604..b28ab15d0 100644 --- a/src/regex/test_regex_integration.c +++ b/src/regex/test_regex_integration.c | |||
@@ -25,6 +25,7 @@ | |||
25 | * @author Christian Grothoff | 25 | * @author Christian Grothoff |
26 | */ | 26 | */ |
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_applications.h" | ||
28 | #include "gnunet_util_lib.h" | 29 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_tun_lib.h" | 30 | #include "gnunet_tun_lib.h" |
30 | #include "gnunet_testing_lib.h" | 31 | #include "gnunet_testing_lib.h" |
@@ -75,7 +76,6 @@ end (void *cls, | |||
75 | static void | 76 | static void |
76 | end_badly () | 77 | end_badly () |
77 | { | 78 | { |
78 | die_task = NULL; | ||
79 | FPRINTF (stderr, "%s", "Testcase failed (timeout).\n"); | 79 | FPRINTF (stderr, "%s", "Testcase failed (timeout).\n"); |
80 | end (NULL, NULL); | 80 | end (NULL, NULL); |
81 | ok = 1; | 81 | ok = 1; |
@@ -125,9 +125,13 @@ run (void *cls, | |||
125 | struct GNUNET_TESTING_Peer *peer) | 125 | struct GNUNET_TESTING_Peer *peer) |
126 | { | 126 | { |
127 | char rxstr4[GNUNET_TUN_IPV4_REGEXLEN]; | 127 | char rxstr4[GNUNET_TUN_IPV4_REGEXLEN]; |
128 | char rxstr6[GNUNET_TUN_IPV4_REGEXLEN]; | 128 | char rxstr6[GNUNET_TUN_IPV6_REGEXLEN]; |
129 | char *p4r; | ||
130 | char *p6r; | ||
129 | char *p4; | 131 | char *p4; |
130 | char *p6; | 132 | char *p6; |
133 | char *ss4; | ||
134 | char *ss6; | ||
131 | struct in_addr i4; | 135 | struct in_addr i4; |
132 | struct in6_addr i6; | 136 | struct in6_addr i6; |
133 | 137 | ||
@@ -148,8 +152,26 @@ run (void *cls, | |||
148 | GNUNET_TUN_ipv6toregexsearch (&i6, | 152 | GNUNET_TUN_ipv6toregexsearch (&i6, |
149 | 8686, | 153 | 8686, |
150 | rxstr6); | 154 | rxstr6); |
151 | p4 = GNUNET_TUN_ipv4policy2regex ("0.0.0.0/0:!25;"); | 155 | GNUNET_asprintf (&ss4, |
152 | p6 = GNUNET_TUN_ipv6policy2regex ("::/0:!25;"); | 156 | "%s%s", |
157 | GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, | ||
158 | rxstr4); | ||
159 | GNUNET_asprintf (&ss6, | ||
160 | "%s%s", | ||
161 | GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, | ||
162 | rxstr6); | ||
163 | p4r = GNUNET_TUN_ipv4policy2regex ("0.0.0.0/0:!25;"); | ||
164 | p6r = GNUNET_TUN_ipv6policy2regex ("::/0:!25;"); | ||
165 | GNUNET_asprintf (&p4, | ||
166 | "%s%s", | ||
167 | GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, | ||
168 | p4r); | ||
169 | GNUNET_asprintf (&p6, | ||
170 | "%s%s", | ||
171 | GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, | ||
172 | p6r); | ||
173 | GNUNET_free (p4r); | ||
174 | GNUNET_free (p6r); | ||
153 | a4 = GNUNET_REGEX_announce (cfg, | 175 | a4 = GNUNET_REGEX_announce (cfg, |
154 | p4, | 176 | p4, |
155 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 177 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, |
@@ -164,11 +186,13 @@ run (void *cls, | |||
164 | GNUNET_free (p6); | 186 | GNUNET_free (p6); |
165 | 187 | ||
166 | s4 = GNUNET_REGEX_search (cfg, | 188 | s4 = GNUNET_REGEX_search (cfg, |
167 | rxstr4, | 189 | ss4, |
168 | &found_cb, "4"); | 190 | &found_cb, "4"); |
169 | s6 = GNUNET_REGEX_search (cfg, | 191 | s6 = GNUNET_REGEX_search (cfg, |
170 | rxstr6, | 192 | ss6, |
171 | &found_cb, "6"); | 193 | &found_cb, "6"); |
194 | GNUNET_free (ss4); | ||
195 | GNUNET_free (ss6); | ||
172 | } | 196 | } |
173 | 197 | ||
174 | 198 | ||