aboutsummaryrefslogtreecommitdiff
path: root/src/regex
diff options
context:
space:
mode:
authorMaximilian Szengel <gnunet@maxsz.de>2013-08-19 19:56:49 +0000
committerMaximilian Szengel <gnunet@maxsz.de>2013-08-19 19:56:49 +0000
commit1492d04011bf60ec0c28a6d94977a105f6c3b15b (patch)
tree70d7bb792f33bc8c972e1022f7e28eed1a3b3324 /src/regex
parentb841c7123c01a61da81d48906119543ebc13a1b6 (diff)
downloadgnunet-1492d04011bf60ec0c28a6d94977a105f6c3b15b.tar.gz
gnunet-1492d04011bf60ec0c28a6d94977a105f6c3b15b.zip
Fix 'way too many REGEX PUTs' issue.
Diffstat (limited to 'src/regex')
-rw-r--r--src/regex/regex_internal.c14
-rw-r--r--src/regex/test_regex_iterate_api.c115
2 files changed, 87 insertions, 42 deletions
diff --git a/src/regex/regex_internal.c b/src/regex/regex_internal.c
index a1fab7694..eac420835 100644
--- a/src/regex/regex_internal.c
+++ b/src/regex/regex_internal.c
@@ -3437,17 +3437,19 @@ REGEX_INTERNAL_iterate_all_edges (struct REGEX_INTERNAL_Automaton *a,
3437 3437
3438 num_edges = state_get_edges (s, edges); 3438 num_edges = state_get_edges (s, edges);
3439 if ( ( (NULL != s->proof) && 3439 if ( ( (NULL != s->proof) &&
3440 (0 < strlen (s->proof)) ) || s->accepting) 3440 (GNUNET_REGEX_INITIAL_BYTES <= strlen (s->proof)) ) || s->accepting)
3441 iterator (iterator_cls, &s->hash, s->proof, 3441 iterator (iterator_cls, &s->hash, s->proof,
3442 s->accepting, 3442 s->accepting,
3443 num_edges, edges); 3443 num_edges, edges);
3444 s->marked = GNUNET_NO; 3444 s->marked = GNUNET_NO;
3445 } 3445 }
3446 3446
3447 iterate_initial_edge (GNUNET_REGEX_INITIAL_BYTES, 3447 iterate_initial_edge (1,
3448 GNUNET_REGEX_INITIAL_BYTES, 3448 GNUNET_REGEX_INITIAL_BYTES,
3449 NULL, a->start, 3449 NULL, a->start,
3450 iterator, iterator_cls); 3450 iterator, iterator_cls);
3451
3452
3451} 3453}
3452 3454
3453 3455
diff --git a/src/regex/test_regex_iterate_api.c b/src/regex/test_regex_iterate_api.c
index 69badb5d8..99652cb8b 100644
--- a/src/regex/test_regex_iterate_api.c
+++ b/src/regex/test_regex_iterate_api.c
@@ -46,16 +46,21 @@ struct IteratorContext
46 int error; 46 int error;
47 int should_save_graph; 47 int should_save_graph;
48 FILE *graph_filep; 48 FILE *graph_filep;
49 unsigned int string_count; 49 unsigned int valid_string_count;
50 char *const *strings; 50 char *const *valid_strings;
51 unsigned int match_count; 51 unsigned int match_count;
52 unsigned int invalid_string_count;
53 char *const *invalid_strings;
54 unsigned int invalid_match_count;
52}; 55};
53 56
54struct RegexStringPair 57struct RegexStringPair
55{ 58{
56 char *regex; 59 char *regex;
57 unsigned int string_count; 60 unsigned int valid_string_count;
58 char *strings[20]; 61 char *valid_strings[20];
62 unsigned int invalid_string_count;
63 char *invalid_strings[20];
59}; 64};
60 65
61 66
@@ -97,12 +102,19 @@ key_iterator (void *cls, const struct GNUNET_HashCode *key,
97 transition_counter++; 102 transition_counter++;
98 } 103 }
99 104
100 for (i = 0; i < ctx->string_count; i++) 105 for (i = 0; i < ctx->valid_string_count; i++)
101 { 106 {
102 if (0 == strcmp (proof, ctx->strings[i])) 107 if (0 == strcmp (proof, ctx->valid_strings[i]))
103 ctx->match_count++; 108 ctx->match_count++;
104 } 109 }
105 110
111 for (i = 0; i < ctx->invalid_string_count; i++)
112 {
113 if (0 == strcmp (proof, ctx->invalid_strings[i])) {
114 ctx->invalid_match_count++;
115 }
116 }
117
106 if (GNUNET_OK != REGEX_BLOCK_check_proof (proof, strlen (proof), key)) 118 if (GNUNET_OK != REGEX_BLOCK_check_proof (proof, strlen (proof), key))
107 { 119 {
108 ctx->error++; 120 ctx->error++;
@@ -127,36 +139,45 @@ main (int argc, char *argv[])
127 139
128 error = 0; 140 error = 0;
129 141
130 const struct RegexStringPair rxstr[13] = { 142 const struct RegexStringPair rxstr[14] = {
131 {INITIAL_PADDING "ab(c|d)+c*(a(b|c)+d)+(bla)+", 2, 143 {INITIAL_PADDING "ab(c|d)+c*(a(b|c)+d)+(bla)+", 2,
132 {INITIAL_PADDING "abcdcdca", INITIAL_PADDING "abcabdbl"}}, 144 {INITIAL_PADDING "abcdcdca", INITIAL_PADDING "abcabdbl"}, 2,
145 {INITIAL_PADDING, INITIAL_PADDING "ab"}},
133 {INITIAL_PADDING 146 {INITIAL_PADDING
134 "abcdefghixxxxxxxxxxxxxjklmnop*qstoisdjfguisdfguihsdfgbdsuivggsd", 1, 147 "abcdefghixxxxxxxxxxxxxjklmnop*qstoisdjfguisdfguihsdfgbdsuivggsd", 1,
135 {INITIAL_PADDING "abcdefgh"}}, 148 {INITIAL_PADDING "abcdefgh"}, 2, {INITIAL_PADDING, INITIAL_PADDING "a"}},
136 {INITIAL_PADDING "VPN-4-1(0|1)*", 2, 149 {INITIAL_PADDING "VPN-4-1(0|1)*", 2,
137 {INITIAL_PADDING "VPN-4-10", INITIAL_PADDING "VPN-4-11"}}, 150 {INITIAL_PADDING "VPN-4-10", INITIAL_PADDING "VPN-4-11"},
151 1, {INITIAL_PADDING}},
138 {INITIAL_PADDING "(a+X*y+c|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*)", 2, 152 {INITIAL_PADDING "(a+X*y+c|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*)", 2,
139 {INITIAL_PADDING "aaaaaaaa", INITIAL_PADDING "aaXXyyyc"}}, 153 {INITIAL_PADDING "aaaaaaaa", INITIAL_PADDING "aaXXyyyc"}},
140 {INITIAL_PADDING "a*", 1, {INITIAL_PADDING "aaaaaaaa"}}, 154 {INITIAL_PADDING "a*", 2, {INITIAL_PADDING "aaaaaaaa", INITIAL_PADDING}},
141 {INITIAL_PADDING "xzxzxzxzxz", 1, {INITIAL_PADDING "xzxzxzxz"}}, 155 {INITIAL_PADDING "xzxzxzxzxz", 1, {INITIAL_PADDING "xzxzxzxz"},
142 {INITIAL_PADDING "xyz*", 1, {INITIAL_PADDING "xyzzzzzz"}}, 156 1, {INITIAL_PADDING}},
157 {INITIAL_PADDING "xyz*", 1, {INITIAL_PADDING "xyzzzzzz"},
158 1, {INITIAL_PADDING}},
143 {INITIAL_PADDING 159 {INITIAL_PADDING
144 "abcd:(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1):(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)", 160 "abcd:(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1):(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)",
145 2, {INITIAL_PADDING "abcd:000", INITIAL_PADDING "abcd:101"}}, 161 2, {INITIAL_PADDING "abcd:000", INITIAL_PADDING "abcd:101"},
162 1, {INITIAL_PADDING}},
146 {INITIAL_PADDING "(x*|(0|1|2)(a|b|c|d)+)", 2, 163 {INITIAL_PADDING "(x*|(0|1|2)(a|b|c|d)+)", 2,
147 {INITIAL_PADDING "xxxxxxxx", INITIAL_PADDING "0abcdbad"}}, 164 {INITIAL_PADDING "xxxxxxxx", INITIAL_PADDING "0abcdbad"}},
148 {INITIAL_PADDING "(0|1)(0|1)23456789ABC", 1, {INITIAL_PADDING "11234567"}}, 165 {INITIAL_PADDING "(0|1)(0|1)23456789ABC", 1, {INITIAL_PADDING "11234567"},
166 1, {INITIAL_PADDING}},
149 {INITIAL_PADDING "0*123456789ABC*", 3, 167 {INITIAL_PADDING "0*123456789ABC*", 3,
150 {INITIAL_PADDING "00123456", INITIAL_PADDING "00000000", 168 {INITIAL_PADDING "00123456", INITIAL_PADDING "00000000",
151 INITIAL_PADDING "12345678"}}, 169 INITIAL_PADDING "12345678"}},
152 {INITIAL_PADDING "0123456789A*BC", 1, {INITIAL_PADDING "01234567"}}, 170 {INITIAL_PADDING "0123456789A*BC", 1, {INITIAL_PADDING "01234567"}},
153 {"GNUNETVPN000100000IPEX6-fc5a:4e1:c2ba::1", 1, {"GNUNETVPN000100000IPEX6-"}} 171 {"GNUNETVPN000100000IPEX6-fc5a:4e1:c2ba::1", 1, {"GNUNETVPN000100000IPEX6-"},
172 1, {INITIAL_PADDING}},
173 {"my long prefix - hello world(0|1)*", 0, {"my long prefix - hello world"},
174 1, {"my long prefix"}}
154 }; 175 };
155 176
156 const char *graph_start_str = "digraph G {\nrankdir=LR\n"; 177 const char *graph_start_str = "digraph G {\nrankdir=LR\n";
157 const char *graph_end_str = "\n}\n"; 178 const char *graph_end_str = "\n}\n";
158 179
159 for (i = 0; i < 13; i++) 180 for (i = 0; i < 14; i++)
160 { 181 {
161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating DFA for regex %s\n", 182 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating DFA for regex %s\n",
162 rxstr[i].regex); 183 rxstr[i].regex);
@@ -188,36 +209,36 @@ main (int argc, char *argv[])
188 } 209 }
189 210
190 /* Iterate over DFA edges */ 211 /* Iterate over DFA edges */
191 transition_counter = 0; 212 ctx.valid_string_count = rxstr[i].valid_string_count;
192 ctx.string_count = rxstr[i].string_count; 213 ctx.valid_strings = rxstr[i].valid_strings;
193 ctx.strings = rxstr[i].strings;
194 ctx.match_count = 0; 214 ctx.match_count = 0;
215 ctx.invalid_string_count = rxstr[i].invalid_string_count;
216 ctx.invalid_strings = rxstr[i].invalid_strings;
217 ctx.invalid_match_count = 0;
195 dfa = 218 dfa =
196 REGEX_INTERNAL_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex), 0); 219 REGEX_INTERNAL_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex), 1);
197 REGEX_INTERNAL_iterate_all_edges (dfa, key_iterator, &ctx); 220 REGEX_INTERNAL_iterate_all_edges (dfa, key_iterator, &ctx);
198 num_transitions =
199 REGEX_INTERNAL_get_transition_count (dfa) - dfa->start->transition_count;
200 221
201 if (transition_counter < num_transitions) 222 if (0 != ctx.invalid_match_count)
202 { 223 {
203 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 224 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
204 "Automaton has %d transitions, iterated over %d transitions\n", 225 "Found invalid initial states for regex %s\n",
205 num_transitions, transition_counter); 226 rxstr[i].regex);
206 error += 1; 227 error += ctx.invalid_match_count;
207 } 228 }
208 229
209 if (ctx.match_count < ctx.string_count) 230 if (ctx.match_count < ctx.valid_string_count)
210 { 231 {
211 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 232 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
212 "Missing initial states for regex %s\n", rxstr[i].regex); 233 "Missing initial states for regex %s\n", rxstr[i].regex);
213 error += (ctx.string_count - ctx.match_count); 234 error += (ctx.valid_string_count - ctx.match_count);
214 } 235 }
215 else if (ctx.match_count > ctx.string_count) 236 else if (ctx.match_count > ctx.valid_string_count)
216 { 237 {
217 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 238 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
218 "Duplicate initial transitions for regex %s\n", 239 "Duplicate initial transitions for regex %s\n",
219 rxstr[i].regex); 240 rxstr[i].regex);
220 error += (ctx.string_count - ctx.match_count); 241 error += (ctx.valid_string_count - ctx.match_count);
221 } 242 }
222 243
223 REGEX_INTERNAL_automaton_destroy (dfa); 244 REGEX_INTERNAL_automaton_destroy (dfa);
@@ -233,22 +254,44 @@ main (int argc, char *argv[])
233 } 254 }
234 255
235 256
236 for (i = 0; i < 13; i++) 257 for (i = 0; i < 14; i++)
237 { 258 {
238 ctx.string_count = rxstr[i].string_count; 259 transition_counter = 0;
239 ctx.strings = rxstr[i].strings; 260 ctx.valid_string_count = rxstr[i].valid_string_count;
261 ctx.valid_strings = rxstr[i].valid_strings;
240 ctx.match_count = 0; 262 ctx.match_count = 0;
263 ctx.invalid_string_count = rxstr[i].invalid_string_count;
264 ctx.invalid_strings = rxstr[i].invalid_strings;
265 ctx.invalid_match_count = 0;
241 266
242 dfa = 267 dfa =
243 REGEX_INTERNAL_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex), 0); 268 REGEX_INTERNAL_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex), 0);
244 REGEX_INTERNAL_dfa_add_multi_strides (NULL, dfa, 2); 269 REGEX_INTERNAL_dfa_add_multi_strides (NULL, dfa, 2);
245 REGEX_INTERNAL_iterate_all_edges (dfa, key_iterator, &ctx); 270 REGEX_INTERNAL_iterate_all_edges (dfa, key_iterator, &ctx);
271 num_transitions =
272 REGEX_INTERNAL_get_transition_count (dfa) - dfa->start->transition_count;
273
274 if (transition_counter < num_transitions)
275 {
276 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
277 "Automaton has %d transitions, iterated over %d transitions\n",
278 num_transitions, transition_counter);
279 error += 1;
280 }
246 281
247 if (ctx.match_count < ctx.string_count) 282 if (ctx.match_count < ctx.valid_string_count)
248 { 283 {
249 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 284 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
250 "Missing initial states for regex %s\n", rxstr[i].regex); 285 "Missing initial states for regex %s\n", rxstr[i].regex);
251 error += (ctx.string_count - ctx.match_count); 286 error += (ctx.valid_string_count - ctx.match_count);
287 }
288
289 if (0 != ctx.invalid_match_count)
290 {
291 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
292 "Found invalid initial states for regex %s\n",
293 rxstr[i].regex);
294 error += ctx.invalid_match_count;
252 } 295 }
253 296
254 REGEX_INTERNAL_automaton_destroy (dfa); 297 REGEX_INTERNAL_automaton_destroy (dfa);