aboutsummaryrefslogtreecommitdiff
path: root/src/regex/regex_internal_dht.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/regex/regex_internal_dht.c')
-rw-r--r--src/regex/regex_internal_dht.c657
1 files changed, 331 insertions, 326 deletions
diff --git a/src/regex/regex_internal_dht.c b/src/regex/regex_internal_dht.c
index 611fb0a23..3cf48f3c2 100644
--- a/src/regex/regex_internal_dht.c
+++ b/src/regex/regex_internal_dht.c
@@ -32,7 +32,7 @@
32#include "gnunet_signatures.h" 32#include "gnunet_signatures.h"
33 33
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/** 37/**
38 * DHT replication level to use. 38 * DHT replication level to use.
@@ -53,7 +53,8 @@
53/** 53/**
54 * Handle to store cached data about a regex announce. 54 * Handle to store cached data about a regex announce.
55 */ 55 */
56struct REGEX_INTERNAL_Announcement { 56struct REGEX_INTERNAL_Announcement
57{
57 /** 58 /**
58 * DHT handle to use, must be initialized externally. 59 * DHT handle to use, must be initialized externally.
59 */ 60 */
@@ -92,92 +93,93 @@ struct REGEX_INTERNAL_Announcement {
92 * @param edges edges leaving current state. 93 * @param edges edges leaving current state.
93 */ 94 */
94static void 95static void
95regex_iterator(void *cls, 96regex_iterator (void *cls,
96 const struct GNUNET_HashCode *key, 97 const struct GNUNET_HashCode *key,
97 const char *proof, 98 const char *proof,
98 int accepting, 99 int accepting,
99 unsigned int num_edges, 100 unsigned int num_edges,
100 const struct REGEX_BLOCK_Edge *edges) 101 const struct REGEX_BLOCK_Edge *edges)
101{ 102{
102 struct REGEX_INTERNAL_Announcement *h = cls; 103 struct REGEX_INTERNAL_Announcement *h = cls;
103 struct RegexBlock *block; 104 struct RegexBlock *block;
104 size_t size; 105 size_t size;
105 unsigned int i; 106 unsigned int i;
106 107
107 LOG(GNUNET_ERROR_TYPE_INFO, 108 LOG (GNUNET_ERROR_TYPE_INFO,
108 "DHT PUT for state %s with proof `%s' and %u edges:\n", 109 "DHT PUT for state %s with proof `%s' and %u edges:\n",
109 GNUNET_h2s(key), 110 GNUNET_h2s (key),
110 proof, 111 proof,
111 num_edges); 112 num_edges);
112 for (i = 0; i < num_edges; i++) 113 for (i = 0; i < num_edges; i++)
113 { 114 {
114 LOG(GNUNET_ERROR_TYPE_INFO, 115 LOG (GNUNET_ERROR_TYPE_INFO,
115 "Edge %u `%s' towards %s\n", 116 "Edge %u `%s' towards %s\n",
116 i, 117 i,
117 edges[i].label, 118 edges[i].label,
118 GNUNET_h2s(&edges[i].destination)); 119 GNUNET_h2s (&edges[i].destination));
119 } 120 }
120 if (GNUNET_YES == accepting) 121 if (GNUNET_YES == accepting)
121 { 122 {
122 struct RegexAcceptBlock ab; 123 struct RegexAcceptBlock ab;
123 124
124 LOG(GNUNET_ERROR_TYPE_INFO, 125 LOG (GNUNET_ERROR_TYPE_INFO,
125 "State %s is accepting, putting own id\n", 126 "State %s is accepting, putting own id\n",
126 GNUNET_h2s(key)); 127 GNUNET_h2s (key));
127 size = sizeof(struct RegexAcceptBlock); 128 size = sizeof(struct RegexAcceptBlock);
128 ab.purpose.size = ntohl(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + 129 ab.purpose.size = ntohl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
129 sizeof(struct GNUNET_TIME_AbsoluteNBO) + 130 + sizeof(struct GNUNET_TIME_AbsoluteNBO)
130 sizeof(struct GNUNET_HashCode)); 131 + sizeof(struct GNUNET_HashCode));
131 ab.purpose.purpose = ntohl(GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT); 132 ab.purpose.purpose = ntohl (GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT);
132 ab.expiration_time = GNUNET_TIME_absolute_hton(GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_DHT_MAX_EXPIRATION)); 133 ab.expiration_time = GNUNET_TIME_absolute_hton (
133 ab.key = *key; 134 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_DHT_MAX_EXPIRATION));
134 GNUNET_CRYPTO_eddsa_key_get_public(h->priv, 135 ab.key = *key;
135 &ab.peer.public_key); 136 GNUNET_CRYPTO_eddsa_key_get_public (h->priv,
136 GNUNET_assert(GNUNET_OK == 137 &ab.peer.public_key);
137 GNUNET_CRYPTO_eddsa_sign(h->priv, 138 GNUNET_assert (GNUNET_OK ==
139 GNUNET_CRYPTO_eddsa_sign (h->priv,
138 &ab.purpose, 140 &ab.purpose,
139 &ab.signature)); 141 &ab.signature));
140 142
141 GNUNET_STATISTICS_update(h->stats, "# regex accepting blocks stored", 143 GNUNET_STATISTICS_update (h->stats, "# regex accepting blocks stored",
142 1, GNUNET_NO); 144 1, GNUNET_NO);
143 GNUNET_STATISTICS_update(h->stats, "# regex accepting block bytes stored", 145 GNUNET_STATISTICS_update (h->stats, "# regex accepting block bytes stored",
144 sizeof(struct RegexAcceptBlock), GNUNET_NO); 146 sizeof(struct RegexAcceptBlock), GNUNET_NO);
145 (void) 147 (void)
146 GNUNET_DHT_put(h->dht, key, 148 GNUNET_DHT_put (h->dht, key,
147 DHT_REPLICATION, 149 DHT_REPLICATION,
148 DHT_OPT | GNUNET_DHT_RO_RECORD_ROUTE, 150 DHT_OPT | GNUNET_DHT_RO_RECORD_ROUTE,
149 GNUNET_BLOCK_TYPE_REGEX_ACCEPT, 151 GNUNET_BLOCK_TYPE_REGEX_ACCEPT,
150 size, 152 size,
151 &ab, 153 &ab,
152 GNUNET_TIME_relative_to_absolute(DHT_TTL), 154 GNUNET_TIME_relative_to_absolute (DHT_TTL),
153 NULL, NULL); 155 NULL, NULL);
154 } 156 }
155 block = REGEX_BLOCK_create(proof, 157 block = REGEX_BLOCK_create (proof,
156 num_edges, 158 num_edges,
157 edges, 159 edges,
158 accepting, 160 accepting,
159 &size); 161 &size);
160 if (NULL == block) 162 if (NULL == block)
161 return; 163 return;
162 (void)GNUNET_DHT_put(h->dht, 164 (void) GNUNET_DHT_put (h->dht,
163 key, 165 key,
164 DHT_REPLICATION, 166 DHT_REPLICATION,
165 DHT_OPT, 167 DHT_OPT,
166 GNUNET_BLOCK_TYPE_REGEX, 168 GNUNET_BLOCK_TYPE_REGEX,
167 size, 169 size,
168 block, 170 block,
169 GNUNET_TIME_relative_to_absolute(DHT_TTL), 171 GNUNET_TIME_relative_to_absolute (DHT_TTL),
170 NULL, 172 NULL,
171 NULL); 173 NULL);
172 GNUNET_STATISTICS_update(h->stats, 174 GNUNET_STATISTICS_update (h->stats,
173 "# regex blocks stored", 175 "# regex blocks stored",
174 1, 176 1,
175 GNUNET_NO); 177 GNUNET_NO);
176 GNUNET_STATISTICS_update(h->stats, 178 GNUNET_STATISTICS_update (h->stats,
177 "# regex block bytes stored", 179 "# regex block bytes stored",
178 size, 180 size,
179 GNUNET_NO); 181 GNUNET_NO);
180 GNUNET_free(block); 182 GNUNET_free (block);
181} 183}
182 184
183 185
@@ -194,22 +196,22 @@ regex_iterator(void *cls,
194 * Must be freed by calling #REGEX_INTERNAL_announce_cancel(). 196 * Must be freed by calling #REGEX_INTERNAL_announce_cancel().
195 */ 197 */
196struct REGEX_INTERNAL_Announcement * 198struct REGEX_INTERNAL_Announcement *
197REGEX_INTERNAL_announce(struct GNUNET_DHT_Handle *dht, 199REGEX_INTERNAL_announce (struct GNUNET_DHT_Handle *dht,
198 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, 200 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
199 const char *regex, 201 const char *regex,
200 uint16_t compression, 202 uint16_t compression,
201 struct GNUNET_STATISTICS_Handle *stats) 203 struct GNUNET_STATISTICS_Handle *stats)
202{ 204{
203 struct REGEX_INTERNAL_Announcement *h; 205 struct REGEX_INTERNAL_Announcement *h;
204 206
205 GNUNET_assert(NULL != dht); 207 GNUNET_assert (NULL != dht);
206 h = GNUNET_new(struct REGEX_INTERNAL_Announcement); 208 h = GNUNET_new (struct REGEX_INTERNAL_Announcement);
207 h->regex = regex; 209 h->regex = regex;
208 h->dht = dht; 210 h->dht = dht;
209 h->stats = stats; 211 h->stats = stats;
210 h->priv = priv; 212 h->priv = priv;
211 h->dfa = REGEX_INTERNAL_construct_dfa(regex, strlen(regex), compression); 213 h->dfa = REGEX_INTERNAL_construct_dfa (regex, strlen (regex), compression);
212 REGEX_INTERNAL_reannounce(h); 214 REGEX_INTERNAL_reannounce (h);
213 return h; 215 return h;
214} 216}
215 217
@@ -221,15 +223,15 @@ REGEX_INTERNAL_announce(struct GNUNET_DHT_Handle *dht,
221 * @param h Handle returned by a previous #REGEX_INTERNAL_announce call(). 223 * @param h Handle returned by a previous #REGEX_INTERNAL_announce call().
222 */ 224 */
223void 225void
224REGEX_INTERNAL_reannounce(struct REGEX_INTERNAL_Announcement *h) 226REGEX_INTERNAL_reannounce (struct REGEX_INTERNAL_Announcement *h)
225{ 227{
226 GNUNET_assert(NULL != h->dfa); /* make sure to call announce first */ 228 GNUNET_assert (NULL != h->dfa); /* make sure to call announce first */
227 LOG(GNUNET_ERROR_TYPE_INFO, 229 LOG (GNUNET_ERROR_TYPE_INFO,
228 "REGEX_INTERNAL_reannounce: %s\n", 230 "REGEX_INTERNAL_reannounce: %s\n",
229 h->regex); 231 h->regex);
230 REGEX_INTERNAL_iterate_reachable_edges(h->dfa, 232 REGEX_INTERNAL_iterate_reachable_edges (h->dfa,
231 &regex_iterator, 233 &regex_iterator,
232 h); 234 h);
233} 235}
234 236
235 237
@@ -240,10 +242,10 @@ REGEX_INTERNAL_reannounce(struct REGEX_INTERNAL_Announcement *h)
240 * @param h Handle returned by a previous #REGEX_INTERNAL_announce() call. 242 * @param h Handle returned by a previous #REGEX_INTERNAL_announce() call.
241 */ 243 */
242void 244void
243REGEX_INTERNAL_announce_cancel(struct REGEX_INTERNAL_Announcement *h) 245REGEX_INTERNAL_announce_cancel (struct REGEX_INTERNAL_Announcement *h)
244{ 246{
245 REGEX_INTERNAL_automaton_destroy(h->dfa); 247 REGEX_INTERNAL_automaton_destroy (h->dfa);
246 GNUNET_free(h); 248 GNUNET_free (h);
247} 249}
248 250
249 251
@@ -254,7 +256,8 @@ REGEX_INTERNAL_announce_cancel(struct REGEX_INTERNAL_Announcement *h)
254 * Struct to keep state of running searches that have consumed a part of 256 * Struct to keep state of running searches that have consumed a part of
255 * the inital string. 257 * the inital string.
256 */ 258 */
257struct RegexSearchContext { 259struct RegexSearchContext
260{
258 /** 261 /**
259 * Part of the description already consumed by 262 * Part of the description already consumed by
260 * this particular search branch. 263 * this particular search branch.
@@ -282,7 +285,8 @@ struct RegexSearchContext {
282/** 285/**
283 * Type of values in `dht_get_results`. 286 * Type of values in `dht_get_results`.
284 */ 287 */
285struct Result { 288struct Result
289{
286 /** 290 /**
287 * Number of bytes in data. 291 * Number of bytes in data.
288 */ 292 */
@@ -299,7 +303,8 @@ struct Result {
299 * Struct to keep information of searches of services described by a regex 303 * Struct to keep information of searches of services described by a regex
300 * using a user-provided string service description. 304 * using a user-provided string service description.
301 */ 305 */
302struct REGEX_INTERNAL_Search { 306struct REGEX_INTERNAL_Search
307{
303 /** 308 /**
304 * DHT handle to use, must be initialized externally. 309 * DHT handle to use, must be initialized externally.
305 */ 310 */
@@ -356,9 +361,9 @@ struct REGEX_INTERNAL_Search {
356 * @param ctx Context of the search. 361 * @param ctx Context of the search.
357 */ 362 */
358static void 363static void
359regex_next_edge(const struct RegexBlock *block, 364regex_next_edge (const struct RegexBlock *block,
360 size_t size, 365 size_t size,
361 struct RegexSearchContext *ctx); 366 struct RegexSearchContext *ctx);
362 367
363 368
364/** 369/**
@@ -377,33 +382,33 @@ regex_next_edge(const struct RegexBlock *block,
377 * @param data Pointer to the result data. 382 * @param data Pointer to the result data.
378 */ 383 */
379static void 384static void
380dht_get_string_accept_handler(void *cls, struct GNUNET_TIME_Absolute exp, 385dht_get_string_accept_handler (void *cls, struct GNUNET_TIME_Absolute exp,
381 const struct GNUNET_HashCode *key, 386 const struct GNUNET_HashCode *key,
382 const struct GNUNET_PeerIdentity *get_path, 387 const struct GNUNET_PeerIdentity *get_path,
383 unsigned int get_path_length, 388 unsigned int get_path_length,
384 const struct GNUNET_PeerIdentity *put_path, 389 const struct GNUNET_PeerIdentity *put_path,
385 unsigned int put_path_length, 390 unsigned int put_path_length,
386 enum GNUNET_BLOCK_Type type, 391 enum GNUNET_BLOCK_Type type,
387 size_t size, const void *data) 392 size_t size, const void *data)
388{ 393{
389 const struct RegexAcceptBlock *block = data; 394 const struct RegexAcceptBlock *block = data;
390 struct RegexSearchContext *ctx = cls; 395 struct RegexSearchContext *ctx = cls;
391 struct REGEX_INTERNAL_Search *info = ctx->info; 396 struct REGEX_INTERNAL_Search *info = ctx->info;
392 397
393 LOG(GNUNET_ERROR_TYPE_DEBUG, 398 LOG (GNUNET_ERROR_TYPE_DEBUG,
394 "Regex result accept for %s (key %s)\n", 399 "Regex result accept for %s (key %s)\n",
395 info->description, GNUNET_h2s(key)); 400 info->description, GNUNET_h2s (key));
396 401
397 GNUNET_STATISTICS_update(info->stats, 402 GNUNET_STATISTICS_update (info->stats,
398 "# regex accepting blocks found", 403 "# regex accepting blocks found",
399 1, GNUNET_NO); 404 1, GNUNET_NO);
400 GNUNET_STATISTICS_update(info->stats, 405 GNUNET_STATISTICS_update (info->stats,
401 "# regex accepting block bytes found", 406 "# regex accepting block bytes found",
402 size, GNUNET_NO); 407 size, GNUNET_NO);
403 info->callback(info->callback_cls, 408 info->callback (info->callback_cls,
404 &block->peer, 409 &block->peer,
405 get_path, get_path_length, 410 get_path, get_path_length,
406 put_path, put_path_length); 411 put_path, put_path_length);
407} 412}
408 413
409 414
@@ -415,28 +420,28 @@ dht_get_string_accept_handler(void *cls, struct GNUNET_TIME_Absolute exp,
415 * @param ctx Context containing info about the string, tunnel, etc. 420 * @param ctx Context containing info about the string, tunnel, etc.
416 */ 421 */
417static void 422static void
418regex_find_path(const struct GNUNET_HashCode *key, 423regex_find_path (const struct GNUNET_HashCode *key,
419 struct RegexSearchContext *ctx) 424 struct RegexSearchContext *ctx)
420{ 425{
421 struct GNUNET_DHT_GetHandle *get_h; 426 struct GNUNET_DHT_GetHandle *get_h;
422 427
423 LOG(GNUNET_ERROR_TYPE_DEBUG, 428 LOG (GNUNET_ERROR_TYPE_DEBUG,
424 "Accept state found, now searching for paths to %s\n", 429 "Accept state found, now searching for paths to %s\n",
425 GNUNET_h2s(key), 430 GNUNET_h2s (key),
426 (unsigned int)ctx->position); 431 (unsigned int) ctx->position);
427 get_h = GNUNET_DHT_get_start(ctx->info->dht, /* handle */ 432 get_h = GNUNET_DHT_get_start (ctx->info->dht, /* handle */
428 GNUNET_BLOCK_TYPE_REGEX_ACCEPT, /* type */ 433 GNUNET_BLOCK_TYPE_REGEX_ACCEPT, /* type */
429 key, /* key to search */ 434 key, /* key to search */
430 DHT_REPLICATION, /* replication level */ 435 DHT_REPLICATION, /* replication level */
431 DHT_OPT | GNUNET_DHT_RO_RECORD_ROUTE, 436 DHT_OPT | GNUNET_DHT_RO_RECORD_ROUTE,
432 NULL, /* xquery */ // FIXME BLOOMFILTER 437 NULL, /* xquery */ // FIXME BLOOMFILTER
433 0, /* xquery bits */ // FIXME BLOOMFILTER SIZE 438 0, /* xquery bits */ // FIXME BLOOMFILTER SIZE
434 &dht_get_string_accept_handler, ctx); 439 &dht_get_string_accept_handler, ctx);
435 GNUNET_break(GNUNET_OK == 440 GNUNET_break (GNUNET_OK ==
436 GNUNET_CONTAINER_multihashmap_put(ctx->info->dht_get_handles, 441 GNUNET_CONTAINER_multihashmap_put (ctx->info->dht_get_handles,
437 key, 442 key,
438 get_h, 443 get_h,
439 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 444 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
440} 445}
441 446
442 447
@@ -458,14 +463,14 @@ regex_find_path(const struct GNUNET_HashCode *key,
458 * TODO: re-issue the request after certain time? cancel after X results? 463 * TODO: re-issue the request after certain time? cancel after X results?
459 */ 464 */
460static void 465static void
461dht_get_string_handler(void *cls, struct GNUNET_TIME_Absolute exp, 466dht_get_string_handler (void *cls, struct GNUNET_TIME_Absolute exp,
462 const struct GNUNET_HashCode *key, 467 const struct GNUNET_HashCode *key,
463 const struct GNUNET_PeerIdentity *get_path, 468 const struct GNUNET_PeerIdentity *get_path,
464 unsigned int get_path_length, 469 unsigned int get_path_length,
465 const struct GNUNET_PeerIdentity *put_path, 470 const struct GNUNET_PeerIdentity *put_path,
466 unsigned int put_path_length, 471 unsigned int put_path_length,
467 enum GNUNET_BLOCK_Type type, 472 enum GNUNET_BLOCK_Type type,
468 size_t size, const void *data) 473 size_t size, const void *data)
469{ 474{
470 const struct RegexBlock *block = data; 475 const struct RegexBlock *block = data;
471 struct RegexSearchContext *ctx = cls; 476 struct RegexSearchContext *ctx = cls;
@@ -473,32 +478,32 @@ dht_get_string_handler(void *cls, struct GNUNET_TIME_Absolute exp,
473 size_t len; 478 size_t len;
474 struct Result *copy; 479 struct Result *copy;
475 480
476 LOG(GNUNET_ERROR_TYPE_INFO, 481 LOG (GNUNET_ERROR_TYPE_INFO,
477 "DHT GET result for %s (%s)\n", 482 "DHT GET result for %s (%s)\n",
478 GNUNET_h2s(key), ctx->info->description); 483 GNUNET_h2s (key), ctx->info->description);
479 copy = GNUNET_malloc(sizeof(struct Result) + size); 484 copy = GNUNET_malloc (sizeof(struct Result) + size);
480 copy->size = size; 485 copy->size = size;
481 copy->data = &copy[1]; 486 copy->data = &copy[1];
482 GNUNET_memcpy(&copy[1], block, size); 487 GNUNET_memcpy (&copy[1], block, size);
483 GNUNET_break(GNUNET_OK == 488 GNUNET_break (GNUNET_OK ==
484 GNUNET_CONTAINER_multihashmap_put(info->dht_get_results, 489 GNUNET_CONTAINER_multihashmap_put (info->dht_get_results,
485 key, copy, 490 key, copy,
486 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 491 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
487 len = strlen(info->description); 492 len = strlen (info->description);
488 if (len == ctx->position) // String processed 493 if (len == ctx->position) // String processed
494 {
495 if (GNUNET_YES == GNUNET_BLOCK_is_accepting (block, size))
489 { 496 {
490 if (GNUNET_YES == GNUNET_BLOCK_is_accepting(block, size)) 497 regex_find_path (key, ctx);
491 {
492 regex_find_path(key, ctx);
493 }
494 else
495 {
496 LOG(GNUNET_ERROR_TYPE_INFO, "block not accepting!\n");
497 /* FIXME REGEX this block not successful, wait for more? start timeout? */
498 }
499 return;
500 } 498 }
501 regex_next_edge(block, size, ctx); 499 else
500 {
501 LOG (GNUNET_ERROR_TYPE_INFO, "block not accepting!\n");
502 /* FIXME REGEX this block not successful, wait for more? start timeout? */
503 }
504 return;
505 }
506 regex_next_edge (block, size, ctx);
502} 507}
503 508
504 509
@@ -511,32 +516,32 @@ dht_get_string_handler(void *cls, struct GNUNET_TIME_Absolute exp,
511 * @return #GNUNET_YES: we should always continue to iterate. 516 * @return #GNUNET_YES: we should always continue to iterate.
512 */ 517 */
513static int 518static int
514regex_result_iterator(void *cls, 519regex_result_iterator (void *cls,
515 const struct GNUNET_HashCode * key, 520 const struct GNUNET_HashCode *key,
516 void *value) 521 void *value)
517{ 522{
518 struct Result *result = value; 523 struct Result *result = value;
519 const struct RegexBlock *block = result->data; 524 const struct RegexBlock *block = result->data;
520 struct RegexSearchContext *ctx = cls; 525 struct RegexSearchContext *ctx = cls;
521 526
522 if ((GNUNET_YES == 527 if ((GNUNET_YES ==
523 GNUNET_BLOCK_is_accepting(block, result->size)) && 528 GNUNET_BLOCK_is_accepting (block, result->size)) &&
524 (ctx->position == strlen(ctx->info->description))) 529 (ctx->position == strlen (ctx->info->description)))
525 { 530 {
526 LOG(GNUNET_ERROR_TYPE_INFO, 531 LOG (GNUNET_ERROR_TYPE_INFO,
527 "Found accepting known block\n"); 532 "Found accepting known block\n");
528 regex_find_path(key, ctx); 533 regex_find_path (key, ctx);
529 return GNUNET_YES; // We found an accept state! 534 return GNUNET_YES; // We found an accept state!
530 } 535 }
531 LOG(GNUNET_ERROR_TYPE_DEBUG, 536 LOG (GNUNET_ERROR_TYPE_DEBUG,
532 "* %u, %u, [%u]\n", 537 "* %u, %u, [%u]\n",
533 ctx->position, 538 ctx->position,
534 strlen(ctx->info->description), 539 strlen (ctx->info->description),
535 GNUNET_BLOCK_is_accepting(block, result->size)); 540 GNUNET_BLOCK_is_accepting (block, result->size));
536 regex_next_edge(block, result->size, ctx); 541 regex_next_edge (block, result->size, ctx);
537 542
538 GNUNET_STATISTICS_update(ctx->info->stats, "# regex cadet blocks iterated", 543 GNUNET_STATISTICS_update (ctx->info->stats, "# regex cadet blocks iterated",
539 1, GNUNET_NO); 544 1, GNUNET_NO);
540 545
541 return GNUNET_YES; 546 return GNUNET_YES;
542} 547}
@@ -552,43 +557,43 @@ regex_result_iterator(void *cls,
552 * @return #GNUNET_YES if should keep iterating, #GNUNET_NO otherwise. 557 * @return #GNUNET_YES if should keep iterating, #GNUNET_NO otherwise.
553 */ 558 */
554static int 559static int
555regex_edge_iterator(void *cls, 560regex_edge_iterator (void *cls,
556 const char *token, 561 const char *token,
557 size_t len, 562 size_t len,
558 const struct GNUNET_HashCode *key) 563 const struct GNUNET_HashCode *key)
559{ 564{
560 struct RegexSearchContext *ctx = cls; 565 struct RegexSearchContext *ctx = cls;
561 struct REGEX_INTERNAL_Search *info = ctx->info; 566 struct REGEX_INTERNAL_Search *info = ctx->info;
562 const char *current; 567 const char *current;
563 size_t current_len; 568 size_t current_len;
564 569
565 GNUNET_STATISTICS_update(info->stats, "# regex edges iterated", 570 GNUNET_STATISTICS_update (info->stats, "# regex edges iterated",
566 1, GNUNET_NO); 571 1, GNUNET_NO);
567 current = &info->description[ctx->position]; 572 current = &info->description[ctx->position];
568 current_len = strlen(info->description) - ctx->position; 573 current_len = strlen (info->description) - ctx->position;
569 if (len > current_len) 574 if (len > current_len)
570 { 575 {
571 LOG(GNUNET_ERROR_TYPE_DEBUG, "Token too long, END\n"); 576 LOG (GNUNET_ERROR_TYPE_DEBUG, "Token too long, END\n");
572 return GNUNET_YES; 577 return GNUNET_YES;
573 } 578 }
574 if (0 != strncmp(current, token, len)) 579 if (0 != strncmp (current, token, len))
575 { 580 {
576 LOG(GNUNET_ERROR_TYPE_DEBUG, "Token doesn't match, END\n"); 581 LOG (GNUNET_ERROR_TYPE_DEBUG, "Token doesn't match, END\n");
577 return GNUNET_YES; 582 return GNUNET_YES;
578 } 583 }
579 584
580 if (len > ctx->longest_match) 585 if (len > ctx->longest_match)
581 { 586 {
582 LOG(GNUNET_ERROR_TYPE_DEBUG, "Token is longer, KEEP\n"); 587 LOG (GNUNET_ERROR_TYPE_DEBUG, "Token is longer, KEEP\n");
583 ctx->longest_match = len; 588 ctx->longest_match = len;
584 ctx->hash = *key; 589 ctx->hash = *key;
585 } 590 }
586 else 591 else
587 { 592 {
588 LOG(GNUNET_ERROR_TYPE_DEBUG, "Token is not longer, IGNORE\n"); 593 LOG (GNUNET_ERROR_TYPE_DEBUG, "Token is not longer, IGNORE\n");
589 } 594 }
590 595
591 LOG(GNUNET_ERROR_TYPE_DEBUG, "* End of regex edge iterator\n"); 596 LOG (GNUNET_ERROR_TYPE_DEBUG, "* End of regex edge iterator\n");
592 return GNUNET_YES; 597 return GNUNET_YES;
593} 598}
594 599
@@ -601,9 +606,9 @@ regex_edge_iterator(void *cls,
601 * @param ctx Context of the search. 606 * @param ctx Context of the search.
602 */ 607 */
603static void 608static void
604regex_next_edge(const struct RegexBlock *block, 609regex_next_edge (const struct RegexBlock *block,
605 size_t size, 610 size_t size,
606 struct RegexSearchContext *ctx) 611 struct RegexSearchContext *ctx)
607{ 612{
608 struct RegexSearchContext *new_ctx; 613 struct RegexSearchContext *new_ctx;
609 struct REGEX_INTERNAL_Search *info = ctx->info; 614 struct REGEX_INTERNAL_Search *info = ctx->info;
@@ -612,69 +617,69 @@ regex_next_edge(const struct RegexBlock *block,
612 const char *rest; 617 const char *rest;
613 int result; 618 int result;
614 619
615 LOG(GNUNET_ERROR_TYPE_DEBUG, "Next edge\n"); 620 LOG (GNUNET_ERROR_TYPE_DEBUG, "Next edge\n");
616 /* Find the longest match for the current string position, 621 /* Find the longest match for the current string position,
617 * among tokens in the given block */ 622 * among tokens in the given block */
618 ctx->longest_match = 0; 623 ctx->longest_match = 0;
619 result = REGEX_BLOCK_iterate(block, size, 624 result = REGEX_BLOCK_iterate (block, size,
620 &regex_edge_iterator, ctx); 625 &regex_edge_iterator, ctx);
621 GNUNET_break(GNUNET_OK == result); 626 GNUNET_break (GNUNET_OK == result);
622 627
623 /* Did anything match? */ 628 /* Did anything match? */
624 if (0 == ctx->longest_match) 629 if (0 == ctx->longest_match)
625 { 630 {
626 LOG(GNUNET_ERROR_TYPE_DEBUG, 631 LOG (GNUNET_ERROR_TYPE_DEBUG,
627 "no match in block\n"); 632 "no match in block\n");
628 return; 633 return;
629 } 634 }
630 635
631 hash = &ctx->hash; 636 hash = &ctx->hash;
632 new_ctx = GNUNET_new(struct RegexSearchContext); 637 new_ctx = GNUNET_new (struct RegexSearchContext);
633 new_ctx->info = info; 638 new_ctx->info = info;
634 new_ctx->position = ctx->position + ctx->longest_match; 639 new_ctx->position = ctx->position + ctx->longest_match;
635 GNUNET_array_append(info->contexts, info->n_contexts, new_ctx); 640 GNUNET_array_append (info->contexts, info->n_contexts, new_ctx);
636 641
637 /* Check whether we already have a DHT GET running for it */ 642 /* Check whether we already have a DHT GET running for it */
638 if (GNUNET_YES == 643 if (GNUNET_YES ==
639 GNUNET_CONTAINER_multihashmap_contains(info->dht_get_handles, hash)) 644 GNUNET_CONTAINER_multihashmap_contains (info->dht_get_handles, hash))
640 { 645 {
641 LOG(GNUNET_ERROR_TYPE_DEBUG, 646 LOG (GNUNET_ERROR_TYPE_DEBUG,
642 "GET for %s running, END\n", 647 "GET for %s running, END\n",
643 GNUNET_h2s(hash)); 648 GNUNET_h2s (hash));
644 GNUNET_CONTAINER_multihashmap_get_multiple(info->dht_get_results, 649 GNUNET_CONTAINER_multihashmap_get_multiple (info->dht_get_results,
645 hash, 650 hash,
646 &regex_result_iterator, 651 &regex_result_iterator,
647 new_ctx); 652 new_ctx);
648 return; /* We are already looking for it */ 653 return; /* We are already looking for it */
649 } 654 }
650 655
651 GNUNET_STATISTICS_update(info->stats, "# regex nodes traversed", 656 GNUNET_STATISTICS_update (info->stats, "# regex nodes traversed",
652 1, GNUNET_NO); 657 1, GNUNET_NO);
653 658
654 LOG(GNUNET_ERROR_TYPE_DEBUG, 659 LOG (GNUNET_ERROR_TYPE_DEBUG,
655 "Following edges at %s for offset %u in `%s'\n", 660 "Following edges at %s for offset %u in `%s'\n",
656 GNUNET_h2s(hash), 661 GNUNET_h2s (hash),
657 (unsigned int)ctx->position, 662 (unsigned int) ctx->position,
658 info->description); 663 info->description);
659 rest = &new_ctx->info->description[new_ctx->position]; 664 rest = &new_ctx->info->description[new_ctx->position];
660 get_h = 665 get_h =
661 GNUNET_DHT_get_start(info->dht, /* handle */ 666 GNUNET_DHT_get_start (info->dht, /* handle */
662 GNUNET_BLOCK_TYPE_REGEX, /* type */ 667 GNUNET_BLOCK_TYPE_REGEX, /* type */
663 hash, /* key to search */ 668 hash, /* key to search */
664 DHT_REPLICATION, /* replication level */ 669 DHT_REPLICATION, /* replication level */
665 DHT_OPT, 670 DHT_OPT,
666 rest, /* xquery */ 671 rest, /* xquery */
667 strlen(rest) + 1, /* xquery bits */ 672 strlen (rest) + 1, /* xquery bits */
668 &dht_get_string_handler, new_ctx); 673 &dht_get_string_handler, new_ctx);
669 if (GNUNET_OK != 674 if (GNUNET_OK !=
670 GNUNET_CONTAINER_multihashmap_put(info->dht_get_handles, 675 GNUNET_CONTAINER_multihashmap_put (info->dht_get_handles,
671 hash, 676 hash,
672 get_h, 677 get_h,
673 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) 678 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
674 { 679 {
675 GNUNET_break(0); 680 GNUNET_break (0);
676 return; 681 return;
677 } 682 }
678} 683}
679 684
680 685
@@ -692,11 +697,11 @@ regex_next_edge(const struct RegexBlock *block,
692 * Must be freed by calling #REGEX_INTERNAL_search_cancel(). 697 * Must be freed by calling #REGEX_INTERNAL_search_cancel().
693 */ 698 */
694struct REGEX_INTERNAL_Search * 699struct REGEX_INTERNAL_Search *
695REGEX_INTERNAL_search(struct GNUNET_DHT_Handle *dht, 700REGEX_INTERNAL_search (struct GNUNET_DHT_Handle *dht,
696 const char *string, 701 const char *string,
697 REGEX_INTERNAL_Found callback, 702 REGEX_INTERNAL_Found callback,
698 void *callback_cls, 703 void *callback_cls,
699 struct GNUNET_STATISTICS_Handle *stats) 704 struct GNUNET_STATISTICS_Handle *stats)
700{ 705{
701 struct REGEX_INTERNAL_Search *h; 706 struct REGEX_INTERNAL_Search *h;
702 struct GNUNET_DHT_GetHandle *get_h; 707 struct GNUNET_DHT_GetHandle *get_h;
@@ -706,49 +711,49 @@ REGEX_INTERNAL_search(struct GNUNET_DHT_Handle *dht,
706 size_t len; 711 size_t len;
707 712
708 /* Initialize handle */ 713 /* Initialize handle */
709 GNUNET_assert(NULL != dht); 714 GNUNET_assert (NULL != dht);
710 GNUNET_assert(NULL != callback); 715 GNUNET_assert (NULL != callback);
711 h = GNUNET_new(struct REGEX_INTERNAL_Search); 716 h = GNUNET_new (struct REGEX_INTERNAL_Search);
712 h->dht = dht; 717 h->dht = dht;
713 h->description = GNUNET_strdup(string); 718 h->description = GNUNET_strdup (string);
714 h->callback = callback; 719 h->callback = callback;
715 h->callback_cls = callback_cls; 720 h->callback_cls = callback_cls;
716 h->stats = stats; 721 h->stats = stats;
717 h->dht_get_handles = GNUNET_CONTAINER_multihashmap_create(32, GNUNET_NO); 722 h->dht_get_handles = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
718 h->dht_get_results = GNUNET_CONTAINER_multihashmap_create(32, GNUNET_NO); 723 h->dht_get_results = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
719 724
720 /* Initialize context */ 725 /* Initialize context */
721 len = strlen(string); 726 len = strlen (string);
722 size = REGEX_INTERNAL_get_first_key(string, len, &key); 727 size = REGEX_INTERNAL_get_first_key (string, len, &key);
723 LOG(GNUNET_ERROR_TYPE_INFO, 728 LOG (GNUNET_ERROR_TYPE_INFO,
724 "Initial key for `%s' is %s (based on `%.*s')\n", 729 "Initial key for `%s' is %s (based on `%.*s')\n",
725 string, 730 string,
726 GNUNET_h2s(&key), 731 GNUNET_h2s (&key),
727 size, 732 size,
728 string); 733 string);
729 ctx = GNUNET_new(struct RegexSearchContext); 734 ctx = GNUNET_new (struct RegexSearchContext);
730 ctx->position = size; 735 ctx->position = size;
731 ctx->info = h; 736 ctx->info = h;
732 GNUNET_array_append(h->contexts, 737 GNUNET_array_append (h->contexts,
733 h->n_contexts, 738 h->n_contexts,
734 ctx); 739 ctx);
735 /* Start search in DHT */ 740 /* Start search in DHT */
736 get_h = GNUNET_DHT_get_start(h->dht, /* handle */ 741 get_h = GNUNET_DHT_get_start (h->dht, /* handle */
737 GNUNET_BLOCK_TYPE_REGEX, /* type */ 742 GNUNET_BLOCK_TYPE_REGEX, /* type */
738 &key, /* key to search */ 743 &key, /* key to search */
739 DHT_REPLICATION, /* replication level */ 744 DHT_REPLICATION, /* replication level */
740 DHT_OPT, 745 DHT_OPT,
741 &h->description[size], /* xquery */ 746 &h->description[size], /* xquery */
742 // FIXME add BLOOMFILTER to exclude filtered peers 747 // FIXME add BLOOMFILTER to exclude filtered peers
743 len + 1 - size, /* xquery bits */ 748 len + 1 - size, /* xquery bits */
744 // FIXME add BLOOMFILTER SIZE 749 // FIXME add BLOOMFILTER SIZE
745 &dht_get_string_handler, ctx); 750 &dht_get_string_handler, ctx);
746 GNUNET_break( 751 GNUNET_break (
747 GNUNET_OK == 752 GNUNET_OK ==
748 GNUNET_CONTAINER_multihashmap_put(h->dht_get_handles, 753 GNUNET_CONTAINER_multihashmap_put (h->dht_get_handles,
749 &key, 754 &key,
750 get_h, 755 get_h,
751 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST) 756 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)
752 ); 757 );
753 758
754 return h; 759 return h;
@@ -766,13 +771,13 @@ REGEX_INTERNAL_search(struct GNUNET_DHT_Handle *dht,
766 * #GNUNET_NO if not. 771 * #GNUNET_NO if not.
767 */ 772 */
768static int 773static int
769regex_cancel_dht_get(void *cls, 774regex_cancel_dht_get (void *cls,
770 const struct GNUNET_HashCode * key, 775 const struct GNUNET_HashCode *key,
771 void *value) 776 void *value)
772{ 777{
773 struct GNUNET_DHT_GetHandle *h = value; 778 struct GNUNET_DHT_GetHandle *h = value;
774 779
775 GNUNET_DHT_get_stop(h); 780 GNUNET_DHT_get_stop (h);
776 return GNUNET_YES; 781 return GNUNET_YES;
777} 782}
778 783
@@ -788,11 +793,11 @@ regex_cancel_dht_get(void *cls,
788 * #GNUNET_NO if not. 793 * #GNUNET_NO if not.
789 */ 794 */
790static int 795static int
791regex_free_result(void *cls, 796regex_free_result (void *cls,
792 const struct GNUNET_HashCode * key, 797 const struct GNUNET_HashCode *key,
793 void *value) 798 void *value)
794{ 799{
795 GNUNET_free(value); 800 GNUNET_free (value);
796 return GNUNET_YES; 801 return GNUNET_YES;
797} 802}
798 803
@@ -803,24 +808,24 @@ regex_free_result(void *cls,
803 * @param h the search context. 808 * @param h the search context.
804 */ 809 */
805void 810void
806REGEX_INTERNAL_search_cancel(struct REGEX_INTERNAL_Search *h) 811REGEX_INTERNAL_search_cancel (struct REGEX_INTERNAL_Search *h)
807{ 812{
808 unsigned int i; 813 unsigned int i;
809 814
810 GNUNET_free(h->description); 815 GNUNET_free (h->description);
811 GNUNET_CONTAINER_multihashmap_iterate(h->dht_get_handles, 816 GNUNET_CONTAINER_multihashmap_iterate (h->dht_get_handles,
812 &regex_cancel_dht_get, NULL); 817 &regex_cancel_dht_get, NULL);
813 GNUNET_CONTAINER_multihashmap_iterate(h->dht_get_results, 818 GNUNET_CONTAINER_multihashmap_iterate (h->dht_get_results,
814 &regex_free_result, NULL); 819 &regex_free_result, NULL);
815 GNUNET_CONTAINER_multihashmap_destroy(h->dht_get_results); 820 GNUNET_CONTAINER_multihashmap_destroy (h->dht_get_results);
816 GNUNET_CONTAINER_multihashmap_destroy(h->dht_get_handles); 821 GNUNET_CONTAINER_multihashmap_destroy (h->dht_get_handles);
817 if (0 < h->n_contexts) 822 if (0 < h->n_contexts)
818 { 823 {
819 for (i = 0; i < h->n_contexts; i++) 824 for (i = 0; i < h->n_contexts; i++)
820 GNUNET_free(h->contexts[i]); 825 GNUNET_free (h->contexts[i]);
821 GNUNET_free(h->contexts); 826 GNUNET_free (h->contexts);
822 } 827 }
823 GNUNET_free(h); 828 GNUNET_free (h);
824} 829}
825 830
826 831