diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-07-02 14:38:54 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-07-02 14:38:54 +0000 |
commit | 15a8471c0edc4134f57c19884c033a63f49a04dd (patch) | |
tree | 4465bb0b1198f1869163706e6cfeeaba5ff3fabf /src/regex/regex_internal_dht.c | |
parent | 2a453cf6aec60af36f655bd053847ab15ff7ae8f (diff) | |
download | gnunet-15a8471c0edc4134f57c19884c033a63f49a04dd.tar.gz gnunet-15a8471c0edc4134f57c19884c033a63f49a04dd.zip |
-implementing regex test
Diffstat (limited to 'src/regex/regex_internal_dht.c')
-rw-r--r-- | src/regex/regex_internal_dht.c | 227 |
1 files changed, 116 insertions, 111 deletions
diff --git a/src/regex/regex_internal_dht.c b/src/regex/regex_internal_dht.c index 15f53e953..317c6ef48 100644 --- a/src/regex/regex_internal_dht.c +++ b/src/regex/regex_internal_dht.c | |||
@@ -34,16 +34,9 @@ | |||
34 | 34 | ||
35 | #define LOG(kind,...) GNUNET_log_from (kind,"regex-dht",__VA_ARGS__) | 35 | #define LOG(kind,...) GNUNET_log_from (kind,"regex-dht",__VA_ARGS__) |
36 | 36 | ||
37 | /* FIXME: OPTION (API, CONFIG) */ | ||
38 | #define DHT_REPLICATION 5 | 37 | #define DHT_REPLICATION 5 |
39 | #define DHT_TTL GNUNET_TIME_UNIT_HOURS | 38 | #define DHT_TTL GNUNET_TIME_UNIT_HOURS |
40 | #define DEBUG_DHT GNUNET_NO | ||
41 | |||
42 | #if DEBUG_DHT | ||
43 | #define DHT_OPT GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE | GNUNET_DHT_RO_RECORD_ROUTE | ||
44 | #else | ||
45 | #define DHT_OPT GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE | 39 | #define DHT_OPT GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE |
46 | #endif | ||
47 | 40 | ||
48 | 41 | ||
49 | /** | 42 | /** |
@@ -113,9 +106,9 @@ regex_iterator (void *cls, | |||
113 | "State %s is accepting, putting own id\n", | 106 | "State %s is accepting, putting own id\n", |
114 | GNUNET_h2s(key)); | 107 | GNUNET_h2s(key)); |
115 | size = sizeof (struct RegexAcceptBlock); | 108 | size = sizeof (struct RegexAcceptBlock); |
116 | ab.purpose.size = sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + | 109 | ab.purpose.size = ntohl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + |
117 | sizeof (struct GNUNET_TIME_AbsoluteNBO) + | 110 | sizeof (struct GNUNET_TIME_AbsoluteNBO) + |
118 | sizeof (struct GNUNET_HashCode); | 111 | sizeof (struct GNUNET_HashCode)); |
119 | ab.purpose.purpose = ntohl (GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT); | 112 | ab.purpose.purpose = ntohl (GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT); |
120 | ab.expiration_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_DHT_MAX_EXPIRATION)); | 113 | ab.expiration_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_DHT_MAX_EXPIRATION)); |
121 | ab.key = *key; | 114 | ab.key = *key; |
@@ -191,8 +184,8 @@ REGEX_INTERNAL_announce (struct GNUNET_DHT_Handle *dht, | |||
191 | h->stats = stats; | 184 | h->stats = stats; |
192 | h->priv = priv; | 185 | h->priv = priv; |
193 | h->dfa = REGEX_INTERNAL_construct_dfa (regex, | 186 | h->dfa = REGEX_INTERNAL_construct_dfa (regex, |
194 | strlen (regex), | 187 | strlen (regex), |
195 | compression); | 188 | compression); |
196 | REGEX_INTERNAL_reannounce (h); | 189 | REGEX_INTERNAL_reannounce (h); |
197 | return h; | 190 | return h; |
198 | } | 191 | } |
@@ -208,13 +201,14 @@ void | |||
208 | REGEX_INTERNAL_reannounce (struct REGEX_INTERNAL_Announcement *h) | 201 | REGEX_INTERNAL_reannounce (struct REGEX_INTERNAL_Announcement *h) |
209 | { | 202 | { |
210 | GNUNET_assert (NULL != h->dfa); /* make sure to call announce first */ | 203 | GNUNET_assert (NULL != h->dfa); /* make sure to call announce first */ |
211 | LOG (GNUNET_ERROR_TYPE_INFO, "REGEX_INTERNAL_reannounce: %.60s\n", h->regex); | 204 | LOG (GNUNET_ERROR_TYPE_INFO, |
212 | LOG (GNUNET_ERROR_TYPE_DEBUG, " full: %s\n", h->regex); | 205 | "REGEX_INTERNAL_reannounce: %s\n", |
213 | REGEX_INTERNAL_iterate_all_edges (h->dfa, ®ex_iterator, h); | 206 | h->regex); |
207 | REGEX_INTERNAL_iterate_all_edges (h->dfa, | ||
208 | ®ex_iterator, h); | ||
214 | } | 209 | } |
215 | 210 | ||
216 | 211 | ||
217 | |||
218 | /** | 212 | /** |
219 | * Clear all cached data used by a regex announce. | 213 | * Clear all cached data used by a regex announce. |
220 | * Does not close DHT connection. | 214 | * Does not close DHT connection. |
@@ -263,44 +257,62 @@ struct RegexSearchContext | |||
263 | 257 | ||
264 | 258 | ||
265 | /** | 259 | /** |
260 | * Type of values in 'dht_get_results'. | ||
261 | */ | ||
262 | struct Result | ||
263 | { | ||
264 | /** | ||
265 | * Number of bytes in data. | ||
266 | */ | ||
267 | size_t size; | ||
268 | |||
269 | /** | ||
270 | * The raw result data. | ||
271 | */ | ||
272 | const void *data; | ||
273 | }; | ||
274 | |||
275 | |||
276 | /** | ||
266 | * Struct to keep information of searches of services described by a regex | 277 | * Struct to keep information of searches of services described by a regex |
267 | * using a user-provided string service description. | 278 | * using a user-provided string service description. |
268 | */ | 279 | */ |
269 | struct REGEX_INTERNAL_Search | 280 | struct REGEX_INTERNAL_Search |
270 | { | 281 | { |
271 | /** | 282 | /** |
272 | * DHT handle to use, must be initialized externally. | 283 | * DHT handle to use, must be initialized externally. |
273 | */ | 284 | */ |
274 | struct GNUNET_DHT_Handle *dht; | 285 | struct GNUNET_DHT_Handle *dht; |
275 | 286 | ||
276 | /** | 287 | /** |
277 | * Optional statistics handle to report usage. Can be NULL. | 288 | * Optional statistics handle to report usage. Can be NULL. |
278 | */ | 289 | */ |
279 | struct GNUNET_STATISTICS_Handle *stats; | 290 | struct GNUNET_STATISTICS_Handle *stats; |
280 | 291 | ||
281 | /** | 292 | /** |
282 | * User provided description of the searched service. | 293 | * User provided description of the searched service. |
283 | */ | 294 | */ |
284 | char *description; | 295 | char *description; |
285 | 296 | ||
286 | /** | 297 | /** |
287 | * Running DHT GETs. | 298 | * Running DHT GETs. |
288 | */ | 299 | */ |
289 | struct GNUNET_CONTAINER_MultiHashMap *dht_get_handles; | 300 | struct GNUNET_CONTAINER_MultiHashMap *dht_get_handles; |
290 | 301 | ||
291 | /** | 302 | /** |
292 | * Results from running DHT GETs. | 303 | * Results from running DHT GETs, values are of type |
293 | */ | 304 | * 'struct Result'. |
305 | */ | ||
294 | struct GNUNET_CONTAINER_MultiHashMap *dht_get_results; | 306 | struct GNUNET_CONTAINER_MultiHashMap *dht_get_results; |
295 | 307 | ||
296 | /** | 308 | /** |
297 | * Contexts, for each running DHT GET. Free all on end of search. | 309 | * Contexts, for each running DHT GET. Free all on end of search. |
298 | */ | 310 | */ |
299 | struct RegexSearchContext **contexts; | 311 | struct RegexSearchContext **contexts; |
300 | 312 | ||
301 | /** | 313 | /** |
302 | * Number of contexts (branches/steps in search). | 314 | * Number of contexts (branches/steps in search). |
303 | */ | 315 | */ |
304 | unsigned int n_contexts; | 316 | unsigned int n_contexts; |
305 | 317 | ||
306 | /** | 318 | /** |
@@ -315,15 +327,12 @@ struct REGEX_INTERNAL_Search | |||
315 | }; | 327 | }; |
316 | 328 | ||
317 | 329 | ||
318 | |||
319 | /** | 330 | /** |
320 | * Jump to the next edge, with the longest matching token. | 331 | * Jump to the next edge, with the longest matching token. |
321 | * | 332 | * |
322 | * @param block Block found in the DHT. | 333 | * @param block Block found in the DHT. |
323 | * @param size Size of the block. | 334 | * @param size Size of the block. |
324 | * @param ctx Context of the search. | 335 | * @param ctx Context of the search. |
325 | * | ||
326 | * @return GNUNET_YES if should keep iterating, GNUNET_NO otherwise. | ||
327 | */ | 336 | */ |
328 | static void | 337 | static void |
329 | regex_next_edge (const struct RegexBlock *block, | 338 | regex_next_edge (const struct RegexBlock *block, |
@@ -361,13 +370,15 @@ dht_get_string_accept_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
361 | struct REGEX_INTERNAL_Search *info = ctx->info; | 370 | struct REGEX_INTERNAL_Search *info = ctx->info; |
362 | struct GNUNET_PeerIdentity pid; | 371 | struct GNUNET_PeerIdentity pid; |
363 | 372 | ||
364 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Got regex results from DHT!\n"); | 373 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
365 | LOG (GNUNET_ERROR_TYPE_INFO, " accept for %s (key %s)\n", | 374 | "Regex result accept for %s (key %s)\n", |
366 | info->description, GNUNET_h2s(key)); | 375 | info->description, GNUNET_h2s(key)); |
367 | 376 | ||
368 | GNUNET_STATISTICS_update (info->stats, "# regex accepting blocks found", | 377 | GNUNET_STATISTICS_update (info->stats, |
378 | "# regex accepting blocks found", | ||
369 | 1, GNUNET_NO); | 379 | 1, GNUNET_NO); |
370 | GNUNET_STATISTICS_update (info->stats, "# regex accepting block bytes found", | 380 | GNUNET_STATISTICS_update (info->stats, |
381 | "# regex accepting block bytes found", | ||
371 | size, GNUNET_NO); | 382 | size, GNUNET_NO); |
372 | GNUNET_CRYPTO_hash (&block->public_key, | 383 | GNUNET_CRYPTO_hash (&block->public_key, |
373 | sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded), | 384 | sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded), |
@@ -392,8 +403,9 @@ regex_find_path (const struct GNUNET_HashCode *key, | |||
392 | { | 403 | { |
393 | struct GNUNET_DHT_GetHandle *get_h; | 404 | struct GNUNET_DHT_GetHandle *get_h; |
394 | 405 | ||
395 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Found peer by service\n"); | 406 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
396 | LOG (GNUNET_ERROR_TYPE_INFO, " find accept for %s\n", GNUNET_h2s (key)); | 407 | "regex finds path for %s\n", |
408 | GNUNET_h2s (key)); | ||
397 | get_h = GNUNET_DHT_get_start (ctx->info->dht, /* handle */ | 409 | get_h = GNUNET_DHT_get_start (ctx->info->dht, /* handle */ |
398 | GNUNET_BLOCK_TYPE_REGEX_ACCEPT, /* type */ | 410 | GNUNET_BLOCK_TYPE_REGEX_ACCEPT, /* type */ |
399 | key, /* key to search */ | 411 | key, /* key to search */ |
@@ -440,40 +452,24 @@ dht_get_string_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
440 | const struct RegexBlock *block = data; | 452 | const struct RegexBlock *block = data; |
441 | struct RegexSearchContext *ctx = cls; | 453 | struct RegexSearchContext *ctx = cls; |
442 | struct REGEX_INTERNAL_Search *info = ctx->info; | 454 | struct REGEX_INTERNAL_Search *info = ctx->info; |
443 | void *copy; | ||
444 | size_t len; | 455 | size_t len; |
445 | char *datastore; | 456 | struct Result *copy; |
446 | 457 | ||
447 | #if DEBUG_DHT | 458 | LOG (GNUNET_ERROR_TYPE_INFO, |
448 | if ( (NULL != put_path) && | 459 | "DHT GET result for %s (%s)\n", |
449 | (0 != put_path_length) ) | 460 | GNUNET_h2s (key), ctx->info->description); |
450 | { | 461 | copy = GNUNET_malloc (sizeof (struct Result) + size); |
451 | datastore = GNUNET_strdup (GNUNET_i2s (&put_path[put_path_length - 1])); | 462 | copy->size = size; |
452 | } | 463 | copy->data = ©[1]; |
453 | else | 464 | memcpy (©[1], block, size); |
454 | { | 465 | GNUNET_break (GNUNET_OK == |
455 | GNUNET_asprintf (&datastore, "?? %u/%u", put_path_length, get_path_length); | 466 | GNUNET_CONTAINER_multihashmap_put (info->dht_get_results, |
456 | } | 467 | key, copy, |
457 | #else | 468 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
458 | datastore = GNUNET_strdup ("N/A"); | ||
459 | #endif | ||
460 | |||
461 | LOG (GNUNET_ERROR_TYPE_INFO, " DHT GET result for %s (%s) at %s\n", | ||
462 | GNUNET_h2s (key), ctx->info->description, datastore); | ||
463 | GNUNET_free (datastore); | ||
464 | |||
465 | copy = GNUNET_malloc (size); | ||
466 | memcpy (copy, block, size); | ||
467 | GNUNET_break ( | ||
468 | GNUNET_OK == | ||
469 | GNUNET_CONTAINER_multihashmap_put (info->dht_get_results, | ||
470 | key, copy, | ||
471 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE) | ||
472 | ); | ||
473 | len = strlen (info->description); | 469 | len = strlen (info->description); |
474 | if (len == ctx->position) // String processed | 470 | if (len == ctx->position) // String processed |
475 | { | 471 | { |
476 | if (GNUNET_YES == GNUNET_BLOCK_is_accepting (block)) | 472 | if (GNUNET_YES == GNUNET_BLOCK_is_accepting (block, size)) |
477 | { | 473 | { |
478 | regex_find_path (key, ctx); | 474 | regex_find_path (key, ctx); |
479 | } | 475 | } |
@@ -501,22 +497,25 @@ regex_result_iterator (void *cls, | |||
501 | const struct GNUNET_HashCode * key, | 497 | const struct GNUNET_HashCode * key, |
502 | void *value) | 498 | void *value) |
503 | { | 499 | { |
504 | struct RegexBlock *block = value; | 500 | struct Result *result = value; |
501 | const struct RegexBlock *block = result->data; | ||
505 | struct RegexSearchContext *ctx = cls; | 502 | struct RegexSearchContext *ctx = cls; |
506 | 503 | ||
507 | if ( (GNUNET_YES == | 504 | if ( (GNUNET_YES == |
508 | GNUNET_BLOCK_is_accepting (block)) && | 505 | GNUNET_BLOCK_is_accepting (block, result->size)) && |
509 | (ctx->position == strlen (ctx->info->description)) ) | 506 | (ctx->position == strlen (ctx->info->description)) ) |
510 | { | 507 | { |
511 | LOG (GNUNET_ERROR_TYPE_INFO, " * Found accepting known block\n"); | 508 | LOG (GNUNET_ERROR_TYPE_INFO, |
509 | "Found accepting known block\n"); | ||
512 | regex_find_path (key, ctx); | 510 | regex_find_path (key, ctx); |
513 | return GNUNET_YES; // We found an accept state! | 511 | return GNUNET_YES; // We found an accept state! |
514 | } | 512 | } |
515 | LOG (GNUNET_ERROR_TYPE_DEBUG, "* %u, %u, [%u]\n", | 513 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
516 | ctx->position, strlen(ctx->info->description), | 514 | "* %u, %u, [%u]\n", |
517 | GNUNET_BLOCK_is_accepting (block)); | 515 | ctx->position, |
518 | 516 | strlen (ctx->info->description), | |
519 | regex_next_edge (block, SIZE_MAX, ctx); | 517 | GNUNET_BLOCK_is_accepting (block, result->size)); |
518 | regex_next_edge (block, result->size, ctx); | ||
520 | 519 | ||
521 | GNUNET_STATISTICS_update (ctx->info->stats, "# regex mesh blocks iterated", | 520 | GNUNET_STATISTICS_update (ctx->info->stats, "# regex mesh blocks iterated", |
522 | 1, GNUNET_NO); | 521 | 1, GNUNET_NO); |
@@ -548,37 +547,28 @@ regex_edge_iterator (void *cls, | |||
548 | 547 | ||
549 | GNUNET_STATISTICS_update (info->stats, "# regex edges iterated", | 548 | GNUNET_STATISTICS_update (info->stats, "# regex edges iterated", |
550 | 1, GNUNET_NO); | 549 | 1, GNUNET_NO); |
551 | |||
552 | LOG (GNUNET_ERROR_TYPE_DEBUG, "* Start of regex edge iterator\n"); | ||
553 | LOG (GNUNET_ERROR_TYPE_DEBUG, "* descr : %s\n", info->description); | ||
554 | LOG (GNUNET_ERROR_TYPE_DEBUG, "* posit : %u\n", ctx->position); | ||
555 | current = &info->description[ctx->position]; | 550 | current = &info->description[ctx->position]; |
556 | LOG (GNUNET_ERROR_TYPE_DEBUG, "* currt : %s\n", current); | ||
557 | current_len = strlen (info->description) - ctx->position; | 551 | current_len = strlen (info->description) - ctx->position; |
558 | LOG (GNUNET_ERROR_TYPE_DEBUG, "* ctlen : %u\n", current_len); | ||
559 | LOG (GNUNET_ERROR_TYPE_DEBUG, "* tklen : %u\n", len); | ||
560 | LOG (GNUNET_ERROR_TYPE_DEBUG, "* token : %.*s\n", len, token); | ||
561 | LOG (GNUNET_ERROR_TYPE_DEBUG, "* nextk : %s\n", GNUNET_h2s(key)); | ||
562 | if (len > current_len) | 552 | if (len > current_len) |
563 | { | 553 | { |
564 | LOG (GNUNET_ERROR_TYPE_DEBUG, "* Token too long, END\n"); | 554 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Token too long, END\n"); |
565 | return GNUNET_YES; // Token too long, wont match | 555 | return GNUNET_YES; |
566 | } | 556 | } |
567 | if (0 != strncmp (current, token, len)) | 557 | if (0 != strncmp (current, token, len)) |
568 | { | 558 | { |
569 | LOG (GNUNET_ERROR_TYPE_DEBUG, "* Token doesn't match, END\n"); | 559 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Token doesn't match, END\n"); |
570 | return GNUNET_YES; // Token doesn't match | 560 | return GNUNET_YES; |
571 | } | 561 | } |
572 | 562 | ||
573 | if (len > ctx->longest_match) | 563 | if (len > ctx->longest_match) |
574 | { | 564 | { |
575 | LOG (GNUNET_ERROR_TYPE_DEBUG, "* Token is longer, KEEP\n"); | 565 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Token is longer, KEEP\n"); |
576 | ctx->longest_match = len; | 566 | ctx->longest_match = len; |
577 | ctx->hash = *key; | 567 | ctx->hash = *key; |
578 | } | 568 | } |
579 | else | 569 | else |
580 | { | 570 | { |
581 | LOG (GNUNET_ERROR_TYPE_DEBUG, "* Token is not longer, IGNORE\n"); | 571 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Token is not longer, IGNORE\n"); |
582 | } | 572 | } |
583 | 573 | ||
584 | LOG (GNUNET_ERROR_TYPE_DEBUG, "* End of regex edge iterator\n"); | 574 | LOG (GNUNET_ERROR_TYPE_DEBUG, "* End of regex edge iterator\n"); |
@@ -592,8 +582,6 @@ regex_edge_iterator (void *cls, | |||
592 | * @param block Block found in the DHT. | 582 | * @param block Block found in the DHT. |
593 | * @param size Size of the block. | 583 | * @param size Size of the block. |
594 | * @param ctx Context of the search. | 584 | * @param ctx Context of the search. |
595 | * | ||
596 | * @return GNUNET_YES if should keep iterating, GNUNET_NO otherwise. | ||
597 | */ | 585 | */ |
598 | static void | 586 | static void |
599 | regex_next_edge (const struct RegexBlock *block, | 587 | regex_next_edge (const struct RegexBlock *block, |
@@ -611,13 +599,14 @@ regex_next_edge (const struct RegexBlock *block, | |||
611 | * among tokens in the given block */ | 599 | * among tokens in the given block */ |
612 | ctx->longest_match = 0; | 600 | ctx->longest_match = 0; |
613 | result = REGEX_BLOCK_iterate (block, size, | 601 | result = REGEX_BLOCK_iterate (block, size, |
614 | ®ex_edge_iterator, ctx); | 602 | ®ex_edge_iterator, ctx); |
615 | GNUNET_break (GNUNET_OK == result); | 603 | GNUNET_break (GNUNET_OK == result); |
616 | 604 | ||
617 | /* Did anything match? */ | 605 | /* Did anything match? */ |
618 | if (0 == ctx->longest_match) | 606 | if (0 == ctx->longest_match) |
619 | { | 607 | { |
620 | LOG (GNUNET_ERROR_TYPE_DEBUG, " no match in block\n"); | 608 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
609 | "no match in block\n"); | ||
621 | return; | 610 | return; |
622 | } | 611 | } |
623 | 612 | ||
@@ -631,7 +620,8 @@ regex_next_edge (const struct RegexBlock *block, | |||
631 | if (GNUNET_YES == | 620 | if (GNUNET_YES == |
632 | GNUNET_CONTAINER_multihashmap_contains (info->dht_get_handles, hash)) | 621 | GNUNET_CONTAINER_multihashmap_contains (info->dht_get_handles, hash)) |
633 | { | 622 | { |
634 | LOG (GNUNET_ERROR_TYPE_DEBUG, "* GET for %s running, END\n", | 623 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
624 | "GET for %s running, END\n", | ||
635 | GNUNET_h2s (hash)); | 625 | GNUNET_h2s (hash)); |
636 | GNUNET_CONTAINER_multihashmap_get_multiple (info->dht_get_results, | 626 | GNUNET_CONTAINER_multihashmap_get_multiple (info->dht_get_results, |
637 | hash, | 627 | hash, |
@@ -643,8 +633,9 @@ regex_next_edge (const struct RegexBlock *block, | |||
643 | GNUNET_STATISTICS_update (info->stats, "# regex nodes traversed", | 633 | GNUNET_STATISTICS_update (info->stats, "# regex nodes traversed", |
644 | 1, GNUNET_NO); | 634 | 1, GNUNET_NO); |
645 | 635 | ||
646 | /* Start search in DHT */ | 636 | LOG (GNUNET_ERROR_TYPE_INFO, |
647 | LOG (GNUNET_ERROR_TYPE_INFO, " looking for %s\n", GNUNET_h2s (hash)); | 637 | "looking for %s\n", |
638 | GNUNET_h2s (hash)); | ||
648 | rest = &new_ctx->info->description[new_ctx->position]; | 639 | rest = &new_ctx->info->description[new_ctx->position]; |
649 | get_h = | 640 | get_h = |
650 | GNUNET_DHT_get_start (info->dht, /* handle */ | 641 | GNUNET_DHT_get_start (info->dht, /* handle */ |
@@ -653,9 +644,7 @@ regex_next_edge (const struct RegexBlock *block, | |||
653 | DHT_REPLICATION, /* replication level */ | 644 | DHT_REPLICATION, /* replication level */ |
654 | DHT_OPT, | 645 | DHT_OPT, |
655 | rest, /* xquery */ | 646 | rest, /* xquery */ |
656 | // FIXME add BLOOMFILTER to exclude filtered peers | 647 | strlen (rest) + 1, /* xquery bits */ |
657 | strlen(rest) + 1, /* xquery bits */ | ||
658 | // FIXME add BLOOMFILTER SIZE | ||
659 | &dht_get_string_handler, new_ctx); | 648 | &dht_get_string_handler, new_ctx); |
660 | if (GNUNET_OK != | 649 | if (GNUNET_OK != |
661 | GNUNET_CONTAINER_multihashmap_put(info->dht_get_handles, | 650 | GNUNET_CONTAINER_multihashmap_put(info->dht_get_handles, |
@@ -669,6 +658,20 @@ regex_next_edge (const struct RegexBlock *block, | |||
669 | } | 658 | } |
670 | 659 | ||
671 | 660 | ||
661 | /** | ||
662 | * Search for a peer offering a regex matching certain string in the DHT. | ||
663 | * The search runs until REGEX_INTERNAL_search_cancel is called, even if results | ||
664 | * are returned. | ||
665 | * | ||
666 | * @param dht An existing and valid DHT service handle. | ||
667 | * @param string String to match against the regexes in the DHT. | ||
668 | * @param callback Callback for found peers. | ||
669 | * @param callback_cls Closure for @c callback. | ||
670 | * @param stats Optional statistics handle to report usage. Can be NULL. | ||
671 | * | ||
672 | * @return Handle to stop search and free resources. | ||
673 | * Must be freed by calling REGEX_INTERNAL_search_cancel. | ||
674 | */ | ||
672 | struct REGEX_INTERNAL_Search * | 675 | struct REGEX_INTERNAL_Search * |
673 | REGEX_INTERNAL_search (struct GNUNET_DHT_Handle *dht, | 676 | REGEX_INTERNAL_search (struct GNUNET_DHT_Handle *dht, |
674 | const char *string, | 677 | const char *string, |
@@ -703,8 +706,10 @@ REGEX_INTERNAL_search (struct GNUNET_DHT_Handle *dht, | |||
703 | ctx->position = size; | 706 | ctx->position = size; |
704 | ctx->info = h; | 707 | ctx->info = h; |
705 | GNUNET_array_append (h->contexts, h->n_contexts, ctx); | 708 | GNUNET_array_append (h->contexts, h->n_contexts, ctx); |
706 | LOG (GNUNET_ERROR_TYPE_DEBUG, " consumed %u bits out of %u\n", size, len); | 709 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
707 | LOG (GNUNET_ERROR_TYPE_INFO, " looking for %s\n", GNUNET_h2s (&key)); | 710 | "consumed %u bits out of %u, now looking for %s\n", |
711 | size, len, | ||
712 | GNUNET_h2s (&key)); | ||
708 | 713 | ||
709 | /* Start search in DHT */ | 714 | /* Start search in DHT */ |
710 | get_h = GNUNET_DHT_get_start (h->dht, /* handle */ | 715 | get_h = GNUNET_DHT_get_start (h->dht, /* handle */ |