aboutsummaryrefslogtreecommitdiff
path: root/src/regex
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-05-22 13:26:36 +0000
committerChristian Grothoff <christian@grothoff.org>2015-05-22 13:26:36 +0000
commitbad29fd9a1cc3b1c7df7b992212568918c961b52 (patch)
tree692be9fda2a949f844690e360ce9d6d5f50f8916 /src/regex
parent7b636c9e74039f14b25e70d1050432d9782efef9 (diff)
downloadgnunet-bad29fd9a1cc3b1c7df7b992212568918c961b52.tar.gz
gnunet-bad29fd9a1cc3b1c7df7b992212568918c961b52.zip
add logging and in particular checks to make sure no '.' wildcards are during initial transitions of the DFA
Diffstat (limited to 'src/regex')
-rw-r--r--src/regex/regex_block_lib.h55
-rw-r--r--src/regex/regex_internal.c224
-rw-r--r--src/regex/regex_internal_dht.c44
-rw-r--r--src/regex/regex_internal_lib.h89
-rw-r--r--src/regex/test_regex_integration.c8
5 files changed, 253 insertions, 167 deletions
diff --git a/src/regex/regex_block_lib.h b/src/regex/regex_block_lib.h
index e5685ba9a..20cfd6ceb 100644
--- a/src/regex/regex_block_lib.h
+++ b/src/regex/regex_block_lib.h
@@ -52,7 +52,8 @@ struct RegexBlock;
52struct REGEX_BLOCK_Edge 52struct REGEX_BLOCK_Edge
53{ 53{
54 /** 54 /**
55 * Label of the edge. FIXME: might want to not consume exactly multiples of 8 bits, need length! 55 * Label of the edge. FIXME: might want to not consume exactly
56 * multiples of 8 bits, need length!
56 */ 57 */
57 const char *label; 58 const char *label;
58 59
@@ -67,10 +68,9 @@ struct REGEX_BLOCK_Edge
67 * Check if the given 'proof' matches the given 'key'. 68 * Check if the given 'proof' matches the given 'key'.
68 * 69 *
69 * @param proof partial regex of a state 70 * @param proof partial regex of a state
70 * @param proof_len number of bytes in 'proof' 71 * @param proof_len number of bytes in @a proof
71 * @param key hash of a state. 72 * @param key hash of a state.
72 * 73 * @return #GNUNET_OK if the proof is valid for the given key.
73 * @return GNUNET_OK if the proof is valid for the given key.
74 */ 74 */
75int 75int
76REGEX_BLOCK_check_proof (const char *proof, 76REGEX_BLOCK_check_proof (const char *proof,
@@ -82,14 +82,13 @@ REGEX_BLOCK_check_proof (const char *proof,
82 * Check if the regex block is well formed, including all edges. 82 * Check if the regex block is well formed, including all edges.
83 * 83 *
84 * @param block The start of the block. 84 * @param block The start of the block.
85 * @param size The size of the block. 85 * @param size The size of the @a block.
86 * @param query the query for the block 86 * @param query the query for the @a block
87 * @param xquery String describing the edge we are looking for. 87 * @param xquery String describing the edge we are looking for.
88 * Can be NULL in case this is a put block. 88 * Can be NULL in case this is a put block.
89 * 89 * @return #GNUNET_OK in case it's fine.
90 * @return GNUNET_OK in case it's fine. 90 * #GNUNET_NO in case the xquery exists and is not found (IRRELEVANT).
91 * GNUNET_NO in case the xquery exists and is not found (IRRELEVANT). 91 * #GNUNET_SYSERR if the block is invalid.
92 * GNUNET_SYSERR if the block is invalid.
93 */ 92 */
94int 93int
95REGEX_BLOCK_check (const struct RegexBlock *block, 94REGEX_BLOCK_check (const struct RegexBlock *block,
@@ -107,13 +106,13 @@ REGEX_BLOCK_check (const struct RegexBlock *block,
107 * @param token Token that follows to next state. 106 * @param token Token that follows to next state.
108 * @param len Length of token. 107 * @param len Length of token.
109 * @param key Hash of next state. 108 * @param key Hash of next state.
110 * 109 * @return #GNUNET_YES if should keep iterating, #GNUNET_NO otherwise.
111 * @return GNUNET_YES if should keep iterating, GNUNET_NO otherwise.
112 */ 110 */
113typedef int (*REGEX_INTERNAL_EgdeIterator)(void *cls, 111typedef int
114 const char *token, 112(*REGEX_INTERNAL_EgdeIterator)(void *cls,
115 size_t len, 113 const char *token,
116 const struct GNUNET_HashCode *key); 114 size_t len,
115 const struct GNUNET_HashCode *key);
117 116
118 117
119/** 118/**
@@ -122,29 +121,29 @@ typedef int (*REGEX_INTERNAL_EgdeIterator)(void *cls,
122 * @param block Block to iterate over. 121 * @param block Block to iterate over.
123 * @param size Size of block. 122 * @param size Size of block.
124 * @param iterator Function to call on each edge in the block. 123 * @param iterator Function to call on each edge in the block.
125 * @param iter_cls Closure for the iterator. 124 * @param iter_cls Closure for the @a iterator.
126 * 125 * @return #GNUNET_SYSERR if an error has been encountered.
127 * @return GNUNET_SYSERR if an error has been encountered. 126 * #GNUNET_OK if no error has been encountered.
128 * GNUNET_OK if no error has been encountered.
129 * Note that if the iterator stops the iteration by returning 127 * Note that if the iterator stops the iteration by returning
130 * GNUNET_NO, the block will no longer be checked for further errors. 128 * #GNUNET_NO, the block will no longer be checked for further errors.
131 * The return value will be GNUNET_OK meaning that no errors were 129 * The return value will be #GNUNET_OK meaning that no errors were
132 * found until the edge last notified to the iterator, but there might 130 * found until the edge last notified to the iterator, but there might
133 * be errors in further edges. 131 * be errors in further edges.
134 */ 132 */
135int 133int
136REGEX_BLOCK_iterate (const struct RegexBlock *block, 134REGEX_BLOCK_iterate (const struct RegexBlock *block,
137 size_t size, 135 size_t size,
138 REGEX_INTERNAL_EgdeIterator iterator, 136 REGEX_INTERNAL_EgdeIterator iterator,
139 void *iter_cls); 137 void *iter_cls);
138
140 139
141/** 140/**
142 * Obtain the key that a particular block is to be stored under. 141 * Obtain the key that a particular block is to be stored under.
143 * 142 *
144 * @param block block to get the key from 143 * @param block block to get the key from
145 * @param block_len number of bytes in block 144 * @param block_len number of bytes in @a block
146 * @param key where to store the key 145 * @param key where to store the key
147 * @return GNUNET_OK on success, GNUNET_SYSERR if the block is malformed 146 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the block is malformed
148 */ 147 */
149int 148int
150REGEX_BLOCK_get_key (const struct RegexBlock *block, 149REGEX_BLOCK_get_key (const struct RegexBlock *block,
@@ -157,7 +156,7 @@ REGEX_BLOCK_get_key (const struct RegexBlock *block,
157 * 156 *
158 * @param block block to test 157 * @param block block to test
159 * @param size number of bytes in block 158 * @param size number of bytes in block
160 * @return GNUNET_YES if the block is accepting, GNUNET_NO if not 159 * @return #GNUNET_YES if the block is accepting, #GNUNET_NO if not
161 */ 160 */
162int 161int
163GNUNET_BLOCK_is_accepting (const struct RegexBlock *block, 162GNUNET_BLOCK_is_accepting (const struct RegexBlock *block,
diff --git a/src/regex/regex_internal.c b/src/regex/regex_internal.c
index 56c6e74de..2dccd657f 100644
--- a/src/regex/regex_internal.c
+++ b/src/regex/regex_internal.c
@@ -31,7 +31,7 @@
31 31
32 32
33/** 33/**
34 * Set this to GNUNET_YES to enable state naming. Used to debug NFA->DFA 34 * Set this to #GNUNET_YES to enable state naming. Used to debug NFA->DFA
35 * creation. Disabled by default for better performance. 35 * creation. Disabled by default for better performance.
36 */ 36 */
37#define REGEX_DEBUG_DFA GNUNET_NO 37#define REGEX_DEBUG_DFA GNUNET_NO
@@ -59,7 +59,7 @@ struct REGEX_INTERNAL_StateSet_MDLL
59 59
60 60
61/** 61/**
62 * Append state to the given StateSet ' 62 * Append state to the given StateSet.
63 * 63 *
64 * @param set set to be modified 64 * @param set set to be modified
65 * @param state state to be appended 65 * @param state state to be appended
@@ -95,7 +95,7 @@ nullstrcmp (const char *str1, const char *str2)
95 95
96 96
97/** 97/**
98 * Adds a transition from one state to another on 'label'. Does not add 98 * Adds a transition from one state to another on @a label. Does not add
99 * duplicate states. 99 * duplicate states.
100 * 100 *
101 * @param ctx context 101 * @param ctx context
@@ -105,7 +105,8 @@ nullstrcmp (const char *str1, const char *str2)
105 */ 105 */
106static void 106static void
107state_add_transition (struct REGEX_INTERNAL_Context *ctx, 107state_add_transition (struct REGEX_INTERNAL_Context *ctx,
108 struct REGEX_INTERNAL_State *from_state, const char *label, 108 struct REGEX_INTERNAL_State *from_state,
109 const char *label,
109 struct REGEX_INTERNAL_State *to_state) 110 struct REGEX_INTERNAL_State *to_state)
110{ 111{
111 struct REGEX_INTERNAL_Transition *t; 112 struct REGEX_INTERNAL_Transition *t;
@@ -113,7 +114,8 @@ state_add_transition (struct REGEX_INTERNAL_Context *ctx,
113 114
114 if (NULL == from_state) 115 if (NULL == from_state)
115 { 116 {
116 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not create Transition.\n"); 117 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
118 "Could not create Transition.\n");
117 return; 119 return;
118 } 120 }
119 121
@@ -196,16 +198,17 @@ state_compare (const void *a, const void *b)
196 198
197 199
198/** 200/**
199 * Get all edges leaving state 's'. 201 * Get all edges leaving state @a s.
200 * 202 *
201 * @param s state. 203 * @param s state.
202 * @param edges all edges leaving 's', expected to be allocated and have enough 204 * @param edges all edges leaving @a s, expected to be allocated and have enough
203 * space for s->transitions_count elements. 205 * space for `s->transitions_count` elements.
204 * 206 *
205 * @return number of edges. 207 * @return number of edges.
206 */ 208 */
207static unsigned int 209static unsigned int
208state_get_edges (struct REGEX_INTERNAL_State *s, struct REGEX_BLOCK_Edge *edges) 210state_get_edges (struct REGEX_INTERNAL_State *s,
211 struct REGEX_BLOCK_Edge *edges)
209{ 212{
210 struct REGEX_INTERNAL_Transition *t; 213 struct REGEX_INTERNAL_Transition *t;
211 unsigned int count; 214 unsigned int count;
@@ -293,7 +296,7 @@ automaton_fragment_clear (struct REGEX_INTERNAL_Automaton *a)
293 296
294 297
295/** 298/**
296 * Frees the memory used by State 's' 299 * Frees the memory used by State @a s
297 * 300 *
298 * @param s state that should be destroyed 301 * @param s state that should be destroyed
299 */ 302 */
@@ -498,17 +501,17 @@ automaton_state_traverse (struct REGEX_INTERNAL_State *s, int *marks,
498 * @param start start state, pass a->start or NULL to traverse the whole automaton. 501 * @param start start state, pass a->start or NULL to traverse the whole automaton.
499 * @param check function that is checked before advancing on each transition 502 * @param check function that is checked before advancing on each transition
500 * in the DFS. 503 * in the DFS.
501 * @param check_cls closure for check. 504 * @param check_cls closure for @a check.
502 * @param action action to be performed on each state. 505 * @param action action to be performed on each state.
503 * @param action_cls closure for action 506 * @param action_cls closure for @a action
504 */ 507 */
505void 508void
506REGEX_INTERNAL_automaton_traverse (const struct REGEX_INTERNAL_Automaton *a, 509REGEX_INTERNAL_automaton_traverse (const struct REGEX_INTERNAL_Automaton *a,
507 struct REGEX_INTERNAL_State *start, 510 struct REGEX_INTERNAL_State *start,
508 REGEX_INTERNAL_traverse_check check, 511 REGEX_INTERNAL_traverse_check check,
509 void *check_cls, 512 void *check_cls,
510 REGEX_INTERNAL_traverse_action action, 513 REGEX_INTERNAL_traverse_action action,
511 void *action_cls) 514 void *action_cls)
512{ 515{
513 unsigned int count; 516 unsigned int count;
514 struct REGEX_INTERNAL_State *s; 517 struct REGEX_INTERNAL_State *s;
@@ -532,8 +535,9 @@ REGEX_INTERNAL_automaton_traverse (const struct REGEX_INTERNAL_Automaton *a,
532 else 535 else
533 s = start; 536 s = start;
534 537
535 automaton_state_traverse (s, marks, &count, check, check_cls, action, 538 automaton_state_traverse (s, marks, &count,
536 action_cls); 539 check, check_cls,
540 action, action_cls);
537} 541}
538 542
539 543
@@ -559,7 +563,7 @@ struct StringBuffer
559 size_t slen; 563 size_t slen;
560 564
561 /** 565 /**
562 * Number of bytes allocated for 'sbuf' 566 * Number of bytes allocated for @e sbuf
563 */ 567 */
564 unsigned int blen; 568 unsigned int blen;
565 569
@@ -570,7 +574,7 @@ struct StringBuffer
570 574
571 /** 575 /**
572 * If this entry is part of the last/current generation array, 576 * If this entry is part of the last/current generation array,
573 * this flag is GNUNET_YES if the last and current generation are 577 * this flag is #GNUNET_YES if the last and current generation are
574 * identical (and thus copying is unnecessary if the value didn't 578 * identical (and thus copying is unnecessary if the value didn't
575 * change). This is used in an optimization that improves 579 * change). This is used in an optimization that improves
576 * performance by about 1% --- if we use int16_t here. With just 580 * performance by about 1% --- if we use int16_t here. With just
@@ -604,7 +608,7 @@ sb_nullstrcmp (const struct StringBuffer *s1,
604 return -1; 608 return -1;
605 return memcmp (s1->sbuf, s2->sbuf, s1->slen); 609 return memcmp (s1->sbuf, s2->sbuf, s1->slen);
606} 610}
607 611
608 612
609/** 613/**
610 * Compare two strings for equality. 614 * Compare two strings for equality.
@@ -622,7 +626,7 @@ sb_strcmp (const struct StringBuffer *s1,
622 return -1; 626 return -1;
623 return memcmp (s1->sbuf, s2->sbuf, s1->slen); 627 return memcmp (s1->sbuf, s2->sbuf, s1->slen);
624} 628}
625 629
626 630
627/** 631/**
628 * Reallocate the buffer of 'ret' to fit 'nlen' characters; 632 * Reallocate the buffer of 'ret' to fit 'nlen' characters;
@@ -669,7 +673,7 @@ sb_append (struct StringBuffer *ret,
669 sarg->slen); 673 sarg->slen);
670 ret->slen += sarg->slen; 674 ret->slen += sarg->slen;
671} 675}
672 676
673 677
674/** 678/**
675 * Append a C string. 679 * Append a C string.
@@ -693,7 +697,7 @@ sb_append_cstr (struct StringBuffer *ret,
693 cstr_len); 697 cstr_len);
694 ret->slen += cstr_len; 698 ret->slen += cstr_len;
695} 699}
696 700
697 701
698/** 702/**
699 * Wrap a string buffer, that is, set ret to the format string 703 * Wrap a string buffer, that is, set ret to the format string
@@ -854,7 +858,7 @@ sb_free (struct StringBuffer *sb)
854static void 858static void
855sb_strdup (struct StringBuffer *out, 859sb_strdup (struct StringBuffer *out,
856 const struct StringBuffer *in) 860 const struct StringBuffer *in)
857 861
858{ 862{
859 out->null_flag = in->null_flag; 863 out->null_flag = in->null_flag;
860 if (GNUNET_YES == out->null_flag) 864 if (GNUNET_YES == out->null_flag)
@@ -900,12 +904,12 @@ sb_strdup_cstr (struct StringBuffer *out,
900 904
901 905
902/** 906/**
903 * Check if the given string 'str' needs parentheses around it when 907 * Check if the given string @a str needs parentheses around it when
904 * using it to generate a regex. 908 * using it to generate a regex.
905 * 909 *
906 * @param str string 910 * @param str string
907 * 911 *
908 * @return GNUNET_YES if parentheses are needed, GNUNET_NO otherwise 912 * @return #GNUNET_YES if parentheses are needed, #GNUNET_NO otherwise
909 */ 913 */
910static int 914static int
911needs_parentheses (const struct StringBuffer *str) 915needs_parentheses (const struct StringBuffer *str)
@@ -949,9 +953,9 @@ needs_parentheses (const struct StringBuffer *str)
949 953
950 954
951/** 955/**
952 * Remove parentheses surrounding string 'str'. 956 * Remove parentheses surrounding string @a str.
953 * Example: "(a)" becomes "a", "(a|b)|(a|c)" stays the same. 957 * Example: "(a)" becomes "a", "(a|b)|(a|c)" stays the same.
954 * You need to GNUNET_free the returned string. 958 * You need to #GNUNET_free() the returned string.
955 * 959 *
956 * @param str string, modified to contain a 960 * @param str string, modified to contain a
957 * @return string without surrounding parentheses, string 'str' if no preceding 961 * @return string without surrounding parentheses, string 'str' if no preceding
@@ -1799,8 +1803,10 @@ dfa_state_create (struct REGEX_INTERNAL_Context *ctx,
1799 for (i = 0; i < nfa_states->off; i++) 1803 for (i = 0; i < nfa_states->off; i++)
1800 { 1804 {
1801 cstate = nfa_states->states[i]; 1805 cstate = nfa_states->states[i];
1802 GNUNET_snprintf (pos, pos - s->name + len, 1806 GNUNET_snprintf (pos,
1803 "%i,", cstate->id); 1807 pos - s->name + len,
1808 "%i,",
1809 cstate->id);
1804 pos += strlen (pos); 1810 pos += strlen (pos);
1805 1811
1806 /* Add a transition for each distinct label to NULL state */ 1812 /* Add a transition for each distinct label to NULL state */
@@ -1867,16 +1873,18 @@ dfa_move (struct REGEX_INTERNAL_State **s, const char *str)
1867 1873
1868 1874
1869/** 1875/**
1870 * Set the given state 'marked' to GNUNET_YES. Used by the 1876 * Set the given state 'marked' to #GNUNET_YES. Used by the
1871 * 'dfa_remove_unreachable_states' function to detect unreachable states in the 1877 * #dfa_remove_unreachable_states() function to detect unreachable states in the
1872 * automaton. 1878 * automaton.
1873 * 1879 *
1874 * @param cls closure, not used. 1880 * @param cls closure, not used.
1875 * @param count count, not used. 1881 * @param count count, not used.
1876 * @param s state where the marked attribute will be set to GNUNET_YES. 1882 * @param s state where the marked attribute will be set to #GNUNET_YES.
1877 */ 1883 */
1878static void 1884static void
1879mark_states (void *cls, const unsigned int count, struct REGEX_INTERNAL_State *s) 1885mark_states (void *cls,
1886 const unsigned int count,
1887 struct REGEX_INTERNAL_State *s)
1880{ 1888{
1881 s->marked = GNUNET_YES; 1889 s->marked = GNUNET_YES;
1882} 1890}
@@ -1958,7 +1966,7 @@ dfa_remove_dead_states (struct REGEX_INTERNAL_Automaton *a)
1958 * 1966 *
1959 * @param ctx context 1967 * @param ctx context
1960 * @param a DFA automaton 1968 * @param a DFA automaton
1961 * @return GNUNET_OK on success 1969 * @return #GNUNET_OK on success
1962 */ 1970 */
1963static int 1971static int
1964dfa_merge_nondistinguishable_states (struct REGEX_INTERNAL_Context *ctx, 1972dfa_merge_nondistinguishable_states (struct REGEX_INTERNAL_Context *ctx,
@@ -3115,10 +3123,11 @@ REGEX_INTERNAL_automaton_destroy (struct REGEX_INTERNAL_Automaton *a)
3115 * @param a automaton, type must be DFA 3123 * @param a automaton, type must be DFA
3116 * @param string string that should be evaluated 3124 * @param string string that should be evaluated
3117 * 3125 *
3118 * @return 0 if string matches, non 0 otherwise 3126 * @return 0 if string matches, non-0 otherwise
3119 */ 3127 */
3120static int 3128static int
3121evaluate_dfa (struct REGEX_INTERNAL_Automaton *a, const char *string) 3129evaluate_dfa (struct REGEX_INTERNAL_Automaton *a,
3130 const char *string)
3122{ 3131{
3123 const char *strp; 3132 const char *strp;
3124 struct REGEX_INTERNAL_State *s; 3133 struct REGEX_INTERNAL_State *s;
@@ -3157,11 +3166,11 @@ evaluate_dfa (struct REGEX_INTERNAL_Automaton *a, const char *string)
3157 * 3166 *
3158 * @param a automaton, type must be NFA 3167 * @param a automaton, type must be NFA
3159 * @param string string that should be evaluated 3168 * @param string string that should be evaluated
3160 * 3169 * @return 0 if string matches, non-0 otherwise
3161 * @return 0 if string matches, non 0 otherwise
3162 */ 3170 */
3163static int 3171static int
3164evaluate_nfa (struct REGEX_INTERNAL_Automaton *a, const char *string) 3172evaluate_nfa (struct REGEX_INTERNAL_Automaton *a,
3173 const char *string)
3165{ 3174{
3166 const char *strp; 3175 const char *strp;
3167 char str[2]; 3176 char str[2];
@@ -3215,15 +3224,15 @@ evaluate_nfa (struct REGEX_INTERNAL_Automaton *a, const char *string)
3215 3224
3216 3225
3217/** 3226/**
3218 * Evaluates the given 'string' against the given compiled regex 3227 * Evaluates the given @a string against the given compiled regex @a a
3219 * 3228 *
3220 * @param a automaton 3229 * @param a automaton
3221 * @param string string to check 3230 * @param string string to check
3222 * 3231 * @return 0 if string matches, non-0 otherwise
3223 * @return 0 if string matches, non 0 otherwise
3224 */ 3232 */
3225int 3233int
3226REGEX_INTERNAL_eval (struct REGEX_INTERNAL_Automaton *a, const char *string) 3234REGEX_INTERNAL_eval (struct REGEX_INTERNAL_Automaton *a,
3235 const char *string)
3227{ 3236{
3228 int result; 3237 int result;
3229 3238
@@ -3292,19 +3301,19 @@ REGEX_INTERNAL_get_transition_count (struct REGEX_INTERNAL_Automaton *a)
3292 3301
3293 3302
3294/** 3303/**
3295 * Get the first key for the given 'input_string'. This hashes the first x bits 3304 * Get the first key for the given @a input_string. This hashes the first x bits
3296 * of the 'input_string'. 3305 * of the @a input_string.
3297 * 3306 *
3298 * @param input_string string. 3307 * @param input_string string.
3299 * @param string_len length of the 'input_string'. 3308 * @param string_len length of the @a input_string.
3300 * @param key pointer to where to write the hash code. 3309 * @param key pointer to where to write the hash code.
3301 * 3310 * @return number of bits of @a input_string that have been consumed
3302 * @return number of bits of 'input_string' that have been consumed
3303 * to construct the key 3311 * to construct the key
3304 */ 3312 */
3305size_t 3313size_t
3306REGEX_INTERNAL_get_first_key (const char *input_string, size_t string_len, 3314REGEX_INTERNAL_get_first_key (const char *input_string,
3307 struct GNUNET_HashCode * key) 3315 size_t string_len,
3316 struct GNUNET_HashCode *key)
3308{ 3317{
3309 size_t size; 3318 size_t size;
3310 3319
@@ -3330,12 +3339,15 @@ REGEX_INTERNAL_get_first_key (const char *input_string, size_t string_len,
3330 * @param consumed_string string consumed by traversing the graph till this state. 3339 * @param consumed_string string consumed by traversing the graph till this state.
3331 * @param state current state of the automaton. 3340 * @param state current state of the automaton.
3332 * @param iterator iterator function called for each edge. 3341 * @param iterator iterator function called for each edge.
3333 * @param iterator_cls closure for the iterator function. 3342 * @param iterator_cls closure for the @a iterator function.
3334 */ 3343 */
3335static void 3344static void
3336iterate_initial_edge (const unsigned int min_len, const unsigned int max_len, 3345iterate_initial_edge (unsigned int min_len,
3337 char *consumed_string, struct REGEX_INTERNAL_State *state, 3346 unsigned int max_len,
3338 REGEX_INTERNAL_KeyIterator iterator, void *iterator_cls) 3347 char *consumed_string,
3348 struct REGEX_INTERNAL_State *state,
3349 REGEX_INTERNAL_KeyIterator iterator,
3350 void *iterator_cls)
3339{ 3351{
3340 char *temp; 3352 char *temp;
3341 struct REGEX_INTERNAL_Transition *t; 3353 struct REGEX_INTERNAL_Transition *t;
@@ -3351,21 +3363,36 @@ iterate_initial_edge (const unsigned int min_len, const unsigned int max_len,
3351 else 3363 else
3352 cur_len = 0; 3364 cur_len = 0;
3353 3365
3354 if ((cur_len >= min_len || GNUNET_YES == state->accepting) && cur_len > 0 && 3366 if ( ( (cur_len >= min_len) ||
3355 NULL != consumed_string) 3367 (GNUNET_YES == state->accepting) ) &&
3368 (cur_len > 0) &&
3369 (NULL != consumed_string) )
3356 { 3370 {
3357 if (cur_len <= max_len) 3371 if (cur_len <= max_len)
3358 { 3372 {
3359 if (state->proof != NULL && 0 != strcmp (consumed_string, state->proof)) 3373 if ( (NULL != state->proof) &&
3374 (0 != strcmp (consumed_string,
3375 state->proof)) )
3360 { 3376 {
3361 (void) state_get_edges (state, edges); 3377 (void) state_get_edges (state, edges);
3362 GNUNET_CRYPTO_hash (consumed_string, strlen (consumed_string), &hash); 3378 GNUNET_CRYPTO_hash (consumed_string,
3363 iterator (iterator_cls, &hash, consumed_string, state->accepting, 3379 strlen (consumed_string),
3380 &hash);
3381 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3382 "Start state for string `%s' is %s\n",
3383 consumed_string,
3384 GNUNET_h2s (&hash));
3385 iterator (iterator_cls,
3386 &hash,
3387 consumed_string,
3388 state->accepting,
3364 num_edges, edges); 3389 num_edges, edges);
3365 } 3390 }
3366 3391
3367 if (GNUNET_YES == state->accepting && cur_len > 1 && 3392 if ( (GNUNET_YES == state->accepting) &&
3368 state->transition_count < 1 && cur_len < max_len) 3393 (cur_len > 1) &&
3394 (state->transition_count < 1) &&
3395 (cur_len < max_len) )
3369 { 3396 {
3370 /* Special case for regex consisting of just a string that is shorter than 3397 /* Special case for regex consisting of just a string that is shorter than
3371 * max_len */ 3398 * max_len */
@@ -3373,8 +3400,18 @@ iterate_initial_edge (const unsigned int min_len, const unsigned int max_len,
3373 edge[0].destination = state->hash; 3400 edge[0].destination = state->hash;
3374 temp = GNUNET_strdup (consumed_string); 3401 temp = GNUNET_strdup (consumed_string);
3375 temp[cur_len - 1] = '\0'; 3402 temp[cur_len - 1] = '\0';
3376 GNUNET_CRYPTO_hash (temp, cur_len - 1, &hash_new); 3403 GNUNET_CRYPTO_hash (temp,
3377 iterator (iterator_cls, &hash_new, temp, GNUNET_NO, 1, edge); 3404 cur_len - 1,
3405 &hash_new);
3406 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3407 "Start state for short string `%s' is %s\n",
3408 temp,
3409 GNUNET_h2s (&hash_new));
3410 iterator (iterator_cls,
3411 &hash_new,
3412 temp,
3413 GNUNET_NO, 1,
3414 edge);
3378 GNUNET_free (temp); 3415 GNUNET_free (temp);
3379 } 3416 }
3380 } 3417 }
@@ -3386,7 +3423,17 @@ iterate_initial_edge (const unsigned int min_len, const unsigned int max_len,
3386 temp = GNUNET_strdup (consumed_string); 3423 temp = GNUNET_strdup (consumed_string);
3387 temp[max_len] = '\0'; 3424 temp[max_len] = '\0';
3388 GNUNET_CRYPTO_hash (temp, max_len, &hash); 3425 GNUNET_CRYPTO_hash (temp, max_len, &hash);
3389 iterator (iterator_cls, &hash, temp, GNUNET_NO, 1, edge); 3426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3427 "Start state at split edge `%s'-`%s` is %s\n",
3428 temp,
3429 edge[0].label,
3430 GNUNET_h2s (&hash_new));
3431 iterator (iterator_cls,
3432 &hash,
3433 temp,
3434 GNUNET_NO,
3435 1,
3436 edge);
3390 GNUNET_free (temp); 3437 GNUNET_free (temp);
3391 } 3438 }
3392 } 3439 }
@@ -3395,12 +3442,27 @@ iterate_initial_edge (const unsigned int min_len, const unsigned int max_len,
3395 { 3442 {
3396 for (t = state->transitions_head; NULL != t; t = t->next) 3443 for (t = state->transitions_head; NULL != t; t = t->next)
3397 { 3444 {
3445 if (NULL != strchr (t->label,
3446 (int) '.'))
3447 {
3448 /* Wildcards not allowed during starting states */
3449 GNUNET_break (0);
3450 continue;
3451 }
3398 if (NULL != consumed_string) 3452 if (NULL != consumed_string)
3399 GNUNET_asprintf (&temp, "%s%s", consumed_string, t->label); 3453 GNUNET_asprintf (&temp,
3454 "%s%s",
3455 consumed_string,
3456 t->label);
3400 else 3457 else
3401 GNUNET_asprintf (&temp, "%s", t->label); 3458 GNUNET_asprintf (&temp,
3402 3459 "%s",
3403 iterate_initial_edge (min_len, max_len, temp, t->to_state, iterator, 3460 t->label);
3461 iterate_initial_edge (min_len,
3462 max_len,
3463 temp,
3464 t->to_state,
3465 iterator,
3404 iterator_cls); 3466 iterator_cls);
3405 GNUNET_free (temp); 3467 GNUNET_free (temp);
3406 } 3468 }
@@ -3423,6 +3485,14 @@ REGEX_INTERNAL_iterate_all_edges (struct REGEX_INTERNAL_Automaton *a,
3423{ 3485{
3424 struct REGEX_INTERNAL_State *s; 3486 struct REGEX_INTERNAL_State *s;
3425 3487
3488 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3489 "Iterating over starting edges\n");
3490 iterate_initial_edge (GNUNET_REGEX_INITIAL_BYTES,
3491 GNUNET_REGEX_INITIAL_BYTES,
3492 NULL, a->start,
3493 iterator, iterator_cls);
3494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3495 "Iterating over DFA edges\n");
3426 for (s = a->states_head; NULL != s; s = s->next) 3496 for (s = a->states_head; NULL != s; s = s->next)
3427 { 3497 {
3428 struct REGEX_BLOCK_Edge edges[s->transition_count]; 3498 struct REGEX_BLOCK_Edge edges[s->transition_count];
@@ -3431,18 +3501,20 @@ REGEX_INTERNAL_iterate_all_edges (struct REGEX_INTERNAL_Automaton *a,
3431 num_edges = state_get_edges (s, edges); 3501 num_edges = state_get_edges (s, edges);
3432 if ( ( (NULL != s->proof) && 3502 if ( ( (NULL != s->proof) &&
3433 (0 < strlen (s->proof)) ) || s->accepting) 3503 (0 < strlen (s->proof)) ) || s->accepting)
3504 {
3505 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3506 "Creating DFA edges at `%s' under key %s\n",
3507 s->proof,
3508 GNUNET_h2s (&s->hash));
3434 iterator (iterator_cls, &s->hash, s->proof, 3509 iterator (iterator_cls, &s->hash, s->proof,
3435 s->accepting, 3510 s->accepting,
3436 num_edges, edges); 3511 num_edges, edges);
3512 }
3437 s->marked = GNUNET_NO; 3513 s->marked = GNUNET_NO;
3438 } 3514 }
3439
3440 iterate_initial_edge (GNUNET_REGEX_INITIAL_BYTES,
3441 GNUNET_REGEX_INITIAL_BYTES,
3442 NULL, a->start,
3443 iterator, iterator_cls);
3444} 3515}
3445 3516
3517
3446/** 3518/**
3447 * Struct to hold all the relevant state information in the HashMap. 3519 * Struct to hold all the relevant state information in the HashMap.
3448 * 3520 *
diff --git a/src/regex/regex_internal_dht.c b/src/regex/regex_internal_dht.c
index 7fa15ba45..f11a39589 100644
--- a/src/regex/regex_internal_dht.c
+++ b/src/regex/regex_internal_dht.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2012 Christian Grothoff (and other contributing authors) 3 Copyright (C) 2012, 2015 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
@@ -34,8 +34,19 @@
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/**
38 * DHT replication level to use.
39 */
37#define DHT_REPLICATION 5 40#define DHT_REPLICATION 5
41
42/**
43 * DHT record lifetime to use.
44 */
38#define DHT_TTL GNUNET_TIME_UNIT_HOURS 45#define DHT_TTL GNUNET_TIME_UNIT_HOURS
46
47/**
48 * DHT options to set.
49 */
39#define DHT_OPT GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE 50#define DHT_OPT GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE
40 51
41 52
@@ -57,7 +68,7 @@ struct REGEX_INTERNAL_Announcement
57 /** 68 /**
58 * Automaton representation of the regex (expensive to build). 69 * Automaton representation of the regex (expensive to build).
59 */ 70 */
60 struct REGEX_INTERNAL_Automaton* dfa; 71 struct REGEX_INTERNAL_Automaton *dfa;
61 72
62 /** 73 /**
63 * Our private key. 74 * Our private key.
@@ -77,7 +88,7 @@ struct REGEX_INTERNAL_Announcement
77 * @param cls closure. 88 * @param cls closure.
78 * @param key hash for current state. 89 * @param key hash for current state.
79 * @param proof proof for current state. 90 * @param proof proof for current state.
80 * @param accepting GNUNET_YES if this is an accepting state, GNUNET_NO if not. 91 * @param accepting #GNUNET_YES if this is an accepting state, #GNUNET_NO if not.
81 * @param num_edges number of edges leaving current state. 92 * @param num_edges number of edges leaving current state.
82 * @param edges edges leaving current state. 93 * @param edges edges leaving current state.
83 */ 94 */
@@ -95,17 +106,17 @@ regex_iterator (void *cls,
95 unsigned int i; 106 unsigned int i;
96 107
97 LOG (GNUNET_ERROR_TYPE_INFO, 108 LOG (GNUNET_ERROR_TYPE_INFO,
98 "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",
99 GNUNET_h2s (key), 110 GNUNET_h2s (key),
100 proof, 111 proof,
101 num_edges); 112 num_edges);
102 for (i = 0; i < num_edges; i++) 113 for (i = 0; i < num_edges; i++)
103 { 114 {
104 LOG (GNUNET_ERROR_TYPE_INFO, 115 LOG (GNUNET_ERROR_TYPE_INFO,
105 " edge %s towards %s (%s)\n", 116 "Edge %u `%s' towards %s\n",
117 i,
106 edges[i].label, 118 edges[i].label,
107 GNUNET_h2s (&edges[i].destination), 119 GNUNET_h2s (&edges[i].destination));
108 proof);
109 } 120 }
110 if (GNUNET_YES == accepting) 121 if (GNUNET_YES == accepting)
111 { 122 {
@@ -156,9 +167,11 @@ regex_iterator (void *cls,
156 GNUNET_TIME_relative_to_absolute (DHT_TTL), 167 GNUNET_TIME_relative_to_absolute (DHT_TTL),
157 DHT_TTL, 168 DHT_TTL,
158 NULL, NULL); 169 NULL, NULL);
159 GNUNET_STATISTICS_update (h->stats, "# regex blocks stored", 170 GNUNET_STATISTICS_update (h->stats,
171 "# regex blocks stored",
160 1, GNUNET_NO); 172 1, GNUNET_NO);
161 GNUNET_STATISTICS_update (h->stats, "# regex block bytes stored", 173 GNUNET_STATISTICS_update (h->stats,
174 "# regex block bytes stored",
162 size, GNUNET_NO); 175 size, GNUNET_NO);
163 GNUNET_free (block); 176 GNUNET_free (block);
164} 177}
@@ -166,16 +179,15 @@ regex_iterator (void *cls,
166 179
167/** 180/**
168 * Announce a regular expression: put all states of the automaton in the DHT. 181 * Announce a regular expression: put all states of the automaton in the DHT.
169 * Does not free resources, must call REGEX_INTERNAL_announce_cancel for that. 182 * Does not free resources, must call #REGEX_INTERNAL_announce_cancel() for that.
170 * 183 *
171 * @param dht An existing and valid DHT service handle. CANNOT be NULL. 184 * @param dht An existing and valid DHT service handle. CANNOT be NULL.
172 * @param priv our private key, must remain valid until the announcement is cancelled 185 * @param priv our private key, must remain valid until the announcement is cancelled
173 * @param regex Regular expression to announce. 186 * @param regex Regular expression to announce.
174 * @param compression How many characters per edge can we squeeze? 187 * @param compression How many characters per edge can we squeeze?
175 * @param stats Optional statistics handle to report usage. Can be NULL. 188 * @param stats Optional statistics handle to report usage. Can be NULL.
176 *
177 * @return Handle to reuse o free cached resources. 189 * @return Handle to reuse o free cached resources.
178 * Must be freed by calling REGEX_INTERNAL_announce_cancel. 190 * Must be freed by calling #REGEX_INTERNAL_announce_cancel().
179 */ 191 */
180struct REGEX_INTERNAL_Announcement * 192struct REGEX_INTERNAL_Announcement *
181REGEX_INTERNAL_announce (struct GNUNET_DHT_Handle *dht, 193REGEX_INTERNAL_announce (struct GNUNET_DHT_Handle *dht,
@@ -202,7 +214,7 @@ REGEX_INTERNAL_announce (struct GNUNET_DHT_Handle *dht,
202 * Announce again a regular expression previously announced. 214 * Announce again a regular expression previously announced.
203 * Does use caching to speed up process. 215 * Does use caching to speed up process.
204 * 216 *
205 * @param h Handle returned by a previous REGEX_INTERNAL_announce call. 217 * @param h Handle returned by a previous #REGEX_INTERNAL_announce call().
206 */ 218 */
207void 219void
208REGEX_INTERNAL_reannounce (struct REGEX_INTERNAL_Announcement *h) 220REGEX_INTERNAL_reannounce (struct REGEX_INTERNAL_Announcement *h)
@@ -211,7 +223,9 @@ REGEX_INTERNAL_reannounce (struct REGEX_INTERNAL_Announcement *h)
211 LOG (GNUNET_ERROR_TYPE_INFO, 223 LOG (GNUNET_ERROR_TYPE_INFO,
212 "REGEX_INTERNAL_reannounce: %s\n", 224 "REGEX_INTERNAL_reannounce: %s\n",
213 h->regex); 225 h->regex);
214 REGEX_INTERNAL_iterate_reachable_edges (h->dfa, &regex_iterator, h); 226 REGEX_INTERNAL_iterate_reachable_edges (h->dfa,
227 &regex_iterator,
228 h);
215} 229}
216 230
217 231
@@ -219,7 +233,7 @@ REGEX_INTERNAL_reannounce (struct REGEX_INTERNAL_Announcement *h)
219 * Clear all cached data used by a regex announce. 233 * Clear all cached data used by a regex announce.
220 * Does not close DHT connection. 234 * Does not close DHT connection.
221 * 235 *
222 * @param h Handle returned by a previous REGEX_INTERNAL_announce call. 236 * @param h Handle returned by a previous #REGEX_INTERNAL_announce() call.
223 */ 237 */
224void 238void
225REGEX_INTERNAL_announce_cancel (struct REGEX_INTERNAL_Announcement *h) 239REGEX_INTERNAL_announce_cancel (struct REGEX_INTERNAL_Announcement *h)
diff --git a/src/regex/regex_internal_lib.h b/src/regex/regex_internal_lib.h
index 2703565fe..81af08197 100644
--- a/src/regex/regex_internal_lib.h
+++ b/src/regex/regex_internal_lib.h
@@ -61,11 +61,12 @@ struct REGEX_INTERNAL_Automaton;
61 * @param max_path_len limit the path compression length to the 61 * @param max_path_len limit the path compression length to the
62 * given value. If set to 1, no path compression is applied. Set to 0 for 62 * given value. If set to 1, no path compression is applied. Set to 0 for
63 * maximal possible path compression (generally not desireable). 63 * maximal possible path compression (generally not desireable).
64 * @return DFA, needs to be freed using REGEX_INTERNAL_automaton_destroy. 64 * @return DFA, needs to be freed using #REGEX_INTERNAL_automaton_destroy().
65 */ 65 */
66struct REGEX_INTERNAL_Automaton * 66struct REGEX_INTERNAL_Automaton *
67REGEX_INTERNAL_construct_dfa (const char *regex, const size_t len, 67REGEX_INTERNAL_construct_dfa (const char *regex,
68 unsigned int max_path_len); 68 const size_t len,
69 unsigned int max_path_len);
69 70
70 71
71/** 72/**
@@ -88,23 +89,23 @@ REGEX_INTERNAL_automaton_destroy (struct REGEX_INTERNAL_Automaton *a);
88 */ 89 */
89int 90int
90REGEX_INTERNAL_eval (struct REGEX_INTERNAL_Automaton *a, 91REGEX_INTERNAL_eval (struct REGEX_INTERNAL_Automaton *a,
91 const char *string); 92 const char *string);
92 93
93 94
94/** 95/**
95 * Get the first key for the given 'input_string'. This hashes 96 * Get the first key for the given @a input_string. This hashes
96 * the first x bits of the 'input_string'. 97 * the first x bits of the @a input_string.
97 * 98 *
98 * @param input_string string. 99 * @param input_string string.
99 * @param string_len length of the 'input_string'. 100 * @param string_len length of the @a input_string.
100 * @param key pointer to where to write the hash code. 101 * @param key pointer to where to write the hash code.
101 * 102 * @return number of bits of @a input_string that have been consumed
102 * @return number of bits of 'input_string' that have been consumed
103 * to construct the key 103 * to construct the key
104 */ 104 */
105size_t 105size_t
106REGEX_INTERNAL_get_first_key (const char *input_string, size_t string_len, 106REGEX_INTERNAL_get_first_key (const char *input_string,
107 struct GNUNET_HashCode * key); 107 size_t string_len,
108 struct GNUNET_HashCode * key);
108 109
109 110
110/** 111/**
@@ -113,16 +114,17 @@ REGEX_INTERNAL_get_first_key (const char *input_string, size_t string_len,
113 * @param cls closure. 114 * @param cls closure.
114 * @param key hash for current state. 115 * @param key hash for current state.
115 * @param proof proof for current state 116 * @param proof proof for current state
116 * @param accepting GNUNET_YES if this is an accepting state, GNUNET_NO if not. 117 * @param accepting #GNUNET_YES if this is an accepting state, #GNUNET_NO if not.
117 * @param num_edges number of edges leaving current state. 118 * @param num_edges number of edges leaving current state.
118 * @param edges edges leaving current state. 119 * @param edges edges leaving current state.
119 */ 120 */
120typedef void (*REGEX_INTERNAL_KeyIterator)(void *cls, 121typedef void
121 const struct GNUNET_HashCode *key, 122(*REGEX_INTERNAL_KeyIterator)(void *cls,
122 const char *proof, 123 const struct GNUNET_HashCode *key,
123 int accepting, 124 const char *proof,
124 unsigned int num_edges, 125 int accepting,
125 const struct REGEX_BLOCK_Edge *edges); 126 unsigned int num_edges,
127 const struct REGEX_BLOCK_Edge *edges);
126 128
127 129
128/** 130/**
@@ -135,13 +137,13 @@ typedef void (*REGEX_INTERNAL_KeyIterator)(void *cls,
135 */ 137 */
136void 138void
137REGEX_INTERNAL_iterate_all_edges (struct REGEX_INTERNAL_Automaton *a, 139REGEX_INTERNAL_iterate_all_edges (struct REGEX_INTERNAL_Automaton *a,
138 REGEX_INTERNAL_KeyIterator iterator, 140 REGEX_INTERNAL_KeyIterator iterator,
139 void *iterator_cls); 141 void *iterator_cls);
140 142
141 143
142/** 144/**
143 * Iterate over all edges of automaton 'a' that are reachable from a state with 145 * Iterate over all edges of automaton 'a' that are reachable from a state with
144 * a proof of at least GNUNET_REGEX_INITIAL_BYTES characters. 146 * a proof of at least #GNUNET_REGEX_INITIAL_BYTES characters.
145 * 147 *
146 * Call the iterator for each such edge. 148 * Call the iterator for each such edge.
147 * 149 *
@@ -169,16 +171,15 @@ struct REGEX_INTERNAL_Search;
169 171
170/** 172/**
171 * Announce a regular expression: put all states of the automaton in the DHT. 173 * Announce a regular expression: put all states of the automaton in the DHT.
172 * Does not free resources, must call REGEX_INTERNAL_announce_cancel for that. 174 * Does not free resources, must call #REGEX_INTERNAL_announce_cancel() for that.
173 * 175 *
174 * @param dht An existing and valid DHT service handle. CANNOT be NULL. 176 * @param dht An existing and valid DHT service handle. CANNOT be NULL.
175 * @param priv our private key, must remain valid until the announcement is cancelled 177 * @param priv our private key, must remain valid until the announcement is cancelled
176 * @param regex Regular expression to announce. 178 * @param regex Regular expression to announce.
177 * @param compression How many characters per edge can we squeeze? 179 * @param compression How many characters per edge can we squeeze?
178 * @param stats Optional statistics handle to report usage. Can be NULL. 180 * @param stats Optional statistics handle to report usage. Can be NULL.
179 *
180 * @return Handle to reuse o free cached resources. 181 * @return Handle to reuse o free cached resources.
181 * Must be freed by calling REGEX_INTERNAL_announce_cancel. 182 * Must be freed by calling #REGEX_INTERNAL_announce_cancel().
182 */ 183 */
183struct REGEX_INTERNAL_Announcement * 184struct REGEX_INTERNAL_Announcement *
184REGEX_INTERNAL_announce (struct GNUNET_DHT_Handle *dht, 185REGEX_INTERNAL_announce (struct GNUNET_DHT_Handle *dht,
@@ -192,7 +193,7 @@ REGEX_INTERNAL_announce (struct GNUNET_DHT_Handle *dht,
192 * Announce again a regular expression previously announced. 193 * Announce again a regular expression previously announced.
193 * Does use caching to speed up process. 194 * Does use caching to speed up process.
194 * 195 *
195 * @param h Handle returned by a previous REGEX_INTERNAL_announce call. 196 * @param h Handle returned by a previous #REGEX_INTERNAL_announce() call.
196 */ 197 */
197void 198void
198REGEX_INTERNAL_reannounce (struct REGEX_INTERNAL_Announcement *h); 199REGEX_INTERNAL_reannounce (struct REGEX_INTERNAL_Announcement *h);
@@ -202,7 +203,7 @@ REGEX_INTERNAL_reannounce (struct REGEX_INTERNAL_Announcement *h);
202 * Clear all cached data used by a regex announce. 203 * Clear all cached data used by a regex announce.
203 * Does not close DHT connection. 204 * Does not close DHT connection.
204 * 205 *
205 * @param h Handle returned by a previous REGEX_INTERNAL_announce call. 206 * @param h Handle returned by a previous #REGEX_INTERNAL_announce() call.
206 */ 207 */
207void 208void
208REGEX_INTERNAL_announce_cancel (struct REGEX_INTERNAL_Announcement *h); 209REGEX_INTERNAL_announce_cancel (struct REGEX_INTERNAL_Announcement *h);
@@ -211,24 +212,25 @@ REGEX_INTERNAL_announce_cancel (struct REGEX_INTERNAL_Announcement *h);
211/** 212/**
212 * Search callback function. 213 * Search callback function.
213 * 214 *
214 * @param cls Closure provided in REGEX_INTERNAL_search. 215 * @param cls Closure provided in #REGEX_INTERNAL_search().
215 * @param id Peer providing a regex that matches the string. 216 * @param id Peer providing a regex that matches the string.
216 * @param get_path Path of the get request. 217 * @param get_path Path of the get request.
217 * @param get_path_length Lenght of get_path. 218 * @param get_path_length Length of @a get_path.
218 * @param put_path Path of the put request. 219 * @param put_path Path of the put request.
219 * @param put_path_length Length of the put_path. 220 * @param put_path_length Length of the @a put_path.
220 */ 221 */
221typedef void (*REGEX_INTERNAL_Found)(void *cls, 222typedef void
222 const struct GNUNET_PeerIdentity *id, 223(*REGEX_INTERNAL_Found)(void *cls,
223 const struct GNUNET_PeerIdentity *get_path, 224 const struct GNUNET_PeerIdentity *id,
224 unsigned int get_path_length, 225 const struct GNUNET_PeerIdentity *get_path,
225 const struct GNUNET_PeerIdentity *put_path, 226 unsigned int get_path_length,
226 unsigned int put_path_length); 227 const struct GNUNET_PeerIdentity *put_path,
228 unsigned int put_path_length);
227 229
228 230
229/** 231/**
230 * Search for a peer offering a regex matching certain string in the DHT. 232 * Search for a peer offering a regex matching certain string in the DHT.
231 * The search runs until REGEX_INTERNAL_search_cancel is called, even if results 233 * The search runs until #REGEX_INTERNAL_search_cancel() is called, even if results
232 * are returned. 234 * are returned.
233 * 235 *
234 * @param dht An existing and valid DHT service handle. 236 * @param dht An existing and valid DHT service handle.
@@ -236,22 +238,21 @@ typedef void (*REGEX_INTERNAL_Found)(void *cls,
236 * @param callback Callback for found peers. 238 * @param callback Callback for found peers.
237 * @param callback_cls Closure for @c callback. 239 * @param callback_cls Closure for @c callback.
238 * @param stats Optional statistics handle to report usage. Can be NULL. 240 * @param stats Optional statistics handle to report usage. Can be NULL.
239 *
240 * @return Handle to stop search and free resources. 241 * @return Handle to stop search and free resources.
241 * Must be freed by calling REGEX_INTERNAL_search_cancel. 242 * Must be freed by calling #REGEX_INTERNAL_search_cancel().
242 */ 243 */
243struct REGEX_INTERNAL_Search * 244struct REGEX_INTERNAL_Search *
244REGEX_INTERNAL_search (struct GNUNET_DHT_Handle *dht, 245REGEX_INTERNAL_search (struct GNUNET_DHT_Handle *dht,
245 const char *string, 246 const char *string,
246 REGEX_INTERNAL_Found callback, 247 REGEX_INTERNAL_Found callback,
247 void *callback_cls, 248 void *callback_cls,
248 struct GNUNET_STATISTICS_Handle *stats); 249 struct GNUNET_STATISTICS_Handle *stats);
249 250
250/** 251/**
251 * Stop search and free all data used by a REGEX_INTERNAL_search call. 252 * Stop search and free all data used by a #REGEX_INTERNAL_search() call.
252 * Does not close DHT connection. 253 * Does not close DHT connection.
253 * 254 *
254 * @param h Handle returned by a previous REGEX_INTERNAL_search call. 255 * @param h Handle returned by a previous #REGEX_INTERNAL_search() call.
255 */ 256 */
256void 257void
257REGEX_INTERNAL_search_cancel (struct REGEX_INTERNAL_Search *h); 258REGEX_INTERNAL_search_cancel (struct REGEX_INTERNAL_Search *h);
diff --git a/src/regex/test_regex_integration.c b/src/regex/test_regex_integration.c
index b28ab15d0..0cb177fcc 100644
--- a/src/regex/test_regex_integration.c
+++ b/src/regex/test_regex_integration.c
@@ -85,7 +85,7 @@ end_badly ()
85/** 85/**
86 * Search callback function, invoked for every result that was found. 86 * Search callback function, invoked for every result that was found.
87 * 87 *
88 * @param cls Closure provided in GNUNET_REGEX_search. 88 * @param cls Closure provided in #GNUNET_REGEX_search().
89 * @param id Peer providing a regex that matches the string. 89 * @param id Peer providing a regex that matches the string.
90 * @param get_path Path of the get request. 90 * @param get_path Path of the get request.
91 * @param get_path_length Length of @a get_path. 91 * @param get_path_length Length of @a get_path.
@@ -103,9 +103,9 @@ found_cb (void *cls,
103 const char *str = cls; 103 const char *str = cls;
104 static int found; 104 static int found;
105 105
106 fprintf (stderr, 106 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
107 "IPv%s-exit found\n", 107 "IPv%s-exit found\n",
108 str); 108 str);
109 if (0 == strcmp (str, "4")) 109 if (0 == strcmp (str, "4"))
110 found |= 4; 110 found |= 4;
111 if (0 == strcmp (str, "6")) 111 if (0 == strcmp (str, "6"))