2 This file is part of GNUnet.
3 (C) 2010, 2011, 2012 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file namestore/namestore_api.c
23 * @brief API to access the NAMESTORE service
24 * @author Martin Schanzenbach
25 * @author Matthias Wachs
26 * @author Christian Grothoff
30 #include "gnunet_util_lib.h"
31 #include "gnunet_crypto_lib.h"
32 #include "gnunet_constants.h"
33 #include "gnunet_dnsparser_lib.h"
34 #include "gnunet_arm_service.h"
35 #include "gnunet_signatures.h"
36 #include "gnunet_namestore_service.h"
37 #include "namestore.h"
40 #define LOG(kind,...) GNUNET_log_from (kind, "namestore-api",__VA_ARGS__)
44 * An QueueEntry used to store information for a pending
45 * NAMESTORE record operation
47 struct GNUNET_NAMESTORE_QueueEntry
53 struct GNUNET_NAMESTORE_QueueEntry *next;
58 struct GNUNET_NAMESTORE_QueueEntry *prev;
61 * Main handle to access the namestore.
63 struct GNUNET_NAMESTORE_Handle *nsh;
66 * Continuation to call
68 GNUNET_NAMESTORE_ContinuationWithStatus cont;
76 * Function to call with the records we get back; or NULL.
78 GNUNET_NAMESTORE_RecordProcessor proc;
86 * The operation id this zone iteration operation has
94 * Handle for a zone iterator operation
96 struct GNUNET_NAMESTORE_ZoneIterator
102 struct GNUNET_NAMESTORE_ZoneIterator *next;
107 struct GNUNET_NAMESTORE_ZoneIterator *prev;
110 * Main handle to access the namestore.
112 struct GNUNET_NAMESTORE_Handle *h;
115 * The continuation to call with the results
117 GNUNET_NAMESTORE_RecordProcessor proc;
120 * Closure for 'proc'.
125 * If this iterator iterates over a specific zone this value contains the
126 * short hash of the zone
128 struct GNUNET_CRYPTO_ShortHashCode zone;
131 * The operation id this zone iteration operation has
136 * GNUNET_YES if this iterator iterates over a specific zone
137 * GNUNET_NO if this iterator iterates over all zones
139 * Zone is stored GNUNET_CRYPTO_ShortHashCode 'zone';
146 * Message in linked list we should send to the service. The
147 * actual binary message follows this struct.
149 struct PendingMessage
155 struct PendingMessage *next;
160 struct PendingMessage *prev;
163 * Size of the message.
168 * Is this the 'START' message?
175 * Connection to the NAMESTORE service.
177 struct GNUNET_NAMESTORE_Handle
181 * Configuration to use.
183 const struct GNUNET_CONFIGURATION_Handle *cfg;
186 * Socket (if available).
188 struct GNUNET_CLIENT_Connection *client;
191 * Currently pending transmission request (or NULL).
193 struct GNUNET_CLIENT_TransmitHandle *th;
196 * Head of linked list of pending messages to send to the service
198 struct PendingMessage * pending_head;
201 * Tail of linked list of pending messages to send to the service
203 struct PendingMessage * pending_tail;
206 * Head of pending namestore queue entries
208 struct GNUNET_NAMESTORE_QueueEntry * op_head;
211 * Tail of pending namestore queue entries
213 struct GNUNET_NAMESTORE_QueueEntry * op_tail;
216 * Head of pending namestore zone iterator entries
218 struct GNUNET_NAMESTORE_ZoneIterator * z_head;
221 * Tail of pending namestore zone iterator entries
223 struct GNUNET_NAMESTORE_ZoneIterator * z_tail;
228 GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
231 * Should we reconnect to service due to some serious error?
236 * The last operation id used for a NAMESTORE operation
238 uint32_t last_op_id_used;
244 * Disconnect from service and then reconnect.
246 * @param h our handle
249 force_reconnect (struct GNUNET_NAMESTORE_Handle *h);
253 * Handle an incoming message of type 'GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE'
255 * @param qe the respective entry in the message queue
256 * @param msg the message we received
257 * @param size the message size
258 * @return GNUNET_OK on success, GNUNET_SYSERR on error and we did NOT notify the client
261 handle_lookup_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
262 const struct LookupNameResponseMessage * msg,
267 const struct GNUNET_CRYPTO_RsaSignature *signature;
268 struct GNUNET_TIME_Absolute expire;
269 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key_tmp;
277 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received `%s'\n", "LOOKUP_NAME_RESPONSE");
278 rd_len = ntohs (msg->rd_len);
279 rd_count = ntohs (msg->rd_count);
280 msg_len = ntohs (msg->gns_header.header.size);
281 name_len = ntohs (msg->name_len);
282 contains_sig = ntohs (msg->contains_sig);
283 expire = GNUNET_TIME_absolute_ntoh (msg->expire);
284 exp_msg_len = sizeof (struct LookupNameResponseMessage) +
285 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
287 if (msg_len != exp_msg_len)
290 return GNUNET_SYSERR;
292 name = (const char *) &msg[1];
293 if ( (name_len > 0) &&
294 ('\0' != name[name_len -1]) )
297 return GNUNET_SYSERR;
299 rd_tmp = &name[name_len];
301 struct GNUNET_NAMESTORE_RecordData rd[rd_count];
303 if (GNUNET_OK != GNUNET_NAMESTORE_records_deserialize(rd_len, rd_tmp, rd_count, rd))
306 return GNUNET_SYSERR;
308 if (GNUNET_NO == contains_sig)
311 signature = &msg->signature;
315 public_key_tmp = &msg->public_key;
317 public_key_tmp = NULL;
318 if (NULL != qe->proc)
319 qe->proc (qe->proc_cls, public_key_tmp, expire, name, rd_count, (rd_count > 0) ? rd : NULL, signature);
326 * Handle an incoming message of type 'GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE'
328 * @param qe the respective entry in the message queue
329 * @param msg the message we received
330 * @param size the message size
331 * @return GNUNET_OK on success, GNUNET_SYSERR on error and we did NOT notify the client
334 handle_record_put_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
335 const struct RecordPutResponseMessage* msg,
340 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received `%s'\n",
341 "RECORD_PUT_RESPONSE");
342 res = ntohl (msg->op_result);
343 /* TODO: add actual error message from namestore to response... */
344 if (NULL != qe->cont)
345 qe->cont (qe->cont_cls, res, (GNUNET_OK == res) ? NULL : _("Namestore failed to add record"));
351 * Handle an incoming message of type 'GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE'
353 * @param qe the respective entry in the message queue
354 * @param msg the message we received
355 * @param size the message size
356 * @return GNUNET_OK on success, GNUNET_SYSERR on error and we did NOT notify the client
359 handle_record_create_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
360 const struct RecordCreateResponseMessage* msg,
366 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received `%s'\n",
367 "RECORD_CREATE_RESPONSE");
368 /* TODO: add actual error message from namestore to response... */
369 res = ntohl (msg->op_result);
370 if (GNUNET_SYSERR == res)
371 emsg = _("Namestore failed to add record\n");
374 if (NULL != qe->cont)
375 qe->cont (qe->cont_cls, res, emsg);
381 * Handle an incoming message of type 'GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE'
383 * @param qe the respective entry in the message queue
384 * @param msg the message we received
385 * @param size the message size
386 * @return GNUNET_OK on success, GNUNET_SYSERR on error and we did NOT notify the client
389 handle_record_remove_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
390 const struct RecordRemoveResponseMessage* msg,
396 /* Operation done, remove */
397 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received `%s'\n",
398 "RECORD_REMOVE_RESPONSE");
399 switch (ntohl (msg->op_result))
401 case RECORD_REMOVE_RESULT_SUCCESS:
405 case RECORD_REMOVE_RESULT_NO_RECORDS:
409 case RECORD_REMOVE_RESULT_RECORD_NOT_FOUND:
413 case RECORD_REMOVE_RESULT_FAILED_TO_SIGN:
415 emsg = _("Failed to create new signature");
417 case RECORD_REMOVE_RESULT_FAILED_TO_PUT_UPDATE:
419 emsg = _("Failed to put new set of records in database");
421 case RECORD_REMOVE_RESULT_FAILED_TO_REMOVE:
423 emsg = _("Failed to remove records from database");
425 case RECORD_REMOVE_RESULT_FAILED_ACCESS_DATABASE:
427 emsg = _("Failed to access database");
429 case RECORD_REMOVE_RESULT_FAILED_INTERNAL_ERROR:
431 emsg = _("unknown internal error in namestore");
435 if (NULL != qe->cont)
436 qe->cont (qe->cont_cls, GNUNET_SYSERR, _("Protocol error"));
439 if (NULL != qe->cont)
440 qe->cont (qe->cont_cls, ret, emsg);
446 * Handle an incoming message of type 'GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE'
448 * @param qe the respective entry in the message queue
449 * @param msg the message we received
450 * @param size the message size
451 * @return GNUNET_OK on success, GNUNET_NO if we notified the client about
452 * the error, GNUNET_SYSERR on error and we did NOT notify the client
455 handle_zone_to_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
456 const struct ZoneToNameResponseMessage* msg,
460 struct GNUNET_TIME_Absolute expire;
463 unsigned int rd_count;
464 const char * name_tmp;
467 LOG (GNUNET_ERROR_TYPE_DEBUG,
469 "ZONE_TO_NAME_RESPONSE");
470 res = ntohs (msg->res);
474 LOG (GNUNET_ERROR_TYPE_DEBUG, "An error occured during zone to name operation\n");
477 LOG (GNUNET_ERROR_TYPE_DEBUG, "Namestore has no result for zone to name mapping \n");
480 LOG (GNUNET_ERROR_TYPE_DEBUG, "Namestore has result for zone to name mapping \n");
481 name_len = ntohs (msg->name_len);
482 rd_count = ntohs (msg->rd_count);
483 rd_ser_len = ntohs (msg->rd_len);
484 expire = GNUNET_TIME_absolute_ntoh(msg->expire);
485 name_tmp = (const char *) &msg[1];
486 if ( (name_len > 0) &&
487 ('\0' != name_tmp[name_len -1]) )
490 return GNUNET_SYSERR;
492 rd_tmp = &name_tmp[name_len];
494 struct GNUNET_NAMESTORE_RecordData rd[rd_count];
495 if (GNUNET_OK != GNUNET_NAMESTORE_records_deserialize(rd_ser_len, rd_tmp, rd_count, rd))
498 return GNUNET_SYSERR;
500 /* normal end, call continuation with result */
501 if (NULL != qe->proc)
502 qe->proc (qe->proc_cls, &msg->zone_key, expire, name_tmp, rd_count, rd, &msg->signature);
503 /* return is important here: break would call continuation with error! */
508 return GNUNET_SYSERR;
510 /* error case, call continuation with error */
511 if (NULL != qe->proc)
512 qe->proc (qe->proc_cls, NULL, GNUNET_TIME_UNIT_ZERO_ABS, NULL, 0, NULL, NULL);
518 * Handle incoming messages for record operations
520 * @param qe the respective zone iteration handle
521 * @param msg the message we received
522 * @param type the message type in HBO
523 * @param size the message size
524 * @return GNUNET_OK on success, GNUNET_NO if we notified the client about
525 * the error, GNUNET_SYSERR on error and we did NOT notify the client
528 manage_record_operations (struct GNUNET_NAMESTORE_QueueEntry *qe,
529 const struct GNUNET_MessageHeader *msg,
533 /* handle different message type */
536 case GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE:
537 if (size < sizeof (struct LookupNameResponseMessage))
540 return GNUNET_SYSERR;
542 return handle_lookup_name_response (qe, (const struct LookupNameResponseMessage *) msg, size);
543 case GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE:
544 if (size != sizeof (struct RecordPutResponseMessage))
547 return GNUNET_SYSERR;
549 return handle_record_put_response (qe, (const struct RecordPutResponseMessage *) msg, size);
550 case GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE:
551 if (size != sizeof (struct RecordCreateResponseMessage))
554 return GNUNET_SYSERR;
556 return handle_record_create_response (qe, (const struct RecordCreateResponseMessage *) msg, size);
557 case GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE:
558 if (size != sizeof (struct RecordRemoveResponseMessage))
561 return GNUNET_SYSERR;
563 return handle_record_remove_response (qe, (const struct RecordRemoveResponseMessage *) msg, size);
564 case GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE:
565 if (size < sizeof (struct ZoneToNameResponseMessage))
568 return GNUNET_SYSERR;
570 return handle_zone_to_name_response (qe, (const struct ZoneToNameResponseMessage *) msg, size);
573 return GNUNET_SYSERR;
579 * Handle a response from NAMESTORE service for a zone iteration request
581 * @param ze the respective iterator for this operation
582 * @param msg the message containing the respoonse
583 * @param size the message size
584 * @return GNUNET_YES on success, 'ze' should be kept, GNUNET_NO on success if 'ze' should
585 * not be kept any longer, GNUNET_SYSERR on error (disconnect) and 'ze' should be kept
588 handle_zone_iteration_response (struct GNUNET_NAMESTORE_ZoneIterator *ze,
589 const struct ZoneIterationResponseMessage *msg,
592 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubdummy;
598 const char *name_tmp;
599 const char *rd_ser_tmp;
600 struct GNUNET_TIME_Absolute expire;
602 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received `%s'\n",
603 "ZONE_ITERATION_RESPONSE");
604 msg_len = ntohs (msg->gns_header.header.size);
605 rd_len = ntohs (msg->rd_len);
606 rd_count = ntohs (msg->rd_count);
607 name_len = ntohs (msg->name_len);
608 expire = GNUNET_TIME_absolute_ntoh (msg->expire);
609 exp_msg_len = sizeof (struct ZoneIterationResponseMessage) + name_len + rd_len;
610 if (msg_len != exp_msg_len)
613 return GNUNET_SYSERR;
615 GNUNET_break (0 == ntohs (msg->reserved));
616 memset (&pubdummy, '\0', sizeof (pubdummy));
617 if ((0 == name_len) && (0 == (memcmp (&msg->public_key, &pubdummy, sizeof (pubdummy)))))
619 LOG (GNUNET_ERROR_TYPE_DEBUG, "Zone iteration is completed!\n");
620 if (NULL != ze->proc)
621 ze->proc(ze->proc_cls, NULL, GNUNET_TIME_UNIT_ZERO_ABS, NULL , 0, NULL, NULL);
624 name_tmp = (const char *) &msg[1];
625 if ((name_tmp[name_len -1] != '\0') || (name_len > MAX_NAME_LEN))
628 return GNUNET_SYSERR;
630 rd_ser_tmp = (const char *) &name_tmp[name_len];
632 struct GNUNET_NAMESTORE_RecordData rd[rd_count];
634 if (GNUNET_OK != GNUNET_NAMESTORE_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd))
637 return GNUNET_SYSERR;
639 if (NULL != ze->proc)
640 ze->proc(ze->proc_cls, &msg->public_key, expire, name_tmp, rd_count, rd, &msg->signature);
647 * Handle incoming messages for zone iterations
649 * @param ze the respective zone iteration handle
650 * @param msg the message we received
651 * @param type the message type in HBO
652 * @param size the message size
653 * @return GNUNET_YES on success, 'ze' should be kept, GNUNET_NO on success if 'ze' should
654 * not be kept any longer, GNUNET_SYSERR on error (disconnect) and 'ze' should be kept
657 manage_zone_operations (struct GNUNET_NAMESTORE_ZoneIterator *ze,
658 const struct GNUNET_MessageHeader *msg,
659 int type, size_t size)
661 /* handle different message type */
664 case GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE:
665 if (size < sizeof (struct ZoneIterationResponseMessage))
668 return GNUNET_SYSERR;
670 return handle_zone_iteration_response (ze, (const struct ZoneIterationResponseMessage *) msg, size);
673 return GNUNET_SYSERR;
679 * Type of a function to call when we receive a message
682 * @param cls the 'struct GNUNET_NAMESTORE_SchedulingHandle'
683 * @param msg message received, NULL on timeout or fatal error
686 process_namestore_message (void *cls, const struct GNUNET_MessageHeader *msg)
688 struct GNUNET_NAMESTORE_Handle *h = cls;
689 const struct GNUNET_NAMESTORE_Header *gm;
690 struct GNUNET_NAMESTORE_QueueEntry *qe;
691 struct GNUNET_NAMESTORE_ZoneIterator *ze;
702 size = ntohs (msg->size);
703 type = ntohs (msg->type);
704 if (size < sizeof (struct GNUNET_NAMESTORE_Header))
707 GNUNET_CLIENT_receive (h->client, &process_namestore_message, h,
708 GNUNET_TIME_UNIT_FOREVER_REL);
711 gm = (const struct GNUNET_NAMESTORE_Header *) msg;
712 r_id = ntohl (gm->r_id);
714 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received message type %u size %u op %u\n",
717 (unsigned int) r_id);
719 /* Is it a record related operation ? */
720 for (qe = h->op_head; qe != NULL; qe = qe->next)
721 if (qe->op_id == r_id)
725 ret = manage_record_operations (qe, msg, type, size);
726 if (GNUNET_OK != ret)
728 /* protocol error, need to reconnect */
729 h->reconnect = GNUNET_YES;
731 if (GNUNET_SYSERR != ret)
733 /* client was notified about success or failure, clean up 'qe' */
734 GNUNET_CONTAINER_DLL_remove (h->op_head,
741 /* Is it a zone iteration operation ? */
742 for (ze = h->z_head; ze != NULL; ze = ze->next)
743 if (ze->op_id == r_id)
747 ret = manage_zone_operations (ze, msg, type, size);
748 if (GNUNET_NO == ret)
750 /* end of iteration, clean up 'ze' */
751 GNUNET_CONTAINER_DLL_remove (h->z_head,
756 if (GNUNET_SYSERR == ret)
758 /* protocol error, need to reconnect */
759 h->reconnect = GNUNET_YES;
762 if (GNUNET_YES == h->reconnect)
767 GNUNET_CLIENT_receive (h->client, &process_namestore_message, h,
768 GNUNET_TIME_UNIT_FOREVER_REL);
773 * Transmit messages from the message queue to the service
774 * (if there are any, and if we are not already trying).
776 * @param h handle to use
779 do_transmit (struct GNUNET_NAMESTORE_Handle *h);
783 * We can now transmit a message to NAMESTORE. Do it.
785 * @param cls the 'struct GNUNET_NAMESTORE_Handle'
786 * @param size number of bytes we can transmit
787 * @param buf where to copy the messages
788 * @return number of bytes copied into buf
791 transmit_message_to_namestore (void *cls, size_t size, void *buf)
793 struct GNUNET_NAMESTORE_Handle *h = cls;
794 struct PendingMessage *p;
799 if ((0 == size) || (NULL == buf))
806 while ((NULL != (p = h->pending_head)) && (p->size <= size))
808 memcpy (&cbuf[ret], &p[1], p->size);
811 GNUNET_CONTAINER_DLL_remove (h->pending_head, h->pending_tail, p);
812 if (GNUNET_YES == p->is_init)
813 GNUNET_CLIENT_receive (h->client, &process_namestore_message, h,
814 GNUNET_TIME_UNIT_FOREVER_REL);
823 * Transmit messages from the message queue to the service
824 * (if there are any, and if we are not already trying).
826 * @param h handle to use
829 do_transmit (struct GNUNET_NAMESTORE_Handle *h)
831 struct PendingMessage *p;
834 return; /* transmission request already pending */
835 if (NULL == (p = h->pending_head))
836 return; /* transmission queue empty */
837 if (NULL == h->client)
838 return; /* currently reconnecting */
839 h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, p->size,
840 GNUNET_TIME_UNIT_FOREVER_REL,
841 GNUNET_NO, &transmit_message_to_namestore,
847 * Reconnect to namestore service.
849 * @param h the handle to the NAMESTORE service
852 reconnect (struct GNUNET_NAMESTORE_Handle *h)
854 struct PendingMessage *p;
855 struct StartMessage *init;
857 GNUNET_assert (NULL == h->client);
858 h->client = GNUNET_CLIENT_connect ("namestore", h->cfg);
859 GNUNET_assert (NULL != h->client);
860 if ((NULL == (p = h->pending_head)) || (GNUNET_YES != p->is_init))
862 p = GNUNET_malloc (sizeof (struct PendingMessage) +
863 sizeof (struct StartMessage));
864 p->size = sizeof (struct StartMessage);
865 p->is_init = GNUNET_YES;
866 init = (struct StartMessage *) &p[1];
867 init->header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_START);
868 init->header.size = htons (sizeof (struct StartMessage));
869 GNUNET_CONTAINER_DLL_insert (h->pending_head, h->pending_tail, p);
876 * Re-establish the connection to the service.
878 * @param cls handle to use to re-connect.
879 * @param tc scheduler context
882 reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
884 struct GNUNET_NAMESTORE_Handle *h = cls;
886 h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
892 * Disconnect from service and then reconnect.
894 * @param h our handle
897 force_reconnect (struct GNUNET_NAMESTORE_Handle *h)
899 h->reconnect = GNUNET_NO;
900 GNUNET_CLIENT_disconnect (h->client);
902 h->reconnect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
909 * Get a fresh operation id to distinguish between namestore requests
911 * @param h the namestore handle
912 * @return next operation id to use
915 get_op_id (struct GNUNET_NAMESTORE_Handle *h)
917 return h->last_op_id_used++;
922 * Initialize the connection with the NAMESTORE service.
924 * @param cfg configuration to use
925 * @return handle to the GNS service, or NULL on error
927 struct GNUNET_NAMESTORE_Handle *
928 GNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
930 struct GNUNET_NAMESTORE_Handle *h;
932 h = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_Handle));
934 h->reconnect_task = GNUNET_SCHEDULER_add_now (&reconnect_task, h);
935 h->last_op_id_used = 0;
941 * Disconnect from the namestore service (and free associated
944 * @param h handle to the namestore
947 GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h)
949 struct PendingMessage *p;
950 struct GNUNET_NAMESTORE_QueueEntry *q;
951 struct GNUNET_NAMESTORE_ZoneIterator *z;
953 LOG (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
954 GNUNET_assert (NULL != h);
955 while (NULL != (p = h->pending_head))
957 GNUNET_CONTAINER_DLL_remove (h->pending_head, h->pending_tail, p);
960 GNUNET_break (NULL == h->op_head);
961 while (NULL != (q = h->op_head))
963 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, q);
966 GNUNET_break (NULL == h->z_head);
967 while (NULL != (z = h->z_head))
969 GNUNET_CONTAINER_DLL_remove (h->z_head, h->z_tail, z);
972 if (NULL != h->client)
974 GNUNET_CLIENT_disconnect (h->client);
977 if (GNUNET_SCHEDULER_NO_TASK != h->reconnect_task)
979 GNUNET_SCHEDULER_cancel (h->reconnect_task);
980 h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
987 * Store an item in the namestore. If the item is already present,
988 * the expiration time is updated to the max of the existing time and
989 * the new time. This API is used when we cache signatures from other
992 * @param h handle to the namestore
993 * @param zone_key public key of the zone
994 * @param name name that is being mapped (at most 255 characters long)
995 * @param freshness when does the corresponding block in the DHT expire (until
996 * when should we never do a DHT lookup for the same name again)?
997 * @param rd_count number of entries in 'rd' array
998 * @param rd array of records with data to store
999 * @param signature signature for all the records in the zone under the given name
1000 * @param cont continuation to call when done
1001 * @param cont_cls closure for cont
1002 * @return handle to abort the request
1004 struct GNUNET_NAMESTORE_QueueEntry *
1005 GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h,
1006 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
1008 struct GNUNET_TIME_Absolute freshness,
1009 unsigned int rd_count,
1010 const struct GNUNET_NAMESTORE_RecordData *rd,
1011 const struct GNUNET_CRYPTO_RsaSignature *signature,
1012 GNUNET_NAMESTORE_ContinuationWithStatus cont,
1015 struct GNUNET_NAMESTORE_QueueEntry *qe;
1016 struct PendingMessage *pe;
1017 struct RecordPutMessage * msg;
1025 GNUNET_assert (NULL != h);
1026 GNUNET_assert (NULL != zone_key);
1027 GNUNET_assert (NULL != name);
1028 GNUNET_assert (NULL != rd);
1029 GNUNET_assert (NULL != signature);
1030 LOG (GNUNET_ERROR_TYPE_DEBUG,
1031 "Storing %u records under name `%s'\n",
1034 name_len = strlen(name) + 1;
1035 if (name_len > MAX_NAME_LEN)
1040 rid = get_op_id (h);
1041 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
1044 qe->cont_cls = cont_cls;
1046 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1049 rd_ser_len = GNUNET_NAMESTORE_records_get_size(rd_count, rd);
1050 msg_size = sizeof (struct RecordPutMessage) + name_len + rd_ser_len;
1051 pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
1052 pe->size = msg_size;
1053 pe->is_init = GNUNET_NO;
1054 msg = (struct RecordPutMessage *) &pe[1];
1055 msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT);
1056 msg->gns_header.header.size = htons (msg_size);
1057 msg->gns_header.r_id = htonl (rid);
1058 msg->signature = *signature;
1059 msg->name_len = htons (name_len);
1060 msg->expire = GNUNET_TIME_absolute_hton (freshness);
1061 msg->rd_len = htons (rd_ser_len);
1062 msg->rd_count = htons (rd_count);
1063 msg->public_key = *zone_key;
1064 name_tmp = (char *) &msg[1];
1065 memcpy (name_tmp, name, name_len);
1066 rd_ser = &name_tmp[name_len];
1067 GNUNET_NAMESTORE_records_serialize(rd_count, rd, rd_ser_len, rd_ser);
1068 LOG (GNUNET_ERROR_TYPE_DEBUG,
1069 "Sending `%s' message for name `%s' with size %u\n",
1070 "NAMESTORE_RECORD_PUT",
1072 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe);
1079 * Check if a signature is valid. This API is used by the GNS Block
1080 * to validate signatures received from the network.
1082 * @param public_key public key of the zone
1083 * @param freshness block expiration
1084 * @param name name that is being mapped (at most 255 characters long)
1085 * @param rd_count number of entries in 'rd' array
1086 * @param rd array of records with data to store
1087 * @param signature signature for all the records in the zone under the given name
1088 * @return GNUNET_OK if the signature is valid
1091 GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key,
1092 const struct GNUNET_TIME_Absolute freshness,
1094 unsigned int rd_count,
1095 const struct GNUNET_NAMESTORE_RecordData *rd,
1096 const struct GNUNET_CRYPTO_RsaSignature *signature)
1102 struct GNUNET_CRYPTO_RsaSignaturePurpose *sig_purpose;
1103 struct GNUNET_TIME_AbsoluteNBO *expire_tmp;
1104 struct GNUNET_TIME_AbsoluteNBO expire_nbo = GNUNET_TIME_absolute_hton (freshness);
1107 GNUNET_assert (NULL != public_key);
1108 GNUNET_assert (NULL != name);
1109 GNUNET_assert (NULL != rd);
1110 GNUNET_assert (NULL != signature);
1111 name_len = strlen (name) + 1;
1112 if (name_len > MAX_NAME_LEN)
1115 return GNUNET_SYSERR;
1117 rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
1118 sig_len = sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + sizeof (struct GNUNET_TIME_AbsoluteNBO) + rd_ser_len + name_len;
1120 char sig_buf[sig_len] GNUNET_ALIGN;
1122 sig_purpose = (struct GNUNET_CRYPTO_RsaSignaturePurpose *) sig_buf;
1123 sig_purpose->size = htonl (sig_len);
1124 sig_purpose->purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN);
1125 expire_tmp = (struct GNUNET_TIME_AbsoluteNBO *) &sig_purpose[1];
1126 memcpy (expire_tmp, &expire_nbo, sizeof (struct GNUNET_TIME_AbsoluteNBO));
1127 name_tmp = (char *) &expire_tmp[1];
1128 memcpy (name_tmp, name, name_len);
1129 rd_ser = &name_tmp[name_len];
1130 GNUNET_assert (rd_ser_len ==
1131 GNUNET_NAMESTORE_records_serialize (rd_count, rd, rd_ser_len, rd_ser));
1132 return GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN, sig_purpose, signature, public_key);
1138 * Store an item in the namestore. If the item is already present,
1139 * the expiration time is updated to the max of the existing time and
1140 * the new time. This API is used by the authority of a zone.
1142 * @param h handle to the namestore
1143 * @param pkey private key of the zone
1144 * @param name name that is being mapped (at most 255 characters long)
1145 * @param rd record data to store
1146 * @param cont continuation to call when done
1147 * @param cont_cls closure for cont
1148 * @return handle to abort the request
1150 struct GNUNET_NAMESTORE_QueueEntry *
1151 GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h,
1152 const struct GNUNET_CRYPTO_RsaPrivateKey *pkey,
1154 const struct GNUNET_NAMESTORE_RecordData *rd,
1155 GNUNET_NAMESTORE_ContinuationWithStatus cont,
1158 struct GNUNET_NAMESTORE_QueueEntry *qe;
1159 struct PendingMessage *pe;
1168 struct RecordCreateMessage * msg;
1169 struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded * pkey_enc;
1171 GNUNET_assert (NULL != h);
1172 GNUNET_assert (NULL != pkey);
1173 GNUNET_assert (NULL != name);
1174 GNUNET_assert (NULL != rd);
1175 LOG (GNUNET_ERROR_TYPE_DEBUG,
1176 "Creating record of type %u under name `%s'\n",
1179 name_len = strlen(name) + 1;
1180 if (name_len > MAX_NAME_LEN)
1186 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
1189 qe->cont_cls = cont_cls;
1191 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1193 pkey_enc = GNUNET_CRYPTO_rsa_encode_key (pkey);
1194 GNUNET_assert (NULL != pkey_enc);
1197 key_len = ntohs (pkey_enc->len);
1198 rd_ser_len = GNUNET_NAMESTORE_records_get_size(1, rd);
1199 msg_size = sizeof (struct RecordCreateMessage) + key_len + name_len + rd_ser_len;
1200 pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
1201 pe->size = msg_size;
1202 pe->is_init = GNUNET_NO;
1203 msg = (struct RecordCreateMessage *) &pe[1];
1204 msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE);
1205 msg->gns_header.header.size = htons (msg_size);
1206 msg->gns_header.r_id = htonl (rid);
1207 msg->name_len = htons (name_len);
1208 msg->rd_count = htons (1);
1209 msg->rd_len = htons (rd_ser_len);
1210 msg->pkey_len = htons (key_len);
1211 msg->expire = GNUNET_TIME_absolute_hton(GNUNET_TIME_UNIT_FOREVER_ABS);
1212 pkey_tmp = (char *) &msg[1];
1213 memcpy (pkey_tmp, pkey_enc, key_len);
1214 name_tmp = &pkey_tmp[key_len];
1215 memcpy (name_tmp, name, name_len);
1216 rd_ser = &name_tmp[name_len];
1217 GNUNET_NAMESTORE_records_serialize(1, rd, rd_ser_len, rd_ser);
1219 GNUNET_free (pkey_enc);
1221 LOG (GNUNET_ERROR_TYPE_DEBUG,
1222 "Sending `%s' message for name `%s' with size %u\n",
1223 "NAMESTORE_RECORD_CREATE", name, msg_size);
1224 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe);
1231 * Explicitly remove some content from the database. The
1232 * "cont"inuation will be called with status "GNUNET_OK" if content
1233 * was removed, "GNUNET_NO" if no matching entry was found and
1234 * "GNUNET_SYSERR" on all other types of errors.
1235 * This API is used by the authority of a zone.
1237 * @param h handle to the namestore
1238 * @param pkey private key of the zone
1239 * @param name name that is being mapped (at most 255 characters long)
1240 * @param rd record data, remove specific record, NULL to remove the name and all records
1241 * @param cont continuation to call when done
1242 * @param cont_cls closure for cont
1243 * @return handle to abort the request
1245 struct GNUNET_NAMESTORE_QueueEntry *
1246 GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h,
1247 const struct GNUNET_CRYPTO_RsaPrivateKey *pkey,
1249 const struct GNUNET_NAMESTORE_RecordData *rd,
1250 GNUNET_NAMESTORE_ContinuationWithStatus cont,
1253 struct GNUNET_NAMESTORE_QueueEntry *qe;
1254 struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded * pkey_enc;
1255 struct PendingMessage *pe;
1256 struct RecordRemoveMessage * msg;
1267 GNUNET_assert (NULL != h);
1269 LOG (GNUNET_ERROR_TYPE_DEBUG,
1270 "Removing record of type %u under name `%s'\n",
1274 LOG (GNUNET_ERROR_TYPE_DEBUG,
1275 "Removing all records under name `%s'\n",
1278 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
1281 qe->cont_cls = cont_cls;
1283 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1285 pkey_enc = GNUNET_CRYPTO_rsa_encode_key (pkey);
1286 GNUNET_assert (NULL != pkey_enc);
1287 key_len = ntohs (pkey_enc->len);
1289 rd_count = (NULL == rd) ? 0 : 1;
1290 rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
1291 name_len = strlen (name) + 1;
1292 msg_size = sizeof (struct RecordRemoveMessage) + key_len + name_len + rd_ser_len;
1293 pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
1294 pe->size = msg_size;
1295 pe->is_init = GNUNET_NO;
1296 msg = (struct RecordRemoveMessage *) &pe[1];
1297 msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE);
1298 msg->gns_header.header.size = htons (msg_size);
1299 msg->gns_header.r_id = htonl (rid);
1300 msg->name_len = htons (name_len);
1301 msg->rd_len = htons (rd_ser_len);
1302 msg->rd_count = htons (rd_count);
1303 msg->pkey_len = htons (key_len);
1304 pkey_tmp = (char *) &msg[1];
1305 memcpy (pkey_tmp, pkey_enc, key_len);
1306 name_tmp = &pkey_tmp[key_len];
1307 memcpy (name_tmp, name, name_len);
1308 rd_ser = &name_tmp[name_len];
1309 GNUNET_NAMESTORE_records_serialize (rd_count, rd, rd_ser_len, rd_ser);
1311 GNUNET_free (pkey_enc);
1313 LOG (GNUNET_ERROR_TYPE_DEBUG,
1314 "Sending `%s' message for name `%s' with size %u\n",
1315 "NAMESTORE_RECORD_REMOVE", name, msg_size);
1316 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe);
1323 * Get a result for a particular key from the namestore. The processor
1324 * will only be called once.
1326 * @param h handle to the namestore
1327 * @param zone zone to look up a record from
1328 * @param name name to look up
1329 * @param record_type desired record type, 0 for all
1330 * @param proc function to call on the matching records, or with
1331 * NULL (rd_count == 0) if there are no matching records
1332 * @param proc_cls closure for proc
1333 * @return a handle that can be used to
1336 struct GNUNET_NAMESTORE_QueueEntry *
1337 GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h,
1338 const struct GNUNET_CRYPTO_ShortHashCode *zone,
1340 uint32_t record_type,
1341 GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls)
1343 struct GNUNET_NAMESTORE_QueueEntry *qe;
1344 struct PendingMessage *pe;
1345 struct LookupNameMessage * msg;
1350 GNUNET_assert (NULL != h);
1351 GNUNET_assert (NULL != zone);
1352 GNUNET_assert (NULL != name);
1353 LOG (GNUNET_ERROR_TYPE_DEBUG,
1354 "Looking for record of type %u under name `%s'\n",
1357 name_len = strlen (name) + 1;
1358 if ((name_len == 0) || (name_len > MAX_NAME_LEN))
1365 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
1368 qe->proc_cls = proc_cls;
1370 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1372 msg_size = sizeof (struct LookupNameMessage) + name_len;
1373 pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
1374 pe->size = msg_size;
1375 pe->is_init = GNUNET_NO;
1376 msg = (struct LookupNameMessage *) &pe[1];
1377 msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME);
1378 msg->gns_header.header.size = htons (msg_size);
1379 msg->gns_header.r_id = htonl (rid);
1380 msg->record_type = htonl (record_type);
1381 msg->name_len = htonl (name_len);
1383 memcpy (&msg[1], name, name_len);
1385 LOG (GNUNET_ERROR_TYPE_DEBUG,
1386 "Sending `%s' message for name `%s'\n", "NAMESTORE_LOOKUP_NAME", name);
1387 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe);
1394 * Look for an existing PKEY delegation record for a given public key.
1395 * Returns at most one result to the processor.
1397 * @param h handle to the namestore
1398 * @param zone hash of public key of the zone to look up in, never NULL
1399 * @param value_zone hash of the public key of the target zone (value), never NULL
1400 * @param proc function to call on the matching records, or with
1401 * NULL (rd_count == 0) if there are no matching records
1402 * @param proc_cls closure for proc
1403 * @return a handle that can be used to
1406 struct GNUNET_NAMESTORE_QueueEntry *
1407 GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
1408 const struct GNUNET_CRYPTO_ShortHashCode *zone,
1409 const struct GNUNET_CRYPTO_ShortHashCode *value_zone,
1410 GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls)
1412 struct GNUNET_NAMESTORE_QueueEntry *qe;
1413 struct PendingMessage *pe;
1414 struct ZoneToNameMessage * msg;
1418 GNUNET_assert (NULL != h);
1419 GNUNET_assert (NULL != zone);
1420 GNUNET_assert (NULL != value_zone);
1422 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
1425 qe->proc_cls = proc_cls;
1427 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1429 msg_size = sizeof (struct ZoneToNameMessage);
1430 pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
1431 pe->size = msg_size;
1432 pe->is_init = GNUNET_NO;
1433 msg = (struct ZoneToNameMessage *) &pe[1];
1434 msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME);
1435 msg->gns_header.header.size = htons (msg_size);
1436 msg->gns_header.r_id = htonl (rid);
1438 msg->value_zone = *value_zone;
1440 /* transmit message */
1441 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe);
1448 * Starts a new zone iteration (used to periodically PUT all of our
1449 * records into our DHT). This MUST lock the GNUNET_NAMESTORE_Handle
1450 * for any other calls than GNUNET_NAMESTORE_zone_iterator_next and
1451 * GNUNET_NAMESTORE_zone_iteration_stop. "proc" will be called once
1452 * immediately, and then again after
1453 * "GNUNET_NAMESTORE_zone_iterator_next" is invoked.
1455 * @param h handle to the namestore
1456 * @param zone zone to access, NULL for all zones
1457 * @param must_have_flags flags that must be set for the record to be returned
1458 * @param must_not_have_flags flags that must NOT be set for the record to be returned
1459 * @param proc function to call on each name from the zone; it
1460 * will be called repeatedly with a value (if available)
1461 * and always once at the end with a name of NULL.
1462 * @param proc_cls closure for proc
1463 * @return an iterator handle to use for iteration
1465 struct GNUNET_NAMESTORE_ZoneIterator *
1466 GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
1467 const struct GNUNET_CRYPTO_ShortHashCode *zone,
1468 enum GNUNET_NAMESTORE_RecordFlags must_have_flags,
1469 enum GNUNET_NAMESTORE_RecordFlags must_not_have_flags,
1470 GNUNET_NAMESTORE_RecordProcessor proc,
1473 struct GNUNET_NAMESTORE_ZoneIterator *it;
1474 struct PendingMessage *pe;
1475 struct ZoneIterationStartMessage * msg;
1479 GNUNET_assert (NULL != h);
1481 it = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_ZoneIterator));
1484 it->proc_cls = proc_cls;
1489 it->has_zone = GNUNET_YES;
1493 memset (&it->zone, '\0', sizeof (it->zone));
1494 it->has_zone = GNUNET_NO;
1496 GNUNET_CONTAINER_DLL_insert_tail (h->z_head, h->z_tail, it);
1498 msg_size = sizeof (struct ZoneIterationStartMessage);
1499 pe = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size);
1500 pe->size = msg_size;
1501 pe->is_init = GNUNET_NO;
1502 msg = (struct ZoneIterationStartMessage *) &pe[1];
1503 msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START);
1504 msg->gns_header.header.size = htons (msg_size);
1505 msg->gns_header.r_id = htonl (rid);
1508 LOG (GNUNET_ERROR_TYPE_DEBUG,
1509 "Sending `%s' message for zone `%s'\n",
1510 "ZONE_ITERATION_START", GNUNET_short_h2s(zone));
1515 LOG (GNUNET_ERROR_TYPE_DEBUG,
1516 "Sending `%s' message for all zones\n", "ZONE_ITERATION_START");
1517 memset (&msg->zone, '\0', sizeof (msg->zone));
1519 msg->must_have_flags = ntohs (must_have_flags);
1520 msg->must_not_have_flags = ntohs (must_not_have_flags);
1521 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe);
1528 * Calls the record processor specified in GNUNET_NAMESTORE_zone_iteration_start
1529 * for the next record.
1531 * @param it the iterator
1534 GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it)
1536 struct GNUNET_NAMESTORE_Handle *h;
1537 struct ZoneIterationNextMessage * msg;
1538 struct PendingMessage *pe;
1541 GNUNET_assert (NULL != it);
1543 msg_size = sizeof (struct ZoneIterationNextMessage);
1544 pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
1545 pe->size = msg_size;
1546 pe->is_init = GNUNET_NO;
1547 msg = (struct ZoneIterationNextMessage *) &pe[1];
1548 msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT);
1549 msg->gns_header.header.size = htons (msg_size);
1550 msg->gns_header.r_id = htonl (it->op_id);
1551 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "ZONE_ITERATION_NEXT");
1552 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe);
1558 * Stops iteration and releases the namestore handle for further calls.
1560 * @param it the iterator
1563 GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it)
1565 struct GNUNET_NAMESTORE_Handle *h;
1566 struct PendingMessage *pe;
1568 struct ZoneIterationStopMessage * msg;
1570 GNUNET_assert (NULL != it);
1572 GNUNET_CONTAINER_DLL_remove (h->z_head,
1575 msg_size = sizeof (struct ZoneIterationStopMessage);
1576 pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
1577 pe->size = msg_size;
1578 pe->is_init = GNUNET_NO;
1579 msg = (struct ZoneIterationStopMessage *) &pe[1];
1580 msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP);
1581 msg->gns_header.header.size = htons (msg_size);
1582 msg->gns_header.r_id = htonl (it->op_id);
1583 if (GNUNET_YES == it->has_zone)
1584 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1585 "Sending `%s' message for zone `%s'\n", "ZONE_ITERATION_STOP", GNUNET_short_h2s(&it->zone));
1587 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1588 "Sending `%s' message for all zones\n", "ZONE_ITERATION_STOP");
1589 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe);
1596 * Cancel a namestore operation. The final callback from the
1597 * operation must not have been done yet.
1599 * @param qe operation to cancel
1602 GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe)
1604 struct GNUNET_NAMESTORE_Handle *h = qe->nsh;
1606 GNUNET_assert (NULL != qe);
1607 GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, qe);
1611 /* end of namestore_api.c */