aboutsummaryrefslogtreecommitdiff
path: root/src/namestore
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-09-21 10:56:28 +0000
committerChristian Grothoff <christian@grothoff.org>2016-09-21 10:56:28 +0000
commitd4afc6e37a14fe3257263c377a243c1a22ed9ee5 (patch)
treeccfce6d4f92808372d3e7ebfe9f5372e9f21f50c /src/namestore
parent60d02b5b0899f454cb65408bd2ed4c453fa75a3d (diff)
downloadgnunet-d4afc6e37a14fe3257263c377a243c1a22ed9ee5.tar.gz
gnunet-d4afc6e37a14fe3257263c377a243c1a22ed9ee5.zip
migrating more services to new service API
Diffstat (limited to 'src/namestore')
-rw-r--r--src/namestore/gnunet-service-namestore.c713
1 files changed, 318 insertions, 395 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index effb33e51..ae65802b0 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -61,7 +61,7 @@ struct ZoneIteration
61 /** 61 /**
62 * Namestore client which intiated this zone iteration 62 * Namestore client which intiated this zone iteration
63 */ 63 */
64 struct NamestoreClient *client; 64 struct NamestoreClient *nc;
65 65
66 /** 66 /**
67 * The nick to add to the records 67 * The nick to add to the records
@@ -95,21 +95,17 @@ struct ZoneIteration
95 */ 95 */
96struct NamestoreClient 96struct NamestoreClient
97{ 97{
98 /**
99 * Next element in the DLL
100 */
101 struct NamestoreClient *next;
102 98
103 /** 99 /**
104 * Previous element in the DLL 100 * The client
105 */ 101 */
106 struct NamestoreClient *prev; 102 struct GNUNET_SERVICE_Client *client;
107 103
108 /** 104 /**
109 * The client 105 * Message queue for transmission to @e client
110 */ 106 */
111 struct GNUNET_SERVER_Client *client; 107 struct GNUNET_MQ_Handle *mq;
112 108
113 /** 109 /**
114 * Head of the DLL of 110 * Head of the DLL of
115 * Zone iteration operations in progress initiated by this client 111 * Zone iteration operations in progress initiated by this client
@@ -152,7 +148,7 @@ struct ZoneMonitor
152 /** 148 /**
153 * Task active during initial iteration. 149 * Task active during initial iteration.
154 */ 150 */
155 struct GNUNET_SCHEDULER_Task * task; 151 struct GNUNET_SCHEDULER_Task *task;
156 152
157 /** 153 /**
158 * Offset of the zone iteration used to address next result of the zone 154 * Offset of the zone iteration used to address next result of the zone
@@ -190,7 +186,7 @@ struct CacheOperation
190 /** 186 /**
191 * Client to notify about the result. 187 * Client to notify about the result.
192 */ 188 */
193 struct GNUNET_SERVER_Client *client; 189 struct NamestoreClient *nc;
194 190
195 /** 191 /**
196 * Client's request ID. 192 * Client's request ID.
@@ -225,21 +221,6 @@ static struct GNUNET_NAMESTORE_PluginFunctions *GSN_database;
225static char *db_lib_name; 221static char *db_lib_name;
226 222
227/** 223/**
228 * Our notification context.
229 */
230static struct GNUNET_SERVER_NotificationContext *snc;
231
232/**
233 * Head of the Client DLL
234 */
235static struct NamestoreClient *client_head;
236
237/**
238 * Tail of the Client DLL
239 */
240static struct NamestoreClient *client_tail;
241
242/**
243 * Head of cop DLL. 224 * Head of cop DLL.
244 */ 225 */
245static struct CacheOperation *cop_head; 226static struct CacheOperation *cop_head;
@@ -262,8 +243,7 @@ static struct ZoneMonitor *monitor_tail;
262/** 243/**
263 * Notification context shared by all monitors. 244 * Notification context shared by all monitors.
264 */ 245 */
265static struct GNUNET_SERVER_NotificationContext *monitor_nc; 246static struct GNUNET_NotificationContext *monitor_nc;
266
267 247
268 248
269/** 249/**
@@ -274,17 +254,10 @@ static struct GNUNET_SERVER_NotificationContext *monitor_nc;
274static void 254static void
275cleanup_task (void *cls) 255cleanup_task (void *cls)
276{ 256{
277 struct ZoneIteration *no;
278 struct NamestoreClient *nc;
279 struct CacheOperation *cop; 257 struct CacheOperation *cop;
280 258
281 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 259 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
282 "Stopping namestore service\n"); 260 "Stopping namestore service\n");
283 if (NULL != snc)
284 {
285 GNUNET_SERVER_notification_context_destroy (snc);
286 snc = NULL;
287 }
288 while (NULL != (cop = cop_head)) 261 while (NULL != (cop = cop_head))
289 { 262 {
290 GNUNET_NAMECACHE_cancel (cop->qe); 263 GNUNET_NAMECACHE_cancel (cop->qe);
@@ -295,23 +268,13 @@ cleanup_task (void *cls)
295 } 268 }
296 GNUNET_NAMECACHE_disconnect (namecache); 269 GNUNET_NAMECACHE_disconnect (namecache);
297 namecache = NULL; 270 namecache = NULL;
298 while (NULL != (nc = client_head)) 271 GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name,
299 { 272 GSN_database));
300 while (NULL != (no = nc->op_head))
301 {
302 GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, no);
303 GNUNET_free (no);
304 }
305 GNUNET_CONTAINER_DLL_remove (client_head, client_tail, nc);
306 GNUNET_SERVER_client_set_user_context (nc->client, NULL);
307 GNUNET_free (nc);
308 }
309 GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, GSN_database));
310 GNUNET_free (db_lib_name); 273 GNUNET_free (db_lib_name);
311 db_lib_name = NULL; 274 db_lib_name = NULL;
312 if (NULL != monitor_nc) 275 if (NULL != monitor_nc)
313 { 276 {
314 GNUNET_SERVER_notification_context_destroy (monitor_nc); 277 GNUNET_notification_context_destroy (monitor_nc);
315 monitor_nc = NULL; 278 monitor_nc = NULL;
316 } 279 }
317} 280}
@@ -323,26 +286,24 @@ cleanup_task (void *cls)
323 * 286 *
324 * @param cls closure 287 * @param cls closure
325 * @param client identification of the client 288 * @param client identification of the client
289 * @param app_ctx the `struct NamestoreClient` of @a client
326 */ 290 */
327static void 291static void
328client_disconnect_notification (void *cls, 292client_disconnect_cb (void *cls,
329 struct GNUNET_SERVER_Client *client) 293 struct GNUNET_SERVICE_Client *client,
294 void *app_ctx)
330{ 295{
296 struct NamestoreClient *nc = app_ctx;
331 struct ZoneIteration *no; 297 struct ZoneIteration *no;
332 struct NamestoreClient *nc;
333 struct ZoneMonitor *zm; 298 struct ZoneMonitor *zm;
334 struct CacheOperation *cop; 299 struct CacheOperation *cop;
335 300
336 if (NULL == client)
337 return;
338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
339 "Client %p disconnected\n", 302 "Client %p disconnected\n",
340 client); 303 client);
341 if (NULL == (nc = GNUNET_SERVER_client_get_user_context (client, struct NamestoreClient)))
342 return;
343 for (zm = monitor_head; NULL != zm; zm = zm->next) 304 for (zm = monitor_head; NULL != zm; zm = zm->next)
344 { 305 {
345 if (client == zm->nc->client) 306 if (nc == zm->nc)
346 { 307 {
347 GNUNET_CONTAINER_DLL_remove (monitor_head, 308 GNUNET_CONTAINER_DLL_remove (monitor_head,
348 monitor_tail, 309 monitor_tail,
@@ -358,40 +319,39 @@ client_disconnect_notification (void *cls,
358 } 319 }
359 while (NULL != (no = nc->op_head)) 320 while (NULL != (no = nc->op_head))
360 { 321 {
361 GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, no); 322 GNUNET_CONTAINER_DLL_remove (nc->op_head,
323 nc->op_tail,
324 no);
362 GNUNET_free (no); 325 GNUNET_free (no);
363 } 326 }
364 GNUNET_CONTAINER_DLL_remove (client_head, client_tail, nc);
365 GNUNET_free (nc);
366 for (cop = cop_head; NULL != cop; cop = cop->next) 327 for (cop = cop_head; NULL != cop; cop = cop->next)
367 if (client == cop->client) 328 if (nc == cop->nc)
368 cop->client = NULL; 329 cop->nc = NULL;
330 GNUNET_free (nc);
369} 331}
370 332
371 333
372/** 334/**
373 * Add a client to our list of active clients, if it is not yet 335 * Add a client to our list of active clients.
374 * in there.
375 * 336 *
337 * @param cls NULL
376 * @param client client to add 338 * @param client client to add
339 * @param mq message queue for @a client
377 * @return internal namestore client structure for this client 340 * @return internal namestore client structure for this client
378 */ 341 */
379static struct NamestoreClient * 342static void *
380client_lookup (struct GNUNET_SERVER_Client *client) 343client_connect_cb (void *cls,
344 struct GNUNET_SERVICE_Client *client,
345 struct GNUNET_MQ_Handle *mq)
381{ 346{
382 struct NamestoreClient *nc; 347 struct NamestoreClient *nc;
383 348
384 nc = GNUNET_SERVER_client_get_user_context (client, struct NamestoreClient);
385 if (NULL != nc)
386 return nc;
387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 349 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
388 "Client %p connected\n", 350 "Client %p connected\n",
389 client); 351 client);
390 nc = GNUNET_new (struct NamestoreClient); 352 nc = GNUNET_new (struct NamestoreClient);
391 nc->client = client; 353 nc->client = client;
392 GNUNET_SERVER_notification_context_add (snc, client); 354 nc->mq = mq;
393 GNUNET_CONTAINER_DLL_insert (client_head, client_tail, nc);
394 GNUNET_SERVER_client_set_user_context (client, nc);
395 return nc; 355 return nc;
396} 356}
397 357
@@ -415,14 +375,13 @@ lookup_nick_it (void *cls,
415 const struct GNUNET_GNSRECORD_Data *rd) 375 const struct GNUNET_GNSRECORD_Data *rd)
416{ 376{
417 struct GNUNET_GNSRECORD_Data **res = cls; 377 struct GNUNET_GNSRECORD_Data **res = cls;
418 int c;
419 378
420 if (0 != strcmp (label, GNUNET_GNS_MASTERZONE_STR)) 379 if (0 != strcmp (label, GNUNET_GNS_MASTERZONE_STR))
421 { 380 {
422 GNUNET_break (0); 381 GNUNET_break (0);
423 return; 382 return;
424 } 383 }
425 for (c = 0; c < rd_count; c++) 384 for (unsigned int c = 0; c < rd_count; c++)
426 { 385 {
427 if (GNUNET_GNSRECORD_TYPE_NICK == rd[c].record_type) 386 if (GNUNET_GNSRECORD_TYPE_NICK == rd[c].record_type)
428 { 387 {
@@ -537,8 +496,7 @@ merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd,
537 * Generate a `struct LookupNameResponseMessage` and send it to the 496 * Generate a `struct LookupNameResponseMessage` and send it to the
538 * given client using the given notification context. 497 * given client using the given notification context.
539 * 498 *
540 * @param nc notification context to use 499 * @param nc client to unicast to
541 * @param client client to unicast to
542 * @param request_id request ID to use 500 * @param request_id request ID to use
543 * @param zone_key zone key of the zone 501 * @param zone_key zone key of the zone
544 * @param name name 502 * @param name name
@@ -546,21 +504,20 @@ merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd,
546 * @param rd array of records 504 * @param rd array of records
547 */ 505 */
548static void 506static void
549send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc, 507send_lookup_response (struct NamestoreClient *nc,
550 struct GNUNET_SERVER_Client *client,
551 uint32_t request_id, 508 uint32_t request_id,
552 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 509 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
553 const char *name, 510 const char *name,
554 unsigned int rd_count, 511 unsigned int rd_count,
555 const struct GNUNET_GNSRECORD_Data *rd) 512 const struct GNUNET_GNSRECORD_Data *rd)
556{ 513{
514 struct GNUNET_MQ_Envelope *env;
557 struct RecordResultMessage *zir_msg; 515 struct RecordResultMessage *zir_msg;
558 struct GNUNET_GNSRECORD_Data *nick; 516 struct GNUNET_GNSRECORD_Data *nick;
559 struct GNUNET_GNSRECORD_Data *res; 517 struct GNUNET_GNSRECORD_Data *res;
560 unsigned int res_count; 518 unsigned int res_count;
561 size_t name_len; 519 size_t name_len;
562 size_t rd_ser_len; 520 size_t rd_ser_len;
563 size_t msg_size;
564 char *name_tmp; 521 char *name_tmp;
565 char *rd_ser; 522 char *rd_ser;
566 523
@@ -583,31 +540,30 @@ send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc,
583 540
584 name_len = strlen (name) + 1; 541 name_len = strlen (name) + 1;
585 rd_ser_len = GNUNET_GNSRECORD_records_get_size (res_count, res); 542 rd_ser_len = GNUNET_GNSRECORD_records_get_size (res_count, res);
586 msg_size = sizeof (struct RecordResultMessage) + name_len + rd_ser_len; 543 env = GNUNET_MQ_msg_extra (zir_msg,
587 (void) client_lookup (client); 544 name_len + rd_ser_len,
588 zir_msg = GNUNET_malloc (msg_size); 545 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT);
589 zir_msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT);
590 zir_msg->gns_header.header.size = htons (msg_size);
591 zir_msg->gns_header.r_id = htonl (request_id); 546 zir_msg->gns_header.r_id = htonl (request_id);
592 zir_msg->name_len = htons (name_len); 547 zir_msg->name_len = htons (name_len);
593 zir_msg->rd_count = htons (res_count); 548 zir_msg->rd_count = htons (res_count);
594 zir_msg->rd_len = htons (rd_ser_len); 549 zir_msg->rd_len = htons (rd_ser_len);
595 zir_msg->private_key = *zone_key; 550 zir_msg->private_key = *zone_key;
596 name_tmp = (char *) &zir_msg[1]; 551 name_tmp = (char *) &zir_msg[1];
597 GNUNET_memcpy (name_tmp, name, name_len); 552 GNUNET_memcpy (name_tmp,
553 name,
554 name_len);
598 rd_ser = &name_tmp[name_len]; 555 rd_ser = &name_tmp[name_len];
599 GNUNET_GNSRECORD_records_serialize (res_count, res, rd_ser_len, rd_ser); 556 GNUNET_GNSRECORD_records_serialize (res_count,
557 res,
558 rd_ser_len,
559 rd_ser);
600 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 560 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
601 "Sending RECORD_RESULT message with %u records and size %zu\n", 561 "Sending RECORD_RESULT message with %u records\n",
602 res_count, 562 res_count);
603 msg_size); 563 GNUNET_MQ_send (nc->mq,
604 GNUNET_SERVER_notification_context_unicast (nc, 564 env);
605 client,
606 &zir_msg->gns_header.header,
607 GNUNET_NO);
608 if (rd != res) 565 if (rd != res)
609 GNUNET_free (res); 566 GNUNET_free (res);
610 GNUNET_free (zir_msg);
611} 567}
612 568
613 569
@@ -619,22 +575,21 @@ send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc,
619 * @param rid client's request ID 575 * @param rid client's request ID
620 */ 576 */
621static void 577static void
622send_store_response (struct GNUNET_SERVER_Client *client, 578send_store_response (struct NamestoreClient *nc,
623 int res, 579 int res,
624 uint32_t rid) 580 uint32_t rid)
625{ 581{
626 struct RecordStoreResponseMessage rcr_msg; 582 struct GNUNET_MQ_Envelope *env;
583 struct RecordStoreResponseMessage *rcr_msg;
627 584
628 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 585 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
629 "Sending `%s' message\n", 586 "Sending RECORD_STORE_RESPONSE message\n");
630 "RECORD_STORE_RESPONSE"); 587 env = GNUNET_MQ_msg (rcr_msg,
631 rcr_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE); 588 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE);
632 rcr_msg.gns_header.header.size = htons (sizeof (struct RecordStoreResponseMessage)); 589 rcr_msg->gns_header.r_id = htonl (rid);
633 rcr_msg.gns_header.r_id = htonl (rid); 590 rcr_msg->op_result = htonl (res);
634 rcr_msg.op_result = htonl (res); 591 GNUNET_MQ_send (nc->mq,
635 GNUNET_SERVER_notification_context_unicast (snc, client, 592 env);
636 &rcr_msg.gns_header.header,
637 GNUNET_NO);
638} 593}
639 594
640 595
@@ -662,8 +617,8 @@ finish_cache_operation (void *cls,
662 GNUNET_CONTAINER_DLL_remove (cop_head, 617 GNUNET_CONTAINER_DLL_remove (cop_head,
663 cop_tail, 618 cop_tail,
664 cop); 619 cop);
665 if (NULL != cop->client) 620 if (NULL != cop->nc)
666 send_store_response (cop->client, 621 send_store_response (cop->nc,
667 success, 622 success,
668 cop->rid); 623 cop->rid);
669 GNUNET_free (cop); 624 GNUNET_free (cop);
@@ -674,7 +629,7 @@ finish_cache_operation (void *cls,
674 * We just touched the plaintext information about a name in our zone; 629 * We just touched the plaintext information about a name in our zone;
675 * refresh the corresponding (encrypted) block in the namecache. 630 * refresh the corresponding (encrypted) block in the namecache.
676 * 631 *
677 * @param client client responsible for the request 632 * @param nc client responsible for the request, can be NULL
678 * @param rid request ID of the client 633 * @param rid request ID of the client
679 * @param zone_key private key of the zone 634 * @param zone_key private key of the zone
680 * @param name label for the records 635 * @param name label for the records
@@ -682,7 +637,7 @@ finish_cache_operation (void *cls,
682 * @param rd records stored under the given @a name 637 * @param rd records stored under the given @a name
683 */ 638 */
684static void 639static void
685refresh_block (struct GNUNET_SERVER_Client *client, 640refresh_block (struct NamestoreClient *nc,
686 uint32_t rid, 641 uint32_t rid,
687 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 642 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
688 const char *name, 643 const char *name,
@@ -702,7 +657,10 @@ refresh_block (struct GNUNET_SERVER_Client *client,
702 if (NULL != nick) 657 if (NULL != nick)
703 { 658 {
704 nick->flags = (nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE; 659 nick->flags = (nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE;
705 merge_with_nick_records (nick, rd_count,rd, &res_count, &res); 660 merge_with_nick_records (nick,
661 rd_count,rd,
662 &res_count,
663 &res);
706 GNUNET_free (nick); 664 GNUNET_free (nick);
707 } 665 }
708 666
@@ -726,7 +684,7 @@ refresh_block (struct GNUNET_SERVER_Client *client,
726 res_count, 684 res_count,
727 GNUNET_GNSRECORD_z2s (&pkey)); 685 GNUNET_GNSRECORD_z2s (&pkey));
728 cop = GNUNET_new (struct CacheOperation); 686 cop = GNUNET_new (struct CacheOperation);
729 cop->client = client; 687 cop->nc = nc;
730 cop->rid = rid; 688 cop->rid = rid;
731 GNUNET_CONTAINER_DLL_insert (cop_head, 689 GNUNET_CONTAINER_DLL_insert (cop_head,
732 cop_tail, 690 cop_tail,
@@ -824,75 +782,70 @@ lookup_it (void *cls,
824/** 782/**
825 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP message 783 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP message
826 * 784 *
827 * @param cls unused 785 * @param cls client sending the message
828 * @param client client sending the message 786 * @param ll_msg message of type `struct LabelLookupMessage`
829 * @param message message of type 'struct RecordCreateMessage' 787 * @return #GNUNET_OK if @a ll_msg is well-formed
830 */ 788 */
831static void 789static int
832handle_record_lookup (void *cls, 790check_record_lookup (void *cls,
833 struct GNUNET_SERVER_Client *client, 791 const struct LabelLookupMessage *ll_msg)
834 const struct GNUNET_MessageHeader *message)
835{ 792{
836 const struct LabelLookupMessage *ll_msg;
837 struct LabelLookupResponseMessage *llr_msg;
838 struct RecordLookupContext rlc;
839 const char *name_tmp;
840 char *res_name;
841 char *conv_name;
842 uint32_t name_len; 793 uint32_t name_len;
843 size_t src_size; 794 size_t src_size;
844 size_t res_size; 795 const char *name_tmp;
845 int res;
846
847 if (ntohs (message->size) < sizeof (struct LabelLookupMessage))
848 {
849 GNUNET_break (0);
850 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
851 return;
852 }
853 796
854 ll_msg = (const struct LabelLookupMessage *) message;
855 name_len = ntohl (ll_msg->label_len); 797 name_len = ntohl (ll_msg->label_len);
856 src_size = ntohs (message->size); 798 src_size = ntohs (ll_msg->gns_header.header.size);
857 799 if (name_len != src_size - sizeof (struct LabelLookupMessage))
858 if (name_len != src_size - sizeof (struct LabelLookupMessage))
859 { 800 {
860 GNUNET_break (0); 801 GNUNET_break (0);
861 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 802 return GNUNET_SYSERR;
862 return;
863 } 803 }
864 804
865 name_tmp = (const char *) &ll_msg[1]; 805 name_tmp = (const char *) &ll_msg[1];
866 if ('\0' != name_tmp[name_len -1]) 806 if ('\0' != name_tmp[name_len -1])
867 { 807 {
868 GNUNET_break (0); 808 GNUNET_break (0);
869 GNUNET_SERVER_receive_done (client, 809 return GNUNET_SYSERR;
870 GNUNET_SYSERR);
871 return;
872 } 810 }
811 return GNUNET_OK;
812}
873 813
874 GNUNET_SERVER_receive_done (client, 814
875 GNUNET_OK); 815/**
816 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP message
817 *
818 * @param cls client sending the message
819 * @param ll_msg message of type `struct LabelLookupMessage`
820 */
821static void
822handle_record_lookup (void *cls,
823 const struct LabelLookupMessage *ll_msg)
824{
825 struct NamestoreClient *nc = cls;
826 struct GNUNET_MQ_Envelope *env;
827 struct LabelLookupResponseMessage *llr_msg;
828 struct RecordLookupContext rlc;
829 const char *name_tmp;
830 char *res_name;
831 char *conv_name;
832 uint32_t name_len;
833 int res;
834
835 name_len = ntohl (ll_msg->label_len);
836 name_tmp = (const char *) &ll_msg[1];
837 GNUNET_SERVICE_client_continue (nc->client);
876 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 838 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
877 "Received NAMESTORE_RECORD_LOOKUP message for name `%s'\n", 839 "Received NAMESTORE_RECORD_LOOKUP message for name `%s'\n",
878 name_tmp); 840 name_tmp);
879 841
880 if (NULL == (client_lookup (client)))
881 {
882 GNUNET_break (0);
883 GNUNET_SERVER_receive_done (client,
884 GNUNET_SYSERR);
885 return;
886 }
887
888 conv_name = GNUNET_GNSRECORD_string_to_lowercase (name_tmp); 842 conv_name = GNUNET_GNSRECORD_string_to_lowercase (name_tmp);
889 if (NULL == conv_name) 843 if (NULL == conv_name)
890 { 844 {
891 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 845 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
892 "Error converting name `%s'\n", 846 "Error converting name `%s'\n",
893 name_tmp); 847 name_tmp);
894 GNUNET_SERVER_receive_done (client, 848 GNUNET_SERVICE_client_drop (nc->client);
895 GNUNET_SYSERR);
896 return; 849 return;
897 } 850 }
898 rlc.label = conv_name; 851 rlc.label = conv_name;
@@ -907,10 +860,9 @@ handle_record_lookup (void *cls,
907 &lookup_it, 860 &lookup_it,
908 &rlc); 861 &rlc);
909 GNUNET_free (conv_name); 862 GNUNET_free (conv_name);
910 res_size = sizeof (struct LabelLookupResponseMessage) + name_len + rlc.rd_ser_len; 863 env = GNUNET_MQ_msg_extra (llr_msg,
911 llr_msg = GNUNET_malloc (res_size); 864 name_len + rlc.rd_ser_len,
912 llr_msg->gns_header.header.size = htons (res_size); 865 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE);
913 llr_msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE);
914 llr_msg->gns_header.r_id = ll_msg->gns_header.r_id; 866 llr_msg->gns_header.r_id = ll_msg->gns_header.r_id;
915 llr_msg->private_key = ll_msg->zone; 867 llr_msg->private_key = ll_msg->zone;
916 llr_msg->name_len = htons (name_len); 868 llr_msg->name_len = htons (name_len);
@@ -927,31 +879,65 @@ handle_record_lookup (void *cls,
927 GNUNET_memcpy (&res_name[name_len], 879 GNUNET_memcpy (&res_name[name_len],
928 rlc.res_rd, 880 rlc.res_rd,
929 rlc.rd_ser_len); 881 rlc.rd_ser_len);
930 GNUNET_SERVER_notification_context_unicast (snc, 882 GNUNET_MQ_send (nc->mq,
931 client, 883 env);
932 &llr_msg->gns_header.header,
933 GNUNET_NO);
934 GNUNET_free_non_null (rlc.res_rd); 884 GNUNET_free_non_null (rlc.res_rd);
935 GNUNET_free (llr_msg); 885}
886
887
888/**
889 * Checks a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE message
890 *
891 * @param cls client sending the message
892 * @param rp_msg message of type `struct RecordStoreMessage`
893 * @return #GNUNET_OK if @a rp_msg is well-formed
894 */
895static int
896check_record_store (void *cls,
897 const struct RecordStoreMessage *rp_msg)
898{
899 size_t name_len;
900 size_t msg_size;
901 size_t msg_size_exp;
902 size_t rd_ser_len;
903 const char *name_tmp;
904
905 name_len = ntohs (rp_msg->name_len);
906 msg_size = ntohs (rp_msg->gns_header.header.size);
907 rd_ser_len = ntohs (rp_msg->rd_len);
908 msg_size_exp = sizeof (struct RecordStoreMessage) + name_len + rd_ser_len;
909 if (msg_size != msg_size_exp)
910 {
911 GNUNET_break (0);
912 return GNUNET_SYSERR;
913 }
914 if ((0 == name_len) || (name_len > MAX_NAME_LEN))
915 {
916 GNUNET_break (0);
917 return GNUNET_SYSERR;
918 }
919 name_tmp = (const char *) &rp_msg[1];
920 if ('\0' != name_tmp[name_len -1])
921 {
922 GNUNET_break (0);
923 return GNUNET_SYSERR;
924 }
925 return GNUNET_OK;
936} 926}
937 927
938 928
939/** 929/**
940 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE message 930 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE message
941 * 931 *
942 * @param cls unused 932 * @param cls client sending the message
943 * @param client client sending the message 933 * @param rp_msg message of type `struct RecordStoreMessage`
944 * @param message message of type 'struct RecordCreateMessage'
945 */ 934 */
946static void 935static void
947handle_record_store (void *cls, 936handle_record_store (void *cls,
948 struct GNUNET_SERVER_Client *client, 937 const struct RecordStoreMessage *rp_msg)
949 const struct GNUNET_MessageHeader *message)
950{ 938{
951 const struct RecordStoreMessage *rp_msg; 939 struct NamestoreClient *nc = cls;
952 size_t name_len; 940 size_t name_len;
953 size_t msg_size;
954 size_t msg_size_exp;
955 size_t rd_ser_len; 941 size_t rd_ser_len;
956 uint32_t rid; 942 uint32_t rid;
957 const char *name_tmp; 943 const char *name_tmp;
@@ -964,44 +950,13 @@ handle_record_store (void *cls,
964 950
965 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 951 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
966 "Received NAMESTORE_RECORD_STORE message\n"); 952 "Received NAMESTORE_RECORD_STORE message\n");
967 if (ntohs (message->size) < sizeof (struct RecordStoreMessage))
968 {
969 GNUNET_break (0);
970 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
971 return;
972 }
973 rp_msg = (const struct RecordStoreMessage *) message;
974 rid = ntohl (rp_msg->gns_header.r_id); 953 rid = ntohl (rp_msg->gns_header.r_id);
975 name_len = ntohs (rp_msg->name_len); 954 name_len = ntohs (rp_msg->name_len);
976 msg_size = ntohs (message->size);
977 rd_count = ntohs (rp_msg->rd_count); 955 rd_count = ntohs (rp_msg->rd_count);
978 rd_ser_len = ntohs (rp_msg->rd_len); 956 rd_ser_len = ntohs (rp_msg->rd_len);
979 GNUNET_break (0 == ntohs (rp_msg->reserved)); 957 GNUNET_break (0 == ntohs (rp_msg->reserved));
980 msg_size_exp = sizeof (struct RecordStoreMessage) + name_len + rd_ser_len;
981 if (msg_size != msg_size_exp)
982 {
983 GNUNET_break (0);
984 GNUNET_SERVER_receive_done (client,
985 GNUNET_SYSERR);
986 return;
987 }
988 if ((0 == name_len) || (name_len > MAX_NAME_LEN))
989 {
990 GNUNET_break (0);
991 GNUNET_SERVER_receive_done (client,
992 GNUNET_SYSERR);
993 return;
994 }
995 name_tmp = (const char *) &rp_msg[1]; 958 name_tmp = (const char *) &rp_msg[1];
996 rd_ser = &name_tmp[name_len]; 959 rd_ser = &name_tmp[name_len];
997 if ('\0' != name_tmp[name_len -1])
998 {
999 GNUNET_break (0);
1000 GNUNET_SERVER_receive_done (client,
1001 GNUNET_SYSERR);
1002 return;
1003 }
1004 (void) client_lookup (client);
1005 { 960 {
1006 struct GNUNET_GNSRECORD_Data rd[rd_count]; 961 struct GNUNET_GNSRECORD_Data rd[rd_count];
1007 962
@@ -1012,8 +967,7 @@ handle_record_store (void *cls,
1012 rd)) 967 rd))
1013 { 968 {
1014 GNUNET_break (0); 969 GNUNET_break (0);
1015 GNUNET_SERVER_receive_done (client, 970 GNUNET_SERVICE_client_drop (nc->client);
1016 GNUNET_SYSERR);
1017 return; 971 return;
1018 } 972 }
1019 973
@@ -1026,7 +980,7 @@ handle_record_store (void *cls,
1026 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 980 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1027 "Error converting name `%s'\n", 981 "Error converting name `%s'\n",
1028 name_tmp); 982 name_tmp);
1029 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 983 GNUNET_SERVICE_client_drop (nc->client);
1030 return; 984 return;
1031 } 985 }
1032 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 986 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1052,12 +1006,11 @@ handle_record_store (void *cls,
1052 else 1006 else
1053 { 1007 {
1054 struct GNUNET_GNSRECORD_Data rd_clean[rd_count]; 1008 struct GNUNET_GNSRECORD_Data rd_clean[rd_count];
1055 unsigned int i;
1056 unsigned int rd_clean_off; 1009 unsigned int rd_clean_off;
1057 1010
1058 /* remove "NICK" records, unless this is for the "+" label */ 1011 /* remove "NICK" records, unless this is for the "+" label */
1059 rd_clean_off = 0; 1012 rd_clean_off = 0;
1060 for (i=0;i<rd_count;i++) 1013 for (unsigned int i=0;i<rd_count;i++)
1061 { 1014 {
1062 rd_clean[rd_clean_off] = rd[i]; 1015 rd_clean[rd_clean_off] = rd[i];
1063 if ( (0 == strcmp (GNUNET_GNS_MASTERZONE_STR, 1016 if ( (0 == strcmp (GNUNET_GNS_MASTERZONE_STR,
@@ -1083,8 +1036,7 @@ handle_record_store (void *cls,
1083 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1036 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1084 "Notifying monitor about changes under label `%s'\n", 1037 "Notifying monitor about changes under label `%s'\n",
1085 conv_name); 1038 conv_name);
1086 send_lookup_response (monitor_nc, 1039 send_lookup_response (zm->nc,
1087 zm->nc->client,
1088 0, 1040 0,
1089 &rp_msg->private_key, 1041 &rp_msg->private_key,
1090 conv_name, 1042 conv_name,
@@ -1107,22 +1059,22 @@ handle_record_store (void *cls,
1107 } 1059 }
1108 if (GNUNET_OK == res) 1060 if (GNUNET_OK == res)
1109 { 1061 {
1110 refresh_block (client, rid, 1062 refresh_block (nc,
1063 rid,
1111 &rp_msg->private_key, 1064 &rp_msg->private_key,
1112 conv_name, 1065 conv_name,
1113 rd_count, rd); 1066 rd_count,
1114 GNUNET_SERVER_receive_done (client, 1067 rd);
1115 GNUNET_OK); 1068 GNUNET_SERVICE_client_continue (nc->client);
1116 GNUNET_free (conv_name); 1069 GNUNET_free (conv_name);
1117 return; 1070 return;
1118 } 1071 }
1119 GNUNET_free (conv_name); 1072 GNUNET_free (conv_name);
1120 } 1073 }
1121 send_store_response (client, 1074 send_store_response (nc,
1122 res, 1075 res,
1123 rid); 1076 rid);
1124 GNUNET_SERVER_receive_done (client, 1077 GNUNET_SERVICE_client_continue (nc->client);
1125 GNUNET_OK);
1126} 1078}
1127 1079
1128 1080
@@ -1168,6 +1120,7 @@ handle_zone_to_name_it (void *cls,
1168 const struct GNUNET_GNSRECORD_Data *rd) 1120 const struct GNUNET_GNSRECORD_Data *rd)
1169{ 1121{
1170 struct ZoneToNameCtx *ztn_ctx = cls; 1122 struct ZoneToNameCtx *ztn_ctx = cls;
1123 struct GNUNET_MQ_Envelope *env;
1171 struct ZoneToNameResponseMessage *ztnr_msg; 1124 struct ZoneToNameResponseMessage *ztnr_msg;
1172 int16_t res; 1125 int16_t res;
1173 size_t name_len; 1126 size_t name_len;
@@ -1189,8 +1142,9 @@ handle_zone_to_name_it (void *cls,
1189 ztn_ctx->success = GNUNET_SYSERR; 1142 ztn_ctx->success = GNUNET_SYSERR;
1190 return; 1143 return;
1191 } 1144 }
1192 ztnr_msg = GNUNET_malloc (msg_size); 1145 env = GNUNET_MQ_msg_extra (ztnr_msg,
1193 ztnr_msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE); 1146 name_len + rd_ser_len,
1147 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE);
1194 ztnr_msg->gns_header.header.size = htons (msg_size); 1148 ztnr_msg->gns_header.header.size = htons (msg_size);
1195 ztnr_msg->gns_header.r_id = htonl (ztn_ctx->rid); 1149 ztnr_msg->gns_header.r_id = htonl (ztn_ctx->rid);
1196 ztnr_msg->res = htons (res); 1150 ztnr_msg->res = htons (res);
@@ -1199,40 +1153,38 @@ handle_zone_to_name_it (void *cls,
1199 ztnr_msg->name_len = htons (name_len); 1153 ztnr_msg->name_len = htons (name_len);
1200 ztnr_msg->zone = *zone_key; 1154 ztnr_msg->zone = *zone_key;
1201 name_tmp = (char *) &ztnr_msg[1]; 1155 name_tmp = (char *) &ztnr_msg[1];
1202 if (NULL != name) 1156 GNUNET_memcpy (name_tmp,
1203 GNUNET_memcpy (name_tmp, name, name_len); 1157 name,
1158 name_len);
1204 rd_tmp = &name_tmp[name_len]; 1159 rd_tmp = &name_tmp[name_len];
1205 GNUNET_GNSRECORD_records_serialize (rd_count, rd, rd_ser_len, rd_tmp); 1160 GNUNET_GNSRECORD_records_serialize (rd_count,
1161 rd,
1162 rd_ser_len,
1163 rd_tmp);
1206 ztn_ctx->success = GNUNET_OK; 1164 ztn_ctx->success = GNUNET_OK;
1207 GNUNET_SERVER_notification_context_unicast (snc, ztn_ctx->nc->client, 1165 GNUNET_MQ_send (ztn_ctx->nc->mq,
1208 &ztnr_msg->gns_header.header, 1166 env);
1209 GNUNET_NO);
1210 GNUNET_free (ztnr_msg);
1211} 1167}
1212 1168
1213 1169
1214/** 1170/**
1215 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME message 1171 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME message
1216 * 1172 *
1217 * @param cls unused 1173 * @param cls client client sending the message
1218 * @param client client sending the message 1174 * @param ztn_msg message of type 'struct ZoneToNameMessage'
1219 * @param message message of type 'struct ZoneToNameMessage'
1220 */ 1175 */
1221static void 1176static void
1222handle_zone_to_name (void *cls, 1177handle_zone_to_name (void *cls,
1223 struct GNUNET_SERVER_Client *client, 1178 const struct ZoneToNameMessage *ztn_msg)
1224 const struct GNUNET_MessageHeader *message)
1225{ 1179{
1226 struct NamestoreClient *nc; 1180 struct NamestoreClient *nc = cls;
1227 const struct ZoneToNameMessage *ztn_msg;
1228 struct ZoneToNameCtx ztn_ctx; 1181 struct ZoneToNameCtx ztn_ctx;
1229 struct ZoneToNameResponseMessage ztnr_msg; 1182 struct GNUNET_MQ_Envelope *env;
1183 struct ZoneToNameResponseMessage *ztnr_msg;
1230 1184
1231 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1232 "Received `%s' message\n", 1186 "Received `%s' message\n",
1233 "ZONE_TO_NAME"); 1187 "ZONE_TO_NAME");
1234 ztn_msg = (const struct ZoneToNameMessage *) message;
1235 nc = client_lookup (client);
1236 ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id); 1188 ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id);
1237 ztn_ctx.nc = nc; 1189 ztn_ctx.nc = nc;
1238 ztn_ctx.success = GNUNET_NO; 1190 ztn_ctx.success = GNUNET_NO;
@@ -1245,7 +1197,7 @@ handle_zone_to_name (void *cls,
1245 /* internal error, hang up instead of signalling something 1197 /* internal error, hang up instead of signalling something
1246 that might be wrong */ 1198 that might be wrong */
1247 GNUNET_break (0); 1199 GNUNET_break (0);
1248 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1200 GNUNET_SERVICE_client_drop (nc->client);
1249 return; 1201 return;
1250 } 1202 }
1251 if (GNUNET_NO == ztn_ctx.success) 1203 if (GNUNET_NO == ztn_ctx.success)
@@ -1253,17 +1205,14 @@ handle_zone_to_name (void *cls,
1253 /* no result found, send empty response */ 1205 /* no result found, send empty response */
1254 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1206 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1255 "Found no result for zone-to-name lookup.\n"); 1207 "Found no result for zone-to-name lookup.\n");
1256 memset (&ztnr_msg, 0, sizeof (ztnr_msg)); 1208 env = GNUNET_MQ_msg (ztnr_msg,
1257 ztnr_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE); 1209 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE);
1258 ztnr_msg.gns_header.header.size = htons (sizeof (ztnr_msg)); 1210 ztnr_msg->gns_header.r_id = ztn_msg->gns_header.r_id;
1259 ztnr_msg.gns_header.r_id = ztn_msg->gns_header.r_id; 1211 ztnr_msg->res = htons (GNUNET_NO);
1260 ztnr_msg.res = htons (GNUNET_NO); 1212 GNUNET_MQ_send (nc->mq,
1261 GNUNET_SERVER_notification_context_unicast (snc, 1213 env);
1262 client,
1263 &ztnr_msg.gns_header.header,
1264 GNUNET_NO);
1265 } 1214 }
1266 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1215 GNUNET_SERVICE_client_continue (nc->client);
1267} 1216}
1268 1217
1269 1218
@@ -1324,13 +1273,12 @@ struct ZoneIterationProcResult
1324 */ 1273 */
1325static void 1274static void
1326zone_iterate_proc (void *cls, 1275zone_iterate_proc (void *cls,
1327 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 1276 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
1328 const char *name, 1277 const char *name,
1329 unsigned int rd_count, 1278 unsigned int rd_count,
1330 const struct GNUNET_GNSRECORD_Data *rd) 1279 const struct GNUNET_GNSRECORD_Data *rd)
1331{ 1280{
1332 struct ZoneIterationProcResult *proc = cls; 1281 struct ZoneIterationProcResult *proc = cls;
1333 unsigned int i;
1334 int do_refresh_block; 1282 int do_refresh_block;
1335 1283
1336 if ((NULL == zone_key) && (NULL == name)) 1284 if ((NULL == zone_key) && (NULL == name))
@@ -1348,22 +1296,22 @@ zone_iterate_proc (void *cls,
1348 return; 1296 return;
1349 } 1297 }
1350 proc->res_iteration_finished = IT_SUCCESS_MORE_AVAILABLE; 1298 proc->res_iteration_finished = IT_SUCCESS_MORE_AVAILABLE;
1351 send_lookup_response (snc, 1299 send_lookup_response (proc->zi->nc,
1352 proc->zi->client->client,
1353 proc->zi->request_id, 1300 proc->zi->request_id,
1354 zone_key, 1301 zone_key,
1355 name, 1302 name,
1356 rd_count, 1303 rd_count,
1357 rd); 1304 rd);
1358 do_refresh_block = GNUNET_NO; 1305 do_refresh_block = GNUNET_NO;
1359 for (i=0;i<rd_count;i++) 1306 for (unsigned int i=0;i<rd_count;i++)
1360 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) 1307 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
1361 { 1308 {
1362 do_refresh_block = GNUNET_YES; 1309 do_refresh_block = GNUNET_YES;
1363 break; 1310 break;
1364 } 1311 }
1365 if (GNUNET_YES == do_refresh_block) 1312 if (GNUNET_YES == do_refresh_block)
1366 refresh_block (NULL, 0, 1313 refresh_block (NULL,
1314 0,
1367 zone_key, 1315 zone_key,
1368 name, 1316 name,
1369 rd_count, 1317 rd_count,
@@ -1381,7 +1329,8 @@ static void
1381run_zone_iteration_round (struct ZoneIteration *zi) 1329run_zone_iteration_round (struct ZoneIteration *zi)
1382{ 1330{
1383 struct ZoneIterationProcResult proc; 1331 struct ZoneIterationProcResult proc;
1384 struct RecordResultMessage rrm; 1332 struct GNUNET_MQ_Envelope *env;
1333 struct RecordResultMessage *rrm;
1385 int ret; 1334 int ret;
1386 1335
1387 memset (&proc, 0, sizeof (proc)); 1336 memset (&proc, 0, sizeof (proc));
@@ -1411,16 +1360,13 @@ run_zone_iteration_round (struct ZoneIteration *zi)
1411 return; /* more results later */ 1360 return; /* more results later */
1412 } 1361 }
1413 /* send empty response to indicate end of list */ 1362 /* send empty response to indicate end of list */
1414 memset (&rrm, 0, sizeof (rrm)); 1363 env = GNUNET_MQ_msg (rrm,
1415 rrm.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT); 1364 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT);
1416 rrm.gns_header.header.size = htons (sizeof (rrm)); 1365 rrm->gns_header.r_id = htonl (zi->request_id);
1417 rrm.gns_header.r_id = htonl (zi->request_id); 1366 GNUNET_MQ_send (zi->nc->mq,
1418 GNUNET_SERVER_notification_context_unicast (snc, 1367 env);
1419 zi->client->client, 1368 GNUNET_CONTAINER_DLL_remove (zi->nc->op_head,
1420 &rrm.gns_header.header, 1369 zi->nc->op_tail,
1421 GNUNET_NO);
1422 GNUNET_CONTAINER_DLL_remove (zi->client->op_head,
1423 zi->client->op_tail,
1424 zi); 1370 zi);
1425 GNUNET_free (zi); 1371 GNUNET_free (zi);
1426} 1372}
@@ -1429,67 +1375,49 @@ run_zone_iteration_round (struct ZoneIteration *zi)
1429/** 1375/**
1430 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START message 1376 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START message
1431 * 1377 *
1432 * @param cls unused 1378 * @param cls the client sending the message
1433 * @param client the client sending the message 1379 * @param zis_msg message from the client
1434 * @param message message of type 'struct ZoneIterationStartMessage'
1435 */ 1380 */
1436static void 1381static void
1437handle_iteration_start (void *cls, 1382handle_iteration_start (void *cls,
1438 struct GNUNET_SERVER_Client *client, 1383 const struct ZoneIterationStartMessage *zis_msg)
1439 const struct GNUNET_MessageHeader *message)
1440{ 1384{
1441 const struct ZoneIterationStartMessage *zis_msg; 1385 struct NamestoreClient *nc = cls;
1442 struct NamestoreClient *nc;
1443 struct ZoneIteration *zi; 1386 struct ZoneIteration *zi;
1444 1387
1445 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_ITERATION_START"); 1388 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1446 if (NULL == (nc = client_lookup (client))) 1389 "Received ZONE_ITERATION_START message\n");
1447 {
1448 GNUNET_break (0);
1449 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1450 return;
1451 }
1452 zis_msg = (const struct ZoneIterationStartMessage *) message;
1453 zi = GNUNET_new (struct ZoneIteration); 1390 zi = GNUNET_new (struct ZoneIteration);
1454 zi->request_id = ntohl (zis_msg->gns_header.r_id); 1391 zi->request_id = ntohl (zis_msg->gns_header.r_id);
1455 zi->offset = 0; 1392 zi->offset = 0;
1456 zi->client = nc; 1393 zi->nc = nc;
1457 zi->zone = zis_msg->zone; 1394 zi->zone = zis_msg->zone;
1458 1395
1459 1396 GNUNET_CONTAINER_DLL_insert (nc->op_head,
1460 GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi); 1397 nc->op_tail,
1398 zi);
1461 run_zone_iteration_round (zi); 1399 run_zone_iteration_round (zi);
1462 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1400 GNUNET_SERVICE_client_continue (nc->client);
1463} 1401}
1464 1402
1465 1403
1466/** 1404/**
1467 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP message 1405 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP message
1468 * 1406 *
1469 * @param cls unused 1407 * @param cls the client sending the message
1470 * @param client GNUNET_SERVER_Client sending the message 1408 * @param zis_msg message from the client
1471 * @param message message of type 'struct ZoneIterationStopMessage'
1472 */ 1409 */
1473static void 1410static void
1474handle_iteration_stop (void *cls, 1411handle_iteration_stop (void *cls,
1475 struct GNUNET_SERVER_Client *client, 1412 const struct ZoneIterationStopMessage *zis_msg)
1476 const struct GNUNET_MessageHeader *message)
1477{ 1413{
1478 struct NamestoreClient *nc; 1414 struct NamestoreClient *nc = cls;
1479 struct ZoneIteration *zi; 1415 struct ZoneIteration *zi;
1480 const struct ZoneIterationStopMessage *zis_msg;
1481 uint32_t rid; 1416 uint32_t rid;
1482 1417
1483 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1418 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1484 "Received `%s' message\n", 1419 "Received `%s' message\n",
1485 "ZONE_ITERATION_STOP"); 1420 "ZONE_ITERATION_STOP");
1486 if (NULL == (nc = client_lookup(client)))
1487 {
1488 GNUNET_break (0);
1489 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1490 return;
1491 }
1492 zis_msg = (const struct ZoneIterationStopMessage *) message;
1493 rid = ntohl (zis_msg->gns_header.r_id); 1421 rid = ntohl (zis_msg->gns_header.r_id);
1494 for (zi = nc->op_head; NULL != zi; zi = zi->next) 1422 for (zi = nc->op_head; NULL != zi; zi = zi->next)
1495 if (zi->request_id == rid) 1423 if (zi->request_id == rid)
@@ -1497,42 +1425,33 @@ handle_iteration_stop (void *cls,
1497 if (NULL == zi) 1425 if (NULL == zi)
1498 { 1426 {
1499 GNUNET_break (0); 1427 GNUNET_break (0);
1500 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1428 GNUNET_SERVICE_client_drop (nc->client);
1501 return; 1429 return;
1502 } 1430 }
1503 GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, zi); 1431 GNUNET_CONTAINER_DLL_remove (nc->op_head,
1432 nc->op_tail,
1433 zi);
1504 GNUNET_free (zi); 1434 GNUNET_free (zi);
1505 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1435 GNUNET_SERVICE_client_continue (nc->client);
1506} 1436}
1507 1437
1508 1438
1509/** 1439/**
1510 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT message 1440 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT message
1511 * 1441 *
1512 * @param cls unused 1442 * @param cls the client sending the message
1513 * @param client GNUNET_SERVER_Client sending the message 1443 * @param message message from the client
1514 * @param message message of type 'struct ZoneIterationNextMessage'
1515 */ 1444 */
1516static void 1445static void
1517handle_iteration_next (void *cls, 1446handle_iteration_next (void *cls,
1518 struct GNUNET_SERVER_Client *client, 1447 const struct ZoneIterationNextMessage *zis_msg)
1519 const struct GNUNET_MessageHeader *message)
1520{ 1448{
1521 struct NamestoreClient *nc; 1449 struct NamestoreClient *nc = cls;
1522 struct ZoneIteration *zi; 1450 struct ZoneIteration *zi;
1523 const struct ZoneIterationNextMessage *zis_msg;
1524 uint32_t rid; 1451 uint32_t rid;
1525 1452
1526 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1453 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1527 "Received `%s' message\n", 1454 "Received ZONE_ITERATION_NEXT message\n");
1528 "ZONE_ITERATION_NEXT");
1529 if (NULL == (nc = client_lookup(client)))
1530 {
1531 GNUNET_break (0);
1532 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1533 return;
1534 }
1535 zis_msg = (const struct ZoneIterationNextMessage *) message;
1536 rid = ntohl (zis_msg->gns_header.r_id); 1455 rid = ntohl (zis_msg->gns_header.r_id);
1537 for (zi = nc->op_head; NULL != zi; zi = zi->next) 1456 for (zi = nc->op_head; NULL != zi; zi = zi->next)
1538 if (zi->request_id == rid) 1457 if (zi->request_id == rid)
@@ -1540,11 +1459,11 @@ handle_iteration_next (void *cls,
1540 if (NULL == zi) 1459 if (NULL == zi)
1541 { 1460 {
1542 GNUNET_break (0); 1461 GNUNET_break (0);
1543 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1462 GNUNET_SERVICE_client_drop (nc->client);
1544 return; 1463 return;
1545 } 1464 }
1546 run_zone_iteration_round (zi); 1465 run_zone_iteration_round (zi);
1547 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1466 GNUNET_SERVICE_client_continue (nc->client);
1548} 1467}
1549 1468
1550 1469
@@ -1556,14 +1475,13 @@ handle_iteration_next (void *cls,
1556static void 1475static void
1557monitor_sync (struct ZoneMonitor *zm) 1476monitor_sync (struct ZoneMonitor *zm)
1558{ 1477{
1559 struct GNUNET_MessageHeader sync; 1478 struct GNUNET_MQ_Envelope *env;
1560 1479 struct GNUNET_MessageHeader *sync;
1561 sync.size = htons (sizeof (struct GNUNET_MessageHeader)); 1480
1562 sync.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC); 1481 env = GNUNET_MQ_msg (sync,
1563 GNUNET_SERVER_notification_context_unicast (monitor_nc, 1482 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC);
1564 zm->nc->client, 1483 GNUNET_MQ_send (zm->nc->mq,
1565 &sync, 1484 env);
1566 GNUNET_NO);
1567} 1485}
1568 1486
1569 1487
@@ -1600,47 +1518,45 @@ monitor_iterate_cb (void *cls,
1600 monitor_sync (zm); 1518 monitor_sync (zm);
1601 return; 1519 return;
1602 } 1520 }
1603 send_lookup_response (monitor_nc, 1521 send_lookup_response (zm->nc,
1604 zm->nc->client,
1605 0, 1522 0,
1606 zone_key, 1523 zone_key,
1607 name, 1524 name,
1608 rd_count, 1525 rd_count,
1609 rd); 1526 rd);
1610 zm->task = GNUNET_SCHEDULER_add_now (&monitor_next, zm); 1527 zm->task = GNUNET_SCHEDULER_add_now (&monitor_next,
1528 zm);
1611} 1529}
1612 1530
1613 1531
1614/** 1532/**
1615 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START message 1533 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START message
1616 * 1534 *
1617 * @param cls unused 1535 * @param cls the client sending the message
1618 * @param client the client sending the message 1536 * @param message message from the client
1619 * @param message message of type 'struct ZoneMonitorStartMessage'
1620 */ 1537 */
1621static void 1538static void
1622handle_monitor_start (void *cls, 1539handle_monitor_start (void *cls,
1623 struct GNUNET_SERVER_Client *client, 1540 const struct ZoneMonitorStartMessage *zis_msg)
1624 const struct GNUNET_MessageHeader *message)
1625{ 1541{
1626 const struct ZoneMonitorStartMessage *zis_msg; 1542 struct NamestoreClient *nc = cls;
1627 struct ZoneMonitor *zm; 1543 struct ZoneMonitor *zm;
1628 1544
1629 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1545 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1630 "Received `%s' message\n", 1546 "Received ZONE_MONITOR_START message\n");
1631 "ZONE_MONITOR_START");
1632 zis_msg = (const struct ZoneMonitorStartMessage *) message;
1633 zm = GNUNET_new (struct ZoneMonitor); 1547 zm = GNUNET_new (struct ZoneMonitor);
1634 zm->offset = 0; 1548 zm->nc = nc;
1635 zm->nc = client_lookup (client);
1636 zm->zone = zis_msg->zone; 1549 zm->zone = zis_msg->zone;
1637 GNUNET_CONTAINER_DLL_insert (monitor_head, monitor_tail, zm); 1550 GNUNET_CONTAINER_DLL_insert (monitor_head,
1638 GNUNET_SERVER_client_mark_monitor (client); 1551 monitor_tail,
1639 GNUNET_SERVER_disable_receive_done_warning (client); 1552 zm);
1640 GNUNET_SERVER_notification_context_add (monitor_nc, 1553 GNUNET_SERVICE_client_mark_monitor (nc->client);
1641 client); 1554 GNUNET_SERVICE_client_disable_continue_warning (nc->client);
1555 GNUNET_notification_context_add (monitor_nc,
1556 nc->mq);
1642 if (GNUNET_YES == ntohl (zis_msg->iterate_first)) 1557 if (GNUNET_YES == ntohl (zis_msg->iterate_first))
1643 zm->task = GNUNET_SCHEDULER_add_now (&monitor_next, zm); 1558 zm->task = GNUNET_SCHEDULER_add_now (&monitor_next,
1559 zm);
1644 else 1560 else
1645 monitor_sync (zm); 1561 monitor_sync (zm);
1646} 1562}
@@ -1659,14 +1575,17 @@ monitor_next (void *cls)
1659 1575
1660 zm->task = NULL; 1576 zm->task = NULL;
1661 ret = GSN_database->iterate_records (GSN_database->cls, 1577 ret = GSN_database->iterate_records (GSN_database->cls,
1662 (0 == memcmp (&zm->zone, &zero, sizeof (zero))) 1578 (0 == memcmp (&zm->zone,
1579 &zero,
1580 sizeof (zero)))
1663 ? NULL 1581 ? NULL
1664 : &zm->zone, 1582 : &zm->zone,
1665 zm->offset++, 1583 zm->offset++,
1666 &monitor_iterate_cb, zm); 1584 &monitor_iterate_cb,
1585 zm);
1667 if (GNUNET_SYSERR == ret) 1586 if (GNUNET_SYSERR == ret)
1668 { 1587 {
1669 GNUNET_SERVER_client_disconnect (zm->nc->client); 1588 GNUNET_SERVICE_client_drop (zm->nc->client);
1670 return; 1589 return;
1671 } 1590 }
1672 if (GNUNET_NO == ret) 1591 if (GNUNET_NO == ret)
@@ -1682,35 +1601,20 @@ monitor_next (void *cls)
1682 * Process namestore requests. 1601 * Process namestore requests.
1683 * 1602 *
1684 * @param cls closure 1603 * @param cls closure
1685 * @param server the initialized server
1686 * @param cfg configuration to use 1604 * @param cfg configuration to use
1605 * @param service the initialized service
1687 */ 1606 */
1688static void 1607static void
1689run (void *cls, struct GNUNET_SERVER_Handle *server, 1608run (void *cls,
1690 const struct GNUNET_CONFIGURATION_Handle *cfg) 1609 const struct GNUNET_CONFIGURATION_Handle *cfg,
1610 struct GNUNET_SERVICE_Handle *service)
1691{ 1611{
1692 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
1693 {&handle_record_store, NULL,
1694 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE, 0},
1695 {&handle_record_lookup, NULL,
1696 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP, 0},
1697 {&handle_zone_to_name, NULL,
1698 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME, sizeof (struct ZoneToNameMessage) },
1699 {&handle_iteration_start, NULL,
1700 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START, sizeof (struct ZoneIterationStartMessage) },
1701 {&handle_iteration_next, NULL,
1702 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT, sizeof (struct ZoneIterationNextMessage) },
1703 {&handle_iteration_stop, NULL,
1704 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP, sizeof (struct ZoneIterationStopMessage) },
1705 {&handle_monitor_start, NULL,
1706 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START, sizeof (struct ZoneMonitorStartMessage) },
1707 {NULL, NULL, 0, 0}
1708 };
1709 char *database; 1612 char *database;
1710 1613
1711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting namestore service\n"); 1614 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1615 "Starting namestore service\n");
1712 GSN_cfg = cfg; 1616 GSN_cfg = cfg;
1713 monitor_nc = GNUNET_SERVER_notification_context_create (server, 1); 1617 monitor_nc = GNUNET_notification_context_create (1);
1714 namecache = GNUNET_NAMECACHE_connect (cfg); 1618 namecache = GNUNET_NAMECACHE_connect (cfg);
1715 /* Loading database plugin */ 1619 /* Loading database plugin */
1716 if (GNUNET_OK != 1620 if (GNUNET_OK !=
@@ -1727,39 +1631,58 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1727 GSN_database = GNUNET_PLUGIN_load (db_lib_name, 1631 GSN_database = GNUNET_PLUGIN_load (db_lib_name,
1728 (void *) GSN_cfg); 1632 (void *) GSN_cfg);
1729 GNUNET_free (database); 1633 GNUNET_free (database);
1634 GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
1635 NULL);
1730 if (NULL == GSN_database) 1636 if (NULL == GSN_database)
1731 { 1637 {
1732 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1638 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1733 "Could not load database backend `%s'\n", 1639 "Could not load database backend `%s'\n",
1734 db_lib_name); 1640 db_lib_name);
1735 GNUNET_SCHEDULER_add_now (&cleanup_task, NULL); 1641 GNUNET_SCHEDULER_shutdown ();
1736 return; 1642 return;
1737 } 1643 }
1738
1739 /* Configuring server handles */
1740 GNUNET_SERVER_add_handlers (server, handlers);
1741 snc = GNUNET_SERVER_notification_context_create (server, 16);
1742 GNUNET_SERVER_disconnect_notify (server,
1743 &client_disconnect_notification,
1744 NULL);
1745 GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
1746 NULL);
1747} 1644}
1748 1645
1749 1646
1750/** 1647/**
1751 * The main function for the template service. 1648 * Define "main" method using service macro.
1752 *
1753 * @param argc number of arguments from the command line
1754 * @param argv command line arguments
1755 * @return 0 ok, 1 on error
1756 */ 1649 */
1757int 1650GNUNET_SERVICE_MAIN
1758main (int argc, char *const *argv) 1651("namestore",
1759{ 1652 GNUNET_SERVICE_OPTION_NONE,
1760 return (GNUNET_OK == 1653 &run,
1761 GNUNET_SERVICE_run (argc, argv, "namestore", 1654 &client_connect_cb,
1762 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; 1655 &client_disconnect_cb,
1763} 1656 NULL,
1657 GNUNET_MQ_hd_var_size (record_store,
1658 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE,
1659 struct RecordStoreMessage,
1660 NULL),
1661 GNUNET_MQ_hd_var_size (record_lookup,
1662 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP,
1663 struct LabelLookupMessage,
1664 NULL),
1665 GNUNET_MQ_hd_fixed_size (zone_to_name,
1666 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME,
1667 struct ZoneToNameMessage,
1668 NULL),
1669 GNUNET_MQ_hd_fixed_size (iteration_start,
1670 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START,
1671 struct ZoneIterationStartMessage,
1672 NULL),
1673 GNUNET_MQ_hd_fixed_size (iteration_next,
1674 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT,
1675 struct ZoneIterationNextMessage,
1676 NULL),
1677 GNUNET_MQ_hd_fixed_size (iteration_stop,
1678 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP,
1679 struct ZoneIterationStopMessage,
1680 NULL),
1681 GNUNET_MQ_hd_fixed_size (monitor_start,
1682 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START,
1683 struct ZoneMonitorStartMessage,
1684 NULL),
1685 GNUNET_MQ_handler_end ());
1686
1764 1687
1765/* end of gnunet-service-namestore.c */ 1688/* end of gnunet-service-namestore.c */