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);
264 process_pending_messages (h);
270 * @param cls the handle
271 * @param tc task context
274 reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
276 struct GNUNET_GNS_Handle *h = cls;
278 h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
284 * Disconnect from service and then reconnect.
286 * @param h our handle
289 force_reconnect (struct GNUNET_GNS_Handle *h)
291 h->reconnect = GNUNET_NO;
292 GNUNET_CLIENT_disconnect (h->client);
294 h->reconnect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
300 * Transmit the next pending message, called by notify_transmit_ready
303 transmit_pending (void *cls, size_t size, void *buf);
306 * Handler for messages received from the GNS service
308 * @param cls the 'struct GNUNET_GNS_Handle'
309 * @param msg the incoming message
312 process_message (void *cls, const struct GNUNET_MessageHeader *msg);
315 * Try to send messages from list of messages to send
318 process_pending_messages (struct GNUNET_GNS_Handle *handle)
320 struct PendingMessage *p;
322 if (handle->client == NULL)
324 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
325 "process_pending_messages called, but client is null\n");
329 if (handle->th != NULL)
332 if (NULL == (p = handle->pending_head))
335 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
336 "Trying to transmit %d bytes...\n", p->size);
339 GNUNET_CLIENT_notify_transmit_ready (handle->client,
341 GNUNET_TIME_UNIT_FOREVER_REL,
342 GNUNET_NO, &transmit_pending,
344 if (NULL != handle->th)
347 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
348 "notify_transmit_ready returned NULL!\n");
353 * Transmit the next pending message, called by notify_transmit_ready
356 transmit_pending (void *cls, size_t size, void *buf)
358 struct GNUNET_GNS_Handle *handle = cls;
359 struct PendingMessage *p;
365 if ((size == 0) || (buf == NULL))
367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
368 "Transmission to GNS service failed!\n");
369 force_reconnect(handle);
376 if (NULL == (p = handle->pending_head))
379 while ((NULL != (p = handle->pending_head)) && (p->size <= size))
381 memcpy (&cbuf[tsize], &p[1], p->size);
384 GNUNET_CONTAINER_DLL_remove (handle->pending_head, handle->pending_tail, p);
385 if (GNUNET_YES != handle->in_receive)
387 GNUNET_CLIENT_receive (handle->client, &process_message, handle,
388 GNUNET_TIME_UNIT_FOREVER_REL);
389 handle->in_receive = GNUNET_YES;
394 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
395 "Sending %d bytes\n", tsize);
397 process_pending_messages(handle);
402 * Process a given reply that might match the given
405 * @param qe a queue entry
406 * @param msg the shorten msg received
409 process_shorten_reply (struct GNUNET_GNS_ShortenRequest *qe,
410 const struct GNUNET_GNS_ClientShortenResultMessage *msg)
412 struct GNUNET_GNS_Handle *h = qe->gns_handle;
413 const char *short_name;
415 GNUNET_CONTAINER_DLL_remove (h->shorten_head, h->shorten_tail, qe);
416 short_name = (char*)(&msg[1]);
418 if (ntohs (((struct GNUNET_MessageHeader*)msg)->size) <
419 sizeof (struct GNUNET_GNS_ClientShortenResultMessage))
427 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
428 "Received shortened reply `%s' from GNS service\n",
431 GNUNET_CLIENT_receive (h->client, &process_message, h,
432 GNUNET_TIME_UNIT_FOREVER_REL);
433 qe->shorten_proc (qe->proc_cls, short_name);
440 * Process a given reply that might match the given
443 * @param qe the handle to the request
444 * @param msg the message to process
447 process_get_auth_reply (struct GNUNET_GNS_GetAuthRequest *qe,
448 const struct GNUNET_GNS_ClientGetAuthResultMessage *msg)
450 struct GNUNET_GNS_Handle *h = qe->gns_handle;
451 const char *auth_name;
453 GNUNET_CONTAINER_DLL_remove (h->get_auth_head, h->get_auth_tail, qe);
454 auth_name = (char*)&msg[1];
456 if (ntohs (((struct GNUNET_MessageHeader*)msg)->size) <
457 sizeof (struct GNUNET_GNS_ClientGetAuthResultMessage))
465 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
466 "Received GET_AUTH reply `%s' from GNS service\n",
469 GNUNET_CLIENT_receive (h->client, &process_message, h,
470 GNUNET_TIME_UNIT_FOREVER_REL);
471 qe->auth_proc (qe->proc_cls, auth_name);
476 * Process a given reply to the lookup request
478 * @param qe a queue entry
479 * @param msg the lookup message received
482 process_lookup_reply (struct GNUNET_GNS_LookupRequest *qe,
483 const struct GNUNET_GNS_ClientLookupResultMessage *msg)
485 struct GNUNET_GNS_Handle *h = qe->gns_handle;
486 int rd_count = ntohl(msg->rd_count);
487 size_t len = ntohs (((struct GNUNET_MessageHeader*)msg)->size);
488 struct GNUNET_NAMESTORE_RecordData rd[rd_count];
490 GNUNET_CONTAINER_DLL_remove (h->lookup_head, h->lookup_tail, qe);
492 if (len < sizeof (struct GNUNET_GNS_ClientLookupResultMessage))
500 len -= sizeof (struct GNUNET_GNS_ClientLookupResultMessage);
501 GNUNET_CLIENT_receive (h->client, &process_message, h,
502 GNUNET_TIME_UNIT_FOREVER_REL);
503 if (GNUNET_SYSERR == GNUNET_NAMESTORE_records_deserialize (len,
508 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
509 "Failed to serialize lookup reply from GNS service!\n");
510 qe->lookup_proc (qe->proc_cls, 0, NULL);
515 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
516 "Received lookup reply from GNS service (count=%d)\n",
517 ntohl (msg->rd_count));
518 qe->lookup_proc (qe->proc_cls, rd_count, rd);
524 * Handler for messages received from the GNS service
526 * @param cls the 'struct GNUNET_GNS_Handle'
527 * @param msg the incoming message
530 process_message (void *cls, const struct GNUNET_MessageHeader *msg)
532 struct GNUNET_GNS_Handle *handle = cls;
533 struct GNUNET_GNS_LookupRequest *lr;
534 struct GNUNET_GNS_ShortenRequest *sr;
535 struct GNUNET_GNS_GetAuthRequest *gar;
536 const struct GNUNET_GNS_ClientLookupResultMessage *lookup_msg;
537 const struct GNUNET_GNS_ClientShortenResultMessage *shorten_msg;
538 const struct GNUNET_GNS_ClientGetAuthResultMessage *get_auth_msg;
542 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
546 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
547 "Error receiving data from GNS service, reconnecting\n");
548 force_reconnect (handle);
552 type = ntohs (msg->type);
554 if (type == GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT)
556 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
558 lookup_msg = (const struct GNUNET_GNS_ClientLookupResultMessage *) msg;
559 r_id = ntohl (lookup_msg->id);
561 if (r_id > handle->r_id)
563 /** no request found */
565 GNUNET_CLIENT_receive (handle->client, &process_message, handle,
566 GNUNET_TIME_UNIT_FOREVER_REL);
570 for (lr = handle->lookup_head; NULL != lr; lr = lr->next)
572 if (lr->r_id == r_id)
576 process_lookup_reply(lr, lookup_msg);
581 else if (type == GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT)
583 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
584 "Got SHORTEN_RESULT msg\n");
585 shorten_msg = (struct GNUNET_GNS_ClientShortenResultMessage *) msg;
587 r_id = ntohl (shorten_msg->id);
589 if (r_id > handle->r_id)
591 /** no request found */
593 GNUNET_CLIENT_receive (handle->client, &process_message, handle,
594 GNUNET_TIME_UNIT_FOREVER_REL);
598 for (sr = handle->shorten_head; NULL != sr; sr = sr->next)
600 if (sr->r_id == r_id)
604 process_shorten_reply (sr, shorten_msg);
607 else if (type == GNUNET_MESSAGE_TYPE_GNS_GET_AUTH_RESULT)
609 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
610 "Got GET_AUTH_RESULT msg\n");
611 get_auth_msg = (struct GNUNET_GNS_ClientGetAuthResultMessage *) msg;
613 r_id = ntohl (get_auth_msg->id);
615 if (r_id > handle->r_id)
617 /** no request found */
619 GNUNET_CLIENT_receive (handle->client, &process_message, handle,
620 GNUNET_TIME_UNIT_FOREVER_REL);
624 for (gar = handle->get_auth_head; NULL != gar; gar = gar->next)
626 if (gar->r_id == r_id)
630 process_get_auth_reply (gar, get_auth_msg);
635 if (GNUNET_YES == handle->reconnect)
636 force_reconnect (handle);
641 * Initialize the connection with the GNS service.
643 * @param cfg configuration to use
644 * @return handle to the GNS service, or NULL on error
646 struct GNUNET_GNS_Handle *
647 GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
649 struct GNUNET_GNS_Handle *handle;
651 handle = GNUNET_malloc (sizeof (struct GNUNET_GNS_Handle));
652 handle->reconnect = GNUNET_NO;
655 handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
657 handle->in_receive = GNUNET_NO;
663 * Shutdown connection with the GNS service.
665 * @param handle handle of the GNS connection to stop
668 GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle)
670 GNUNET_CLIENT_disconnect (handle->client);
671 if (GNUNET_SCHEDULER_NO_TASK != handle->reconnect_task)
673 GNUNET_SCHEDULER_cancel (handle->reconnect_task);
674 handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
677 GNUNET_assert (NULL == handle->lookup_head);
678 GNUNET_assert (NULL == handle->shorten_head);
679 GNUNET_assert (NULL == handle->get_auth_head);
686 * Helper function to generate request ids
692 get_request_id (struct GNUNET_GNS_Handle *h)
694 uint32_t r_id = h->r_id;
701 * Cancel pending lookup request
703 * @param lr the lookup request to cancel
706 GNUNET_GNS_cancel_lookup_request (struct GNUNET_GNS_LookupRequest *lr)
708 struct PendingMessage *tmp;
709 GNUNET_assert (NULL != lr->gns_handle);
711 for (tmp = lr->gns_handle->pending_head;
712 NULL != tmp; tmp = tmp->next)
714 if (tmp->r_id == lr->r_id)
720 GNUNET_CONTAINER_DLL_remove (lr->gns_handle->pending_head,
721 lr->gns_handle->pending_tail,
726 GNUNET_CONTAINER_DLL_remove (lr->gns_handle->lookup_head,
727 lr->gns_handle->lookup_tail,
735 * Cancel pending shorten request
737 * @param sr the lookup request to cancel
740 GNUNET_GNS_cancel_shorten_request (struct GNUNET_GNS_ShortenRequest *sr)
742 struct PendingMessage *tmp;
743 GNUNET_assert (NULL != sr->gns_handle);
745 for (tmp = sr->gns_handle->pending_head;
746 NULL != tmp; tmp = tmp->next)
748 if (tmp->r_id == sr->r_id)
754 GNUNET_CONTAINER_DLL_remove (sr->gns_handle->pending_head,
755 sr->gns_handle->pending_tail,
760 GNUNET_CONTAINER_DLL_remove (sr->gns_handle->shorten_head,
761 sr->gns_handle->shorten_tail,
769 * Cancel pending get auth request
771 * @param gar the lookup request to cancel
774 GNUNET_GNS_cancel_get_auth_request (struct GNUNET_GNS_GetAuthRequest *gar)
776 struct PendingMessage *tmp;
777 GNUNET_assert (NULL != gar->gns_handle);
779 for (tmp = gar->gns_handle->pending_head;
780 NULL != tmp; tmp = tmp->next)
782 if (tmp->r_id == gar->r_id)
788 GNUNET_CONTAINER_DLL_remove (gar->gns_handle->pending_head,
789 gar->gns_handle->pending_tail,
794 GNUNET_CONTAINER_DLL_remove (gar->gns_handle->get_auth_head,
795 gar->gns_handle->get_auth_tail,
802 * Perform an asynchronous Lookup operation on the GNS.
804 * @param handle handle to the GNS service
805 * @param name the name to look up
806 * @param zone the zone to start the resolution in
807 * @param type the record type to look up
808 * @param only_cached GNUNET_YES to only check locally not DHT for performance
809 * @param shorten_key the private key of the shorten zone (can be NULL)
810 * @param proc processor to call on result
811 * @param proc_cls closure for processor
812 * @return handle to the get request
814 struct GNUNET_GNS_LookupRequest*
815 GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle,
817 struct GNUNET_CRYPTO_ShortHashCode *zone,
818 enum GNUNET_GNS_RecordType type,
820 struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key,
821 GNUNET_GNS_LookupResultProcessor proc,
824 /* IPC to shorten gns names, return shorten_handle */
825 struct GNUNET_GNS_ClientLookupMessage *lookup_msg;
826 struct GNUNET_GNS_LookupRequest *lr;
828 struct PendingMessage *pending;
829 struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *pkey_enc=NULL;
838 if (NULL != shorten_key)
840 pkey_enc = GNUNET_CRYPTO_rsa_encode_key (shorten_key);
841 GNUNET_assert (pkey_enc != NULL);
842 key_len = ntohs (pkey_enc->len);
845 msize = sizeof (struct GNUNET_GNS_ClientLookupMessage)
846 + key_len + strlen(name) + 1;
847 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to lookup %s in GNS\n", name);
849 lr = GNUNET_malloc(sizeof (struct GNUNET_GNS_LookupRequest));
850 lr->gns_handle = handle;
851 lr->lookup_proc = proc;
852 lr->proc_cls = proc_cls;
853 lr->r_id = get_request_id (handle);
854 GNUNET_CONTAINER_DLL_insert_tail (handle->lookup_head,
855 handle->lookup_tail, lr);
857 pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
858 memset (pending, 0, (sizeof (struct PendingMessage) + msize));
860 pending->size = msize;
861 pending->r_id = lr->r_id;
863 lookup_msg = (struct GNUNET_GNS_ClientLookupMessage *) &pending[1];
864 lookup_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_LOOKUP);
865 lookup_msg->header.size = htons (msize);
866 lookup_msg->id = htonl (lr->r_id);
867 lookup_msg->only_cached = htonl(only_cached);
871 lookup_msg->use_default_zone = htonl (0);
872 memcpy (&lookup_msg->zone, zone, sizeof (struct GNUNET_CRYPTO_ShortHashCode));
876 lookup_msg->use_default_zone = htonl (1);
877 memset (&lookup_msg->zone, 0, sizeof(struct GNUNET_CRYPTO_ShortHashCode));
880 lookup_msg->type = htonl (type);
882 pkey_tmp = (char *) &lookup_msg[1];
884 if (pkey_enc != NULL)
886 lookup_msg->have_key = htonl(1);
887 memcpy (pkey_tmp, pkey_enc, key_len);
890 lookup_msg->have_key = htonl (0);
892 memcpy (&pkey_tmp[key_len], name, strlen (name));
894 GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head, handle->pending_tail,
896 GNUNET_free_non_null (pkey_enc);
897 process_pending_messages (handle);
902 * Perform an asynchronous Lookup operation on the GNS.
904 * @param handle handle to the GNS service
905 * @param name the name to look up
906 * @param type the record type to look up
907 * @param only_cached GNUNET_YES to only check locally not DHT for performance
908 * @param shorten_key the private key of the shorten zone (can be NULL)
909 * @param proc processor to call on result
910 * @param proc_cls closure for processor
911 * @return handle to the lookup request
913 struct GNUNET_GNS_LookupRequest*
914 GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
916 enum GNUNET_GNS_RecordType type,
918 struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key,
919 GNUNET_GNS_LookupResultProcessor proc,
922 return GNUNET_GNS_lookup_zone (handle, name,
930 * Perform a name shortening operation on the GNS.
932 * @param handle handle to the GNS service
933 * @param name the name to look up
934 * @param private_zone the public zone of the private zone
935 * @param shorten_zone the public zone of the shorten zone
936 * @param zone the zone to start the resolution in
937 * @param proc function to call on result
938 * @param proc_cls closure for processor
939 * @return handle to the operation
941 struct GNUNET_GNS_ShortenRequest*
942 GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle,
944 struct GNUNET_CRYPTO_ShortHashCode *private_zone,
945 struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
946 struct GNUNET_CRYPTO_ShortHashCode *zone,
947 GNUNET_GNS_ShortenResultProcessor proc,
950 /* IPC to shorten gns names, return shorten_handle */
951 struct GNUNET_GNS_ClientShortenMessage *shorten_msg;
952 struct GNUNET_GNS_ShortenRequest *sr;
954 struct PendingMessage *pending;
961 msize = sizeof (struct GNUNET_GNS_ClientShortenMessage) + strlen(name) + 1;
962 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to shorten %s in GNS\n", name);
964 sr = GNUNET_malloc(sizeof (struct GNUNET_GNS_ShortenRequest));
965 sr->gns_handle = handle;
966 sr->shorten_proc = proc;
967 sr->proc_cls = proc_cls;
968 sr->r_id = get_request_id (handle);
969 GNUNET_CONTAINER_DLL_insert_tail (handle->shorten_head,
970 handle->shorten_tail, sr);
972 pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
973 memset(pending, 0, (sizeof (struct PendingMessage) + msize));
975 pending->size = msize;
976 pending->r_id = sr->r_id;
978 shorten_msg = (struct GNUNET_GNS_ClientShortenMessage *) &pending[1];
979 shorten_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_SHORTEN);
980 shorten_msg->header.size = htons (msize);
981 shorten_msg->id = htonl (sr->r_id);
982 shorten_msg->private_zone = *private_zone;
983 shorten_msg->shorten_zone = *shorten_zone;
987 shorten_msg->use_default_zone = htonl (0);
988 memcpy (&shorten_msg->zone, zone,
989 sizeof (struct GNUNET_CRYPTO_ShortHashCode));
993 shorten_msg->use_default_zone = htonl (1);
994 memset (&shorten_msg->zone, 0, sizeof (struct GNUNET_CRYPTO_ShortHashCode));
997 memcpy (&shorten_msg[1], name, strlen (name));
999 GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head, handle->pending_tail,
1002 process_pending_messages (handle);
1007 * Perform a name shortening operation on the GNS.
1009 * @param handle handle to the GNS service
1010 * @param name the name to look up
1011 * @param private_zone the public zone of the private zone
1012 * @param shorten_zone the public zone of the shorten zone
1013 * @param proc function to call on result
1014 * @param proc_cls closure for processor
1015 * @return handle to the operation
1017 struct GNUNET_GNS_ShortenRequest*
1018 GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle,
1020 struct GNUNET_CRYPTO_ShortHashCode *private_zone,
1021 struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
1022 GNUNET_GNS_ShortenResultProcessor proc,
1025 return GNUNET_GNS_shorten_zone (handle, name,
1026 private_zone, shorten_zone,
1027 NULL, proc, proc_cls);
1032 * Perform an authority lookup for a given name.
1034 * @param handle handle to the GNS service
1035 * @param name the name to look up authority for
1036 * @param proc function to call on result
1037 * @param proc_cls closure for processor
1038 * @return handle to the operation
1040 struct GNUNET_GNS_GetAuthRequest*
1041 GNUNET_GNS_get_authority (struct GNUNET_GNS_Handle *handle,
1043 GNUNET_GNS_GetAuthResultProcessor proc,
1046 struct GNUNET_GNS_ClientGetAuthMessage *get_auth_msg;
1047 struct GNUNET_GNS_GetAuthRequest *gar;
1049 struct PendingMessage *pending;
1056 msize = sizeof (struct GNUNET_GNS_ClientGetAuthMessage) + strlen(name) + 1;
1057 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1058 "Trying to look up authority for %s in GNS\n", name);
1060 gar = GNUNET_malloc (sizeof (struct GNUNET_GNS_GetAuthRequest));
1061 gar->gns_handle = handle;
1062 gar->auth_proc = proc;
1063 gar->proc_cls = proc_cls;
1064 gar->r_id = get_request_id (handle);
1065 GNUNET_CONTAINER_DLL_insert_tail (handle->get_auth_head,
1066 handle->get_auth_tail, gar);
1068 pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
1069 memset (pending, 0, (sizeof (struct PendingMessage) + msize));
1071 pending->size = msize;
1072 pending->r_id = gar->r_id;
1074 get_auth_msg = (struct GNUNET_GNS_ClientGetAuthMessage *) &pending[1];
1075 get_auth_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_GET_AUTH);
1076 get_auth_msg->header.size = htons (msize);
1077 get_auth_msg->id = htonl (gar->r_id);
1079 memcpy(&get_auth_msg[1], name, strlen(name));
1081 GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head, handle->pending_tail,
1084 process_pending_messages (handle);
1089 /* end of gns_api.c */