diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-06-26 12:16:12 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-06-26 12:16:12 +0000 |
commit | 248fc3245a98731cf6fbb1bf460cd4e2e2d56de8 (patch) | |
tree | c0606c24a1c74d5f507d267b03d267a5cfaf4009 /src | |
parent | c0101989bb0864a3688f57370e712c91c14ab1cd (diff) | |
download | gnunet-248fc3245a98731cf6fbb1bf460cd4e2e2d56de8.tar.gz gnunet-248fc3245a98731cf6fbb1bf460cd4e2e2d56de8.zip |
-moving REGEX_INTERNAL_check_proof to libgnunetregexblock, integrating proof check into block plugin
Diffstat (limited to 'src')
-rw-r--r-- | src/regex/Makefile.am | 2 | ||||
-rw-r--r-- | src/regex/regex_block_lib.c | 42 | ||||
-rw-r--r-- | src/regex/regex_block_lib.h | 25 | ||||
-rw-r--r-- | src/regex/regex_internal.c | 25 | ||||
-rw-r--r-- | src/regex/regex_internal_dht.c | 12 | ||||
-rw-r--r-- | src/regex/regex_internal_lib.h | 15 | ||||
-rw-r--r-- | src/regex/test_regex_iterate_api.c | 6 |
7 files changed, 67 insertions, 60 deletions
diff --git a/src/regex/Makefile.am b/src/regex/Makefile.am index 2c20c5904..fac89e38d 100644 --- a/src/regex/Makefile.am +++ b/src/regex/Makefile.am | |||
@@ -183,8 +183,8 @@ test_regex_iterate_api_SOURCES = \ | |||
183 | test_regex_iterate_api.c | 183 | test_regex_iterate_api.c |
184 | test_regex_iterate_api_LDADD = -lm \ | 184 | test_regex_iterate_api_LDADD = -lm \ |
185 | $(top_builddir)/src/regex/libgnunetregex_internal.a \ | 185 | $(top_builddir)/src/regex/libgnunetregex_internal.a \ |
186 | $(top_builddir)/src/dht/libgnunetdht.la \ | ||
187 | $(top_builddir)/src/regex/libgnunetregexblock.la \ | 186 | $(top_builddir)/src/regex/libgnunetregexblock.la \ |
187 | $(top_builddir)/src/dht/libgnunetdht.la \ | ||
188 | $(top_builddir)/src/util/libgnunetutil.la | 188 | $(top_builddir)/src/util/libgnunetutil.la |
189 | 189 | ||
190 | test_regex_proofs_SOURCES = \ | 190 | test_regex_proofs_SOURCES = \ |
diff --git a/src/regex/regex_block_lib.c b/src/regex/regex_block_lib.c index 3a18a731f..83b61b7c6 100644 --- a/src/regex/regex_block_lib.c +++ b/src/regex/regex_block_lib.c | |||
@@ -28,6 +28,35 @@ | |||
28 | 28 | ||
29 | #define LOG(kind,...) GNUNET_log_from (kind,"regex-bck",__VA_ARGS__) | 29 | #define LOG(kind,...) GNUNET_log_from (kind,"regex-bck",__VA_ARGS__) |
30 | 30 | ||
31 | |||
32 | /** | ||
33 | * Check if the given 'proof' matches the given 'key'. | ||
34 | * | ||
35 | * @param proof partial regex of a state | ||
36 | * @param proof_len number of bytes in 'proof' | ||
37 | * @param key hash of a state. | ||
38 | * | ||
39 | * @return GNUNET_OK if the proof is valid for the given key. | ||
40 | */ | ||
41 | int | ||
42 | REGEX_INTERNAL_check_proof (const char *proof, | ||
43 | size_t proof_len, | ||
44 | const struct GNUNET_HashCode *key) | ||
45 | { | ||
46 | struct GNUNET_HashCode key_check; | ||
47 | |||
48 | if ( (NULL == proof) || (NULL == key)) | ||
49 | { | ||
50 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Proof check failed, was NULL.\n"); | ||
51 | return GNUNET_NO; | ||
52 | } | ||
53 | |||
54 | GNUNET_CRYPTO_hash (proof, proof_len, &key_check); | ||
55 | return (0 == | ||
56 | GNUNET_CRYPTO_hash_cmp (key, &key_check)) ? GNUNET_OK : GNUNET_NO; | ||
57 | } | ||
58 | |||
59 | |||
31 | /** | 60 | /** |
32 | * Struct to keep track of the xquery while iterating all the edges in a block. | 61 | * Struct to keep track of the xquery while iterating all the edges in a block. |
33 | */ | 62 | */ |
@@ -100,11 +129,22 @@ REGEX_BLOCK_check (const struct RegexBlock *block, | |||
100 | { | 129 | { |
101 | struct CheckEdgeContext ctx; | 130 | struct CheckEdgeContext ctx; |
102 | int res; | 131 | int res; |
132 | uint32_t len; | ||
103 | 133 | ||
104 | // FIXME: fails to check the proof! | ||
105 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 134 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
106 | "Checking block with xquery `%s'\n", | 135 | "Checking block with xquery `%s'\n", |
107 | NULL != xquery ? xquery : "NULL"); | 136 | NULL != xquery ? xquery : "NULL"); |
137 | len = ntohl (block->n_proof); | ||
138 | if (size < sizeof (struct RegexBlock) + len) | ||
139 | { | ||
140 | GNUNET_break_op (0); | ||
141 | return GNUNET_SYSERR; | ||
142 | } | ||
143 | if (GNUNET_OK != REGEX_INTERNAL_check_proof ((const char *) &block[1], len, &block->key)) | ||
144 | { | ||
145 | GNUNET_break_op (0); | ||
146 | return GNUNET_SYSERR; | ||
147 | } | ||
108 | if ( (GNUNET_YES == ntohl (block->accepting)) && | 148 | if ( (GNUNET_YES == ntohl (block->accepting)) && |
109 | ( (NULL == xquery) || ('\0' == xquery[0]) ) ) | 149 | ( (NULL == xquery) || ('\0' == xquery[0]) ) ) |
110 | return GNUNET_OK; | 150 | return GNUNET_OK; |
diff --git a/src/regex/regex_block_lib.h b/src/regex/regex_block_lib.h index 79bd20a1e..fb1c91353 100644 --- a/src/regex/regex_block_lib.h +++ b/src/regex/regex_block_lib.h | |||
@@ -58,6 +58,21 @@ struct REGEX_BLOCK_Edge | |||
58 | 58 | ||
59 | 59 | ||
60 | /** | 60 | /** |
61 | * Check if the given 'proof' matches the given 'key'. | ||
62 | * | ||
63 | * @param proof partial regex of a state | ||
64 | * @param proof_len number of bytes in 'proof' | ||
65 | * @param key hash of a state. | ||
66 | * | ||
67 | * @return GNUNET_OK if the proof is valid for the given key. | ||
68 | */ | ||
69 | int | ||
70 | REGEX_INTERNAL_check_proof (const char *proof, | ||
71 | size_t proof_len, | ||
72 | const struct GNUNET_HashCode *key); | ||
73 | |||
74 | |||
75 | /** | ||
61 | * Check if the regex block is well formed, including all edges. | 76 | * Check if the regex block is well formed, including all edges. |
62 | * | 77 | * |
63 | * @param block The start of the block. | 78 | * @param block The start of the block. |
@@ -71,8 +86,8 @@ struct REGEX_BLOCK_Edge | |||
71 | */ | 86 | */ |
72 | int | 87 | int |
73 | REGEX_BLOCK_check (const struct RegexBlock *block, | 88 | REGEX_BLOCK_check (const struct RegexBlock *block, |
74 | size_t size, | 89 | size_t size, |
75 | const char *xquery); | 90 | const char *xquery); |
76 | 91 | ||
77 | 92 | ||
78 | /* FIXME: might want to use 'struct REGEX_BLOCK_Edge' here instead of 3 arguments! */ | 93 | /* FIXME: might want to use 'struct REGEX_BLOCK_Edge' here instead of 3 arguments! */ |
@@ -88,9 +103,9 @@ REGEX_BLOCK_check (const struct RegexBlock *block, | |||
88 | * @return GNUNET_YES if should keep iterating, GNUNET_NO otherwise. | 103 | * @return GNUNET_YES if should keep iterating, GNUNET_NO otherwise. |
89 | */ | 104 | */ |
90 | typedef int (*REGEX_INTERNAL_EgdeIterator)(void *cls, | 105 | typedef int (*REGEX_INTERNAL_EgdeIterator)(void *cls, |
91 | const char *token, | 106 | const char *token, |
92 | size_t len, | 107 | size_t len, |
93 | const struct GNUNET_HashCode *key); | 108 | const struct GNUNET_HashCode *key); |
94 | 109 | ||
95 | 110 | ||
96 | /** | 111 | /** |
diff --git a/src/regex/regex_internal.c b/src/regex/regex_internal.c index 059aaaed6..4ad27c441 100644 --- a/src/regex/regex_internal.c +++ b/src/regex/regex_internal.c | |||
@@ -3329,31 +3329,6 @@ REGEX_INTERNAL_get_first_key (const char *input_string, size_t string_len, | |||
3329 | 3329 | ||
3330 | 3330 | ||
3331 | /** | 3331 | /** |
3332 | * Check if the given 'proof' matches the given 'key'. | ||
3333 | * | ||
3334 | * @param proof partial regex of a state. | ||
3335 | * @param key hash of a state. | ||
3336 | * | ||
3337 | * @return GNUNET_OK if the proof is valid for the given key. | ||
3338 | */ | ||
3339 | int | ||
3340 | REGEX_INTERNAL_check_proof (const char *proof, const struct GNUNET_HashCode *key) | ||
3341 | { | ||
3342 | struct GNUNET_HashCode key_check; | ||
3343 | |||
3344 | if (NULL == proof || NULL == key) | ||
3345 | { | ||
3346 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Proof check failed, was NULL.\n"); | ||
3347 | return GNUNET_NO; | ||
3348 | } | ||
3349 | |||
3350 | GNUNET_CRYPTO_hash (proof, strlen (proof), &key_check); | ||
3351 | return (0 == | ||
3352 | GNUNET_CRYPTO_hash_cmp (key, &key_check)) ? GNUNET_OK : GNUNET_NO; | ||
3353 | } | ||
3354 | |||
3355 | |||
3356 | /** | ||
3357 | * Recursive function that calls the iterator for each synthetic start state. | 3332 | * Recursive function that calls the iterator for each synthetic start state. |
3358 | * | 3333 | * |
3359 | * @param min_len minimum length of the path in the graph. | 3334 | * @param min_len minimum length of the path in the graph. |
diff --git a/src/regex/regex_internal_dht.c b/src/regex/regex_internal_dht.c index bf15b9a96..af775ef95 100644 --- a/src/regex/regex_internal_dht.c +++ b/src/regex/regex_internal_dht.c | |||
@@ -423,18 +423,6 @@ dht_get_string_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
423 | &((struct RegexBlock *)copy)->key, copy, | 423 | &((struct RegexBlock *)copy)->key, copy, |
424 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE) | 424 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE) |
425 | ); | 425 | ); |
426 | len = ntohl (block->n_proof); | ||
427 | { | ||
428 | char proof[len + 1]; | ||
429 | |||
430 | memcpy (proof, &block[1], len); | ||
431 | proof[len] = '\0'; | ||
432 | if (GNUNET_OK != REGEX_INTERNAL_check_proof (proof, key)) | ||
433 | { | ||
434 | GNUNET_break_op (0); | ||
435 | return; | ||
436 | } | ||
437 | } | ||
438 | len = strlen (info->description); | 426 | len = strlen (info->description); |
439 | if (len == ctx->position) // String processed | 427 | if (len == ctx->position) // String processed |
440 | { | 428 | { |
diff --git a/src/regex/regex_internal_lib.h b/src/regex/regex_internal_lib.h index 1c8946449..3d4a1b65c 100644 --- a/src/regex/regex_internal_lib.h +++ b/src/regex/regex_internal_lib.h | |||
@@ -108,24 +108,11 @@ REGEX_INTERNAL_get_first_key (const char *input_string, size_t string_len, | |||
108 | 108 | ||
109 | 109 | ||
110 | /** | 110 | /** |
111 | * Check if the given 'proof' matches the given 'key'. | ||
112 | * | ||
113 | * @param proof partial regex of a state. | ||
114 | * @param key hash of a state. | ||
115 | * | ||
116 | * @return GNUNET_OK if the proof is valid for the given key. | ||
117 | */ | ||
118 | int | ||
119 | REGEX_INTERNAL_check_proof (const char *proof, | ||
120 | const struct GNUNET_HashCode *key); | ||
121 | |||
122 | |||
123 | /** | ||
124 | * Iterator callback function. | 111 | * Iterator callback function. |
125 | * | 112 | * |
126 | * @param cls closure. | 113 | * @param cls closure. |
127 | * @param key hash for current state. | 114 | * @param key hash for current state. |
128 | * @param proof proof for current state. | 115 | * @param proof proof for current state |
129 | * @param accepting GNUNET_YES if this is an accepting state, GNUNET_NO if not. | 116 | * @param accepting GNUNET_YES if this is an accepting state, GNUNET_NO if not. |
130 | * @param num_edges number of edges leaving current state. | 117 | * @param num_edges number of edges leaving current state. |
131 | * @param edges edges leaving current state. | 118 | * @param edges edges leaving current state. |
diff --git a/src/regex/test_regex_iterate_api.c b/src/regex/test_regex_iterate_api.c index fa94c58ab..060288897 100644 --- a/src/regex/test_regex_iterate_api.c +++ b/src/regex/test_regex_iterate_api.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <time.h> | 26 | #include <time.h> |
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "regex_internal_lib.h" | 28 | #include "regex_internal_lib.h" |
29 | #include "regex_block_lib.h" | ||
29 | #include "regex_internal.h" | 30 | #include "regex_internal.h" |
30 | 31 | ||
31 | /** | 32 | /** |
@@ -59,7 +60,8 @@ struct RegexStringPair | |||
59 | 60 | ||
60 | 61 | ||
61 | static void | 62 | static void |
62 | key_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof, | 63 | key_iterator (void *cls, const struct GNUNET_HashCode *key, |
64 | const char *proof, | ||
63 | int accepting, unsigned int num_edges, | 65 | int accepting, unsigned int num_edges, |
64 | const struct REGEX_BLOCK_Edge *edges) | 66 | const struct REGEX_BLOCK_Edge *edges) |
65 | { | 67 | { |
@@ -101,7 +103,7 @@ key_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof, | |||
101 | ctx->match_count++; | 103 | ctx->match_count++; |
102 | } | 104 | } |
103 | 105 | ||
104 | if (GNUNET_OK != REGEX_INTERNAL_check_proof (proof, key)) | 106 | if (GNUNET_OK != REGEX_INTERNAL_check_proof (proof, strlen (proof), key)) |
105 | { | 107 | { |
106 | ctx->error++; | 108 | ctx->error++; |
107 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 109 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |