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.
163 * This message has been transmitted
165 unsigned int transmitted;
171 * Connection to the GNS service.
173 struct GNUNET_GNS_Handle
177 * Configuration to use.
179 const struct GNUNET_CONFIGURATION_Handle *cfg;
182 * Socket (if available).
184 struct GNUNET_CLIENT_Connection *client;
187 * Currently pending transmission request (or NULL).
189 struct GNUNET_CLIENT_TransmitHandle *th;
192 * Head of linked list of shorten messages we would like to transmit.
194 struct PendingMessage *pending_head;
197 * Tail of linked list of shorten messages we would like to transmit.
199 struct PendingMessage *pending_tail;
202 * Head of linked list of shorten messages we would like to transmit.
204 struct GNUNET_GNS_ShortenRequest *shorten_head;
207 * Tail of linked list of shorten messages we would like to transmit.
209 struct GNUNET_GNS_ShortenRequest *shorten_tail;
212 * Head of linked list of lookup messages we would like to transmit.
214 struct GNUNET_GNS_LookupRequest *lookup_head;
217 * Tail of linked list of lookup messages we would like to transmit.
219 struct GNUNET_GNS_LookupRequest *lookup_tail;
222 * Head of linked list of authority lookup messages we would like to transmit.
224 struct GNUNET_GNS_GetAuthRequest *get_auth_head;
227 * Tail of linked list of authority lookup messages we would like to transmit.
229 struct GNUNET_GNS_GetAuthRequest *get_auth_tail;
234 GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
239 * Did we start our receive loop yet?
247 * Try to send messages from list of messages to send
248 * @param handle GNS_Handle
251 process_pending_messages (struct GNUNET_GNS_Handle *handle);
255 * Reconnect to GNS service.
257 * @param h the handle to the GNS service
260 reconnect (struct GNUNET_GNS_Handle *h)
262 GNUNET_assert (NULL == h->client);
263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
264 "Trying to connect to GNS\n");
265 h->client = GNUNET_CLIENT_connect ("gns", h->cfg);
266 GNUNET_assert (NULL != h->client);
267 process_pending_messages (h);
274 * @param cls the handle
275 * @param tc task context
278 reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
280 struct GNUNET_GNS_Handle *h = cls;
282 h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
288 * Disconnect from service and then reconnect.
290 * @param h our handle
293 force_reconnect (struct GNUNET_GNS_Handle *h)
295 GNUNET_CLIENT_disconnect (h->client);
297 h->in_receive = GNUNET_NO;
298 /* FIXME: 1s too long, exponential-backoff, starting at 1ms! (max = 1s might be OK) */
299 h->reconnect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
306 * Transmit the next pending message, called by notify_transmit_ready
311 transmit_pending (void *cls, size_t size, void *buf);
315 * Handler for messages received from the GNS service
317 * @param cls the 'struct GNUNET_GNS_Handle'
318 * @param msg the incoming message
321 process_message (void *cls, const struct GNUNET_MessageHeader *msg);
325 * Try to send messages from list of messages to send
330 process_pending_messages (struct GNUNET_GNS_Handle *handle)
332 struct PendingMessage *p = handle->pending_head;
334 if (NULL == handle->client)
335 return; /* wait for reconnect */
336 if (NULL != handle->th)
337 return; /* transmission request already pending */
339 while ((NULL != p) && (p->transmitted == GNUNET_YES))
342 return; /* no messages pending */
344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
345 "Trying to transmit %u bytes\n",
346 (unsigned int) p->size);
348 GNUNET_CLIENT_notify_transmit_ready (handle->client,
350 GNUNET_TIME_UNIT_FOREVER_REL,
351 GNUNET_NO, &transmit_pending,
353 GNUNET_break (NULL != handle->th);
358 * Transmit the next pending message, called by notify_transmit_ready
363 transmit_pending (void *cls, size_t size, void *buf)
365 struct GNUNET_GNS_Handle *handle = cls;
367 struct PendingMessage *p;
371 if ((0 == size) || (NULL == buf))
373 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
374 "Transmission to GNS service failed!\n");
375 force_reconnect(handle);
378 if (NULL == (p = handle->pending_head))
382 while ((NULL != (p = handle->pending_head)) && (p->size <= size))
384 memcpy (&cbuf[tsize], &p[1], p->size);
387 p->transmitted = GNUNET_YES;
388 if (GNUNET_YES != handle->in_receive)
390 GNUNET_CLIENT_receive (handle->client, &process_message, handle,
391 GNUNET_TIME_UNIT_FOREVER_REL);
392 handle->in_receive = GNUNET_YES;
395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
396 "Sending %u bytes\n",
397 (unsigned int) tsize);
398 process_pending_messages (handle);
404 * Process a given reply that might match the given
407 * @param qe a queue entry
408 * @param msg the shorten msg received
411 process_shorten_reply (struct GNUNET_GNS_ShortenRequest *qe,
412 const struct GNUNET_GNS_ClientShortenResultMessage *msg)
414 struct GNUNET_GNS_Handle *h = qe->gns_handle;
415 struct PendingMessage *p = (struct PendingMessage *)&qe[1];
416 const char *short_name;
420 mlen = ntohs (msg->header.size);
421 if (ntohs (msg->header.size) == sizeof (struct GNUNET_GNS_ClientShortenResultMessage))
423 /* service reports resolution failed */
428 short_name = (const char *) &msg[1];
429 if ('\0' != short_name[mlen - sizeof (struct GNUNET_GNS_ClientShortenResultMessage) - 1])
432 // FIXME: reconnect and queue management logic is broken...
433 p->transmitted = GNUNET_NO;
438 GNUNET_CONTAINER_DLL_remove (h->shorten_head, h->shorten_tail, qe);
439 GNUNET_CONTAINER_DLL_remove (h->pending_head,
442 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
443 "Received shortened reply `%s' from GNS service\n",
445 qe->shorten_proc (qe->proc_cls, short_name);
451 * Process a given reply that might match the given
454 * @param qe the handle to the request
455 * @param msg the message to process
458 process_get_auth_reply (struct GNUNET_GNS_GetAuthRequest *qe,
459 const struct GNUNET_GNS_ClientGetAuthResultMessage *msg)
461 struct GNUNET_GNS_Handle *h = qe->gns_handle;
462 struct PendingMessage *p = (struct PendingMessage *)&qe[1];
463 const char *auth_name;
466 mlen = ntohs (msg->header.size);
467 if (mlen == sizeof (struct GNUNET_GNS_ClientGetAuthResultMessage))
473 auth_name = (char*)&msg[1];
474 if ('\0' != auth_name[mlen - sizeof (struct GNUNET_GNS_ClientGetAuthResultMessage) - 1])
477 p->transmitted = GNUNET_NO;
483 GNUNET_CONTAINER_DLL_remove (h->get_auth_head, h->get_auth_tail, qe);
484 GNUNET_CONTAINER_DLL_remove (h->pending_head,
487 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
488 "Received GET_AUTH reply `%s' from GNS service\n",
490 qe->auth_proc (qe->proc_cls, auth_name);
496 * Process a given reply to the lookup request
498 * @param qe a queue entry
499 * @param msg the lookup message received
502 process_lookup_reply (struct GNUNET_GNS_LookupRequest *qe,
503 const struct GNUNET_GNS_ClientLookupResultMessage *msg)
505 struct GNUNET_GNS_Handle *h = qe->gns_handle;
506 struct PendingMessage *p = (struct PendingMessage *)&qe[1];
507 int rd_count = ntohl(msg->rd_count);
508 struct GNUNET_NAMESTORE_RecordData rd[rd_count];
511 mlen = ntohs (msg->header.size);
512 mlen -= sizeof (struct GNUNET_GNS_ClientLookupResultMessage);
513 if (GNUNET_SYSERR == GNUNET_NAMESTORE_records_deserialize (mlen,
518 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
519 _("Failed to serialize lookup reply from GNS service!\n"));
520 qe->lookup_proc (qe->proc_cls, 0, NULL);
525 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
526 "Received lookup reply from GNS service (count=%u)\n",
527 ntohl (msg->rd_count));
528 qe->lookup_proc (qe->proc_cls, rd_count, rd);
530 GNUNET_CONTAINER_DLL_remove (h->lookup_head, h->lookup_tail, qe);
531 GNUNET_CONTAINER_DLL_remove (h->pending_head,
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;
557 force_reconnect (handle);
560 switch (ntohs (msg->type))
562 case GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT:
563 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
564 "Got LOOKUP_RESULT msg\n");
565 if (ntohs (msg->size) < sizeof (struct GNUNET_GNS_ClientLookupResultMessage))
568 force_reconnect (handle);
571 lookup_msg = (const struct GNUNET_GNS_ClientLookupResultMessage *) msg;
572 r_id = ntohl (lookup_msg->id);
573 for (lr = handle->lookup_head; NULL != lr; lr = lr->next)
574 if (lr->r_id == r_id)
576 process_lookup_reply(lr, lookup_msg);
580 case GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT:
581 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
582 "Got SHORTEN_RESULT msg\n");
583 if (ntohs (msg->size) < sizeof (struct GNUNET_GNS_ClientShortenResultMessage))
586 force_reconnect (handle);
589 shorten_msg = (const struct GNUNET_GNS_ClientShortenResultMessage *) msg;
590 r_id = ntohl (shorten_msg->id);
591 for (sr = handle->shorten_head; NULL != sr; sr = sr->next)
592 if (sr->r_id == r_id)
594 process_shorten_reply (sr, shorten_msg);
598 case GNUNET_MESSAGE_TYPE_GNS_GET_AUTH_RESULT:
599 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
600 "Got GET_AUTH_RESULT msg\n");
601 if (ntohs (msg->size) < sizeof (struct GNUNET_GNS_ClientGetAuthResultMessage))
604 force_reconnect (handle);
607 get_auth_msg = (const struct GNUNET_GNS_ClientGetAuthResultMessage *) msg;
608 r_id = ntohl (get_auth_msg->id);
609 for (gar = handle->get_auth_head; NULL != gar; gar = gar->next)
610 if (gar->r_id == r_id)
612 process_get_auth_reply (gar, get_auth_msg);
618 force_reconnect (handle);
621 GNUNET_CLIENT_receive (handle->client, &process_message, handle,
622 GNUNET_TIME_UNIT_FOREVER_REL);
627 * Initialize the connection with the GNS service.
629 * @param cfg configuration to use
630 * @return handle to the GNS service, or NULL on error
632 struct GNUNET_GNS_Handle *
633 GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
635 struct GNUNET_GNS_Handle *handle;
637 handle = GNUNET_malloc (sizeof (struct GNUNET_GNS_Handle));
645 * Shutdown connection with the GNS service.
647 * @param handle handle of the GNS connection to stop
650 GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle)
652 GNUNET_CLIENT_disconnect (handle->client);
653 if (GNUNET_SCHEDULER_NO_TASK != handle->reconnect_task)
655 GNUNET_SCHEDULER_cancel (handle->reconnect_task);
656 handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
659 /*GNUNET_assert (NULL == handle->lookup_head);
660 GNUNET_assert (NULL == handle->shorten_head);
661 GNUNET_assert (NULL == handle->get_auth_head);*/
668 * Cancel pending lookup request
670 * @param lr the lookup request to cancel
673 GNUNET_GNS_cancel_lookup_request (struct GNUNET_GNS_LookupRequest *lr)
675 struct PendingMessage *tmp = (struct PendingMessage*)&lr[1];
677 GNUNET_assert (NULL != lr->gns_handle);
679 GNUNET_CONTAINER_DLL_remove (lr->gns_handle->pending_head,
680 lr->gns_handle->pending_tail,
683 GNUNET_CONTAINER_DLL_remove (lr->gns_handle->lookup_head,
684 lr->gns_handle->lookup_tail,
692 * Cancel pending shorten request
694 * @param sr the lookup request to cancel
697 GNUNET_GNS_cancel_shorten_request (struct GNUNET_GNS_ShortenRequest *sr)
699 struct PendingMessage *tmp = (struct PendingMessage*)&sr[1];
701 GNUNET_assert (NULL != sr->gns_handle);
703 GNUNET_CONTAINER_DLL_remove (sr->gns_handle->pending_head,
704 sr->gns_handle->pending_tail,
707 GNUNET_CONTAINER_DLL_remove (sr->gns_handle->shorten_head,
708 sr->gns_handle->shorten_tail,
716 * Cancel pending get auth request
718 * @param gar the lookup request to cancel
721 GNUNET_GNS_cancel_get_auth_request (struct GNUNET_GNS_GetAuthRequest *gar)
723 struct PendingMessage *tmp = (struct PendingMessage*)&gar[1];
725 GNUNET_assert (NULL != gar->gns_handle);
728 GNUNET_CONTAINER_DLL_remove (gar->gns_handle->pending_head,
729 gar->gns_handle->pending_tail,
732 GNUNET_CONTAINER_DLL_remove (gar->gns_handle->get_auth_head,
733 gar->gns_handle->get_auth_tail,
741 * Perform an asynchronous Lookup operation on the GNS.
743 * @param handle handle to the GNS service
744 * @param name the name to look up
745 * @param zone the zone to start the resolution in
746 * @param type the record type to look up
747 * @param only_cached GNUNET_YES to only check locally not DHT for performance
748 * @param shorten_key the private key of the shorten zone (can be NULL)
749 * @param proc processor to call on result
750 * @param proc_cls closure for processor
751 * @return handle to the get request
753 struct GNUNET_GNS_LookupRequest*
754 GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle,
756 struct GNUNET_CRYPTO_ShortHashCode *zone,
757 enum GNUNET_GNS_RecordType type,
759 struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key,
760 GNUNET_GNS_LookupResultProcessor proc,
763 /* IPC to shorten gns names, return shorten_handle */
764 struct GNUNET_GNS_ClientLookupMessage *lookup_msg;
765 struct GNUNET_GNS_LookupRequest *lr;
767 struct PendingMessage *pending;
768 struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *pkey_enc;
779 if (NULL != shorten_key)
781 pkey_enc = GNUNET_CRYPTO_rsa_encode_key (shorten_key);
782 GNUNET_assert (pkey_enc != NULL);
783 key_len = ntohs (pkey_enc->len);
790 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
791 "Trying to lookup %s in GNS\n",
793 msize = sizeof (struct GNUNET_GNS_ClientLookupMessage)
794 + key_len + strlen (name) + 1;
795 request_size = sizeof (struct GNUNET_GNS_LookupRequest) +
796 sizeof (struct PendingMessage) + msize;
797 lr = GNUNET_malloc (request_size);
798 lr->gns_handle = handle;
799 lr->lookup_proc = proc;
800 lr->proc_cls = proc_cls;
801 lr->r_id = handle->r_id++;
802 pending = (struct PendingMessage *)&lr[1];
803 pending->size = msize;
804 pending->r_id = lr->r_id;
805 GNUNET_CONTAINER_DLL_insert_tail (handle->lookup_head,
806 handle->lookup_tail, lr);
808 lookup_msg = (struct GNUNET_GNS_ClientLookupMessage *) &pending[1];
809 lookup_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_LOOKUP);
810 lookup_msg->header.size = htons (msize);
811 lookup_msg->id = htonl (lr->r_id);
812 lookup_msg->only_cached = htonl (only_cached);
815 lookup_msg->use_default_zone = htonl (GNUNET_NO);
816 memcpy (&lookup_msg->zone, zone, sizeof (struct GNUNET_CRYPTO_ShortHashCode));
820 lookup_msg->use_default_zone = htonl (GNUNET_YES);
821 memset (&lookup_msg->zone, 0, sizeof(struct GNUNET_CRYPTO_ShortHashCode));
823 lookup_msg->type = htonl (type);
824 pkey_tmp = (char *) &lookup_msg[1];
825 if (pkey_enc != NULL)
827 lookup_msg->have_key = htonl (GNUNET_YES);
828 memcpy (pkey_tmp, pkey_enc, key_len);
831 lookup_msg->have_key = htonl (GNUNET_NO);
832 GNUNET_free_non_null (pkey_enc);
833 memcpy (&pkey_tmp[key_len], name, strlen (name) + 1);
835 GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head,
836 handle->pending_tail,
838 process_pending_messages (handle);
844 * Perform an asynchronous Lookup operation on the GNS.
846 * @param handle handle to the GNS service
847 * @param name the name to look up
848 * @param type the record type to look up
849 * @param only_cached GNUNET_YES to only check locally not DHT for performance
850 * @param shorten_key the private key of the shorten zone (can be NULL)
851 * @param proc processor to call on result
852 * @param proc_cls closure for processor
853 * @return handle to the lookup request
855 struct GNUNET_GNS_LookupRequest*
856 GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
858 enum GNUNET_GNS_RecordType type,
860 struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key,
861 GNUNET_GNS_LookupResultProcessor proc,
864 return GNUNET_GNS_lookup_zone (handle, name,
873 * Perform a name shortening operation on the GNS.
875 * @param handle handle to the GNS service
876 * @param name the name to look up
877 * @param private_zone the public zone of the private zone
878 * @param shorten_zone the public zone of the shorten zone
879 * @param zone the zone to start the resolution in
880 * @param proc function to call on result
881 * @param proc_cls closure for processor
882 * @return handle to the operation
884 struct GNUNET_GNS_ShortenRequest*
885 GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle,
887 struct GNUNET_CRYPTO_ShortHashCode *private_zone,
888 struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
889 struct GNUNET_CRYPTO_ShortHashCode *zone,
890 GNUNET_GNS_ShortenResultProcessor proc,
893 /* IPC to shorten gns names, return shorten_handle */
894 struct GNUNET_GNS_ClientShortenMessage *shorten_msg;
895 struct GNUNET_GNS_ShortenRequest *sr;
898 struct PendingMessage *pending;
905 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to shorten %s in GNS\n", name);
907 msize = sizeof (struct GNUNET_GNS_ClientShortenMessage) + strlen(name) + 1;
908 request_size = sizeof (struct GNUNET_GNS_ShortenRequest) +
909 sizeof (struct PendingMessage) + msize;
910 sr = GNUNET_malloc (request_size);
911 sr->gns_handle = handle;
912 sr->shorten_proc = proc;
913 sr->proc_cls = proc_cls;
914 sr->r_id = handle->r_id++;
915 GNUNET_CONTAINER_DLL_insert_tail (handle->shorten_head,
916 handle->shorten_tail, sr);
918 pending = (struct PendingMessage *)&sr[1];
919 pending->size = msize;
920 pending->r_id = sr->r_id;
922 shorten_msg = (struct GNUNET_GNS_ClientShortenMessage *) &pending[1];
923 shorten_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_SHORTEN);
924 shorten_msg->header.size = htons (msize);
925 shorten_msg->id = htonl (sr->r_id);
926 shorten_msg->private_zone = *private_zone;
927 shorten_msg->shorten_zone = *shorten_zone;
931 shorten_msg->use_default_zone = htonl (GNUNET_NO);
932 memcpy (&shorten_msg->zone, zone,
933 sizeof (struct GNUNET_CRYPTO_ShortHashCode));
937 shorten_msg->use_default_zone = htonl (GNUNET_YES);
938 memset (&shorten_msg->zone, 0, sizeof (struct GNUNET_CRYPTO_ShortHashCode));
941 memcpy (&shorten_msg[1], name, strlen (name) + 1);
943 GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head, handle->pending_tail,
946 process_pending_messages (handle);
952 * Perform a name shortening operation on the GNS.
954 * @param handle handle to the GNS service
955 * @param name the name to look up
956 * @param private_zone the public zone of the private zone
957 * @param shorten_zone the public zone of the shorten zone
958 * @param proc function to call on result
959 * @param proc_cls closure for processor
960 * @return handle to the operation
962 struct GNUNET_GNS_ShortenRequest*
963 GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle,
965 struct GNUNET_CRYPTO_ShortHashCode *private_zone,
966 struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
967 GNUNET_GNS_ShortenResultProcessor proc,
970 return GNUNET_GNS_shorten_zone (handle, name,
971 private_zone, shorten_zone,
972 NULL, proc, proc_cls);
977 * Perform an authority lookup for a given name.
979 * @param handle handle to the GNS service
980 * @param name the name to look up authority for
981 * @param proc function to call on result
982 * @param proc_cls closure for processor
983 * @return handle to the operation
985 struct GNUNET_GNS_GetAuthRequest*
986 GNUNET_GNS_get_authority (struct GNUNET_GNS_Handle *handle,
988 GNUNET_GNS_GetAuthResultProcessor proc,
991 struct GNUNET_GNS_ClientGetAuthMessage *get_auth_msg;
992 struct GNUNET_GNS_GetAuthRequest *gar;
995 struct PendingMessage *pending;
1002 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1003 "Trying to look up authority for %s in GNS\n", name);
1005 msize = sizeof (struct GNUNET_GNS_ClientGetAuthMessage) + strlen (name) + 1;
1006 request_size = sizeof (struct GNUNET_GNS_GetAuthRequest) +
1007 sizeof (struct PendingMessage) + msize;
1008 gar = GNUNET_malloc (request_size);
1009 gar->gns_handle = handle;
1010 gar->auth_proc = proc;
1011 gar->proc_cls = proc_cls;
1012 gar->r_id = handle->r_id++;
1013 GNUNET_CONTAINER_DLL_insert_tail (handle->get_auth_head,
1014 handle->get_auth_tail, gar);
1016 pending = (struct PendingMessage *)&gar[1];
1017 pending->size = msize;
1018 pending->r_id = gar->r_id;
1019 get_auth_msg = (struct GNUNET_GNS_ClientGetAuthMessage *) &pending[1];
1020 get_auth_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_GET_AUTH);
1021 get_auth_msg->header.size = htons (msize);
1022 get_auth_msg->id = htonl (gar->r_id);
1023 memcpy (&get_auth_msg[1], name, strlen(name) + 1);
1025 GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head,
1026 handle->pending_tail,
1028 process_pending_messages (handle);
1033 /* end of gns_api.c */