2 This file is part of GNUnet.
3 (C) 2009, 2010 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.
24 * @brief library to access the GNS service
25 * @author Martin Schanzenbach
29 #include "gnunet_util_lib.h"
30 #include "gnunet_constants.h"
31 #include "gnunet_arm_service.h"
32 #include "gnunet_hello_lib.h"
33 #include "gnunet_protocols.h"
34 #include "gnunet_dht_service.h"
36 #include "gnunet_gns_service.h"
38 /* TODO into gnunet_protocols */
39 #define GNUNET_MESSAGE_TYPE_GNS_LOOKUP 23
40 #define GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT 24
41 #define GNUNET_MESSAGE_TYPE_GNS_SHORTEN 25
42 #define GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT 26
43 #define GNUNET_MESSAGE_TYPE_GNS_GET_AUTH 27
44 #define GNUNET_MESSAGE_TYPE_GNS_GET_AUTH_RESULT 28
47 * Handle to a lookup request
49 struct GNUNET_GNS_LookupRequest
54 struct GNUNET_GNS_LookupRequest *next;
59 struct GNUNET_GNS_LookupRequest *prev;
65 struct GNUNET_GNS_Handle *gns_handle;
67 /* processor to call on lookup result */
68 GNUNET_GNS_LookupResultProcessor lookup_proc;
70 /* processor closure */
77 * Handle to a shorten request
79 struct GNUNET_GNS_ShortenRequest
84 struct GNUNET_GNS_ShortenRequest *next;
89 struct GNUNET_GNS_ShortenRequest *prev;
95 struct GNUNET_GNS_Handle *gns_handle;
97 /* processor to call on shorten result */
98 GNUNET_GNS_ShortenResultProcessor shorten_proc;
100 /* processor closure */
107 * Handle to GetAuthorityRequest
109 struct GNUNET_GNS_GetAuthRequest
114 struct GNUNET_GNS_GetAuthRequest *next;
119 struct GNUNET_GNS_GetAuthRequest *prev;
125 struct GNUNET_GNS_Handle *gns_handle;
127 /* processor to call on authority lookup result */
128 GNUNET_GNS_GetAuthResultProcessor auth_proc;
130 /* processor closure */
137 * Entry in our list of messages to be (re-)transmitted.
139 struct PendingMessage
142 * This is a doubly-linked list.
144 struct PendingMessage *prev;
147 * This is a doubly-linked list.
149 struct PendingMessage *next;
157 * Size of the message.
165 * Connection to the GNS service.
167 struct GNUNET_GNS_Handle
171 * Configuration to use.
173 const struct GNUNET_CONFIGURATION_Handle *cfg;
176 * Socket (if available).
178 struct GNUNET_CLIENT_Connection *client;
181 * Currently pending transmission request (or NULL).
183 struct GNUNET_CLIENT_TransmitHandle *th;
188 * Head of linked list of shorten messages we would like to transmit.
190 struct PendingMessage *pending_head;
193 * Tail of linked list of shorten messages we would like to transmit.
195 struct PendingMessage *pending_tail;
198 * Head of linked list of shorten messages we would like to transmit.
200 struct GNUNET_GNS_ShortenRequest *shorten_head;
203 * Tail of linked list of shorten messages we would like to transmit.
205 struct GNUNET_GNS_ShortenRequest *shorten_tail;
208 * Head of linked list of lookup messages we would like to transmit.
210 struct GNUNET_GNS_LookupRequest *lookup_head;
213 * Tail of linked list of lookup messages we would like to transmit.
215 struct GNUNET_GNS_LookupRequest *lookup_tail;
218 * Head of linked list of authority lookup messages we would like to transmit.
220 struct GNUNET_GNS_GetAuthRequest *get_auth_head;
223 * Tail of linked list of authority lookup messages we would like to transmit.
225 struct GNUNET_GNS_GetAuthRequest *get_auth_tail;
230 GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
233 * Did we start our receive loop yet?
238 * Reconnect necessary
244 * Try to send messages from list of messages to send
245 * @param handle GNS_Handle
248 process_pending_messages (struct GNUNET_GNS_Handle *handle);
252 * Reconnect to GNS service.
254 * @param h the handle to the namestore service
257 reconnect (struct GNUNET_GNS_Handle *h)
259 GNUNET_assert (NULL == h->client);
260 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
261 "Trying to connect to GNS...\n");
262 h->client = GNUNET_CLIENT_connect ("gns", h->cfg);
263 GNUNET_assert (NULL != h->client);
269 * @param cls the handle
270 * @param tc task context
273 reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
275 struct GNUNET_GNS_Handle *h = cls;
277 h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
283 * Disconnect from service and then reconnect.
285 * @param h our handle
288 force_reconnect (struct GNUNET_GNS_Handle *h)
290 h->reconnect = GNUNET_NO;
291 GNUNET_CLIENT_disconnect (h->client);
293 h->reconnect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
299 * Transmit the next pending message, called by notify_transmit_ready
302 transmit_pending (void *cls, size_t size, void *buf);
305 * Handler for messages received from the GNS service
307 * @param cls the 'struct GNUNET_GNS_Handle'
308 * @param msg the incoming message
311 process_message (void *cls, const struct GNUNET_MessageHeader *msg);
314 * Try to send messages from list of messages to send
317 process_pending_messages (struct GNUNET_GNS_Handle *handle)
319 struct PendingMessage *p;
321 if (handle->client == NULL)
323 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
324 "process_pending_messages called, but client is null\n");
328 if (handle->th != NULL)
331 if (NULL == (p = handle->pending_head))
334 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
335 "Trying to transmit %d bytes...\n", p->size);
338 GNUNET_CLIENT_notify_transmit_ready (handle->client,
340 GNUNET_TIME_UNIT_FOREVER_REL,
341 GNUNET_NO, &transmit_pending,
343 if (NULL != handle->th)
346 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
347 "notify_transmit_ready returned NULL!\n");
352 * Transmit the next pending message, called by notify_transmit_ready
355 transmit_pending (void *cls, size_t size, void *buf)
357 struct GNUNET_GNS_Handle *handle = cls;
358 struct PendingMessage *p;
364 if ((size == 0) || (buf == NULL))
366 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
367 "Transmission to GNS service failed!\n");
368 force_reconnect(handle);
375 if (NULL == (p = handle->pending_head))
378 while ((NULL != (p = handle->pending_head)) && (p->size <= size))
380 memcpy (&cbuf[tsize], &p[1], p->size);
383 GNUNET_CONTAINER_DLL_remove (handle->pending_head, handle->pending_tail, p);
384 if (GNUNET_YES != handle->in_receive)
386 GNUNET_CLIENT_receive (handle->client, &process_message, handle,
387 GNUNET_TIME_UNIT_FOREVER_REL);
388 handle->in_receive = GNUNET_YES;
393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
394 "Sending %d bytes\n", tsize);
396 process_pending_messages(handle);
401 * Process a given reply that might match the given
404 * @param qe a queue entry
405 * @param msg the shorten msg received
408 process_shorten_reply (struct GNUNET_GNS_ShortenRequest *qe,
409 const struct GNUNET_GNS_ClientShortenResultMessage *msg)
411 struct GNUNET_GNS_Handle *h = qe->gns_handle;
412 const char *short_name;
414 GNUNET_CONTAINER_DLL_remove (h->shorten_head, h->shorten_tail, qe);
415 short_name = (char*)(&msg[1]);
417 if (ntohs (((struct GNUNET_MessageHeader*)msg)->size) <
418 sizeof (struct GNUNET_GNS_ClientShortenResultMessage))
426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
427 "Received shortened reply `%s' from GNS service\n",
430 GNUNET_CLIENT_receive (h->client, &process_message, h,
431 GNUNET_TIME_UNIT_FOREVER_REL);
432 qe->shorten_proc (qe->proc_cls, short_name);
439 * Process a given reply that might match the given
442 * @param qe the handle to the request
443 * @param msg the message to process
446 process_get_auth_reply (struct GNUNET_GNS_GetAuthRequest *qe,
447 const struct GNUNET_GNS_ClientGetAuthResultMessage *msg)
449 struct GNUNET_GNS_Handle *h = qe->gns_handle;
450 const char *auth_name;
452 GNUNET_CONTAINER_DLL_remove (h->get_auth_head, h->get_auth_tail, qe);
453 auth_name = (char*)&msg[1];
455 if (ntohs (((struct GNUNET_MessageHeader*)msg)->size) <
456 sizeof (struct GNUNET_GNS_ClientGetAuthResultMessage))
464 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
465 "Received GET_AUTH reply `%s' from GNS service\n",
468 GNUNET_CLIENT_receive (h->client, &process_message, h,
469 GNUNET_TIME_UNIT_FOREVER_REL);
470 qe->auth_proc (qe->proc_cls, auth_name);
475 * Process a given reply to the lookup request
477 * @param qe a queue entry
478 * @param msg the lookup message received
481 process_lookup_reply (struct GNUNET_GNS_LookupRequest *qe,
482 const struct GNUNET_GNS_ClientLookupResultMessage *msg)
484 struct GNUNET_GNS_Handle *h = qe->gns_handle;
485 int rd_count = ntohl(msg->rd_count);
486 size_t len = ntohs (((struct GNUNET_MessageHeader*)msg)->size);
487 struct GNUNET_NAMESTORE_RecordData rd[rd_count];
489 GNUNET_CONTAINER_DLL_remove (h->lookup_head, h->lookup_tail, qe);
491 if (len < sizeof (struct GNUNET_GNS_ClientLookupResultMessage))
499 len -= sizeof (struct GNUNET_GNS_ClientLookupResultMessage);
500 GNUNET_CLIENT_receive (h->client, &process_message, h,
501 GNUNET_TIME_UNIT_FOREVER_REL);
502 if (GNUNET_SYSERR == GNUNET_NAMESTORE_records_deserialize (len,
507 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
508 "Failed to serialize lookup reply from GNS service!\n");
509 qe->lookup_proc (qe->proc_cls, 0, NULL);
514 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
515 "Received lookup reply from GNS service (count=%d)\n",
516 ntohl (msg->rd_count));
517 qe->lookup_proc (qe->proc_cls, rd_count, rd);
523 * Handler for messages received from the GNS service
525 * @param cls the 'struct GNUNET_GNS_Handle'
526 * @param msg the incoming message
529 process_message (void *cls, const struct GNUNET_MessageHeader *msg)
531 struct GNUNET_GNS_Handle *handle = cls;
532 struct GNUNET_GNS_LookupRequest *lr;
533 struct GNUNET_GNS_ShortenRequest *sr;
534 struct GNUNET_GNS_GetAuthRequest *gar;
535 const struct GNUNET_GNS_ClientLookupResultMessage *lookup_msg;
536 const struct GNUNET_GNS_ClientShortenResultMessage *shorten_msg;
537 const struct GNUNET_GNS_ClientGetAuthResultMessage *get_auth_msg;
541 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
545 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
546 "Error receiving data from GNS service, reconnecting\n");
547 force_reconnect (handle);
551 type = ntohs (msg->type);
553 if (type == GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT)
555 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
557 lookup_msg = (const struct GNUNET_GNS_ClientLookupResultMessage *) msg;
558 r_id = ntohl (lookup_msg->id);
560 if (r_id > handle->r_id)
562 /** no request found */
564 GNUNET_CLIENT_receive (handle->client, &process_message, handle,
565 GNUNET_TIME_UNIT_FOREVER_REL);
569 for (lr = handle->lookup_head; NULL != lr; lr = lr->next)
571 if (lr->r_id == r_id)
575 process_lookup_reply(lr, lookup_msg);
580 else if (type == GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT)
582 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
583 "Got SHORTEN_RESULT msg\n");
584 shorten_msg = (struct GNUNET_GNS_ClientShortenResultMessage *) msg;
586 r_id = ntohl (shorten_msg->id);
588 if (r_id > handle->r_id)
590 /** no request found */
592 GNUNET_CLIENT_receive (handle->client, &process_message, handle,
593 GNUNET_TIME_UNIT_FOREVER_REL);
597 for (sr = handle->shorten_head; NULL != sr; sr = sr->next)
599 if (sr->r_id == r_id)
603 process_shorten_reply (sr, shorten_msg);
606 else if (type == GNUNET_MESSAGE_TYPE_GNS_GET_AUTH_RESULT)
608 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
609 "Got GET_AUTH_RESULT msg\n");
610 get_auth_msg = (struct GNUNET_GNS_ClientGetAuthResultMessage *) msg;
612 r_id = ntohl (get_auth_msg->id);
614 if (r_id > handle->r_id)
616 /** no request found */
618 GNUNET_CLIENT_receive (handle->client, &process_message, handle,
619 GNUNET_TIME_UNIT_FOREVER_REL);
623 for (gar = handle->get_auth_head; NULL != gar; gar = gar->next)
625 if (gar->r_id == r_id)
629 process_get_auth_reply (gar, get_auth_msg);
634 if (GNUNET_YES == handle->reconnect)
635 force_reconnect (handle);
640 * Initialize the connection with the GNS service.
642 * @param cfg configuration to use
643 * @return handle to the GNS service, or NULL on error
645 struct GNUNET_GNS_Handle *
646 GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
648 struct GNUNET_GNS_Handle *handle;
650 handle = GNUNET_malloc (sizeof (struct GNUNET_GNS_Handle));
651 handle->reconnect = GNUNET_NO;
654 handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
656 handle->in_receive = GNUNET_NO;
662 * Shutdown connection with the GNS service.
664 * @param handle handle of the GNS connection to stop
667 GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle)
669 GNUNET_CLIENT_disconnect (handle->client);
670 if (GNUNET_SCHEDULER_NO_TASK != handle->reconnect_task)
672 GNUNET_SCHEDULER_cancel (handle->reconnect_task);
673 handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
676 GNUNET_assert (NULL == handle->lookup_head);
677 GNUNET_assert (NULL == handle->shorten_head);
678 GNUNET_assert (NULL == handle->get_auth_head);
685 * Helper function to generate request ids
691 get_request_id (struct GNUNET_GNS_Handle *h)
693 uint32_t r_id = h->r_id;
700 * Cancel pending lookup request
702 * @param lr the lookup request to cancel
705 GNUNET_GNS_cancel_lookup_request (struct GNUNET_GNS_LookupRequest *lr)
707 struct PendingMessage *tmp;
708 GNUNET_assert (NULL != lr->gns_handle);
710 for (tmp = lr->gns_handle->pending_head;
711 NULL != tmp; tmp = tmp->next)
713 if (tmp->r_id == lr->r_id)
719 GNUNET_CONTAINER_DLL_remove (lr->gns_handle->pending_head,
720 lr->gns_handle->pending_tail,
725 GNUNET_CONTAINER_DLL_remove (lr->gns_handle->lookup_head,
726 lr->gns_handle->lookup_tail,
734 * Cancel pending shorten request
736 * @param sr the lookup request to cancel
739 GNUNET_GNS_cancel_shorten_request (struct GNUNET_GNS_ShortenRequest *sr)
741 struct PendingMessage *tmp;
742 GNUNET_assert (NULL != sr->gns_handle);
744 for (tmp = sr->gns_handle->pending_head;
745 NULL != tmp; tmp = tmp->next)
747 if (tmp->r_id == sr->r_id)
753 GNUNET_CONTAINER_DLL_remove (sr->gns_handle->pending_head,
754 sr->gns_handle->pending_tail,
759 GNUNET_CONTAINER_DLL_remove (sr->gns_handle->shorten_head,
760 sr->gns_handle->shorten_tail,
768 * Cancel pending get auth request
770 * @param gar the lookup request to cancel
773 GNUNET_GNS_cancel_get_auth_request (struct GNUNET_GNS_GetAuthRequest *gar)
775 struct PendingMessage *tmp;
776 GNUNET_assert (NULL != gar->gns_handle);
778 for (tmp = gar->gns_handle->pending_head;
779 NULL != tmp; tmp = tmp->next)
781 if (tmp->r_id == gar->r_id)
787 GNUNET_CONTAINER_DLL_remove (gar->gns_handle->pending_head,
788 gar->gns_handle->pending_tail,
793 GNUNET_CONTAINER_DLL_remove (gar->gns_handle->get_auth_head,
794 gar->gns_handle->get_auth_tail,
801 * Perform an asynchronous Lookup operation on the GNS.
803 * @param handle handle to the GNS service
804 * @param name the name to look up
805 * @param zone the zone to start the resolution in
806 * @param type the record type to look up
807 * @param only_cached GNUNET_YES to only check locally not DHT for performance
808 * @param shorten_key the private key of the shorten zone (can be NULL)
809 * @param proc processor to call on result
810 * @param proc_cls closure for processor
811 * @return handle to the get request
813 struct GNUNET_GNS_LookupRequest*
814 GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle,
816 struct GNUNET_CRYPTO_ShortHashCode *zone,
817 enum GNUNET_GNS_RecordType type,
819 struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key,
820 GNUNET_GNS_LookupResultProcessor proc,
823 /* IPC to shorten gns names, return shorten_handle */
824 struct GNUNET_GNS_ClientLookupMessage *lookup_msg;
825 struct GNUNET_GNS_LookupRequest *lr;
827 struct PendingMessage *pending;
828 struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *pkey_enc=NULL;
837 if (NULL != shorten_key)
839 pkey_enc = GNUNET_CRYPTO_rsa_encode_key (shorten_key);
840 GNUNET_assert (pkey_enc != NULL);
841 key_len = ntohs (pkey_enc->len);
844 msize = sizeof (struct GNUNET_GNS_ClientLookupMessage)
845 + key_len + strlen(name) + 1;
846 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to lookup %s in GNS\n", name);
848 lr = GNUNET_malloc(sizeof (struct GNUNET_GNS_LookupRequest));
849 lr->gns_handle = handle;
850 lr->lookup_proc = proc;
851 lr->proc_cls = proc_cls;
852 lr->r_id = get_request_id (handle);
853 GNUNET_CONTAINER_DLL_insert_tail (handle->lookup_head,
854 handle->lookup_tail, lr);
856 pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
857 memset (pending, 0, (sizeof (struct PendingMessage) + msize));
859 pending->size = msize;
860 pending->r_id = lr->r_id;
862 lookup_msg = (struct GNUNET_GNS_ClientLookupMessage *) &pending[1];
863 lookup_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_LOOKUP);
864 lookup_msg->header.size = htons (msize);
865 lookup_msg->id = htonl (lr->r_id);
866 lookup_msg->only_cached = htonl(only_cached);
870 lookup_msg->use_default_zone = htonl (0);
871 memcpy (&lookup_msg->zone, zone, sizeof (struct GNUNET_CRYPTO_ShortHashCode));
875 lookup_msg->use_default_zone = htonl (1);
876 memset (&lookup_msg->zone, 0, sizeof(struct GNUNET_CRYPTO_ShortHashCode));
879 lookup_msg->type = htonl (type);
881 pkey_tmp = (char *) &lookup_msg[1];
883 if (pkey_enc != NULL)
885 lookup_msg->have_key = htonl(1);
886 memcpy (pkey_tmp, pkey_enc, key_len);
889 lookup_msg->have_key = htonl (0);
891 memcpy (&pkey_tmp[key_len], name, strlen (name));
893 GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head, handle->pending_tail,
895 GNUNET_free_non_null (pkey_enc);
896 process_pending_messages (handle);
901 * Perform an asynchronous Lookup operation on the GNS.
903 * @param handle handle to the GNS service
904 * @param name the name to look up
905 * @param type the record type to look up
906 * @param only_cached GNUNET_YES to only check locally not DHT for performance
907 * @param shorten_key the private key of the shorten zone (can be NULL)
908 * @param proc processor to call on result
909 * @param proc_cls closure for processor
910 * @return handle to the lookup request
912 struct GNUNET_GNS_LookupRequest*
913 GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
915 enum GNUNET_GNS_RecordType type,
917 struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key,
918 GNUNET_GNS_LookupResultProcessor proc,
921 return GNUNET_GNS_lookup_zone (handle, name,
929 * Perform a name shortening operation on the GNS.
931 * @param handle handle to the GNS service
932 * @param name the name to look up
933 * @param private_zone the public zone of the private zone
934 * @param shorten_zone the public zone of the shorten zone
935 * @param zone the zone to start the resolution in
936 * @param proc function to call on result
937 * @param proc_cls closure for processor
938 * @return handle to the operation
940 struct GNUNET_GNS_ShortenRequest*
941 GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle,
943 struct GNUNET_CRYPTO_ShortHashCode *private_zone,
944 struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
945 struct GNUNET_CRYPTO_ShortHashCode *zone,
946 GNUNET_GNS_ShortenResultProcessor proc,
949 /* IPC to shorten gns names, return shorten_handle */
950 struct GNUNET_GNS_ClientShortenMessage *shorten_msg;
951 struct GNUNET_GNS_ShortenRequest *sr;
953 struct PendingMessage *pending;
960 msize = sizeof (struct GNUNET_GNS_ClientShortenMessage) + strlen(name) + 1;
961 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to shorten %s in GNS\n", name);
963 sr = GNUNET_malloc(sizeof (struct GNUNET_GNS_ShortenRequest));
964 sr->gns_handle = handle;
965 sr->shorten_proc = proc;
966 sr->proc_cls = proc_cls;
967 sr->r_id = get_request_id (handle);
968 GNUNET_CONTAINER_DLL_insert_tail (handle->shorten_head,
969 handle->shorten_tail, sr);
971 pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
972 memset(pending, 0, (sizeof (struct PendingMessage) + msize));
974 pending->size = msize;
975 pending->r_id = sr->r_id;
977 shorten_msg = (struct GNUNET_GNS_ClientShortenMessage *) &pending[1];
978 shorten_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_SHORTEN);
979 shorten_msg->header.size = htons (msize);
980 shorten_msg->id = htonl (sr->r_id);
981 shorten_msg->private_zone = *private_zone;
982 shorten_msg->shorten_zone = *shorten_zone;
986 shorten_msg->use_default_zone = htonl (0);
987 memcpy (&shorten_msg->zone, zone,
988 sizeof (struct GNUNET_CRYPTO_ShortHashCode));
992 shorten_msg->use_default_zone = htonl (1);
993 memset (&shorten_msg->zone, 0, sizeof (struct GNUNET_CRYPTO_ShortHashCode));
996 memcpy (&shorten_msg[1], name, strlen (name));
998 GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head, handle->pending_tail,
1001 process_pending_messages (handle);
1006 * Perform a name shortening operation on the GNS.
1008 * @param handle handle to the GNS service
1009 * @param name the name to look up
1010 * @param private_zone the public zone of the private zone
1011 * @param shorten_zone the public zone of the shorten zone
1012 * @param proc function to call on result
1013 * @param proc_cls closure for processor
1014 * @return handle to the operation
1016 struct GNUNET_GNS_ShortenRequest*
1017 GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle,
1019 struct GNUNET_CRYPTO_ShortHashCode *private_zone,
1020 struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
1021 GNUNET_GNS_ShortenResultProcessor proc,
1024 return GNUNET_GNS_shorten_zone (handle, name,
1025 private_zone, shorten_zone,
1026 NULL, proc, proc_cls);
1031 * Perform an authority lookup for a given name.
1033 * @param handle handle to the GNS service
1034 * @param name the name to look up authority for
1035 * @param proc function to call on result
1036 * @param proc_cls closure for processor
1037 * @return handle to the operation
1039 struct GNUNET_GNS_GetAuthRequest*
1040 GNUNET_GNS_get_authority (struct GNUNET_GNS_Handle *handle,
1042 GNUNET_GNS_GetAuthResultProcessor proc,
1045 struct GNUNET_GNS_ClientGetAuthMessage *get_auth_msg;
1046 struct GNUNET_GNS_GetAuthRequest *gar;
1048 struct PendingMessage *pending;
1055 msize = sizeof (struct GNUNET_GNS_ClientGetAuthMessage) + strlen(name) + 1;
1056 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1057 "Trying to look up authority for %s in GNS\n", name);
1059 gar = GNUNET_malloc (sizeof (struct GNUNET_GNS_GetAuthRequest));
1060 gar->gns_handle = handle;
1061 gar->auth_proc = proc;
1062 gar->proc_cls = proc_cls;
1063 gar->r_id = get_request_id (handle);
1064 GNUNET_CONTAINER_DLL_insert_tail (handle->get_auth_head,
1065 handle->get_auth_tail, gar);
1067 pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
1068 memset (pending, 0, (sizeof (struct PendingMessage) + msize));
1070 pending->size = msize;
1071 pending->r_id = gar->r_id;
1073 get_auth_msg = (struct GNUNET_GNS_ClientGetAuthMessage *) &pending[1];
1074 get_auth_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_GET_AUTH);
1075 get_auth_msg->header.size = htons (msize);
1076 get_auth_msg->id = htonl (gar->r_id);
1078 memcpy(&get_auth_msg[1], name, strlen(name));
1080 GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head, handle->pending_tail,
1083 process_pending_messages (handle);
1088 /* end of gns_api.c */