2 This file is part of GNUnet.
3 (C) 2009, 2010, 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 * @brief library to access the GNS service
23 * @author Martin Schanzenbach
24 * @author Christian Grothoff
27 #include "gnunet_util_lib.h"
28 #include "gnunet_constants.h"
29 #include "gnunet_arm_service.h"
30 #include "gnunet_hello_lib.h"
31 #include "gnunet_protocols.h"
32 #include "gnunet_dht_service.h"
34 #include "gnunet_gns_service.h"
38 * Handle to a lookup request
40 struct GNUNET_GNS_LookupRequest
46 struct GNUNET_GNS_LookupRequest *next;
51 struct GNUNET_GNS_LookupRequest *prev;
56 struct GNUNET_GNS_Handle *gns_handle;
59 * processor to call on lookup result
61 GNUNET_GNS_LookupResultProcessor lookup_proc;
77 * Handle to a shorten request
79 struct GNUNET_GNS_ShortenRequest
84 struct GNUNET_GNS_ShortenRequest *next;
89 struct GNUNET_GNS_ShortenRequest *prev;
92 struct GNUNET_GNS_Handle *gns_handle;
94 /* processor to call on shorten result */
95 GNUNET_GNS_ShortenResultProcessor shorten_proc;
97 /* processor closure */
108 * Handle to GetAuthorityRequest
110 struct GNUNET_GNS_GetAuthRequest
115 struct GNUNET_GNS_GetAuthRequest *next;
120 struct GNUNET_GNS_GetAuthRequest *prev;
123 struct GNUNET_GNS_Handle *gns_handle;
125 /* processor to call on authority lookup result */
126 GNUNET_GNS_GetAuthResultProcessor auth_proc;
128 /* processor closure */
138 * Entry in our list of messages to be (re-)transmitted.
140 struct PendingMessage
143 * This is a doubly-linked list.
145 struct PendingMessage *prev;
148 * This is a doubly-linked list.
150 struct PendingMessage *next;
158 * Size of the message.
166 * Connection to the GNS service.
168 struct GNUNET_GNS_Handle
172 * Configuration to use.
174 const struct GNUNET_CONFIGURATION_Handle *cfg;
177 * Socket (if available).
179 struct GNUNET_CLIENT_Connection *client;
182 * Currently pending transmission request (or NULL).
184 struct GNUNET_CLIENT_TransmitHandle *th;
187 * Head of linked list of shorten messages we would like to transmit.
189 struct PendingMessage *pending_head;
192 * Tail of linked list of shorten messages we would like to transmit.
194 struct PendingMessage *pending_tail;
197 * Head of linked list of shorten messages we would like to transmit.
199 struct GNUNET_GNS_ShortenRequest *shorten_head;
202 * Tail of linked list of shorten messages we would like to transmit.
204 struct GNUNET_GNS_ShortenRequest *shorten_tail;
207 * Head of linked list of lookup messages we would like to transmit.
209 struct GNUNET_GNS_LookupRequest *lookup_head;
212 * Tail of linked list of lookup messages we would like to transmit.
214 struct GNUNET_GNS_LookupRequest *lookup_tail;
217 * Head of linked list of authority lookup messages we would like to transmit.
219 struct GNUNET_GNS_GetAuthRequest *get_auth_head;
222 * Tail of linked list of authority lookup messages we would like to transmit.
224 struct GNUNET_GNS_GetAuthRequest *get_auth_tail;
229 GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
234 * Did we start our receive loop yet?
242 * Try to send messages from list of messages to send
243 * @param handle GNS_Handle
246 process_pending_messages (struct GNUNET_GNS_Handle *handle);
250 * Reconnect to GNS service.
252 * @param h the handle to the GNS service
255 reconnect (struct GNUNET_GNS_Handle *h)
257 GNUNET_assert (NULL == h->client);
258 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
259 "Trying to connect to GNS\n");
260 h->client = GNUNET_CLIENT_connect ("gns", h->cfg);
261 GNUNET_assert (NULL != h->client);
262 process_pending_messages (h);
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 GNUNET_CLIENT_disconnect (h->client);
292 h->in_receive = GNUNET_NO;
293 /* FIXME: 1s too long, exponential-backoff, starting at 1ms! (max = 1s might be OK) */
294 h->reconnect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
301 * Transmit the next pending message, called by notify_transmit_ready
306 transmit_pending (void *cls, size_t size, void *buf);
310 * Handler for messages received from the GNS service
312 * @param cls the 'struct GNUNET_GNS_Handle'
313 * @param msg the incoming message
316 process_message (void *cls, const struct GNUNET_MessageHeader *msg);
320 * Try to send messages from list of messages to send
325 process_pending_messages (struct GNUNET_GNS_Handle *handle)
327 struct PendingMessage *p;
329 if (NULL == handle->client)
330 return; /* wait for reconnect */
331 if (NULL != handle->th)
332 return; /* transmission request already pending */
333 if (NULL == (p = handle->pending_head))
334 return; /* no messages pending */
335 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
336 "Trying to transmit %u bytes\n",
337 (unsigned int) p->size);
339 GNUNET_CLIENT_notify_transmit_ready (handle->client,
341 GNUNET_TIME_UNIT_FOREVER_REL,
342 GNUNET_NO, &transmit_pending,
344 GNUNET_break (NULL != handle->th);
349 * Transmit the next pending message, called by notify_transmit_ready
354 transmit_pending (void *cls, size_t size, void *buf)
356 struct GNUNET_GNS_Handle *handle = cls;
358 struct PendingMessage *p;
362 if ((0 == size) || (NULL == buf))
364 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
365 "Transmission to GNS service failed!\n");
366 force_reconnect(handle);
369 if (NULL == (p = handle->pending_head))
373 while ((NULL != (p = handle->pending_head)) && (p->size <= size))
375 memcpy (&cbuf[tsize], &p[1], p->size);
378 GNUNET_CONTAINER_DLL_remove (handle->pending_head, handle->pending_tail, p);
379 if (GNUNET_YES != handle->in_receive)
381 GNUNET_CLIENT_receive (handle->client, &process_message, handle,
382 GNUNET_TIME_UNIT_FOREVER_REL);
383 handle->in_receive = GNUNET_YES;
387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
388 "Sending %u bytes\n",
389 (unsigned int) tsize);
390 process_pending_messages (handle);
396 * Process a given reply that might match the given
399 * @param qe a queue entry
400 * @param msg the shorten msg received
403 process_shorten_reply (struct GNUNET_GNS_ShortenRequest *qe,
404 const struct GNUNET_GNS_ClientShortenResultMessage *msg)
406 struct GNUNET_GNS_Handle *h = qe->gns_handle;
407 const char *short_name;
410 GNUNET_CONTAINER_DLL_remove (h->shorten_head, h->shorten_tail, qe);
411 mlen = ntohs (msg->header.size);
412 short_name = (const char *) &msg[1];
414 if ( (ntohs (msg->header.size) <= sizeof (struct GNUNET_GNS_ClientShortenResultMessage)) ||
415 ('\0' != short_name[mlen - sizeof (struct GNUNET_GNS_ClientShortenResultMessage) - 1]) )
418 // FIXME: reconnect and queue management logic is broken...
419 qe->shorten_proc (qe->proc_cls, NULL);
424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
425 "Received shortened reply `%s' from GNS service\n",
427 qe->shorten_proc (qe->proc_cls, short_name);
433 * Process a given reply that might match the given
436 * @param qe the handle to the request
437 * @param msg the message to process
440 process_get_auth_reply (struct GNUNET_GNS_GetAuthRequest *qe,
441 const struct GNUNET_GNS_ClientGetAuthResultMessage *msg)
443 struct GNUNET_GNS_Handle *h = qe->gns_handle;
444 const char *auth_name;
446 GNUNET_CONTAINER_DLL_remove (h->get_auth_head, h->get_auth_tail, qe);
447 auth_name = (char*)&msg[1];
449 if (ntohs (((struct GNUNET_MessageHeader*)msg)->size) <
450 sizeof (struct GNUNET_GNS_ClientGetAuthResultMessage))
458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
459 "Received GET_AUTH reply `%s' from GNS service\n",
461 qe->auth_proc (qe->proc_cls, auth_name);
467 * Process a given reply to the lookup request
469 * @param qe a queue entry
470 * @param msg the lookup message received
473 process_lookup_reply (struct GNUNET_GNS_LookupRequest *qe,
474 const struct GNUNET_GNS_ClientLookupResultMessage *msg)
476 struct GNUNET_GNS_Handle *h = qe->gns_handle;
477 int rd_count = ntohl(msg->rd_count);
478 size_t len = ntohs (((struct GNUNET_MessageHeader*)msg)->size);
479 struct GNUNET_NAMESTORE_RecordData rd[rd_count];
481 GNUNET_CONTAINER_DLL_remove (h->lookup_head, h->lookup_tail, qe);
483 if (len < sizeof (struct GNUNET_GNS_ClientLookupResultMessage))
491 len -= sizeof (struct GNUNET_GNS_ClientLookupResultMessage);
492 if (GNUNET_SYSERR == GNUNET_NAMESTORE_records_deserialize (len,
497 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
498 "Failed to serialize lookup reply from GNS service!\n");
499 qe->lookup_proc (qe->proc_cls, 0, NULL);
504 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
505 "Received lookup reply from GNS service (count=%d)\n",
506 ntohl (msg->rd_count));
507 qe->lookup_proc (qe->proc_cls, rd_count, rd);
513 * Handler for messages received from the GNS service
515 * @param cls the 'struct GNUNET_GNS_Handle'
516 * @param msg the incoming message
519 process_message (void *cls, const struct GNUNET_MessageHeader *msg)
521 struct GNUNET_GNS_Handle *handle = cls;
522 struct GNUNET_GNS_LookupRequest *lr;
523 struct GNUNET_GNS_ShortenRequest *sr;
524 struct GNUNET_GNS_GetAuthRequest *gar;
525 const struct GNUNET_GNS_ClientLookupResultMessage *lookup_msg;
526 const struct GNUNET_GNS_ClientShortenResultMessage *shorten_msg;
527 const struct GNUNET_GNS_ClientGetAuthResultMessage *get_auth_msg;
532 force_reconnect (handle);
535 switch (ntohs (msg->type))
537 case GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT:
538 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
539 "Got LOOKUP_RESULT msg\n");
540 if (ntohs (msg->size) < sizeof (struct GNUNET_GNS_ClientLookupResultMessage))
543 force_reconnect (handle);
546 lookup_msg = (const struct GNUNET_GNS_ClientLookupResultMessage *) msg;
547 r_id = ntohl (lookup_msg->id);
548 for (lr = handle->lookup_head; NULL != lr; lr = lr->next)
549 if (lr->r_id == r_id)
551 process_lookup_reply(lr, lookup_msg);
555 case GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT:
556 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
557 "Got SHORTEN_RESULT msg\n");
558 if (ntohs (msg->size) < sizeof (struct GNUNET_GNS_ClientShortenResultMessage))
561 force_reconnect (handle);
564 shorten_msg = (const struct GNUNET_GNS_ClientShortenResultMessage *) msg;
565 r_id = ntohl (shorten_msg->id);
566 for (sr = handle->shorten_head; NULL != sr; sr = sr->next)
567 if (sr->r_id == r_id)
569 process_shorten_reply (sr, shorten_msg);
573 case GNUNET_MESSAGE_TYPE_GNS_GET_AUTH_RESULT:
574 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
575 "Got GET_AUTH_RESULT msg\n");
576 if (ntohs (msg->size) < sizeof (struct GNUNET_GNS_ClientGetAuthResultMessage))
579 force_reconnect (handle);
582 get_auth_msg = (const struct GNUNET_GNS_ClientGetAuthResultMessage *) msg;
583 r_id = ntohl (get_auth_msg->id);
584 for (gar = handle->get_auth_head; NULL != gar; gar = gar->next)
585 if (gar->r_id == r_id)
587 process_get_auth_reply (gar, get_auth_msg);
593 force_reconnect (handle);
596 GNUNET_CLIENT_receive (handle->client, &process_message, handle,
597 GNUNET_TIME_UNIT_FOREVER_REL);
602 * Initialize the connection with the GNS service.
604 * @param cfg configuration to use
605 * @return handle to the GNS service, or NULL on error
607 struct GNUNET_GNS_Handle *
608 GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
610 struct GNUNET_GNS_Handle *handle;
612 handle = GNUNET_malloc (sizeof (struct GNUNET_GNS_Handle));
620 * Shutdown connection with the GNS service.
622 * @param handle handle of the GNS connection to stop
625 GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle)
627 GNUNET_CLIENT_disconnect (handle->client);
628 if (GNUNET_SCHEDULER_NO_TASK != handle->reconnect_task)
630 GNUNET_SCHEDULER_cancel (handle->reconnect_task);
631 handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
633 GNUNET_assert (NULL == handle->lookup_head);
634 GNUNET_assert (NULL == handle->shorten_head);
635 GNUNET_assert (NULL == handle->get_auth_head);
642 * Cancel pending lookup request
644 * @param lr the lookup request to cancel
647 GNUNET_GNS_cancel_lookup_request (struct GNUNET_GNS_LookupRequest *lr)
649 struct PendingMessage *tmp;
651 GNUNET_assert (NULL != lr->gns_handle);
652 for (tmp = lr->gns_handle->pending_head;
653 NULL != tmp; tmp = tmp->next)
655 if (tmp->r_id == lr->r_id)
661 GNUNET_CONTAINER_DLL_remove (lr->gns_handle->pending_head,
662 lr->gns_handle->pending_tail,
667 GNUNET_CONTAINER_DLL_remove (lr->gns_handle->lookup_head,
668 lr->gns_handle->lookup_tail,
676 * Cancel pending shorten request
678 * @param sr the lookup request to cancel
681 GNUNET_GNS_cancel_shorten_request (struct GNUNET_GNS_ShortenRequest *sr)
683 struct PendingMessage *tmp;
685 GNUNET_assert (NULL != sr->gns_handle);
686 for (tmp = sr->gns_handle->pending_head;
687 NULL != tmp; tmp = tmp->next)
689 if (tmp->r_id == sr->r_id)
695 GNUNET_CONTAINER_DLL_remove (sr->gns_handle->pending_head,
696 sr->gns_handle->pending_tail,
701 GNUNET_CONTAINER_DLL_remove (sr->gns_handle->shorten_head,
702 sr->gns_handle->shorten_tail,
710 * Cancel pending get auth request
712 * @param gar the lookup request to cancel
715 GNUNET_GNS_cancel_get_auth_request (struct GNUNET_GNS_GetAuthRequest *gar)
717 struct PendingMessage *tmp;
719 GNUNET_assert (NULL != gar->gns_handle);
720 for (tmp = gar->gns_handle->pending_head;
721 NULL != tmp; tmp = tmp->next)
723 if (tmp->r_id == gar->r_id)
729 GNUNET_CONTAINER_DLL_remove (gar->gns_handle->pending_head,
730 gar->gns_handle->pending_tail,
735 GNUNET_CONTAINER_DLL_remove (gar->gns_handle->get_auth_head,
736 gar->gns_handle->get_auth_tail,
744 * Perform an asynchronous Lookup operation on the GNS.
746 * @param handle handle to the GNS service
747 * @param name the name to look up
748 * @param zone the zone to start the resolution in
749 * @param type the record type to look up
750 * @param only_cached GNUNET_YES to only check locally not DHT for performance
751 * @param shorten_key the private key of the shorten zone (can be NULL)
752 * @param proc processor to call on result
753 * @param proc_cls closure for processor
754 * @return handle to the get request
756 struct GNUNET_GNS_LookupRequest*
757 GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle,
759 struct GNUNET_CRYPTO_ShortHashCode *zone,
760 enum GNUNET_GNS_RecordType type,
762 struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key,
763 GNUNET_GNS_LookupResultProcessor proc,
766 /* IPC to shorten gns names, return shorten_handle */
767 struct GNUNET_GNS_ClientLookupMessage *lookup_msg;
768 struct GNUNET_GNS_LookupRequest *lr;
770 struct PendingMessage *pending;
771 struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *pkey_enc;
781 if (NULL != shorten_key)
783 pkey_enc = GNUNET_CRYPTO_rsa_encode_key (shorten_key);
784 GNUNET_assert (pkey_enc != NULL);
785 key_len = ntohs (pkey_enc->len);
793 msize = sizeof (struct GNUNET_GNS_ClientLookupMessage)
794 + key_len + strlen (name) + 1;
795 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
796 "Trying to lookup %s in GNS\n",
798 lr = GNUNET_malloc (sizeof (struct GNUNET_GNS_LookupRequest));
799 lr->gns_handle = handle;
800 lr->lookup_proc = proc;
801 lr->proc_cls = proc_cls;
802 lr->r_id = handle->r_id++;
803 GNUNET_CONTAINER_DLL_insert_tail (handle->lookup_head,
804 handle->lookup_tail, lr);
806 pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
807 pending->size = msize;
808 pending->r_id = lr->r_id;
810 lookup_msg = (struct GNUNET_GNS_ClientLookupMessage *) &pending[1];
811 lookup_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_LOOKUP);
812 lookup_msg->header.size = htons (msize);
813 lookup_msg->id = htonl (lr->r_id);
814 lookup_msg->only_cached = htonl (only_cached);
817 lookup_msg->use_default_zone = htonl (GNUNET_NO);
818 memcpy (&lookup_msg->zone, zone, sizeof (struct GNUNET_CRYPTO_ShortHashCode));
822 lookup_msg->use_default_zone = htonl (GNUNET_YES);
823 memset (&lookup_msg->zone, 0, sizeof(struct GNUNET_CRYPTO_ShortHashCode));
825 lookup_msg->type = htonl (type);
826 pkey_tmp = (char *) &lookup_msg[1];
827 if (pkey_enc != NULL)
829 lookup_msg->have_key = htonl (GNUNET_YES);
830 memcpy (pkey_tmp, pkey_enc, key_len);
833 lookup_msg->have_key = htonl (GNUNET_NO);
834 GNUNET_free_non_null (pkey_enc);
835 memcpy (&pkey_tmp[key_len], name, strlen (name) + 1);
837 GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head,
838 handle->pending_tail,
840 process_pending_messages (handle);
846 * Perform an asynchronous Lookup operation on the GNS.
848 * @param handle handle to the GNS service
849 * @param name the name to look up
850 * @param type the record type to look up
851 * @param only_cached GNUNET_YES to only check locally not DHT for performance
852 * @param shorten_key the private key of the shorten zone (can be NULL)
853 * @param proc processor to call on result
854 * @param proc_cls closure for processor
855 * @return handle to the lookup request
857 struct GNUNET_GNS_LookupRequest*
858 GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
860 enum GNUNET_GNS_RecordType type,
862 struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key,
863 GNUNET_GNS_LookupResultProcessor proc,
866 return GNUNET_GNS_lookup_zone (handle, name,
875 * Perform a name shortening operation on the GNS.
877 * @param handle handle to the GNS service
878 * @param name the name to look up
879 * @param private_zone the public zone of the private zone
880 * @param shorten_zone the public zone of the shorten zone
881 * @param zone the zone to start the resolution in
882 * @param proc function to call on result
883 * @param proc_cls closure for processor
884 * @return handle to the operation
886 struct GNUNET_GNS_ShortenRequest*
887 GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle,
889 struct GNUNET_CRYPTO_ShortHashCode *private_zone,
890 struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
891 struct GNUNET_CRYPTO_ShortHashCode *zone,
892 GNUNET_GNS_ShortenResultProcessor proc,
895 /* IPC to shorten gns names, return shorten_handle */
896 struct GNUNET_GNS_ClientShortenMessage *shorten_msg;
897 struct GNUNET_GNS_ShortenRequest *sr;
899 struct PendingMessage *pending;
906 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to shorten %s in GNS\n", name);
908 msize = sizeof (struct GNUNET_GNS_ClientShortenMessage) + strlen(name) + 1;
909 sr = GNUNET_malloc (sizeof (struct GNUNET_GNS_ShortenRequest));
910 sr->gns_handle = handle;
911 sr->shorten_proc = proc;
912 sr->proc_cls = proc_cls;
913 sr->r_id = handle->r_id++;
914 GNUNET_CONTAINER_DLL_insert_tail (handle->shorten_head,
915 handle->shorten_tail, sr);
917 pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
918 pending->size = msize;
919 pending->r_id = sr->r_id;
921 shorten_msg = (struct GNUNET_GNS_ClientShortenMessage *) &pending[1];
922 shorten_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_SHORTEN);
923 shorten_msg->header.size = htons (msize);
924 shorten_msg->id = htonl (sr->r_id);
925 shorten_msg->private_zone = *private_zone;
926 shorten_msg->shorten_zone = *shorten_zone;
930 shorten_msg->use_default_zone = htonl (GNUNET_NO);
931 memcpy (&shorten_msg->zone, zone,
932 sizeof (struct GNUNET_CRYPTO_ShortHashCode));
936 shorten_msg->use_default_zone = htonl (GNUNET_YES);
937 memset (&shorten_msg->zone, 0, sizeof (struct GNUNET_CRYPTO_ShortHashCode));
940 memcpy (&shorten_msg[1], name, strlen (name) + 1);
942 GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head, handle->pending_tail,
945 process_pending_messages (handle);
951 * Perform a name shortening operation on the GNS.
953 * @param handle handle to the GNS service
954 * @param name the name to look up
955 * @param private_zone the public zone of the private zone
956 * @param shorten_zone the public zone of the shorten zone
957 * @param proc function to call on result
958 * @param proc_cls closure for processor
959 * @return handle to the operation
961 struct GNUNET_GNS_ShortenRequest*
962 GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle,
964 struct GNUNET_CRYPTO_ShortHashCode *private_zone,
965 struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
966 GNUNET_GNS_ShortenResultProcessor proc,
969 return GNUNET_GNS_shorten_zone (handle, name,
970 private_zone, shorten_zone,
971 NULL, proc, proc_cls);
976 * Perform an authority lookup for a given name.
978 * @param handle handle to the GNS service
979 * @param name the name to look up authority for
980 * @param proc function to call on result
981 * @param proc_cls closure for processor
982 * @return handle to the operation
984 struct GNUNET_GNS_GetAuthRequest*
985 GNUNET_GNS_get_authority (struct GNUNET_GNS_Handle *handle,
987 GNUNET_GNS_GetAuthResultProcessor proc,
990 struct GNUNET_GNS_ClientGetAuthMessage *get_auth_msg;
991 struct GNUNET_GNS_GetAuthRequest *gar;
993 struct PendingMessage *pending;
1000 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1001 "Trying to look up authority for %s in GNS\n", name);
1003 msize = sizeof (struct GNUNET_GNS_ClientGetAuthMessage) + strlen (name) + 1;
1004 gar = GNUNET_malloc (sizeof (struct GNUNET_GNS_GetAuthRequest));
1005 gar->gns_handle = handle;
1006 gar->auth_proc = proc;
1007 gar->proc_cls = proc_cls;
1008 gar->r_id = handle->r_id++;
1009 GNUNET_CONTAINER_DLL_insert_tail (handle->get_auth_head,
1010 handle->get_auth_tail, gar);
1012 pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
1013 pending->size = msize;
1014 pending->r_id = gar->r_id;
1015 get_auth_msg = (struct GNUNET_GNS_ClientGetAuthMessage *) &pending[1];
1016 get_auth_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_GET_AUTH);
1017 get_auth_msg->header.size = htons (msize);
1018 get_auth_msg->id = htonl (gar->r_id);
1019 memcpy (&get_auth_msg[1], name, strlen(name) + 1);
1021 GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head,
1022 handle->pending_tail,
1024 process_pending_messages (handle);
1029 /* end of gns_api.c */