diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-06-26 15:54:54 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-06-26 15:54:54 +0000 |
commit | 7706f0a08b2425622121c23a7d2054794f2d677c (patch) | |
tree | d4b658006d8b0418b2afabe51bfae14c3f59bb97 /src | |
parent | 133a5ecf306d35f9e86fb5a1f8b120783f6afdf9 (diff) | |
download | gnunet-7706f0a08b2425622121c23a7d2054794f2d677c.tar.gz gnunet-7706f0a08b2425622121c23a7d2054794f2d677c.zip |
-removing unnecessary key from regex blocks, compacting some of the other fields
Diffstat (limited to 'src')
-rw-r--r-- | src/include/block_regex.h | 98 | ||||
-rw-r--r-- | src/include/gnunet_namestore_service.h | 118 | ||||
-rw-r--r-- | src/regex/plugin_block_regex.c | 20 | ||||
-rw-r--r-- | src/regex/regex_block_lib.c | 86 | ||||
-rw-r--r-- | src/regex/regex_block_lib.h | 35 | ||||
-rw-r--r-- | src/regex/regex_internal_dht.c | 22 | ||||
-rw-r--r-- | src/set/gnunet-service-set.h | 4 |
7 files changed, 232 insertions, 151 deletions
diff --git a/src/include/block_regex.h b/src/include/block_regex.h index 282c626a2..73d7b70a5 100644 --- a/src/include/block_regex.h +++ b/src/include/block_regex.h | |||
@@ -39,77 +39,75 @@ extern "C" | |||
39 | #include <stdint.h> | 39 | #include <stdint.h> |
40 | 40 | ||
41 | 41 | ||
42 | GNUNET_NETWORK_STRUCT_BEGIN | ||
43 | |||
44 | |||
42 | /** | 45 | /** |
43 | * @brief A RegexBlock contains one or more of this struct in the payload. | 46 | * @brief A RegexBlock contains one or more of this struct in the payload. |
44 | */ | 47 | */ |
45 | struct RegexEdge | 48 | struct RegexEdge |
46 | { | 49 | { |
47 | /** | 50 | /** |
48 | * Destination of this edge. | 51 | * Destination of this edge. |
49 | */ | 52 | */ |
50 | struct GNUNET_HashCode key; | 53 | struct GNUNET_HashCode key; |
51 | 54 | ||
52 | /** | 55 | /** |
53 | * Length of the token towards the new state. | 56 | * Length of the token towards the new state. |
54 | */ | 57 | */ |
55 | unsigned int n_token; | 58 | uint32_t n_token GNUNET_PACKED; |
56 | 59 | ||
57 | /* char token[n_token] */ | 60 | /* char token[n_token] */ |
58 | }; | 61 | }; |
59 | 62 | ||
63 | |||
60 | /** | 64 | /** |
61 | * @brief Block to announce a regex state. | 65 | * @brief Block to announce a regex state. |
62 | */ | 66 | */ |
63 | struct RegexBlock | 67 | struct RegexBlock |
64 | { | 68 | { |
65 | /** | 69 | |
66 | * The key of the state. | 70 | /** |
67 | */ | 71 | * Length of the proof regex string. |
68 | struct GNUNET_HashCode key; | 72 | */ |
69 | 73 | uint16_t proof_len GNUNET_PACKED; | |
70 | /** | 74 | |
71 | * Length of the proof regex string. | 75 | /** |
72 | */ | 76 | * Is this state an accepting state? |
73 | unsigned int n_proof; | 77 | */ |
74 | 78 | int16_t is_accepting GNUNET_PACKED; | |
75 | /** | 79 | |
76 | * Numer of edges parting from this state. | 80 | /** |
77 | */ | 81 | * Numer of edges parting from this state. |
78 | unsigned int n_edges; | 82 | */ |
79 | 83 | uint32_t n_edges GNUNET_PACKED; | |
80 | /** | 84 | |
81 | * Is this state an accepting state? | 85 | /* char proof[n_proof] */ |
82 | */ | 86 | /* struct RegexEdge edges[n_edges] */ |
83 | int accepting; | ||
84 | |||
85 | /* char proof[n_proof] */ | ||
86 | /* struct RegexEdge edges[n_edges] */ | ||
87 | }; | 87 | }; |
88 | 88 | ||
89 | |||
89 | /** | 90 | /** |
90 | * @brief Block to announce a peer accepting a state. | 91 | * @brief Block to announce a peer accepting a state. |
91 | */ | 92 | */ |
92 | struct RegexAccept | 93 | struct RegexAccept |
93 | { | 94 | { |
94 | /** | 95 | /** |
95 | * The key of the state. | 96 | * The key of the state. |
96 | */ | 97 | */ |
97 | struct GNUNET_HashCode key; | 98 | struct GNUNET_HashCode key; |
98 | 99 | ||
99 | /** | 100 | /** |
100 | * Length of the proof regex string. | 101 | * The identity of the peer accepting the state |
101 | * FIXME necessary??? | 102 | */ |
102 | * already present in the leading MeshRegexBlock | 103 | struct GNUNET_PeerIdentity id; |
103 | */ | ||
104 | // unsigned int n_proof; | ||
105 | |||
106 | /** | ||
107 | * The identity of the peer accepting the state | ||
108 | */ | ||
109 | struct GNUNET_PeerIdentity id; | ||
110 | 104 | ||
111 | }; | 105 | }; |
112 | 106 | ||
107 | |||
108 | GNUNET_NETWORK_STRUCT_END | ||
109 | |||
110 | |||
113 | #if 0 /* keep Emacsens' auto-indent happy */ | 111 | #if 0 /* keep Emacsens' auto-indent happy */ |
114 | { | 112 | { |
115 | #endif | 113 | #endif |
@@ -117,4 +115,4 @@ struct RegexAccept | |||
117 | } | 115 | } |
118 | #endif | 116 | #endif |
119 | 117 | ||
120 | #endif \ No newline at end of file | 118 | #endif |
diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h index 38083ed9c..418813734 100644 --- a/src/include/gnunet_namestore_service.h +++ b/src/include/gnunet_namestore_service.h | |||
@@ -1,10 +1,10 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | (C) 2012 Christian Grothoff (and other contributing authors) | 3 | (C) 2012, 2013 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
7 | by the Free Software Foundation; either version 2, or (at your | 7 | by the Free Software Foundation; either version 3, or (at your |
8 | option) any later version. | 8 | option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
@@ -225,9 +225,8 @@ struct GNUNET_NAMESTORE_RecordData | |||
225 | 225 | ||
226 | /** | 226 | /** |
227 | * Store an item in the namestore. If the item is already present, | 227 | * Store an item in the namestore. If the item is already present, |
228 | * the expiration time is updated to the max of the existing time and | 228 | * it is replaced with the new record. Use an empty array to |
229 | * the new time. This API is used when we cache signatures from other | 229 | * remove all records under the given name. |
230 | * authorities. | ||
231 | * | 230 | * |
232 | * @param h handle to the namestore | 231 | * @param h handle to the namestore |
233 | * @param zone_key public key of the zone | 232 | * @param zone_key public key of the zone |
@@ -276,49 +275,26 @@ GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_EccPublicKeyBinary | |||
276 | 275 | ||
277 | /** | 276 | /** |
278 | * Store an item in the namestore. If the item is already present, | 277 | * Store an item in the namestore. If the item is already present, |
279 | * the expiration time is updated to the max of the existing time and | 278 | * it is replaced with the new record. Use an empty array to |
280 | * the new time. This API is used by the authority of a zone. | 279 | * remove all records under the given name. |
281 | * FIXME: consider allowing to pass multiple records in one call! | ||
282 | * | 280 | * |
283 | * @param h handle to the namestore | 281 | * @param h handle to the namestore |
284 | * @param pkey private key of the zone | 282 | * @param pkey private key of the zone |
285 | * @param name name that is being mapped (at most 255 characters long) | 283 | * @param name name that is being mapped (at most 255 characters long) |
286 | * @param rd record data to store | 284 | * @param rd_count number of records in the 'rd' array |
287 | * @param cont continuation to call when done | 285 | * @param rd array of records with data to store |
288 | * @param cont_cls closure for cont | ||
289 | * @return handle to abort the request | ||
290 | */ | ||
291 | struct GNUNET_NAMESTORE_QueueEntry * | ||
292 | GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h, | ||
293 | const struct GNUNET_CRYPTO_EccPrivateKey *pkey, | ||
294 | const char *name, | ||
295 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
296 | GNUNET_NAMESTORE_ContinuationWithStatus cont, | ||
297 | void *cont_cls); | ||
298 | |||
299 | |||
300 | /** | ||
301 | * Explicitly remove some content from the database. The | ||
302 | * "cont"inuation will be called with status "GNUNET_OK" if content | ||
303 | * was removed, "GNUNET_NO" if no matching entry was found and | ||
304 | * "GNUNET_SYSERR" on all other types of errors. | ||
305 | * This API is used by the authority of a zone. | ||
306 | * | ||
307 | * @param h handle to the namestore | ||
308 | * @param pkey private key of the zone | ||
309 | * @param name name that is being mapped (at most 255 characters long) | ||
310 | * @param rd record data, remove specific record, NULL to remove the name and all records | ||
311 | * @param cont continuation to call when done | 286 | * @param cont continuation to call when done |
312 | * @param cont_cls closure for cont | 287 | * @param cont_cls closure for 'cont' |
313 | * @return handle to abort the request | 288 | * @return handle to abort the request |
314 | */ | 289 | */ |
315 | struct GNUNET_NAMESTORE_QueueEntry * | 290 | struct GNUNET_NAMESTORE_QueueEntry * |
316 | GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h, | 291 | GNUNET_NAMESTORE_record_put_by_authority (struct GNUNET_NAMESTORE_Handle *h, |
317 | const struct GNUNET_CRYPTO_EccPrivateKey *pkey, | 292 | const struct GNUNET_CRYPTO_EccPrivateKey *pkey, |
318 | const char *name, | 293 | const char *name, |
319 | const struct GNUNET_NAMESTORE_RecordData *rd, | 294 | unsigned int rd_count, |
320 | GNUNET_NAMESTORE_ContinuationWithStatus cont, | 295 | const struct GNUNET_NAMESTORE_RecordData *rd, |
321 | void *cont_cls); | 296 | GNUNET_NAMESTORE_ContinuationWithStatus cont, |
297 | void *cont_cls); | ||
322 | 298 | ||
323 | 299 | ||
324 | /** | 300 | /** |
@@ -341,7 +317,7 @@ typedef void (*GNUNET_NAMESTORE_RecordProcessor) (void *cls, | |||
341 | const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key, | 317 | const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key, |
342 | struct GNUNET_TIME_Absolute freshness, | 318 | struct GNUNET_TIME_Absolute freshness, |
343 | const char *name, | 319 | const char *name, |
344 | unsigned int rd_len, | 320 | unsigned int rd_count, |
345 | const struct GNUNET_NAMESTORE_RecordData *rd, | 321 | const struct GNUNET_NAMESTORE_RecordData *rd, |
346 | const struct GNUNET_CRYPTO_EccSignature *signature); | 322 | const struct GNUNET_CRYPTO_EccSignature *signature); |
347 | 323 | ||
@@ -462,6 +438,64 @@ GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it); | |||
462 | 438 | ||
463 | 439 | ||
464 | /** | 440 | /** |
441 | * Handle for a monitoring activity. | ||
442 | */ | ||
443 | struct GNUNET_NAMESTORE_ZoneMonitor; | ||
444 | |||
445 | |||
446 | /** | ||
447 | * Function called whenever the records for a given name changed. | ||
448 | * | ||
449 | * @param cls closure | ||
450 | * @param was_removed GNUNET_NO if the record was added, GNUNET_YES if it was removed | ||
451 | * @param freshness when does the corresponding block in the DHT expire (until | ||
452 | * when should we never do a DHT lookup for the same name again)?; | ||
453 | * GNUNET_TIME_UNIT_ZERO_ABS if there are no records of any type in the namestore, | ||
454 | * or the expiration time of the block in the namestore (even if there are zero | ||
455 | * records matching the desired record type) | ||
456 | * @param name name that is being mapped (at most 255 characters long) | ||
457 | * @param rd_count number of entries in 'rd' array | ||
458 | * @param rd array of records with data to store | ||
459 | * @param signature signature of the record block | ||
460 | */ | ||
461 | typedef void (*GNUNET_NAMESTORE_RecordMonitor)(void *cls, | ||
462 | int was_removed, | ||
463 | const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key, | ||
464 | struct GNUNET_TIME_Absolute freshness, | ||
465 | const char *name, | ||
466 | unsigned int rd_len, | ||
467 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
468 | const struct GNUNET_CRYPTO_EccSignature *signature); | ||
469 | |||
470 | |||
471 | /** | ||
472 | * Begin monitoring a zone for changes. Will first call the 'monitor' function | ||
473 | * on all existing records in the selected zone(s) and then call it whenever | ||
474 | * a record changes. | ||
475 | * | ||
476 | * @param cfg configuration to use to connect to namestore | ||
477 | * @param zone zone to monitor, NULL for all zones | ||
478 | * @param monitor function to call on zone changes | ||
479 | * @param monitor_cls closure for 'monitor' | ||
480 | * @return handle to stop monitoring | ||
481 | */ | ||
482 | struct GNUNET_NAMESTORE_ZoneMonitor * | ||
483 | GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
484 | const struct GNUNET_CRYPTO_ShortHashCode *zone, | ||
485 | GNUNET_NAMESTORE_RecordMonitor monitor, | ||
486 | void *monitor_cls); | ||
487 | |||
488 | |||
489 | /** | ||
490 | * Stop monitoring a zone for changes. | ||
491 | * | ||
492 | * @param zm handle to the monitor activity to stop | ||
493 | */ | ||
494 | void | ||
495 | GNUNET_NAMESTORE_zone_monitor_stop (struct GNUNET_NAMESTORE_ZoneMonitor *zm); | ||
496 | |||
497 | |||
498 | /** | ||
465 | * Cancel a namestore operation. The final callback from the | 499 | * Cancel a namestore operation. The final callback from the |
466 | * operation must not have been done yet. Must be called on any | 500 | * operation must not have been done yet. Must be called on any |
467 | * namestore operation that has not yet completed prior to calling | 501 | * namestore operation that has not yet completed prior to calling |
@@ -473,7 +507,6 @@ void | |||
473 | GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe); | 507 | GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe); |
474 | 508 | ||
475 | 509 | ||
476 | |||
477 | /* convenience APIs for serializing / deserializing GNS records */ | 510 | /* convenience APIs for serializing / deserializing GNS records */ |
478 | 511 | ||
479 | /** | 512 | /** |
@@ -579,6 +612,7 @@ GNUNET_NAMESTORE_number_to_typename (uint32_t type); | |||
579 | /** | 612 | /** |
580 | * Test if a given record is expired. | 613 | * Test if a given record is expired. |
581 | * | 614 | * |
615 | * @param rd record to test | ||
582 | * @return GNUNET_YES if the record is expired, | 616 | * @return GNUNET_YES if the record is expired, |
583 | * GNUNET_NO if not | 617 | * GNUNET_NO if not |
584 | */ | 618 | */ |
diff --git a/src/regex/plugin_block_regex.c b/src/regex/plugin_block_regex.c index e17b34d33..9eeb13190 100644 --- a/src/regex/plugin_block_regex.c +++ b/src/regex/plugin_block_regex.c | |||
@@ -80,7 +80,7 @@ rdebug (void *cls, | |||
80 | */ | 80 | */ |
81 | static enum GNUNET_BLOCK_EvaluationResult | 81 | static enum GNUNET_BLOCK_EvaluationResult |
82 | evaluate_block_regex (void *cls, enum GNUNET_BLOCK_Type type, | 82 | evaluate_block_regex (void *cls, enum GNUNET_BLOCK_Type type, |
83 | const struct GNUNET_HashCode * query, | 83 | const struct GNUNET_HashCode *query, |
84 | struct GNUNET_CONTAINER_BloomFilter **bf, | 84 | struct GNUNET_CONTAINER_BloomFilter **bf, |
85 | int32_t bf_mutator, const void *xquery, | 85 | int32_t bf_mutator, const void *xquery, |
86 | size_t xquery_size, const void *reply_block, | 86 | size_t xquery_size, const void *reply_block, |
@@ -106,15 +106,16 @@ evaluate_block_regex (void *cls, enum GNUNET_BLOCK_Type type, | |||
106 | 106 | ||
107 | GNUNET_break_op (0); | 107 | GNUNET_break_op (0); |
108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
109 | "Block with no xquery, key: %s, %u edges\n", | 109 | "Block with no xquery, query: %s, %u edges\n", |
110 | GNUNET_h2s (&rblock->key), | 110 | GNUNET_h2s (query), |
111 | ntohl (rblock->n_edges)); | 111 | ntohl (rblock->n_edges)); |
112 | REGEX_BLOCK_iterate (rblock, reply_block_size, &rdebug, NULL); | 112 | REGEX_BLOCK_iterate (rblock, reply_block_size, &rdebug, NULL); |
113 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 113 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
114 | } | 114 | } |
115 | switch (REGEX_BLOCK_check (reply_block, | 115 | switch (REGEX_BLOCK_check (reply_block, |
116 | reply_block_size, | 116 | reply_block_size, |
117 | xquery)) | 117 | query, |
118 | xquery)) | ||
118 | { | 119 | { |
119 | case GNUNET_SYSERR: | 120 | case GNUNET_SYSERR: |
120 | GNUNET_break_op(0); | 121 | GNUNET_break_op(0); |
@@ -276,12 +277,15 @@ block_plugin_regex_get_key (void *cls, enum GNUNET_BLOCK_Type type, | |||
276 | const void *block, size_t block_size, | 277 | const void *block, size_t block_size, |
277 | struct GNUNET_HashCode * key) | 278 | struct GNUNET_HashCode * key) |
278 | { | 279 | { |
280 | int ret; | ||
281 | |||
279 | switch (type) | 282 | switch (type) |
280 | { | 283 | { |
281 | case GNUNET_BLOCK_TYPE_REGEX: | 284 | case GNUNET_BLOCK_TYPE_REGEX: |
282 | GNUNET_assert (sizeof (struct RegexBlock) <= block_size); | 285 | ret = REGEX_BLOCK_get_key (block, block_size, |
283 | *key = ((struct RegexBlock *) block)->key; | 286 | key); |
284 | return GNUNET_OK; | 287 | GNUNET_break_op (GNUNET_OK == ret); |
288 | return ret; | ||
285 | case GNUNET_BLOCK_TYPE_REGEX_ACCEPT: | 289 | case GNUNET_BLOCK_TYPE_REGEX_ACCEPT: |
286 | GNUNET_assert (sizeof (struct RegexAccept) <= block_size); | 290 | GNUNET_assert (sizeof (struct RegexAccept) <= block_size); |
287 | *key = ((struct RegexAccept *) block)->key; | 291 | *key = ((struct RegexAccept *) block)->key; |
diff --git a/src/regex/regex_block_lib.c b/src/regex/regex_block_lib.c index bd3ec9679..01c591caa 100644 --- a/src/regex/regex_block_lib.c +++ b/src/regex/regex_block_lib.c | |||
@@ -40,8 +40,8 @@ | |||
40 | */ | 40 | */ |
41 | int | 41 | int |
42 | REGEX_BLOCK_check_proof (const char *proof, | 42 | REGEX_BLOCK_check_proof (const char *proof, |
43 | size_t proof_len, | 43 | size_t proof_len, |
44 | const struct GNUNET_HashCode *key) | 44 | const struct GNUNET_HashCode *key) |
45 | { | 45 | { |
46 | struct GNUNET_HashCode key_check; | 46 | struct GNUNET_HashCode key_check; |
47 | 47 | ||
@@ -50,7 +50,6 @@ REGEX_BLOCK_check_proof (const char *proof, | |||
50 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Proof check failed, was NULL.\n"); | 50 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Proof check failed, was NULL.\n"); |
51 | return GNUNET_NO; | 51 | return GNUNET_NO; |
52 | } | 52 | } |
53 | |||
54 | GNUNET_CRYPTO_hash (proof, proof_len, &key_check); | 53 | GNUNET_CRYPTO_hash (proof, proof_len, &key_check); |
55 | return (0 == | 54 | return (0 == |
56 | GNUNET_CRYPTO_hash_cmp (key, &key_check)) ? GNUNET_OK : GNUNET_NO; | 55 | GNUNET_CRYPTO_hash_cmp (key, &key_check)) ? GNUNET_OK : GNUNET_NO; |
@@ -72,10 +71,6 @@ struct CheckEdgeContext | |||
72 | */ | 71 | */ |
73 | int found; | 72 | int found; |
74 | 73 | ||
75 | /** | ||
76 | * Key of the block we are iterating (for debug purposes). | ||
77 | */ | ||
78 | char *key; | ||
79 | }; | 74 | }; |
80 | 75 | ||
81 | 76 | ||
@@ -99,7 +94,7 @@ check_edge (void *cls, | |||
99 | 94 | ||
100 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 95 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
101 | "edge %.*s [%u]: %s->%s\n", | 96 | "edge %.*s [%u]: %s->%s\n", |
102 | (int) len, token, len, ctx->key, GNUNET_h2s(key)); | 97 | (int) len, token, len, GNUNET_h2s(key)); |
103 | if (NULL == ctx->xquery) | 98 | if (NULL == ctx->xquery) |
104 | return GNUNET_YES; | 99 | return GNUNET_YES; |
105 | if (strlen (ctx->xquery) < len) | 100 | if (strlen (ctx->xquery) < len) |
@@ -115,6 +110,7 @@ check_edge (void *cls, | |||
115 | * | 110 | * |
116 | * @param block The start of the block. | 111 | * @param block The start of the block. |
117 | * @param size The size of the block. | 112 | * @param size The size of the block. |
113 | * @param query the query for the block | ||
118 | * @param xquery String describing the edge we are looking for. | 114 | * @param xquery String describing the edge we are looking for. |
119 | * Can be NULL in case this is a put block. | 115 | * Can be NULL in case this is a put block. |
120 | * | 116 | * |
@@ -125,34 +121,33 @@ check_edge (void *cls, | |||
125 | int | 121 | int |
126 | REGEX_BLOCK_check (const struct RegexBlock *block, | 122 | REGEX_BLOCK_check (const struct RegexBlock *block, |
127 | size_t size, | 123 | size_t size, |
124 | const struct GNUNET_HashCode *query, | ||
128 | const char *xquery) | 125 | const char *xquery) |
129 | { | 126 | { |
130 | struct CheckEdgeContext ctx; | 127 | struct CheckEdgeContext ctx; |
131 | int res; | 128 | int res; |
132 | uint32_t len; | 129 | uint16_t len; |
133 | 130 | ||
134 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 131 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
135 | "Checking block with xquery `%s'\n", | 132 | "Checking block with xquery `%s'\n", |
136 | NULL != xquery ? xquery : "NULL"); | 133 | NULL != xquery ? xquery : "NULL"); |
137 | len = ntohl (block->n_proof); | 134 | len = ntohs (block->proof_len); |
138 | if (size < sizeof (struct RegexBlock) + len) | 135 | if (size < sizeof (struct RegexBlock) + len) |
139 | { | 136 | { |
140 | GNUNET_break_op (0); | 137 | GNUNET_break_op (0); |
141 | return GNUNET_SYSERR; | 138 | return GNUNET_SYSERR; |
142 | } | 139 | } |
143 | if (GNUNET_OK != REGEX_BLOCK_check_proof ((const char *) &block[1], len, &block->key)) | 140 | if (GNUNET_OK != REGEX_BLOCK_check_proof ((const char *) &block[1], len, query)) |
144 | { | 141 | { |
145 | GNUNET_break_op (0); | 142 | GNUNET_break_op (0); |
146 | return GNUNET_SYSERR; | 143 | return GNUNET_SYSERR; |
147 | } | 144 | } |
148 | if ( (GNUNET_YES == ntohl (block->accepting)) && | 145 | if ( (GNUNET_YES == ntohs (block->is_accepting)) && |
149 | ( (NULL == xquery) || ('\0' == xquery[0]) ) ) | 146 | ( (NULL == xquery) || ('\0' == xquery[0]) ) ) |
150 | return GNUNET_OK; | 147 | return GNUNET_OK; |
151 | ctx.xquery = xquery; | 148 | ctx.xquery = xquery; |
152 | ctx.found = GNUNET_NO; | 149 | ctx.found = GNUNET_NO; |
153 | ctx.key = GNUNET_strdup (GNUNET_h2s (&block->key)); | ||
154 | res = REGEX_BLOCK_iterate (block, size, &check_edge, &ctx); | 150 | res = REGEX_BLOCK_iterate (block, size, &check_edge, &ctx); |
155 | GNUNET_free (ctx.key); | ||
156 | if (GNUNET_SYSERR == res) | 151 | if (GNUNET_SYSERR == res) |
157 | return GNUNET_SYSERR; | 152 | return GNUNET_SYSERR; |
158 | if (NULL == xquery) | 153 | if (NULL == xquery) |
@@ -162,6 +157,32 @@ REGEX_BLOCK_check (const struct RegexBlock *block, | |||
162 | 157 | ||
163 | 158 | ||
164 | /** | 159 | /** |
160 | * Obtain the key that a particular block is to be stored under. | ||
161 | * | ||
162 | * @param block block to get the key from | ||
163 | * @param block_len number of bytes in block | ||
164 | * @param query where to store the key | ||
165 | * @return GNUNET_OK on success, GNUNET_SYSERR if the block is malformed | ||
166 | */ | ||
167 | int | ||
168 | REGEX_BLOCK_get_key (const struct RegexBlock *block, | ||
169 | size_t block_len, | ||
170 | struct GNUNET_HashCode *key) | ||
171 | { | ||
172 | uint16_t len; | ||
173 | |||
174 | len = ntohs (block->proof_len); | ||
175 | if (block_len < sizeof (struct RegexBlock) + len) | ||
176 | { | ||
177 | GNUNET_break_op (0); | ||
178 | return GNUNET_SYSERR; | ||
179 | } | ||
180 | GNUNET_CRYPTO_hash (&block[1], len, key); | ||
181 | return GNUNET_OK; | ||
182 | } | ||
183 | |||
184 | |||
185 | /** | ||
165 | * Iterate over all edges of a block of a regex state. | 186 | * Iterate over all edges of a block of a regex state. |
166 | * | 187 | * |
167 | * @param block Block to iterate over. | 188 | * @param block Block to iterate over. |
@@ -179,9 +200,9 @@ REGEX_BLOCK_check (const struct RegexBlock *block, | |||
179 | */ | 200 | */ |
180 | int | 201 | int |
181 | REGEX_BLOCK_iterate (const struct RegexBlock *block, | 202 | REGEX_BLOCK_iterate (const struct RegexBlock *block, |
182 | size_t size, | 203 | size_t size, |
183 | REGEX_INTERNAL_EgdeIterator iterator, | 204 | REGEX_INTERNAL_EgdeIterator iterator, |
184 | void *iter_cls) | 205 | void *iter_cls) |
185 | { | 206 | { |
186 | struct RegexEdge *edge; | 207 | struct RegexEdge *edge; |
187 | unsigned int n; | 208 | unsigned int n; |
@@ -196,7 +217,7 @@ REGEX_BLOCK_iterate (const struct RegexBlock *block, | |||
196 | GNUNET_break_op (0); | 217 | GNUNET_break_op (0); |
197 | return GNUNET_SYSERR; | 218 | return GNUNET_SYSERR; |
198 | } | 219 | } |
199 | n = ntohl (block->n_proof); | 220 | n = ntohs (block->proof_len); |
200 | offset += n; | 221 | offset += n; |
201 | if (offset >= size) /* Is it safe to access the regex proof? */ | 222 | if (offset >= size) /* Is it safe to access the regex proof? */ |
202 | { | 223 | { |
@@ -208,7 +229,7 @@ REGEX_BLOCK_iterate (const struct RegexBlock *block, | |||
208 | n = ntohl (block->n_edges); | 229 | n = ntohl (block->n_edges); |
209 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 230 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
210 | "Start iterating block of size %u, proof %u, off %u edges %u\n", | 231 | "Start iterating block of size %u, proof %u, off %u edges %u\n", |
211 | size, ntohl (block->n_proof), offset, n); | 232 | size, ntohs (block->proof_len), offset, n); |
212 | /* aux always points at the end of the previous block */ | 233 | /* aux always points at the end of the previous block */ |
213 | for (i = 0; i < n; i++) | 234 | for (i = 0; i < n; i++) |
214 | { | 235 | { |
@@ -257,15 +278,16 @@ REGEX_BLOCK_iterate (const struct RegexBlock *block, | |||
257 | * @param proof proof string for the block | 278 | * @param proof proof string for the block |
258 | * @param num_edges number of edges in the block | 279 | * @param num_edges number of edges in the block |
259 | * @param edges the edges of the block | 280 | * @param edges the edges of the block |
260 | * @return the regex block | 281 | * @param accepting is this an accepting state |
282 | * @param rsize set to the size of the returned block (OUT-only) | ||
283 | * @return the regex block, NULL on error | ||
261 | */ | 284 | */ |
262 | struct RegexBlock * | 285 | struct RegexBlock * |
263 | REGEX_BLOCK_create (const struct GNUNET_HashCode *key, | 286 | REGEX_BLOCK_create (const char *proof, |
264 | const char *proof, | 287 | unsigned int num_edges, |
265 | unsigned int num_edges, | 288 | const struct REGEX_BLOCK_Edge *edges, |
266 | const struct REGEX_BLOCK_Edge *edges, | 289 | int accepting, |
267 | int accepting, | 290 | size_t *rsize) |
268 | size_t *rsize) | ||
269 | { | 291 | { |
270 | struct RegexBlock *block; | 292 | struct RegexBlock *block; |
271 | struct RegexEdge *block_edge; | 293 | struct RegexEdge *block_edge; |
@@ -275,13 +297,17 @@ REGEX_BLOCK_create (const struct GNUNET_HashCode *key, | |||
275 | unsigned int offset; | 297 | unsigned int offset; |
276 | char *aux; | 298 | char *aux; |
277 | 299 | ||
278 | len = strlen(proof); | 300 | len = strlen (proof); |
301 | if (len > UINT16_MAX) | ||
302 | { | ||
303 | GNUNET_break (0); | ||
304 | return NULL; | ||
305 | } | ||
279 | size = sizeof (struct RegexBlock) + len; | 306 | size = sizeof (struct RegexBlock) + len; |
280 | block = GNUNET_malloc (size); | 307 | block = GNUNET_malloc (size); |
281 | block->key = *key; | 308 | block->proof_len = htons (len); |
282 | block->n_proof = htonl (len); | ||
283 | block->n_edges = htonl (num_edges); | 309 | block->n_edges = htonl (num_edges); |
284 | block->accepting = htonl (accepting); | 310 | block->is_accepting = htons (accepting); |
285 | 311 | ||
286 | /* Store the proof at the end of the block. */ | 312 | /* Store the proof at the end of the block. */ |
287 | aux = (char *) &block[1]; | 313 | aux = (char *) &block[1]; |
diff --git a/src/regex/regex_block_lib.h b/src/regex/regex_block_lib.h index 985296b4f..dec025205 100644 --- a/src/regex/regex_block_lib.h +++ b/src/regex/regex_block_lib.h | |||
@@ -68,8 +68,8 @@ struct REGEX_BLOCK_Edge | |||
68 | */ | 68 | */ |
69 | int | 69 | int |
70 | REGEX_BLOCK_check_proof (const char *proof, | 70 | REGEX_BLOCK_check_proof (const char *proof, |
71 | size_t proof_len, | 71 | size_t proof_len, |
72 | const struct GNUNET_HashCode *key); | 72 | const struct GNUNET_HashCode *key); |
73 | 73 | ||
74 | 74 | ||
75 | /** | 75 | /** |
@@ -77,6 +77,7 @@ REGEX_BLOCK_check_proof (const char *proof, | |||
77 | * | 77 | * |
78 | * @param block The start of the block. | 78 | * @param block The start of the block. |
79 | * @param size The size of the block. | 79 | * @param size The size of the block. |
80 | * @param query the query for the block | ||
80 | * @param xquery String describing the edge we are looking for. | 81 | * @param xquery String describing the edge we are looking for. |
81 | * Can be NULL in case this is a put block. | 82 | * Can be NULL in case this is a put block. |
82 | * | 83 | * |
@@ -87,6 +88,7 @@ REGEX_BLOCK_check_proof (const char *proof, | |||
87 | int | 88 | int |
88 | REGEX_BLOCK_check (const struct RegexBlock *block, | 89 | REGEX_BLOCK_check (const struct RegexBlock *block, |
89 | size_t size, | 90 | size_t size, |
91 | const struct GNUNET_HashCode *query, | ||
90 | const char *xquery); | 92 | const char *xquery); |
91 | 93 | ||
92 | 94 | ||
@@ -130,6 +132,20 @@ REGEX_BLOCK_iterate (const struct RegexBlock *block, | |||
130 | REGEX_INTERNAL_EgdeIterator iterator, | 132 | REGEX_INTERNAL_EgdeIterator iterator, |
131 | void *iter_cls); | 133 | void *iter_cls); |
132 | 134 | ||
135 | /** | ||
136 | * Obtain the key that a particular block is to be stored under. | ||
137 | * | ||
138 | * @param block block to get the key from | ||
139 | * @param block_len number of bytes in block | ||
140 | * @param query where to store the key | ||
141 | * @return GNUNET_OK on success, GNUNET_SYSERR if the block is malformed | ||
142 | */ | ||
143 | int | ||
144 | REGEX_BLOCK_get_key (const struct RegexBlock *block, | ||
145 | size_t block_len, | ||
146 | struct GNUNET_HashCode *key); | ||
147 | |||
148 | |||
133 | 149 | ||
134 | /** | 150 | /** |
135 | * Construct a regex block to be stored in the DHT. | 151 | * Construct a regex block to be stored in the DHT. |
@@ -137,15 +153,16 @@ REGEX_BLOCK_iterate (const struct RegexBlock *block, | |||
137 | * @param proof proof string for the block | 153 | * @param proof proof string for the block |
138 | * @param num_edges number of edges in the block | 154 | * @param num_edges number of edges in the block |
139 | * @param edges the edges of the block | 155 | * @param edges the edges of the block |
140 | * @return the regex block | 156 | * @param accepting is this an accepting state |
157 | * @param rsize set to the size of the returned block (OUT-only) | ||
158 | * @return the regex block, NULL on error | ||
141 | */ | 159 | */ |
142 | struct RegexBlock * | 160 | struct RegexBlock * |
143 | REGEX_BLOCK_create (const struct GNUNET_HashCode *key, | 161 | REGEX_BLOCK_create (const char *proof, |
144 | const char *proof, | 162 | unsigned int num_edges, |
145 | unsigned int num_edges, | 163 | const struct REGEX_BLOCK_Edge *edges, |
146 | const struct REGEX_BLOCK_Edge *edges, | 164 | int accepting, |
147 | int accepting, | 165 | size_t *rsize); |
148 | size_t *rsize); | ||
149 | 166 | ||
150 | 167 | ||
151 | #if 0 /* keep Emacsens' auto-indent happy */ | 168 | #if 0 /* keep Emacsens' auto-indent happy */ |
diff --git a/src/regex/regex_internal_dht.c b/src/regex/regex_internal_dht.c index af775ef95..e7259edcc 100644 --- a/src/regex/regex_internal_dht.c +++ b/src/regex/regex_internal_dht.c | |||
@@ -123,10 +123,10 @@ regex_iterator (void *cls, | |||
123 | DHT_TTL, | 123 | DHT_TTL, |
124 | NULL, NULL); | 124 | NULL, NULL); |
125 | } | 125 | } |
126 | block = REGEX_BLOCK_create (key, proof, | 126 | block = REGEX_BLOCK_create (proof, |
127 | num_edges, edges, | 127 | num_edges, edges, |
128 | accepting, | 128 | accepting, |
129 | &size); | 129 | &size); |
130 | (void) | 130 | (void) |
131 | GNUNET_DHT_put (h->dht, key, | 131 | GNUNET_DHT_put (h->dht, key, |
132 | DHT_REPLICATION, | 132 | DHT_REPLICATION, |
@@ -420,20 +420,20 @@ dht_get_string_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
420 | GNUNET_break ( | 420 | GNUNET_break ( |
421 | GNUNET_OK == | 421 | GNUNET_OK == |
422 | GNUNET_CONTAINER_multihashmap_put (info->dht_get_results, | 422 | GNUNET_CONTAINER_multihashmap_put (info->dht_get_results, |
423 | &((struct RegexBlock *)copy)->key, copy, | 423 | key, copy, |
424 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE) | 424 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE) |
425 | ); | 425 | ); |
426 | len = strlen (info->description); | 426 | len = strlen (info->description); |
427 | if (len == ctx->position) // String processed | 427 | if (len == ctx->position) // String processed |
428 | { | 428 | { |
429 | if (GNUNET_YES == ntohl (block->accepting)) | 429 | if (GNUNET_YES == ntohs (block->is_accepting)) |
430 | { | 430 | { |
431 | regex_find_path (key, ctx); | 431 | regex_find_path (key, ctx); |
432 | } | 432 | } |
433 | else | 433 | else |
434 | { | 434 | { |
435 | LOG (GNUNET_ERROR_TYPE_INFO, " block not accepting!\n"); | 435 | LOG (GNUNET_ERROR_TYPE_INFO, "block not accepting!\n"); |
436 | // FIXME REGEX this block not successful, wait for more? start timeout? | 436 | /* FIXME REGEX this block not successful, wait for more? start timeout? */ |
437 | } | 437 | } |
438 | return; | 438 | return; |
439 | } | 439 | } |
@@ -457,7 +457,7 @@ regex_result_iterator (void *cls, | |||
457 | struct RegexBlock *block = value; | 457 | struct RegexBlock *block = value; |
458 | struct RegexSearchContext *ctx = cls; | 458 | struct RegexSearchContext *ctx = cls; |
459 | 459 | ||
460 | if (GNUNET_YES == ntohl(block->accepting) && | 460 | if (GNUNET_YES == ntohs (block->is_accepting) && |
461 | ctx->position == strlen (ctx->info->description)) | 461 | ctx->position == strlen (ctx->info->description)) |
462 | { | 462 | { |
463 | LOG (GNUNET_ERROR_TYPE_INFO, " * Found accepting known block\n"); | 463 | LOG (GNUNET_ERROR_TYPE_INFO, " * Found accepting known block\n"); |
@@ -466,7 +466,7 @@ regex_result_iterator (void *cls, | |||
466 | } | 466 | } |
467 | LOG (GNUNET_ERROR_TYPE_DEBUG, "* %u, %u, [%u]\n", | 467 | LOG (GNUNET_ERROR_TYPE_DEBUG, "* %u, %u, [%u]\n", |
468 | ctx->position, strlen(ctx->info->description), | 468 | ctx->position, strlen(ctx->info->description), |
469 | ntohl(block->accepting)); | 469 | ntohs (block->is_accepting)); |
470 | 470 | ||
471 | regex_next_edge (block, SIZE_MAX, ctx); | 471 | regex_next_edge (block, SIZE_MAX, ctx); |
472 | 472 | ||
@@ -646,7 +646,7 @@ REGEX_INTERNAL_search (struct GNUNET_DHT_Handle *dht, | |||
646 | h->callback_cls = callback_cls; | 646 | h->callback_cls = callback_cls; |
647 | h->stats = stats; | 647 | h->stats = stats; |
648 | h->dht_get_handles = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); | 648 | h->dht_get_handles = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); |
649 | h->dht_get_results = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_YES); | 649 | h->dht_get_results = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); |
650 | 650 | ||
651 | /* Initialize context */ | 651 | /* Initialize context */ |
652 | len = strlen (string); | 652 | len = strlen (string); |
diff --git a/src/set/gnunet-service-set.h b/src/set/gnunet-service-set.h index 86dd0cfc0..26b1d361e 100644 --- a/src/set/gnunet-service-set.h +++ b/src/set/gnunet-service-set.h | |||
@@ -196,7 +196,8 @@ struct Incoming; | |||
196 | /** | 196 | /** |
197 | * Different types a tunnel can be. | 197 | * Different types a tunnel can be. |
198 | */ | 198 | */ |
199 | enum TunnelContextType { | 199 | enum TunnelContextType |
200 | { | ||
200 | /** | 201 | /** |
201 | * Tunnel is waiting for a set request from the tunnel, | 202 | * Tunnel is waiting for a set request from the tunnel, |
202 | * or for the ack/nack of the client for a received request. | 203 | * or for the ack/nack of the client for a received request. |
@@ -237,6 +238,7 @@ union TunnelContextData | |||
237 | struct IntersectionEvaluateOperation *intersection_op; | 238 | struct IntersectionEvaluateOperation *intersection_op; |
238 | }; | 239 | }; |
239 | 240 | ||
241 | |||
240 | /** | 242 | /** |
241 | * Information about a tunnel we are connected to. | 243 | * Information about a tunnel we are connected to. |
242 | * Used as tunnel context with mesh. | 244 | * Used as tunnel context with mesh. |