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;
62 * associated pending message
64 struct PendingMessage *pending_msg;
70 struct GNUNET_GNS_Handle *gns_handle;
72 /* processor to call on lookup result */
73 GNUNET_GNS_LookupResultProcessor lookup_proc;
75 /* processor closure */
82 * Handle to a shorten request
84 struct GNUNET_GNS_ShortenRequest
89 struct GNUNET_GNS_ShortenRequest *next;
94 struct GNUNET_GNS_ShortenRequest *prev;
97 * associated pending message
99 struct PendingMessage *pending_msg;
105 struct GNUNET_GNS_Handle *gns_handle;
107 /* processor to call on shorten result */
108 GNUNET_GNS_ShortenResultProcessor shorten_proc;
110 /* processor closure */
117 * Handle to GetAuthorityRequest
119 struct GNUNET_GNS_GetAuthRequest
124 struct GNUNET_GNS_GetAuthRequest *next;
129 struct GNUNET_GNS_GetAuthRequest *prev;
132 * associated pending message
134 struct PendingMessage *pending_msg;
140 struct GNUNET_GNS_Handle *gns_handle;
142 /* processor to call on authority lookup result */
143 GNUNET_GNS_GetAuthResultProcessor auth_proc;
145 /* processor closure */
152 * Entry in our list of messages to be (re-)transmitted.
154 struct PendingMessage
157 * This is a doubly-linked list.
159 struct PendingMessage *prev;
162 * This is a doubly-linked list.
164 struct PendingMessage *next;
172 * Size of the message.
180 * Connection to the GNS service.
182 struct GNUNET_GNS_Handle
186 * Configuration to use.
188 const struct GNUNET_CONFIGURATION_Handle *cfg;
191 * Socket (if available).
193 struct GNUNET_CLIENT_Connection *client;
196 * Currently pending transmission request (or NULL).
198 struct GNUNET_CLIENT_TransmitHandle *th;
203 * Head of linked list of shorten messages we would like to transmit.
205 struct PendingMessage *pending_head;
208 * Tail of linked list of shorten messages we would like to transmit.
210 struct PendingMessage *pending_tail;
213 * Head of linked list of shorten messages we would like to transmit.
215 struct GNUNET_GNS_ShortenRequest *shorten_head;
218 * Tail of linked list of shorten messages we would like to transmit.
220 struct GNUNET_GNS_ShortenRequest *shorten_tail;
223 * Head of linked list of lookup messages we would like to transmit.
225 struct GNUNET_GNS_LookupRequest *lookup_head;
228 * Tail of linked list of lookup messages we would like to transmit.
230 struct GNUNET_GNS_LookupRequest *lookup_tail;
233 * Head of linked list of authority lookup messages we would like to transmit.
235 struct GNUNET_GNS_GetAuthRequest *get_auth_head;
238 * Tail of linked list of authority lookup messages we would like to transmit.
240 struct GNUNET_GNS_GetAuthRequest *get_auth_tail;
245 GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
248 * Did we start our receive loop yet?
253 * Reconnect necessary
259 * Try to send messages from list of messages to send
260 * @param handle GNS_Handle
263 process_pending_messages (struct GNUNET_GNS_Handle *handle);
267 * Reconnect to GNS service.
269 * @param h the handle to the namestore service
272 reconnect (struct GNUNET_GNS_Handle *h)
274 GNUNET_assert (NULL == h->client);
275 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
276 "Trying to connect to GNS...\n");
277 h->client = GNUNET_CLIENT_connect ("gns", h->cfg);
278 GNUNET_assert (NULL != h->client);
284 * @param cls the handle
285 * @param tc task context
288 reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
290 struct GNUNET_GNS_Handle *h = cls;
292 h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
298 * Disconnect from service and then reconnect.
300 * @param h our handle
303 force_reconnect (struct GNUNET_GNS_Handle *h)
305 h->reconnect = GNUNET_NO;
306 GNUNET_CLIENT_disconnect (h->client);
308 h->reconnect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
314 * Transmit the next pending message, called by notify_transmit_ready
317 transmit_pending (void *cls, size_t size, void *buf);
320 * Handler for messages received from the GNS service
322 * @param cls the 'struct GNUNET_GNS_Handle'
323 * @param msg the incoming message
326 process_message (void *cls, const struct GNUNET_MessageHeader *msg);
329 * Try to send messages from list of messages to send
332 process_pending_messages (struct GNUNET_GNS_Handle *handle)
334 struct PendingMessage *p;
336 if (handle->client == NULL)
338 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
339 "process_pending_messages called, but client is null\n");
343 if (handle->th != NULL)
346 if (NULL == (p = handle->pending_head))
349 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
350 "Trying to transmit %d bytes...\n", p->size);
353 GNUNET_CLIENT_notify_transmit_ready (handle->client,
355 GNUNET_TIME_UNIT_FOREVER_REL,
356 GNUNET_NO, &transmit_pending,
358 if (NULL != handle->th)
361 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
362 "notify_transmit_ready returned NULL!\n");
367 * Transmit the next pending message, called by notify_transmit_ready
370 transmit_pending (void *cls, size_t size, void *buf)
372 struct GNUNET_GNS_Handle *handle = cls;
373 struct PendingMessage *p;
379 if ((size == 0) || (buf == NULL))
381 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
382 "Transmission to GNS service failed!\n");
383 force_reconnect(handle);
390 if (NULL == (p = handle->pending_head))
393 while ((NULL != (p = handle->pending_head)) && (p->size <= size))
395 memcpy (&cbuf[tsize], &p[1], p->size);
398 GNUNET_CONTAINER_DLL_remove (handle->pending_head, handle->pending_tail, p);
399 if (GNUNET_YES != handle->in_receive)
401 GNUNET_CLIENT_receive (handle->client, &process_message, handle,
402 GNUNET_TIME_UNIT_FOREVER_REL);
403 handle->in_receive = GNUNET_YES;
408 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
409 "Sending %d bytes\n", tsize);
411 process_pending_messages(handle);
416 * Process a given reply that might match the given
419 * @param qe a queue entry
420 * @param msg the shorten msg received
423 process_shorten_reply (struct GNUNET_GNS_ShortenRequest *qe,
424 const struct GNUNET_GNS_ClientShortenResultMessage *msg)
426 struct GNUNET_GNS_Handle *h = qe->gns_handle;
427 const char *short_name;
429 GNUNET_CONTAINER_DLL_remove (h->shorten_head, h->shorten_tail, qe);
430 short_name = (char*)(&msg[1]);
432 if (ntohs (((struct GNUNET_MessageHeader*)msg)->size) <
433 sizeof (struct GNUNET_GNS_ClientShortenResultMessage))
441 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
442 "Received shortened reply `%s' from GNS service\n",
445 GNUNET_CLIENT_receive (h->client, &process_message, h,
446 GNUNET_TIME_UNIT_FOREVER_REL);
447 qe->shorten_proc (qe->proc_cls, short_name);
454 * Process a given reply that might match the given
457 * @param qe the handle to the request
458 * @param msg the message to process
461 process_get_auth_reply (struct GNUNET_GNS_GetAuthRequest *qe,
462 const struct GNUNET_GNS_ClientGetAuthResultMessage *msg)
464 struct GNUNET_GNS_Handle *h = qe->gns_handle;
465 const char *auth_name;
467 GNUNET_CONTAINER_DLL_remove (h->get_auth_head, h->get_auth_tail, qe);
468 auth_name = (char*)&msg[1];
470 if (ntohs (((struct GNUNET_MessageHeader*)msg)->size) <
471 sizeof (struct GNUNET_GNS_ClientGetAuthResultMessage))
479 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
480 "Received GET_AUTH reply `%s' from GNS service\n",
483 GNUNET_CLIENT_receive (h->client, &process_message, h,
484 GNUNET_TIME_UNIT_FOREVER_REL);
485 qe->auth_proc (qe->proc_cls, auth_name);
490 * Process a given reply to the lookup request
492 * @param qe a queue entry
493 * @param msg the lookup message received
496 process_lookup_reply (struct GNUNET_GNS_LookupRequest *qe,
497 const struct GNUNET_GNS_ClientLookupResultMessage *msg)
499 struct GNUNET_GNS_Handle *h = qe->gns_handle;
500 int rd_count = ntohl(msg->rd_count);
501 size_t len = ntohs (((struct GNUNET_MessageHeader*)msg)->size);
502 struct GNUNET_NAMESTORE_RecordData rd[rd_count];
504 GNUNET_CONTAINER_DLL_remove (h->lookup_head, h->lookup_tail, qe);
506 if (len < sizeof (struct GNUNET_GNS_ClientLookupResultMessage))
514 len -= sizeof (struct GNUNET_GNS_ClientLookupResultMessage);
515 GNUNET_CLIENT_receive (h->client, &process_message, h,
516 GNUNET_TIME_UNIT_FOREVER_REL);
517 if (GNUNET_SYSERR == GNUNET_NAMESTORE_records_deserialize (len,
522 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
523 "Failed to serialize lookup reply from GNS service!\n");
524 qe->lookup_proc (qe->proc_cls, 0, NULL);
529 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
530 "Received lookup reply from GNS service (count=%d)\n",
531 ntohl (msg->rd_count));
532 qe->lookup_proc (qe->proc_cls, rd_count, rd);
538 * Handler for messages received from the GNS service
540 * @param cls the 'struct GNUNET_GNS_Handle'
541 * @param msg the incoming message
544 process_message (void *cls, const struct GNUNET_MessageHeader *msg)
546 struct GNUNET_GNS_Handle *handle = cls;
547 struct GNUNET_GNS_LookupRequest *lr;
548 struct GNUNET_GNS_ShortenRequest *sr;
549 struct GNUNET_GNS_GetAuthRequest *gar;
550 const struct GNUNET_GNS_ClientLookupResultMessage *lookup_msg;
551 const struct GNUNET_GNS_ClientShortenResultMessage *shorten_msg;
552 const struct GNUNET_GNS_ClientGetAuthResultMessage *get_auth_msg;
556 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
560 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
561 "Error receiving data from GNS service, reconnecting\n");
562 force_reconnect (handle);
566 type = ntohs (msg->type);
568 if (type == GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT)
570 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
572 lookup_msg = (const struct GNUNET_GNS_ClientLookupResultMessage *) msg;
573 r_id = ntohl (lookup_msg->id);
575 if (r_id > handle->r_id)
577 /** no request found */
579 GNUNET_CLIENT_receive (handle->client, &process_message, handle,
580 GNUNET_TIME_UNIT_FOREVER_REL);
584 for (lr = handle->lookup_head; NULL != lr; lr = lr->next)
586 if (lr->r_id == r_id)
590 process_lookup_reply(lr, lookup_msg);
595 else if (type == GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT)
597 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
598 "Got SHORTEN_RESULT msg\n");
599 shorten_msg = (struct GNUNET_GNS_ClientShortenResultMessage *) msg;
601 r_id = ntohl (shorten_msg->id);
603 if (r_id > handle->r_id)
605 /** no request found */
607 GNUNET_CLIENT_receive (handle->client, &process_message, handle,
608 GNUNET_TIME_UNIT_FOREVER_REL);
612 for (sr = handle->shorten_head; NULL != sr; sr = sr->next)
614 if (sr->r_id == r_id)
618 process_shorten_reply (sr, shorten_msg);
621 else if (type == GNUNET_MESSAGE_TYPE_GNS_GET_AUTH_RESULT)
623 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
624 "Got GET_AUTH_RESULT msg\n");
625 get_auth_msg = (struct GNUNET_GNS_ClientGetAuthResultMessage *) msg;
627 r_id = ntohl (get_auth_msg->id);
629 if (r_id > handle->r_id)
631 /** no request found */
633 GNUNET_CLIENT_receive (handle->client, &process_message, handle,
634 GNUNET_TIME_UNIT_FOREVER_REL);
638 for (gar = handle->get_auth_head; NULL != gar; gar = gar->next)
640 if (gar->r_id == r_id)
644 process_get_auth_reply (gar, get_auth_msg);
649 if (GNUNET_YES == handle->reconnect)
650 force_reconnect (handle);
655 * Initialize the connection with the GNS service.
657 * @param cfg configuration to use
658 * @return handle to the GNS service, or NULL on error
660 struct GNUNET_GNS_Handle *
661 GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
663 struct GNUNET_GNS_Handle *handle;
665 handle = GNUNET_malloc (sizeof (struct GNUNET_GNS_Handle));
666 handle->reconnect = GNUNET_NO;
669 handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
671 handle->in_receive = GNUNET_NO;
677 * Shutdown connection with the GNS service.
679 * @param handle handle of the GNS connection to stop
682 GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle)
684 GNUNET_CLIENT_disconnect (handle->client);
685 if (GNUNET_SCHEDULER_NO_TASK != handle->reconnect_task)
687 GNUNET_SCHEDULER_cancel (handle->reconnect_task);
688 handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
691 GNUNET_assert (NULL == handle->lookup_head);
692 GNUNET_assert (NULL == handle->shorten_head);
693 GNUNET_assert (NULL == handle->get_auth_head);
700 * Helper function to generate request ids
706 get_request_id (struct GNUNET_GNS_Handle *h)
708 uint32_t r_id = h->r_id;
715 * Cancel pending lookup request
717 * @param lr the lookup request to cancel
720 GNUNET_GNS_cancel_lookup_request (struct GNUNET_GNS_LookupRequest *lr)
722 GNUNET_assert (NULL != lr->gns_handle);
724 GNUNET_CONTAINER_DLL_remove (lr->gns_handle->pending_head,
725 lr->gns_handle->pending_tail,
728 GNUNET_free (lr->pending_msg);
730 GNUNET_CONTAINER_DLL_remove (lr->gns_handle->lookup_head,
731 lr->gns_handle->lookup_tail,
739 * Cancel pending shorten request
741 * @param sr the lookup request to cancel
744 GNUNET_GNS_cancel_shorten_request (struct GNUNET_GNS_ShortenRequest *sr)
746 GNUNET_assert (NULL != sr->gns_handle);
748 GNUNET_CONTAINER_DLL_remove (sr->gns_handle->pending_head,
749 sr->gns_handle->pending_tail,
752 GNUNET_free (sr->pending_msg);
754 GNUNET_CONTAINER_DLL_remove (sr->gns_handle->shorten_head,
755 sr->gns_handle->shorten_tail,
763 * Cancel pending get auth request
765 * @param gar the lookup request to cancel
768 GNUNET_GNS_cancel_get_auth_request (struct GNUNET_GNS_GetAuthRequest *gar)
770 GNUNET_assert (NULL != gar->gns_handle);
772 GNUNET_CONTAINER_DLL_remove (gar->gns_handle->pending_head,
773 gar->gns_handle->pending_tail,
776 GNUNET_free (gar->pending_msg);
778 GNUNET_CONTAINER_DLL_remove (gar->gns_handle->get_auth_head,
779 gar->gns_handle->get_auth_tail,
786 * Perform an asynchronous Lookup operation on the GNS.
788 * @param handle handle to the GNS service
789 * @param name the name to look up
790 * @param zone the zone to start the resolution in
791 * @param type the record type to look up
792 * @param only_cached GNUNET_YES to only check locally not DHT for performance
793 * @param shorten_key the private key of the shorten zone (can be NULL)
794 * @param proc processor to call on result
795 * @param proc_cls closure for processor
796 * @return handle to the get request
798 struct GNUNET_GNS_LookupRequest*
799 GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle,
801 struct GNUNET_CRYPTO_ShortHashCode *zone,
802 enum GNUNET_GNS_RecordType type,
804 struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key,
805 GNUNET_GNS_LookupResultProcessor proc,
808 /* IPC to shorten gns names, return shorten_handle */
809 struct GNUNET_GNS_ClientLookupMessage *lookup_msg;
810 struct GNUNET_GNS_LookupRequest *lr;
812 struct PendingMessage *pending;
813 struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *pkey_enc=NULL;
822 if (NULL != shorten_key)
824 pkey_enc = GNUNET_CRYPTO_rsa_encode_key (shorten_key);
825 GNUNET_assert (pkey_enc != NULL);
826 key_len = ntohs (pkey_enc->len);
829 msize = sizeof (struct GNUNET_GNS_ClientLookupMessage)
830 + key_len + strlen(name) + 1;
831 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to lookup %s in GNS\n", name);
833 lr = GNUNET_malloc(sizeof (struct GNUNET_GNS_LookupRequest));
834 lr->gns_handle = handle;
835 lr->lookup_proc = proc;
836 lr->proc_cls = proc_cls;
837 lr->r_id = get_request_id (handle);
838 GNUNET_CONTAINER_DLL_insert_tail (handle->lookup_head,
839 handle->lookup_tail, lr);
841 pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
842 memset (pending, 0, (sizeof (struct PendingMessage) + msize));
844 pending->size = msize;
845 lr->pending_msg = pending;
847 lookup_msg = (struct GNUNET_GNS_ClientLookupMessage *) &pending[1];
848 lookup_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_LOOKUP);
849 lookup_msg->header.size = htons (msize);
850 lookup_msg->id = htonl (lr->r_id);
851 lookup_msg->only_cached = htonl(only_cached);
855 lookup_msg->use_default_zone = htonl (0);
856 memcpy (&lookup_msg->zone, zone, sizeof (struct GNUNET_CRYPTO_ShortHashCode));
860 lookup_msg->use_default_zone = htonl (1);
861 memset (&lookup_msg->zone, 0, sizeof(struct GNUNET_CRYPTO_ShortHashCode));
864 lookup_msg->type = htonl (type);
866 pkey_tmp = (char *) &lookup_msg[1];
868 if (pkey_enc != NULL)
870 lookup_msg->have_key = htonl(1);
871 memcpy (pkey_tmp, pkey_enc, key_len);
874 lookup_msg->have_key = htonl (0);
876 memcpy (&pkey_tmp[key_len], name, strlen (name));
878 GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head, handle->pending_tail,
880 GNUNET_free_non_null (pkey_enc);
881 process_pending_messages (handle);
886 * Perform an asynchronous Lookup operation on the GNS.
888 * @param handle handle to the GNS service
889 * @param name the name to look up
890 * @param type the record type to look up
891 * @param only_cached GNUNET_YES to only check locally not DHT for performance
892 * @param shorten_key the private key of the shorten zone (can be NULL)
893 * @param proc processor to call on result
894 * @param proc_cls closure for processor
895 * @return handle to the lookup request
897 struct GNUNET_GNS_LookupRequest*
898 GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
900 enum GNUNET_GNS_RecordType type,
902 struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key,
903 GNUNET_GNS_LookupResultProcessor proc,
906 return GNUNET_GNS_lookup_zone (handle, name,
914 * Perform a name shortening operation on the GNS.
916 * @param handle handle to the GNS service
917 * @param name the name to look up
918 * @param private_zone the public zone of the private zone
919 * @param shorten_zone the public zone of the shorten zone
920 * @param zone the zone to start the resolution in
921 * @param proc function to call on result
922 * @param proc_cls closure for processor
923 * @return handle to the operation
925 struct GNUNET_GNS_ShortenRequest*
926 GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle,
928 struct GNUNET_CRYPTO_ShortHashCode *private_zone,
929 struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
930 struct GNUNET_CRYPTO_ShortHashCode *zone,
931 GNUNET_GNS_ShortenResultProcessor proc,
934 /* IPC to shorten gns names, return shorten_handle */
935 struct GNUNET_GNS_ClientShortenMessage *shorten_msg;
936 struct GNUNET_GNS_ShortenRequest *sr;
938 struct PendingMessage *pending;
945 msize = sizeof (struct GNUNET_GNS_ClientShortenMessage) + strlen(name) + 1;
946 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to shorten %s in GNS\n", name);
948 sr = GNUNET_malloc(sizeof (struct GNUNET_GNS_ShortenRequest));
949 sr->gns_handle = handle;
950 sr->shorten_proc = proc;
951 sr->proc_cls = proc_cls;
952 sr->r_id = get_request_id (handle);
953 GNUNET_CONTAINER_DLL_insert_tail (handle->shorten_head,
954 handle->shorten_tail, sr);
956 pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
957 memset(pending, 0, (sizeof (struct PendingMessage) + msize));
959 pending->size = msize;
960 sr->pending_msg = pending;
962 shorten_msg = (struct GNUNET_GNS_ClientShortenMessage *) &pending[1];
963 shorten_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_SHORTEN);
964 shorten_msg->header.size = htons (msize);
965 shorten_msg->id = htonl (sr->r_id);
966 shorten_msg->private_zone = *private_zone;
967 shorten_msg->shorten_zone = *shorten_zone;
971 shorten_msg->use_default_zone = htonl (0);
972 memcpy (&shorten_msg->zone, zone,
973 sizeof (struct GNUNET_CRYPTO_ShortHashCode));
977 shorten_msg->use_default_zone = htonl (1);
978 memset (&shorten_msg->zone, 0, sizeof (struct GNUNET_CRYPTO_ShortHashCode));
981 memcpy (&shorten_msg[1], name, strlen (name));
983 GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head, handle->pending_tail,
986 process_pending_messages (handle);
991 * Perform a name shortening operation on the GNS.
993 * @param handle handle to the GNS service
994 * @param name the name to look up
995 * @param private_zone the public zone of the private zone
996 * @param shorten_zone the public zone of the shorten zone
997 * @param proc function to call on result
998 * @param proc_cls closure for processor
999 * @return handle to the operation
1001 struct GNUNET_GNS_ShortenRequest*
1002 GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle,
1004 struct GNUNET_CRYPTO_ShortHashCode *private_zone,
1005 struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
1006 GNUNET_GNS_ShortenResultProcessor proc,
1009 return GNUNET_GNS_shorten_zone (handle, name,
1010 private_zone, shorten_zone,
1011 NULL, proc, proc_cls);
1016 * Perform an authority lookup for a given name.
1018 * @param handle handle to the GNS service
1019 * @param name the name to look up authority for
1020 * @param proc function to call on result
1021 * @param proc_cls closure for processor
1022 * @return handle to the operation
1024 struct GNUNET_GNS_GetAuthRequest*
1025 GNUNET_GNS_get_authority (struct GNUNET_GNS_Handle *handle,
1027 GNUNET_GNS_GetAuthResultProcessor proc,
1030 struct GNUNET_GNS_ClientGetAuthMessage *get_auth_msg;
1031 struct GNUNET_GNS_GetAuthRequest *gar;
1033 struct PendingMessage *pending;
1040 msize = sizeof (struct GNUNET_GNS_ClientGetAuthMessage) + strlen(name) + 1;
1041 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1042 "Trying to look up authority for %s in GNS\n", name);
1044 gar = GNUNET_malloc (sizeof (struct GNUNET_GNS_GetAuthRequest));
1045 gar->gns_handle = handle;
1046 gar->auth_proc = proc;
1047 gar->proc_cls = proc_cls;
1048 gar->r_id = get_request_id (handle);
1049 GNUNET_CONTAINER_DLL_insert_tail (handle->get_auth_head,
1050 handle->get_auth_tail, gar);
1052 pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
1053 memset (pending, 0, (sizeof (struct PendingMessage) + msize));
1055 pending->size = msize;
1056 gar->pending_msg = pending;
1058 get_auth_msg = (struct GNUNET_GNS_ClientGetAuthMessage *) &pending[1];
1059 get_auth_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_GET_AUTH);
1060 get_auth_msg->header.size = htons (msize);
1061 get_auth_msg->id = htonl (gar->r_id);
1063 memcpy(&get_auth_msg[1], name, strlen(name));
1065 GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head, handle->pending_tail,
1068 process_pending_messages (handle);
1073 /* end of gns_api.c */