diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-01-21 16:32:51 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-01-21 16:32:51 +0000 |
commit | 46195e68664242e770a517f2b5d90fde2f1cdd0a (patch) | |
tree | 2ec53a80f4bf8e410a26e5409feb7f54d334bfaf /src | |
parent | 26ebfdc0cc5c15ac8d8ffe07cd90d2e3259b0f7a (diff) | |
download | gnunet-46195e68664242e770a517f2b5d90fde2f1cdd0a.tar.gz gnunet-46195e68664242e770a517f2b5d90fde2f1cdd0a.zip |
- code from mesh
Diffstat (limited to 'src')
-rw-r--r-- | src/regex/regex_dht.c | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/src/regex/regex_dht.c b/src/regex/regex_dht.c index 12681f503..52e8d4841 100644 --- a/src/regex/regex_dht.c +++ b/src/regex/regex_dht.c | |||
@@ -425,13 +425,16 @@ dht_get_string_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
425 | size_t len; | 425 | size_t len; |
426 | 426 | ||
427 | LOG (GNUNET_ERROR_TYPE_DEBUG, "DHT GET STRING RETURNED RESULTS\n"); | 427 | LOG (GNUNET_ERROR_TYPE_DEBUG, "DHT GET STRING RETURNED RESULTS\n"); |
428 | LOG (GNUNET_ERROR_TYPE_DEBUG, " for: %s\n", ctx->info->description); | ||
428 | LOG (GNUNET_ERROR_TYPE_DEBUG, " key: %s\n", GNUNET_h2s (key)); | 429 | LOG (GNUNET_ERROR_TYPE_DEBUG, " key: %s\n", GNUNET_h2s (key)); |
429 | 430 | ||
430 | copy = GNUNET_malloc (size); | 431 | copy = GNUNET_malloc (size); |
431 | memcpy (copy, data, size); | 432 | memcpy (copy, data, size); |
432 | GNUNET_break (GNUNET_OK == | 433 | GNUNET_break ( |
433 | GNUNET_CONTAINER_multihashmap_put(info->dht_get_results, key, copy, | 434 | GNUNET_OK == |
434 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 435 | GNUNET_CONTAINER_multihashmap_put (info->dht_get_results, key, copy, |
436 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE) | ||
437 | ); | ||
435 | len = ntohl (block->n_proof); | 438 | len = ntohl (block->n_proof); |
436 | { | 439 | { |
437 | char proof[len + 1]; | 440 | char proof[len + 1]; |
@@ -449,7 +452,7 @@ dht_get_string_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
449 | { | 452 | { |
450 | if (GNUNET_YES == ntohl (block->accepting)) | 453 | if (GNUNET_YES == ntohl (block->accepting)) |
451 | { | 454 | { |
452 | regex_find_path(key, ctx); | 455 | regex_find_path (key, ctx); |
453 | } | 456 | } |
454 | else | 457 | else |
455 | { | 458 | { |
@@ -651,7 +654,13 @@ GNUNET_REGEX_search (struct GNUNET_DHT_Handle *dht, | |||
651 | struct GNUNET_STATISTICS_Handle *stats) | 654 | struct GNUNET_STATISTICS_Handle *stats) |
652 | { | 655 | { |
653 | struct GNUNET_REGEX_search_handle *h; | 656 | struct GNUNET_REGEX_search_handle *h; |
657 | struct GNUNET_DHT_GetHandle *get_h; | ||
658 | struct RegexSearchContext *ctx; | ||
659 | struct GNUNET_HashCode key; | ||
660 | size_t size; | ||
661 | size_t len; | ||
654 | 662 | ||
663 | /* Initialize handle */ | ||
655 | LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_REGEX_search: %s\n", string); | 664 | LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_REGEX_search: %s\n", string); |
656 | GNUNET_assert (NULL != dht); | 665 | GNUNET_assert (NULL != dht); |
657 | GNUNET_assert (NULL != callback); | 666 | GNUNET_assert (NULL != callback); |
@@ -661,9 +670,40 @@ GNUNET_REGEX_search (struct GNUNET_DHT_Handle *dht, | |||
661 | h->callback = callback; | 670 | h->callback = callback; |
662 | h->callback_cls = callback_cls; | 671 | h->callback_cls = callback_cls; |
663 | h->stats = stats; | 672 | h->stats = stats; |
664 | |||
665 | h->dht_get_handles = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_YES); | 673 | h->dht_get_handles = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_YES); |
666 | h->dht_get_results = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_YES); | 674 | h->dht_get_results = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_YES); |
675 | |||
676 | /* Initialize context */ | ||
677 | len = strlen (string); | ||
678 | size = GNUNET_REGEX_get_first_key (string, len, &key); | ||
679 | ctx = GNUNET_malloc (sizeof (struct RegexSearchContext)); | ||
680 | ctx->position = size; | ||
681 | ctx->info = h; | ||
682 | GNUNET_array_append (h->contexts, h->n_contexts, ctx); | ||
683 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
684 | " consumed %u bits out of %u\n", size, len); | ||
685 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
686 | " looking for %s\n", GNUNET_h2s (&key)); | ||
687 | |||
688 | /* Start search in DHT */ | ||
689 | get_h = GNUNET_DHT_get_start (h->dht, /* handle */ | ||
690 | GNUNET_BLOCK_TYPE_REGEX, /* type */ | ||
691 | &key, /* key to search */ | ||
692 | DHT_REPLICATION, /* replication level */ | ||
693 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | ||
694 | &h->description[size], /* xquery */ | ||
695 | // FIXME add BLOOMFILTER to exclude filtered peers | ||
696 | len + 1 - size, /* xquery bits */ | ||
697 | // FIXME add BLOOMFILTER SIZE | ||
698 | &dht_get_string_handler, ctx); | ||
699 | GNUNET_break ( | ||
700 | GNUNET_OK == | ||
701 | GNUNET_CONTAINER_multihashmap_put (h->dht_get_handles, | ||
702 | &key, | ||
703 | get_h, | ||
704 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST) | ||
705 | ); | ||
706 | |||
667 | return h; | 707 | return h; |
668 | } | 708 | } |
669 | 709 | ||