aboutsummaryrefslogtreecommitdiff
path: root/src/regex/gnunet-service-regex.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/regex/gnunet-service-regex.c')
-rw-r--r--src/regex/gnunet-service-regex.c297
1 files changed, 150 insertions, 147 deletions
diff --git a/src/regex/gnunet-service-regex.c b/src/regex/gnunet-service-regex.c
index 90ea91780..19250d427 100644
--- a/src/regex/gnunet-service-regex.c
+++ b/src/regex/gnunet-service-regex.c
@@ -33,7 +33,8 @@
33/** 33/**
34 * Information about one of our clients. 34 * Information about one of our clients.
35 */ 35 */
36struct ClientEntry { 36struct ClientEntry
37{
37 /** 38 /**
38 * Queue for transmissions to @e client. 39 * Queue for transmissions to @e client.
39 */ 40 */
@@ -88,14 +89,14 @@ static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
88 * @param cls unused 89 * @param cls unused
89 */ 90 */
90static void 91static void
91cleanup_task(void *cls) 92cleanup_task (void *cls)
92{ 93{
93 GNUNET_DHT_disconnect(dht); 94 GNUNET_DHT_disconnect (dht);
94 dht = NULL; 95 dht = NULL;
95 GNUNET_STATISTICS_destroy(stats, 96 GNUNET_STATISTICS_destroy (stats,
96 GNUNET_NO); 97 GNUNET_NO);
97 stats = NULL; 98 stats = NULL;
98 GNUNET_free(my_private_key); 99 GNUNET_free (my_private_key);
99 my_private_key = NULL; 100 my_private_key = NULL;
100} 101}
101 102
@@ -107,14 +108,14 @@ cleanup_task(void *cls)
107 * announcement 108 * announcement
108 */ 109 */
109static void 110static void
110reannounce(void *cls) 111reannounce (void *cls)
111{ 112{
112 struct ClientEntry *ce = cls; 113 struct ClientEntry *ce = cls;
113 114
114 REGEX_INTERNAL_reannounce(ce->ah); 115 REGEX_INTERNAL_reannounce (ce->ah);
115 ce->refresh_task = GNUNET_SCHEDULER_add_delayed(ce->frequency, 116 ce->refresh_task = GNUNET_SCHEDULER_add_delayed (ce->frequency,
116 &reannounce, 117 &reannounce,
117 ce); 118 ce);
118} 119}
119 120
120 121
@@ -126,18 +127,18 @@ reannounce(void *cls)
126 * @return #GNUNET_OK if @am is well-formed 127 * @return #GNUNET_OK if @am is well-formed
127 */ 128 */
128static int 129static int
129check_announce(void *cls, 130check_announce (void *cls,
130 const struct AnnounceMessage *am) 131 const struct AnnounceMessage *am)
131{ 132{
132 struct ClientEntry *ce = cls; 133 struct ClientEntry *ce = cls;
133 134
134 GNUNET_MQ_check_zero_termination(am); 135 GNUNET_MQ_check_zero_termination (am);
135 if (NULL != ce->ah) 136 if (NULL != ce->ah)
136 { 137 {
137 /* only one announcement per client allowed */ 138 /* only one announcement per client allowed */
138 GNUNET_break(0); 139 GNUNET_break (0);
139 return GNUNET_SYSERR; 140 return GNUNET_SYSERR;
140 } 141 }
141 return GNUNET_OK; 142 return GNUNET_OK;
142} 143}
143 144
@@ -149,36 +150,36 @@ check_announce(void *cls,
149 * @param am the actual message 150 * @param am the actual message
150 */ 151 */
151static void 152static void
152handle_announce(void *cls, 153handle_announce (void *cls,
153 const struct AnnounceMessage *am) 154 const struct AnnounceMessage *am)
154{ 155{
155 struct ClientEntry *ce = cls; 156 struct ClientEntry *ce = cls;
156 const char *regex; 157 const char *regex;
157 158
158 regex = (const char *)&am[1]; 159 regex = (const char *) &am[1];
159 ce->frequency = GNUNET_TIME_relative_ntoh(am->refresh_delay); 160 ce->frequency = GNUNET_TIME_relative_ntoh (am->refresh_delay);
160 ce->refresh_task = GNUNET_SCHEDULER_add_delayed(ce->frequency, 161 ce->refresh_task = GNUNET_SCHEDULER_add_delayed (ce->frequency,
161 &reannounce, 162 &reannounce,
162 ce); 163 ce);
163 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 164 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
164 "Starting to announce regex `%s' every %s\n", 165 "Starting to announce regex `%s' every %s\n",
165 regex, 166 regex,
166 GNUNET_STRINGS_relative_time_to_string(ce->frequency, 167 GNUNET_STRINGS_relative_time_to_string (ce->frequency,
167 GNUNET_NO)); 168 GNUNET_NO));
168 ce->ah = REGEX_INTERNAL_announce(dht, 169 ce->ah = REGEX_INTERNAL_announce (dht,
169 my_private_key, 170 my_private_key,
170 regex, 171 regex,
171 ntohs(am->compression), 172 ntohs (am->compression),
172 stats); 173 stats);
173 if (NULL == ce->ah) 174 if (NULL == ce->ah)
174 { 175 {
175 GNUNET_break(0); 176 GNUNET_break (0);
176 GNUNET_SCHEDULER_cancel(ce->refresh_task); 177 GNUNET_SCHEDULER_cancel (ce->refresh_task);
177 ce->refresh_task = NULL; 178 ce->refresh_task = NULL;
178 GNUNET_SERVICE_client_drop(ce->client); 179 GNUNET_SERVICE_client_drop (ce->client);
179 return; 180 return;
180 } 181 }
181 GNUNET_SERVICE_client_continue(ce->client); 182 GNUNET_SERVICE_client_continue (ce->client);
182} 183}
183 184
184 185
@@ -193,12 +194,12 @@ handle_announce(void *cls,
193 * @param put_path_length Length of the @a put_path. 194 * @param put_path_length Length of the @a put_path.
194 */ 195 */
195static void 196static void
196handle_search_result(void *cls, 197handle_search_result (void *cls,
197 const struct GNUNET_PeerIdentity *id, 198 const struct GNUNET_PeerIdentity *id,
198 const struct GNUNET_PeerIdentity *get_path, 199 const struct GNUNET_PeerIdentity *get_path,
199 unsigned int get_path_length, 200 unsigned int get_path_length,
200 const struct GNUNET_PeerIdentity *put_path, 201 const struct GNUNET_PeerIdentity *put_path,
201 unsigned int put_path_length) 202 unsigned int put_path_length)
202{ 203{
203 struct ClientEntry *ce = cls; 204 struct ClientEntry *ce = cls;
204 struct GNUNET_MQ_Envelope *env; 205 struct GNUNET_MQ_Envelope *env;
@@ -208,28 +209,30 @@ handle_search_result(void *cls,
208 209
209 if ((get_path_length >= 65536) || 210 if ((get_path_length >= 65536) ||
210 (put_path_length >= 65536) || 211 (put_path_length >= 65536) ||
211 ((get_path_length + put_path_length) * sizeof(struct GNUNET_PeerIdentity)) 212 ( ((get_path_length + put_path_length) * sizeof(struct
212 + sizeof(struct ResultMessage) >= GNUNET_MAX_MESSAGE_SIZE) 213 GNUNET_PeerIdentity))
213 { 214 + sizeof(struct ResultMessage) >= GNUNET_MAX_MESSAGE_SIZE) )
214 GNUNET_break(0); 215 {
215 return; 216 GNUNET_break (0);
216 } 217 return;
217 size = (get_path_length + put_path_length) * sizeof(struct GNUNET_PeerIdentity); 218 }
218 env = GNUNET_MQ_msg_extra(result, 219 size = (get_path_length + put_path_length) * sizeof(struct
219 size, 220 GNUNET_PeerIdentity);
220 GNUNET_MESSAGE_TYPE_REGEX_RESULT); 221 env = GNUNET_MQ_msg_extra (result,
221 result->get_path_length = htons((uint16_t)get_path_length); 222 size,
222 result->put_path_length = htons((uint16_t)put_path_length); 223 GNUNET_MESSAGE_TYPE_REGEX_RESULT);
224 result->get_path_length = htons ((uint16_t) get_path_length);
225 result->put_path_length = htons ((uint16_t) put_path_length);
223 result->id = *id; 226 result->id = *id;
224 gp = &result->id; 227 gp = &result->id;
225 GNUNET_memcpy(&gp[1], 228 GNUNET_memcpy (&gp[1],
226 get_path, 229 get_path,
227 get_path_length * sizeof(struct GNUNET_PeerIdentity)); 230 get_path_length * sizeof(struct GNUNET_PeerIdentity));
228 GNUNET_memcpy(&gp[1 + get_path_length], 231 GNUNET_memcpy (&gp[1 + get_path_length],
229 put_path, 232 put_path,
230 put_path_length * sizeof(struct GNUNET_PeerIdentity)); 233 put_path_length * sizeof(struct GNUNET_PeerIdentity));
231 GNUNET_MQ_send(ce->mq, 234 GNUNET_MQ_send (ce->mq,
232 env); 235 env);
233} 236}
234 237
235 238
@@ -240,26 +243,26 @@ handle_search_result(void *cls,
240 * @param message the actual message 243 * @param message the actual message
241 */ 244 */
242static int 245static int
243check_search(void *cls, 246check_search (void *cls,
244 const struct RegexSearchMessage *sm) 247 const struct RegexSearchMessage *sm)
245{ 248{
246 struct ClientEntry *ce = cls; 249 struct ClientEntry *ce = cls;
247 const char *string; 250 const char *string;
248 uint16_t size; 251 uint16_t size;
249 252
250 size = ntohs(sm->header.size) - sizeof(*sm); 253 size = ntohs (sm->header.size) - sizeof(*sm);
251 string = (const char *)&sm[1]; 254 string = (const char *) &sm[1];
252 if ('\0' != string[size - 1]) 255 if ('\0' != string[size - 1])
253 { 256 {
254 GNUNET_break(0); 257 GNUNET_break (0);
255 return GNUNET_SYSERR; 258 return GNUNET_SYSERR;
256 } 259 }
257 if (NULL != ce->sh) 260 if (NULL != ce->sh)
258 { 261 {
259 /* only one search allowed per client */ 262 /* only one search allowed per client */
260 GNUNET_break(0); 263 GNUNET_break (0);
261 return GNUNET_SYSERR; 264 return GNUNET_SYSERR;
262 } 265 }
263 return GNUNET_OK; 266 return GNUNET_OK;
264} 267}
265 268
@@ -271,28 +274,28 @@ check_search(void *cls,
271 * @param message the actual message 274 * @param message the actual message
272 */ 275 */
273static void 276static void
274handle_search(void *cls, 277handle_search (void *cls,
275 const struct RegexSearchMessage *sm) 278 const struct RegexSearchMessage *sm)
276{ 279{
277 struct ClientEntry *ce = cls; 280 struct ClientEntry *ce = cls;
278 const char *string; 281 const char *string;
279 282
280 string = (const char *)&sm[1]; 283 string = (const char *) &sm[1];
281 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 284 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
282 "Starting to search for `%s'\n", 285 "Starting to search for `%s'\n",
283 string); 286 string);
284 ce->sh = REGEX_INTERNAL_search(dht, 287 ce->sh = REGEX_INTERNAL_search (dht,
285 string, 288 string,
286 &handle_search_result, 289 &handle_search_result,
287 ce, 290 ce,
288 stats); 291 stats);
289 if (NULL == ce->sh) 292 if (NULL == ce->sh)
290 { 293 {
291 GNUNET_break(0); 294 GNUNET_break (0);
292 GNUNET_SERVICE_client_drop(ce->client); 295 GNUNET_SERVICE_client_drop (ce->client);
293 return; 296 return;
294 } 297 }
295 GNUNET_SERVICE_client_continue(ce->client); 298 GNUNET_SERVICE_client_continue (ce->client);
296} 299}
297 300
298 301
@@ -304,27 +307,27 @@ handle_search(void *cls,
304 * @param service the initialized service 307 * @param service the initialized service
305 */ 308 */
306static void 309static void
307run(void *cls, 310run (void *cls,
308 const struct GNUNET_CONFIGURATION_Handle *cfg, 311 const struct GNUNET_CONFIGURATION_Handle *cfg,
309 struct GNUNET_SERVICE_Handle *service) 312 struct GNUNET_SERVICE_Handle *service)
310{ 313{
311 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration(cfg); 314 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg);
312 if (NULL == my_private_key) 315 if (NULL == my_private_key)
313 { 316 {
314 GNUNET_SCHEDULER_shutdown(); 317 GNUNET_SCHEDULER_shutdown ();
315 return; 318 return;
316 } 319 }
317 dht = GNUNET_DHT_connect(cfg, 1024); 320 dht = GNUNET_DHT_connect (cfg, 1024);
318 if (NULL == dht) 321 if (NULL == dht)
319 { 322 {
320 GNUNET_free(my_private_key); 323 GNUNET_free (my_private_key);
321 my_private_key = NULL; 324 my_private_key = NULL;
322 GNUNET_SCHEDULER_shutdown(); 325 GNUNET_SCHEDULER_shutdown ();
323 return; 326 return;
324 } 327 }
325 GNUNET_SCHEDULER_add_shutdown(&cleanup_task, 328 GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
326 NULL); 329 NULL);
327 stats = GNUNET_STATISTICS_create("regex", cfg); 330 stats = GNUNET_STATISTICS_create ("regex", cfg);
328} 331}
329 332
330 333
@@ -337,13 +340,13 @@ run(void *cls,
337 * @return @a c 340 * @return @a c
338 */ 341 */
339static void * 342static void *
340client_connect_cb(void *cls, 343client_connect_cb (void *cls,
341 struct GNUNET_SERVICE_Client *c, 344 struct GNUNET_SERVICE_Client *c,
342 struct GNUNET_MQ_Handle *mq) 345 struct GNUNET_MQ_Handle *mq)
343{ 346{
344 struct ClientEntry *ce; 347 struct ClientEntry *ce;
345 348
346 ce = GNUNET_new(struct ClientEntry); 349 ce = GNUNET_new (struct ClientEntry);
347 ce->client = c; 350 ce->client = c;
348 ce->mq = mq; 351 ce->mq = mq;
349 return ce; 352 return ce;
@@ -358,28 +361,28 @@ client_connect_cb(void *cls,
358 * @param internal_cls should be equal to @a c 361 * @param internal_cls should be equal to @a c
359 */ 362 */
360static void 363static void
361client_disconnect_cb(void *cls, 364client_disconnect_cb (void *cls,
362 struct GNUNET_SERVICE_Client *c, 365 struct GNUNET_SERVICE_Client *c,
363 void *internal_cls) 366 void *internal_cls)
364{ 367{
365 struct ClientEntry *ce = internal_cls; 368 struct ClientEntry *ce = internal_cls;
366 369
367 if (NULL != ce->refresh_task) 370 if (NULL != ce->refresh_task)
368 { 371 {
369 GNUNET_SCHEDULER_cancel(ce->refresh_task); 372 GNUNET_SCHEDULER_cancel (ce->refresh_task);
370 ce->refresh_task = NULL; 373 ce->refresh_task = NULL;
371 } 374 }
372 if (NULL != ce->ah) 375 if (NULL != ce->ah)
373 { 376 {
374 REGEX_INTERNAL_announce_cancel(ce->ah); 377 REGEX_INTERNAL_announce_cancel (ce->ah);
375 ce->ah = NULL; 378 ce->ah = NULL;
376 } 379 }
377 if (NULL != ce->sh) 380 if (NULL != ce->sh)
378 { 381 {
379 REGEX_INTERNAL_search_cancel(ce->sh); 382 REGEX_INTERNAL_search_cancel (ce->sh);
380 ce->sh = NULL; 383 ce->sh = NULL;
381 } 384 }
382 GNUNET_free(ce); 385 GNUNET_free (ce);
383} 386}
384 387
385 388
@@ -393,15 +396,15 @@ GNUNET_SERVICE_MAIN
393 &client_connect_cb, 396 &client_connect_cb,
394 &client_disconnect_cb, 397 &client_disconnect_cb,
395 NULL, 398 NULL,
396 GNUNET_MQ_hd_var_size(announce, 399 GNUNET_MQ_hd_var_size (announce,
397 GNUNET_MESSAGE_TYPE_REGEX_ANNOUNCE, 400 GNUNET_MESSAGE_TYPE_REGEX_ANNOUNCE,
398 struct AnnounceMessage, 401 struct AnnounceMessage,
399 NULL), 402 NULL),
400 GNUNET_MQ_hd_var_size(search, 403 GNUNET_MQ_hd_var_size (search,
401 GNUNET_MESSAGE_TYPE_REGEX_SEARCH, 404 GNUNET_MESSAGE_TYPE_REGEX_SEARCH,
402 struct RegexSearchMessage, 405 struct RegexSearchMessage,
403 NULL), 406 NULL),
404 GNUNET_MQ_handler_end()); 407 GNUNET_MQ_handler_end ());
405 408
406 409
407/* end of gnunet-service-regex.c */ 410/* end of gnunet-service-regex.c */