diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-05-31 13:04:39 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-05-31 13:04:39 +0000 |
commit | 254fd9d19ec754cd82e40338565790874fb82561 (patch) | |
tree | ab71bf7a9671085ce57f86f56b4410971462833d /src/include | |
parent | 3738046948e0eaacdc851b0b78ff8e66c5401e04 (diff) | |
download | gnunet-254fd9d19ec754cd82e40338565790874fb82561.tar.gz gnunet-254fd9d19ec754cd82e40338565790874fb82561.zip |
-regex service API
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/Makefile.am | 1 | ||||
-rw-r--r-- | src/include/gnunet_regex_service.h | 138 |
2 files changed, 139 insertions, 0 deletions
diff --git a/src/include/Makefile.am b/src/include/Makefile.am index 37b6bb2ca..827e9985a 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am | |||
@@ -70,6 +70,7 @@ gnunetinclude_HEADERS = \ | |||
70 | gnunet_protocols.h \ | 70 | gnunet_protocols.h \ |
71 | gnunet_resolver_service.h \ | 71 | gnunet_resolver_service.h \ |
72 | gnunet_regex_lib.h \ | 72 | gnunet_regex_lib.h \ |
73 | gnunet_regex_service.h \ | ||
73 | gnunet_scheduler_lib.h \ | 74 | gnunet_scheduler_lib.h \ |
74 | gnunet_server_lib.h \ | 75 | gnunet_server_lib.h \ |
75 | gnunet_service_lib.h \ | 76 | gnunet_service_lib.h \ |
diff --git a/src/include/gnunet_regex_service.h b/src/include/gnunet_regex_service.h new file mode 100644 index 000000000..57f98b19f --- /dev/null +++ b/src/include/gnunet_regex_service.h | |||
@@ -0,0 +1,138 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2012, 2013 Christian Grothoff (and other contributing authors) | ||
4 | |||
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 | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file include/gnunet_regex_service.h | ||
22 | * @brief access regex service to advertise capabilities via regex and discover | ||
23 | * respective peers using matching strings | ||
24 | * @author Maximilian Szengel | ||
25 | * @author Christian Grothoff | ||
26 | */ | ||
27 | #ifndef GNUNET_REGEX_SERVICE_H | ||
28 | #define GNUNET_REGEX_SERVICE_H | ||
29 | |||
30 | #include "gnunet_util_lib.h" | ||
31 | |||
32 | #ifdef __cplusplus | ||
33 | extern "C" | ||
34 | { | ||
35 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
36 | } | ||
37 | #endif | ||
38 | #endif | ||
39 | |||
40 | |||
41 | /** | ||
42 | * Constant for how many bytes the initial string regex should have. | ||
43 | */ | ||
44 | #define GNUNET_REGEX_INITIAL_BYTES 24 | ||
45 | |||
46 | |||
47 | /** | ||
48 | * Handle to store cached data about a regex announce. | ||
49 | */ | ||
50 | struct GNUNET_REGEX_Announcement; | ||
51 | |||
52 | /** | ||
53 | * Handle to store data about a regex search. | ||
54 | */ | ||
55 | struct GNUNET_REGEX_Search; | ||
56 | |||
57 | |||
58 | /** | ||
59 | * Announce the given peer under the given regular expression. Does | ||
60 | * not free resources, must call GNUNET_REGEX_announce_cancel for | ||
61 | * that. | ||
62 | * | ||
63 | * @param id ID to announce as provider of regex. Own ID in most cases. | ||
64 | * @param regex Regular expression to announce. | ||
65 | * @param refresh_delay after what delay should the announcement be repeated? | ||
66 | * @param compression How many characters per edge can we squeeze? | ||
67 | * @return Handle to reuse o free cached resources. | ||
68 | * Must be freed by calling GNUNET_REGEX_announce_cancel. | ||
69 | */ | ||
70 | struct GNUNET_REGEX_Announcement * | ||
71 | GNUNET_REGEX_announce (const struct GNUNET_PeerIdentity *id, | ||
72 | const char *regex, | ||
73 | struct GNUNET_TIME_Relative refresh_delay, | ||
74 | uint16_t compression); | ||
75 | |||
76 | |||
77 | /** | ||
78 | * Stop announcing the regex specified by the given handle. | ||
79 | * | ||
80 | * @param h handle returned by a previous GNUNET_REGEX_announce call. | ||
81 | */ | ||
82 | void | ||
83 | GNUNET_REGEX_announce_cancel (struct GNUNET_REGEX_Announcement *h); | ||
84 | |||
85 | |||
86 | /** | ||
87 | * Search callback function, invoked for every result that was found. | ||
88 | * | ||
89 | * @param cls Closure provided in GNUNET_REGEX_search. | ||
90 | * @param id Peer providing a regex that matches the string. | ||
91 | * @param get_path Path of the get request. | ||
92 | * @param get_path_length Lenght of get_path. | ||
93 | * @param put_path Path of the put request. | ||
94 | * @param put_path_length Length of the put_path. | ||
95 | */ | ||
96 | typedef void (*GNUNET_REGEX_Found)(void *cls, | ||
97 | const struct GNUNET_PeerIdentity *id, | ||
98 | const struct GNUNET_PeerIdentity *get_path, | ||
99 | unsigned int get_path_length, | ||
100 | const struct GNUNET_PeerIdentity *put_path, | ||
101 | unsigned int put_path_length); | ||
102 | |||
103 | |||
104 | /** | ||
105 | * Search for a peer offering a regex matching certain string in the DHT. | ||
106 | * The search runs until GNUNET_REGEX_search_cancel is called, even if results | ||
107 | * are returned. | ||
108 | * | ||
109 | * @param string String to match against the regexes in the DHT. | ||
110 | * @param callback Callback for found peers. | ||
111 | * @param callback_cls Closure for @c callback. | ||
112 | * @return Handle to stop search and free resources. | ||
113 | * Must be freed by calling GNUNET_REGEX_search_cancel. | ||
114 | */ | ||
115 | struct GNUNET_REGEX_Search * | ||
116 | GNUNET_REGEX_search (const char *string, | ||
117 | GNUNET_REGEX_Found callback, | ||
118 | void *callback_cls); | ||
119 | |||
120 | |||
121 | /** | ||
122 | * Stop search and free all data used by a GNUNET_REGEX_search call. | ||
123 | * | ||
124 | * @param h Handle returned by a previous GNUNET_REGEX_search call. | ||
125 | */ | ||
126 | void | ||
127 | GNUNET_REGEX_search_cancel (struct GNUNET_REGEX_Search *h); | ||
128 | |||
129 | |||
130 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
131 | { | ||
132 | #endif | ||
133 | #ifdef __cplusplus | ||
134 | } | ||
135 | #endif | ||
136 | |||
137 | /* end of gnunet_regex_service.h */ | ||
138 | #endif | ||