diff options
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/block_regex.h (renamed from src/include/block_mesh.h) | 53 | ||||
-rw-r--r-- | src/include/gnunet_block_lib.h | 4 | ||||
-rw-r--r-- | src/include/gnunet_regex_lib.h | 101 |
3 files changed, 130 insertions, 28 deletions
diff --git a/src/include/block_mesh.h b/src/include/block_regex.h index f051e6666..282c626a2 100644 --- a/src/include/block_mesh.h +++ b/src/include/block_regex.h | |||
@@ -1,6 +1,6 @@ | |||
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 |
@@ -19,37 +19,30 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file include/block_mesh.h | 22 | * @file include/block_regex.h |
23 | * @brief fs block formats (shared between fs and block) | 23 | * @brief regex block formats |
24 | * @author Bartlomiej Polot | 24 | * @author Bartlomiej Polot |
25 | */ | 25 | */ |
26 | #ifndef BLOCK_MESH_H | 26 | #ifndef BLOCK_REGEX_H |
27 | #define BLOCK_MESH_H | 27 | #define BLOCK_REGEX_H |
28 | |||
29 | #ifdef __cplusplus | ||
30 | extern "C" | ||
31 | { | ||
32 | #if 0 | ||
33 | /* keep Emacsens' auto-indent happy */ | ||
34 | } | ||
35 | #endif | ||
36 | #endif | ||
28 | 37 | ||
29 | #include "gnunet_util_lib.h" | 38 | #include "gnunet_util_lib.h" |
30 | #include "gnunet_mesh_service.h" | ||
31 | #include <stdint.h> | 39 | #include <stdint.h> |
32 | 40 | ||
33 | /** | ||
34 | * @brief peer block (announce peer + type) | ||
35 | */ | ||
36 | struct PBlock | ||
37 | { | ||
38 | /** | ||
39 | * Identity of the peer | ||
40 | */ | ||
41 | struct GNUNET_PeerIdentity id; | ||
42 | |||
43 | /** | ||
44 | * Type of service offered | ||
45 | */ | ||
46 | GNUNET_MESH_ApplicationType type; | ||
47 | }; | ||
48 | 41 | ||
49 | /** | 42 | /** |
50 | * @brief A MeshRegexBlock contains one or more of this struct in the payload. | 43 | * @brief A RegexBlock contains one or more of this struct in the payload. |
51 | */ | 44 | */ |
52 | struct MeshRegexEdge | 45 | struct RegexEdge |
53 | { | 46 | { |
54 | /** | 47 | /** |
55 | * Destination of this edge. | 48 | * Destination of this edge. |
@@ -67,7 +60,7 @@ struct MeshRegexEdge | |||
67 | /** | 60 | /** |
68 | * @brief Block to announce a regex state. | 61 | * @brief Block to announce a regex state. |
69 | */ | 62 | */ |
70 | struct MeshRegexBlock | 63 | struct RegexBlock |
71 | { | 64 | { |
72 | /** | 65 | /** |
73 | * The key of the state. | 66 | * The key of the state. |
@@ -90,13 +83,13 @@ struct MeshRegexBlock | |||
90 | int accepting; | 83 | int accepting; |
91 | 84 | ||
92 | /* char proof[n_proof] */ | 85 | /* char proof[n_proof] */ |
93 | /* struct MeshEdge edges[n_edges] */ | 86 | /* struct RegexEdge edges[n_edges] */ |
94 | }; | 87 | }; |
95 | 88 | ||
96 | /** | 89 | /** |
97 | * @brief Block to announce a peer accepting a state. | 90 | * @brief Block to announce a peer accepting a state. |
98 | */ | 91 | */ |
99 | struct MeshRegexAccept | 92 | struct RegexAccept |
100 | { | 93 | { |
101 | /** | 94 | /** |
102 | * The key of the state. | 95 | * The key of the state. |
@@ -116,4 +109,12 @@ struct MeshRegexAccept | |||
116 | struct GNUNET_PeerIdentity id; | 109 | struct GNUNET_PeerIdentity id; |
117 | 110 | ||
118 | }; | 111 | }; |
112 | |||
113 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
114 | { | ||
115 | #endif | ||
116 | #ifdef __cplusplus | ||
117 | } | ||
118 | #endif | ||
119 | |||
119 | #endif \ No newline at end of file | 120 | #endif \ No newline at end of file |
diff --git a/src/include/gnunet_block_lib.h b/src/include/gnunet_block_lib.h index cd4b2a0ac..002d5c11b 100644 --- a/src/include/gnunet_block_lib.h +++ b/src/include/gnunet_block_lib.h | |||
@@ -113,12 +113,12 @@ enum GNUNET_BLOCK_Type | |||
113 | /** | 113 | /** |
114 | * Block to store a mesh regex state | 114 | * Block to store a mesh regex state |
115 | */ | 115 | */ |
116 | GNUNET_BLOCK_TYPE_MESH_REGEX = 22, | 116 | GNUNET_BLOCK_TYPE_REGEX = 22, |
117 | 117 | ||
118 | /** | 118 | /** |
119 | * Block to store a mesh regex accepting state | 119 | * Block to store a mesh regex accepting state |
120 | */ | 120 | */ |
121 | GNUNET_BLOCK_TYPE_MESH_REGEX_ACCEPT = 23 | 121 | GNUNET_BLOCK_TYPE_REGEX_ACCEPT = 23 |
122 | }; | 122 | }; |
123 | 123 | ||
124 | 124 | ||
diff --git a/src/include/gnunet_regex_lib.h b/src/include/gnunet_regex_lib.h index 105ccee54..ebeb9e50c 100644 --- a/src/include/gnunet_regex_lib.h +++ b/src/include/gnunet_regex_lib.h | |||
@@ -28,6 +28,8 @@ | |||
28 | #define GNUNET_REGEX_LIB_H | 28 | #define GNUNET_REGEX_LIB_H |
29 | 29 | ||
30 | #include "gnunet_util_lib.h" | 30 | #include "gnunet_util_lib.h" |
31 | #include "gnunet_dht_service.h" | ||
32 | #include "gnunet_statistics_service.h" | ||
31 | 33 | ||
32 | #ifdef __cplusplus | 34 | #ifdef __cplusplus |
33 | extern "C" | 35 | extern "C" |
@@ -250,6 +252,105 @@ GNUNET_REGEX_ipv6toregex (const struct in6_addr *ipv6, | |||
250 | 252 | ||
251 | 253 | ||
252 | 254 | ||
255 | /** | ||
256 | * Handle to store cached data about a regex announce. | ||
257 | */ | ||
258 | struct GNUNET_REGEX_announce_handle; | ||
259 | |||
260 | /** | ||
261 | * Handle to store data about a regex search. | ||
262 | */ | ||
263 | struct GNUNET_REGEX_search_handle; | ||
264 | |||
265 | /** | ||
266 | * Announce a regular expression: put all states of the automaton in the DHT. | ||
267 | * Does not free resources, must call GNUNET_REGEX_announce_cancel for that. | ||
268 | * | ||
269 | * @param dht An existing and valid DHT service handle. | ||
270 | * @param id ID to announce as provider of regex. Own ID in most cases. | ||
271 | * @param regex Regular expression to announce. | ||
272 | * @param compression How many characters per edge can we squeeze? | ||
273 | * @param stats Optional statistics handle to report usage. Can be NULL. | ||
274 | * | ||
275 | * @return Handle to reuse o free cached resources. | ||
276 | * Must be freed by calling GNUNET_REGEX_announce_cancel. | ||
277 | */ | ||
278 | struct GNUNET_REGEX_announce_handle * | ||
279 | GNUNET_REGEX_announce (struct GNUNET_DHT_Handle *dht, | ||
280 | struct GNUNET_PeerIdentity *id, | ||
281 | const char *regex, | ||
282 | uint16_t compression, | ||
283 | struct GNUNET_STATISTICS_Handle *stats); | ||
284 | |||
285 | /** | ||
286 | * Announce again a regular expression previously announced. | ||
287 | * Does use caching to speed up process. | ||
288 | * | ||
289 | * @param h Handle returned by a previous GNUNET_REGEX_announce call. | ||
290 | */ | ||
291 | void | ||
292 | GNUNET_REGEX_reannounce (struct GNUNET_REGEX_announce_handle *h); | ||
293 | |||
294 | |||
295 | /** | ||
296 | * Clear all cached data used by a regex announce. | ||
297 | * Does not close DHT connection. | ||
298 | * | ||
299 | * @param h Handle returned by a previous GNUNET_REGEX_announce call. | ||
300 | */ | ||
301 | void | ||
302 | GNUNET_REGEX_announce_cancel (struct GNUNET_REGEX_announce_handle *h); | ||
303 | |||
304 | |||
305 | /** | ||
306 | * Search callback function. | ||
307 | * | ||
308 | * @param cls Closure provided in GNUNET_REGEX_search. | ||
309 | * @param id Peer providing a regex that matches the string. | ||
310 | * @param get_path Path of the get request. | ||
311 | * @param get_path_length Lenght of get_path. | ||
312 | * @param put_path Path of the put request. | ||
313 | * @param put_path_length Length of the put_path. | ||
314 | */ | ||
315 | typedef void (*GNUNET_REGEX_Found)(void *cls, | ||
316 | const struct GNUNET_PeerIdentity *id, | ||
317 | const struct GNUNET_PeerIdentity *get_path, | ||
318 | unsigned int get_path_length, | ||
319 | const struct GNUNET_PeerIdentity *put_path, | ||
320 | unsigned int put_path_length); | ||
321 | |||
322 | |||
323 | /** | ||
324 | * Search for a peer offering a regex matching certain string in the DHT. | ||
325 | * The search runs until GNUNET_REGEX_search_cancel is called, even if results | ||
326 | * are returned. | ||
327 | * | ||
328 | * @param dht An existing and valid DHT service handle. | ||
329 | * @param string String to match against the regexes in the DHT. | ||
330 | * @param callback Callback for found peers. | ||
331 | * @param callback_cls Closure for @c callback. | ||
332 | * @param stats Optional statistics handle to report usage. Can be NULL. | ||
333 | * | ||
334 | * @return Handle to stop search and free resources. | ||
335 | * Must be freed by calling GNUNET_REGEX_search_cancel. | ||
336 | */ | ||
337 | struct GNUNET_REGEX_search_handle * | ||
338 | GNUNET_REGEX_search (struct GNUNET_DHT_Handle *dht, | ||
339 | const char *string, | ||
340 | GNUNET_REGEX_Found callback, | ||
341 | void *callback_cls, | ||
342 | struct GNUNET_STATISTICS_Handle *stats); | ||
343 | |||
344 | /** | ||
345 | * Stop search and free all data used by a GNUNET_REGEX_search call. | ||
346 | * Does not close DHT connection. | ||
347 | * | ||
348 | * @param h Handle returned by a previous GNUNET_REGEX_search call. | ||
349 | */ | ||
350 | void | ||
351 | GNUNET_REGEX_search_cancel (struct GNUNET_REGEX_search_handle *h); | ||
352 | |||
353 | |||
253 | #if 0 /* keep Emacsens' auto-indent happy */ | 354 | #if 0 /* keep Emacsens' auto-indent happy */ |
254 | { | 355 | { |
255 | #endif | 356 | #endif |