aboutsummaryrefslogtreecommitdiff
path: root/src/regex/regex_internal_lib.h
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/regex_internal_lib.h
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/regex_internal_lib.h')
-rw-r--r--src/regex/regex_internal_lib.h89
1 files changed, 45 insertions, 44 deletions
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);