aboutsummaryrefslogtreecommitdiff
path: root/src/regex/gnunet-service-regex.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-05-31 17:51:48 +0000
committerChristian Grothoff <christian@grothoff.org>2013-05-31 17:51:48 +0000
commita310c0beee76349ea55f314a7b9736ed9a7a1448 (patch)
tree334d14f2d132a47b25d0d28d3bfbe7661a0af9bb /src/regex/gnunet-service-regex.c
parentca8893f5a65b9f0750aaeb247f415fe3a9334689 (diff)
downloadgnunet-a310c0beee76349ea55f314a7b9736ed9a7a1448.tar.gz
gnunet-a310c0beee76349ea55f314a7b9736ed9a7a1448.zip
-finishing regex service, but untested
Diffstat (limited to 'src/regex/gnunet-service-regex.c')
-rw-r--r--src/regex/gnunet-service-regex.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/src/regex/gnunet-service-regex.c b/src/regex/gnunet-service-regex.c
index 4bddb5042..28f3a20b8 100644
--- a/src/regex/gnunet-service-regex.c
+++ b/src/regex/gnunet-service-regex.c
@@ -20,7 +20,8 @@
20 20
21/** 21/**
22 * @file regex/gnunet-service-regex.c 22 * @file regex/gnunet-service-regex.c
23 * @brief program that tracks template 23 * @brief service to advertise capabilities described as regex and to
24 * lookup capabilities by regex
24 * @author Christian Grothoff 25 * @author Christian Grothoff
25 */ 26 */
26#include "platform.h" 27#include "platform.h"
@@ -93,6 +94,11 @@ static struct ClientEntry *client_head;
93 */ 94 */
94static struct ClientEntry *client_tail; 95static struct ClientEntry *client_tail;
95 96
97/**
98 * Our notification context, used to send back results to the client.
99 */
100static struct GNUNET_SERVER_NotificationContext *nc;
101
96 102
97/** 103/**
98 * Task run during shutdown. 104 * Task run during shutdown.
@@ -107,6 +113,8 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
107 dht = NULL; 113 dht = NULL;
108 GNUNET_STATISTICS_destroy (stats, GNUNET_NO); 114 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
109 stats = NULL; 115 stats = NULL;
116 GNUNET_SERVER_notification_context_destroy (nc);
117 nc = NULL;
110} 118}
111 119
112 120
@@ -240,7 +248,37 @@ handle_search_result (void *cls,
240 const struct GNUNET_PeerIdentity *put_path, 248 const struct GNUNET_PeerIdentity *put_path,
241 unsigned int put_path_length) 249 unsigned int put_path_length)
242{ 250{
251 struct ClientEntry *ce = cls;
252 struct ResultMessage *result;
253 struct GNUNET_PeerIdentity *gp;
254 uint16_t size;
243 255
256 if ( (get_path_length >= 65536) ||
257 (put_path_length >= 65536) ||
258 ( (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity))
259 + sizeof (struct ResultMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
260 {
261 GNUNET_break (0);
262 return;
263 }
264 size = (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity) + sizeof (struct ResultMessage);
265 result = GNUNET_malloc (size);
266 result->header.size = htons (size);
267 result->header.type = htons (GNUNET_MESSAGE_TYPE_REGEX_RESULT);
268 result->get_path_length = htons ((uint16_t) get_path_length);
269 result->put_path_length = htons ((uint16_t) put_path_length);
270 result->id = *id;
271 gp = &result->id;
272 memcpy (&gp[1],
273 get_path,
274 get_path_length * sizeof (struct GNUNET_PeerIdentity));
275 memcpy (&gp[1 + get_path_length],
276 put_path,
277 put_path_length * sizeof (struct GNUNET_PeerIdentity));
278 GNUNET_SERVER_notification_context_unicast (nc,
279 ce->client,
280 &result->header, GNUNET_NO);
281 GNUNET_free (result);
244} 282}
245 283
246 284
@@ -288,6 +326,7 @@ handle_search (void *cls,
288 GNUNET_CONTAINER_DLL_insert (client_head, 326 GNUNET_CONTAINER_DLL_insert (client_head,
289 client_tail, 327 client_tail,
290 ce); 328 ce);
329 GNUNET_SERVER_notification_context_add (nc, client);
291 GNUNET_SERVER_receive_done (client, GNUNET_OK); 330 GNUNET_SERVER_receive_done (client, GNUNET_OK);
292} 331}
293 332
@@ -316,6 +355,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
316 } 355 }
317 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, 356 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
318 NULL); 357 NULL);
358 nc = GNUNET_SERVER_notification_context_create (server, 1);
319 stats = GNUNET_STATISTICS_create ("regex", cfg); 359 stats = GNUNET_STATISTICS_create ("regex", cfg);
320 GNUNET_SERVER_add_handlers (server, handlers); 360 GNUNET_SERVER_add_handlers (server, handlers);
321 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); 361 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);