diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-03-01 02:44:50 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-03-01 02:44:50 +0000 |
commit | af6cb02f6caf6b46f7d35077c6a0947cf9358c7b (patch) | |
tree | bdf8bc44f953f2d78654d3ccb24a452e6c74ab44 /src/regex | |
parent | db1af422f21e61030a12e043d22bf8bc6391d269 (diff) | |
download | gnunet-af6cb02f6caf6b46f7d35077c6a0947cf9358c7b.tar.gz gnunet-af6cb02f6caf6b46f7d35077c6a0947cf9358c7b.zip |
- add INFO level meaningful logging, documentation, style
Diffstat (limited to 'src/regex')
-rw-r--r-- | src/regex/regex_dht.c | 83 |
1 files changed, 42 insertions, 41 deletions
diff --git a/src/regex/regex_dht.c b/src/regex/regex_dht.c index 52e8d4841..41991d75e 100644 --- a/src/regex/regex_dht.c +++ b/src/regex/regex_dht.c | |||
@@ -31,8 +31,10 @@ | |||
31 | 31 | ||
32 | #define LOG(kind,...) GNUNET_log_from (kind,"regex-dht",__VA_ARGS__) | 32 | #define LOG(kind,...) GNUNET_log_from (kind,"regex-dht",__VA_ARGS__) |
33 | 33 | ||
34 | /* FIXME: OPTION (API, CONFIG) */ | ||
34 | #define DHT_REPLICATION 5 | 35 | #define DHT_REPLICATION 5 |
35 | #define DHT_TTL GNUNET_TIME_UNIT_HOURS | 36 | #define DHT_TTL GNUNET_TIME_UNIT_HOURS |
37 | #define DHT_OPT GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE /* | GNUNET_DHT_RO_RECORD_ROUTE*/ | ||
36 | 38 | ||
37 | struct GNUNET_REGEX_announce_handle | 39 | struct GNUNET_REGEX_announce_handle |
38 | { | 40 | { |
@@ -84,7 +86,6 @@ regex_iterator (void *cls, | |||
84 | struct GNUNET_REGEX_announce_handle *h = cls; | 86 | struct GNUNET_REGEX_announce_handle *h = cls; |
85 | struct RegexBlock *block; | 87 | struct RegexBlock *block; |
86 | struct RegexEdge *block_edge; | 88 | struct RegexEdge *block_edge; |
87 | enum GNUNET_DHT_RouteOption opt; | ||
88 | size_t size; | 89 | size_t size; |
89 | size_t len; | 90 | size_t len; |
90 | unsigned int i; | 91 | unsigned int i; |
@@ -97,7 +98,6 @@ regex_iterator (void *cls, | |||
97 | LOG (GNUNET_ERROR_TYPE_DEBUG, " proof: %s\n", proof); | 98 | LOG (GNUNET_ERROR_TYPE_DEBUG, " proof: %s\n", proof); |
98 | LOG (GNUNET_ERROR_TYPE_DEBUG, " num edges: %u\n", num_edges); | 99 | LOG (GNUNET_ERROR_TYPE_DEBUG, " num edges: %u\n", num_edges); |
99 | 100 | ||
100 | opt = GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE; | ||
101 | if (GNUNET_YES == accepting) | 101 | if (GNUNET_YES == accepting) |
102 | { | 102 | { |
103 | struct RegexAccept block; | 103 | struct RegexAccept block; |
@@ -114,13 +114,13 @@ regex_iterator (void *cls, | |||
114 | sizeof (block), GNUNET_NO); | 114 | sizeof (block), GNUNET_NO); |
115 | (void) | 115 | (void) |
116 | GNUNET_DHT_put (h->dht, key, | 116 | GNUNET_DHT_put (h->dht, key, |
117 | 2, /* FIXME option */ | 117 | DHT_REPLICATION, |
118 | opt /* | GNUNET_DHT_RO_RECORD_ROUTE*/, | 118 | DHT_OPT, |
119 | GNUNET_BLOCK_TYPE_REGEX_ACCEPT, | 119 | GNUNET_BLOCK_TYPE_REGEX_ACCEPT, |
120 | size, | 120 | size, |
121 | (char *) &block, | 121 | (char *) &block, |
122 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS), /* FIXME: expiration time should be option */ | 122 | GNUNET_TIME_relative_to_absolute (DHT_TTL), |
123 | GNUNET_TIME_UNIT_HOURS, /* FIXME option */ | 123 | DHT_TTL, |
124 | NULL, NULL); | 124 | NULL, NULL); |
125 | } | 125 | } |
126 | len = strlen(proof); | 126 | len = strlen(proof); |
@@ -161,11 +161,11 @@ regex_iterator (void *cls, | |||
161 | } | 161 | } |
162 | (void) | 162 | (void) |
163 | GNUNET_DHT_put(h->dht, key, | 163 | GNUNET_DHT_put(h->dht, key, |
164 | DHT_REPLICATION, /* FIXME OPTION */ | 164 | DHT_REPLICATION, |
165 | opt, | 165 | DHT_OPT, |
166 | GNUNET_BLOCK_TYPE_REGEX, size, | 166 | GNUNET_BLOCK_TYPE_REGEX, size, |
167 | (char *) block, | 167 | (char *) block, |
168 | GNUNET_TIME_relative_to_absolute (DHT_TTL), /* FIXME: this should be an option */ | 168 | GNUNET_TIME_relative_to_absolute (DHT_TTL), |
169 | DHT_TTL, | 169 | DHT_TTL, |
170 | NULL, NULL); | 170 | NULL, NULL); |
171 | GNUNET_STATISTICS_update (h->stats, "# regex blocks stored", | 171 | GNUNET_STATISTICS_update (h->stats, "# regex blocks stored", |
@@ -202,6 +202,7 @@ GNUNET_REGEX_announce (struct GNUNET_DHT_Handle *dht, | |||
202 | void | 202 | void |
203 | GNUNET_REGEX_reannounce (struct GNUNET_REGEX_announce_handle *h) | 203 | GNUNET_REGEX_reannounce (struct GNUNET_REGEX_announce_handle *h) |
204 | { | 204 | { |
205 | LOG (GNUNET_ERROR_TYPE_INFO, "GNUNET_REGEX_reannounce: %s\n", h->regex); | ||
205 | GNUNET_REGEX_iterate_all_edges (h->dfa, ®ex_iterator, h); | 206 | GNUNET_REGEX_iterate_all_edges (h->dfa, ®ex_iterator, h); |
206 | } | 207 | } |
207 | 208 | ||
@@ -345,7 +346,8 @@ dht_get_string_accept_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
345 | struct GNUNET_REGEX_search_handle *info = ctx->info; | 346 | struct GNUNET_REGEX_search_handle *info = ctx->info; |
346 | 347 | ||
347 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Got regex results from DHT!\n"); | 348 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Got regex results from DHT!\n"); |
348 | LOG (GNUNET_ERROR_TYPE_DEBUG, " for %s\n", info->description); | 349 | LOG (GNUNET_ERROR_TYPE_INFO, " accept for %s (key %s)\n", |
350 | info->description, GNUNET_h2s(key)); | ||
349 | 351 | ||
350 | GNUNET_STATISTICS_update (info->stats, "# regex accepting blocks found", | 352 | GNUNET_STATISTICS_update (info->stats, "# regex accepting blocks found", |
351 | 1, GNUNET_NO); | 353 | 1, GNUNET_NO); |
@@ -374,12 +376,12 @@ regex_find_path (const struct GNUNET_HashCode *key, | |||
374 | struct GNUNET_DHT_GetHandle *get_h; | 376 | struct GNUNET_DHT_GetHandle *get_h; |
375 | 377 | ||
376 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Found peer by service\n"); | 378 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Found peer by service\n"); |
379 | LOG (GNUNET_ERROR_TYPE_INFO, " find accept for %s\n", GNUNET_h2s (key)); | ||
377 | get_h = GNUNET_DHT_get_start (ctx->info->dht, /* handle */ | 380 | get_h = GNUNET_DHT_get_start (ctx->info->dht, /* handle */ |
378 | GNUNET_BLOCK_TYPE_REGEX_ACCEPT, /* type */ | 381 | GNUNET_BLOCK_TYPE_REGEX_ACCEPT, /* type */ |
379 | key, /* key to search */ | 382 | key, /* key to search */ |
380 | DHT_REPLICATION, /* replication level */ | 383 | DHT_REPLICATION, /* replication level */ |
381 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE | | 384 | DHT_OPT | GNUNET_DHT_RO_RECORD_ROUTE, |
382 | GNUNET_DHT_RO_RECORD_ROUTE, | ||
383 | NULL, /* xquery */ // FIXME BLOOMFILTER | 385 | NULL, /* xquery */ // FIXME BLOOMFILTER |
384 | 0, /* xquery bits */ // FIXME BLOOMFILTER SIZE | 386 | 0, /* xquery bits */ // FIXME BLOOMFILTER SIZE |
385 | &dht_get_string_accept_handler, ctx); | 387 | &dht_get_string_accept_handler, ctx); |
@@ -425,8 +427,8 @@ dht_get_string_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
425 | size_t len; | 427 | size_t len; |
426 | 428 | ||
427 | LOG (GNUNET_ERROR_TYPE_DEBUG, "DHT GET STRING RETURNED RESULTS\n"); | 429 | LOG (GNUNET_ERROR_TYPE_DEBUG, "DHT GET STRING RETURNED RESULTS\n"); |
428 | LOG (GNUNET_ERROR_TYPE_DEBUG, " for: %s\n", ctx->info->description); | 430 | LOG (GNUNET_ERROR_TYPE_INFO, " for: %s\n", ctx->info->description); |
429 | LOG (GNUNET_ERROR_TYPE_DEBUG, " key: %s\n", GNUNET_h2s (key)); | 431 | LOG (GNUNET_ERROR_TYPE_INFO, " key: %s\n", GNUNET_h2s (key)); |
430 | 432 | ||
431 | copy = GNUNET_malloc (size); | 433 | copy = GNUNET_malloc (size); |
432 | memcpy (copy, data, size); | 434 | memcpy (copy, data, size); |
@@ -456,7 +458,7 @@ dht_get_string_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
456 | } | 458 | } |
457 | else | 459 | else |
458 | { | 460 | { |
459 | LOG (GNUNET_ERROR_TYPE_DEBUG, " block not accepting!\n"); | 461 | LOG (GNUNET_ERROR_TYPE_INFO, " block not accepting!\n"); |
460 | // FIXME REGEX this block not successful, wait for more? start timeout? | 462 | // FIXME REGEX this block not successful, wait for more? start timeout? |
461 | } | 463 | } |
462 | return; | 464 | return; |
@@ -471,11 +473,10 @@ dht_get_string_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
471 | /** | 473 | /** |
472 | * Iterator over found existing mesh regex blocks that match an ongoing search. | 474 | * Iterator over found existing mesh regex blocks that match an ongoing search. |
473 | * | 475 | * |
474 | * @param cls closure | 476 | * @param cls Closure (current context)- |
475 | * @param key current key code | 477 | * @param key Current key code (key for cached block). |
476 | * @param value value in the hash map | 478 | * @param value Value in the hash map (cached RegexBlock). |
477 | * @return GNUNET_YES if we should continue to iterate, | 479 | * @return GNUNET_YES: we should always continue to iterate. |
478 | * GNUNET_NO if not. | ||
479 | */ | 480 | */ |
480 | static int | 481 | static int |
481 | regex_result_iterator (void *cls, | 482 | regex_result_iterator (void *cls, |
@@ -488,18 +489,15 @@ regex_result_iterator (void *cls, | |||
488 | if (GNUNET_YES == ntohl(block->accepting) && | 489 | if (GNUNET_YES == ntohl(block->accepting) && |
489 | ctx->position == strlen (ctx->info->description)) | 490 | ctx->position == strlen (ctx->info->description)) |
490 | { | 491 | { |
491 | LOG (GNUNET_ERROR_TYPE_DEBUG, "* Found accepting known block\n"); | 492 | LOG (GNUNET_ERROR_TYPE_INFO, " * Found accepting known block\n"); |
492 | regex_find_path (key, ctx); | 493 | regex_find_path (key, ctx); |
493 | return GNUNET_YES; // We found an accept state! | 494 | return GNUNET_YES; // We found an accept state! |
494 | } | 495 | } |
495 | else | 496 | LOG (GNUNET_ERROR_TYPE_DEBUG, "* %u, %u, [%u]\n", |
496 | { | 497 | ctx->position, strlen(ctx->info->description), |
497 | LOG (GNUNET_ERROR_TYPE_DEBUG, "* %u, %u, [%u]\n", | 498 | ntohl(block->accepting)); |
498 | ctx->position, strlen(ctx->info->description), | ||
499 | ntohl(block->accepting)); | ||
500 | 499 | ||
501 | } | 500 | regex_next_edge (block, SIZE_MAX, ctx); |
502 | regex_next_edge(block, SIZE_MAX, ctx); | ||
503 | 501 | ||
504 | GNUNET_STATISTICS_update (ctx->info->stats, "# regex mesh blocks iterated", | 502 | GNUNET_STATISTICS_update (ctx->info->stats, "# regex mesh blocks iterated", |
505 | 1, GNUNET_NO); | 503 | 1, GNUNET_NO); |
@@ -586,6 +584,7 @@ regex_next_edge (const struct RegexBlock *block, | |||
586 | struct RegexSearchContext *new_ctx; | 584 | struct RegexSearchContext *new_ctx; |
587 | struct GNUNET_REGEX_search_handle *info = ctx->info; | 585 | struct GNUNET_REGEX_search_handle *info = ctx->info; |
588 | struct GNUNET_DHT_GetHandle *get_h; | 586 | struct GNUNET_DHT_GetHandle *get_h; |
587 | struct GNUNET_HashCode *hash; | ||
589 | const char *rest; | 588 | const char *rest; |
590 | int result; | 589 | int result; |
591 | 590 | ||
@@ -598,8 +597,12 @@ regex_next_edge (const struct RegexBlock *block, | |||
598 | 597 | ||
599 | /* Did anything match? */ | 598 | /* Did anything match? */ |
600 | if (0 == ctx->longest_match) | 599 | if (0 == ctx->longest_match) |
600 | { | ||
601 | LOG (GNUNET_ERROR_TYPE_DEBUG, " no match in block\n"); | ||
601 | return; | 602 | return; |
603 | } | ||
602 | 604 | ||
605 | hash = &ctx->hash; | ||
603 | new_ctx = GNUNET_malloc (sizeof (struct RegexSearchContext)); | 606 | new_ctx = GNUNET_malloc (sizeof (struct RegexSearchContext)); |
604 | new_ctx->info = info; | 607 | new_ctx->info = info; |
605 | new_ctx->position = ctx->position + ctx->longest_match; | 608 | new_ctx->position = ctx->position + ctx->longest_match; |
@@ -607,28 +610,28 @@ regex_next_edge (const struct RegexBlock *block, | |||
607 | 610 | ||
608 | /* Check whether we already have a DHT GET running for it */ | 611 | /* Check whether we already have a DHT GET running for it */ |
609 | if (GNUNET_YES == | 612 | if (GNUNET_YES == |
610 | GNUNET_CONTAINER_multihashmap_contains(info->dht_get_handles, &ctx->hash)) | 613 | GNUNET_CONTAINER_multihashmap_contains (info->dht_get_handles, hash)) |
611 | { | 614 | { |
612 | LOG (GNUNET_ERROR_TYPE_DEBUG, "* GET running, END\n"); | 615 | LOG (GNUNET_ERROR_TYPE_DEBUG, "* GET running, END\n"); |
613 | GNUNET_CONTAINER_multihashmap_get_multiple (info->dht_get_results, | 616 | GNUNET_CONTAINER_multihashmap_get_multiple (info->dht_get_results, |
614 | &ctx->hash, | 617 | hash, |
615 | ®ex_result_iterator, | 618 | ®ex_result_iterator, |
616 | new_ctx); | 619 | new_ctx); |
617 | // FIXME: "leaks" new_ctx? avoid keeping it around? | 620 | return; /* We are already looking for it */ |
618 | return; // We are already looking for it | ||
619 | } | 621 | } |
620 | 622 | ||
621 | GNUNET_STATISTICS_update (info->stats, "# regex nodes traversed", | 623 | GNUNET_STATISTICS_update (info->stats, "# regex nodes traversed", |
622 | 1, GNUNET_NO); | 624 | 1, GNUNET_NO); |
623 | 625 | ||
624 | /* Start search in DHT */ | 626 | /* Start search in DHT */ |
627 | LOG (GNUNET_ERROR_TYPE_INFO, " looking for %s\n", GNUNET_h2s (hash)); | ||
625 | rest = &new_ctx->info->description[new_ctx->position]; | 628 | rest = &new_ctx->info->description[new_ctx->position]; |
626 | get_h = | 629 | get_h = |
627 | GNUNET_DHT_get_start (info->dht, /* handle */ | 630 | GNUNET_DHT_get_start (info->dht, /* handle */ |
628 | GNUNET_BLOCK_TYPE_REGEX, /* type */ | 631 | GNUNET_BLOCK_TYPE_REGEX, /* type */ |
629 | &ctx->hash, /* key to search */ | 632 | hash, /* key to search */ |
630 | DHT_REPLICATION, /* replication level */ | 633 | DHT_REPLICATION, /* replication level */ |
631 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | 634 | DHT_OPT, |
632 | rest, /* xquery */ | 635 | rest, /* xquery */ |
633 | // FIXME add BLOOMFILTER to exclude filtered peers | 636 | // FIXME add BLOOMFILTER to exclude filtered peers |
634 | strlen(rest) + 1, /* xquery bits */ | 637 | strlen(rest) + 1, /* xquery bits */ |
@@ -636,7 +639,7 @@ regex_next_edge (const struct RegexBlock *block, | |||
636 | &dht_get_string_handler, new_ctx); | 639 | &dht_get_string_handler, new_ctx); |
637 | if (GNUNET_OK != | 640 | if (GNUNET_OK != |
638 | GNUNET_CONTAINER_multihashmap_put(info->dht_get_handles, | 641 | GNUNET_CONTAINER_multihashmap_put(info->dht_get_handles, |
639 | &ctx->hash, | 642 | hash, |
640 | get_h, | 643 | get_h, |
641 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | 644 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) |
642 | { | 645 | { |
@@ -661,7 +664,7 @@ GNUNET_REGEX_search (struct GNUNET_DHT_Handle *dht, | |||
661 | size_t len; | 664 | size_t len; |
662 | 665 | ||
663 | /* Initialize handle */ | 666 | /* Initialize handle */ |
664 | LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_REGEX_search: %s\n", string); | 667 | LOG (GNUNET_ERROR_TYPE_INFO, "GNUNET_REGEX_search: %s\n", string); |
665 | GNUNET_assert (NULL != dht); | 668 | GNUNET_assert (NULL != dht); |
666 | GNUNET_assert (NULL != callback); | 669 | GNUNET_assert (NULL != callback); |
667 | h = GNUNET_malloc (sizeof (struct GNUNET_REGEX_search_handle)); | 670 | h = GNUNET_malloc (sizeof (struct GNUNET_REGEX_search_handle)); |
@@ -680,17 +683,15 @@ GNUNET_REGEX_search (struct GNUNET_DHT_Handle *dht, | |||
680 | ctx->position = size; | 683 | ctx->position = size; |
681 | ctx->info = h; | 684 | ctx->info = h; |
682 | GNUNET_array_append (h->contexts, h->n_contexts, ctx); | 685 | GNUNET_array_append (h->contexts, h->n_contexts, ctx); |
683 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 686 | LOG (GNUNET_ERROR_TYPE_DEBUG, " consumed %u bits out of %u\n", size, len); |
684 | " consumed %u bits out of %u\n", size, len); | 687 | LOG (GNUNET_ERROR_TYPE_INFO, " looking for %s\n", GNUNET_h2s (&key)); |
685 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
686 | " looking for %s\n", GNUNET_h2s (&key)); | ||
687 | 688 | ||
688 | /* Start search in DHT */ | 689 | /* Start search in DHT */ |
689 | get_h = GNUNET_DHT_get_start (h->dht, /* handle */ | 690 | get_h = GNUNET_DHT_get_start (h->dht, /* handle */ |
690 | GNUNET_BLOCK_TYPE_REGEX, /* type */ | 691 | GNUNET_BLOCK_TYPE_REGEX, /* type */ |
691 | &key, /* key to search */ | 692 | &key, /* key to search */ |
692 | DHT_REPLICATION, /* replication level */ | 693 | DHT_REPLICATION, /* replication level */ |
693 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | 694 | DHT_OPT, |
694 | &h->description[size], /* xquery */ | 695 | &h->description[size], /* xquery */ |
695 | // FIXME add BLOOMFILTER to exclude filtered peers | 696 | // FIXME add BLOOMFILTER to exclude filtered peers |
696 | len + 1 - size, /* xquery bits */ | 697 | len + 1 - size, /* xquery bits */ |