summaryrefslogtreecommitdiff
path: root/src/gns/gns_api.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-03-12 10:18:53 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-03-12 10:18:53 +0000
commitf178ee5c79255d00eec5ed421d2e503b8d176fd0 (patch)
tree763cd0fda3c59d96216257d2b5487fe17a7d091f /src/gns/gns_api.c
parentfe61feeb1cdced8020f352289a86f61e3f02d1ad (diff)
downloadgnunet-f178ee5c79255d00eec5ed421d2e503b8d176fd0.tar.gz
gnunet-f178ee5c79255d00eec5ed421d2e503b8d176fd0.zip
-fixes, added get_authority api
Diffstat (limited to 'src/gns/gns_api.c')
-rw-r--r--src/gns/gns_api.c131
1 files changed, 130 insertions, 1 deletions
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c
index f9aa63335..be1ba58f7 100644
--- a/src/gns/gns_api.c
+++ b/src/gns/gns_api.c
@@ -40,6 +40,8 @@
40#define GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT 24 40#define GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT 24
41#define GNUNET_MESSAGE_TYPE_GNS_SHORTEN 25 41#define GNUNET_MESSAGE_TYPE_GNS_SHORTEN 25
42#define GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT 26 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
43 45
44/** 46/**
45 * A QueueEntry. 47 * A QueueEntry.
@@ -67,6 +69,9 @@ struct GNUNET_GNS_QueueEntry
67 69
68 /* processor to call on lookup result */ 70 /* processor to call on lookup result */
69 GNUNET_GNS_LookupResultProcessor lookup_proc; 71 GNUNET_GNS_LookupResultProcessor lookup_proc;
72
73 /* processor to call on authority lookup result */
74 GNUNET_GNS_GetAuthResultProcessor auth_proc;
70 75
71 /* processor closure */ 76 /* processor closure */
72 void *proc_cls; 77 void *proc_cls;
@@ -151,6 +156,16 @@ struct GNUNET_GNS_Handle
151 struct GNUNET_GNS_QueueEntry *lookup_tail; 156 struct GNUNET_GNS_QueueEntry *lookup_tail;
152 157
153 /** 158 /**
159 * Head of linked list of authority lookup messages we would like to transmit.
160 */
161 struct GNUNET_GNS_QueueEntry *get_auth_head;
162
163 /**
164 * Tail of linked list of authority lookup messages we would like to transmit.
165 */
166 struct GNUNET_GNS_QueueEntry *get_auth_tail;
167
168 /**
154 * Reconnect task 169 * Reconnect task
155 */ 170 */
156 GNUNET_SCHEDULER_TaskIdentifier reconnect_task; 171 GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
@@ -360,6 +375,39 @@ process_shorten_reply (struct GNUNET_GNS_QueueEntry *qe,
360 375
361 376
362/** 377/**
378 * Process a given reply that might match the given
379 * request.
380 *
381 * @param qe the handle to the request
382 * @param msg the message to process
383 */
384static void
385process_get_auth_reply (struct GNUNET_GNS_QueueEntry *qe,
386 const struct GNUNET_GNS_ClientGetAuthResultMessage *msg)
387{
388 struct GNUNET_GNS_Handle *h = qe->gns_handle;
389 const char *auth_name;
390
391 GNUNET_CONTAINER_DLL_remove(h->get_auth_head, h->get_auth_tail, qe);
392
393 auth_name = (char*)(&msg[1]);
394
395 if (ntohs (((struct GNUNET_MessageHeader*)msg)->size) <
396 sizeof (struct GNUNET_GNS_ClientGetAuthResultMessage))
397 {
398 GNUNET_break (0);
399 force_reconnect (h);
400 return;
401 }
402
403 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
404 "Received GET_AUTH reply `%s' from GNS service\n",
405 auth_name);
406
407 qe->auth_proc(qe->proc_cls, auth_name);
408
409}
410/**
363 * Process a given reply to the lookup request 411 * Process a given reply to the lookup request
364 * 412 *
365 * @param cls the 'struct GNUNET_GNS_ClientResultMessage' 413 * @param cls the 'struct GNUNET_GNS_ClientResultMessage'
@@ -412,6 +460,7 @@ process_message (void *cls, const struct GNUNET_MessageHeader *msg)
412 struct GNUNET_GNS_QueueEntry *qe; 460 struct GNUNET_GNS_QueueEntry *qe;
413 const struct GNUNET_GNS_ClientLookupResultMessage *lookup_msg; 461 const struct GNUNET_GNS_ClientLookupResultMessage *lookup_msg;
414 const struct GNUNET_GNS_ClientShortenResultMessage *shorten_msg; 462 const struct GNUNET_GNS_ClientShortenResultMessage *shorten_msg;
463 const struct GNUNET_GNS_ClientGetAuthResultMessage *get_auth_msg;
415 uint16_t size; 464 uint16_t size;
416 uint16_t type; 465 uint16_t type;
417 uint32_t r_id; 466 uint32_t r_id;
@@ -457,7 +506,7 @@ process_message (void *cls, const struct GNUNET_MessageHeader *msg)
457 else if (type == GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT) 506 else if (type == GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT)
458 { 507 {
459 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 508 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
460 "Got shorten msg\n"); 509 "Got SHORTEN_RESULT msg\n");
461 shorten_msg = (struct GNUNET_GNS_ClientShortenResultMessage *) msg; 510 shorten_msg = (struct GNUNET_GNS_ClientShortenResultMessage *) msg;
462 511
463 r_id = ntohl (shorten_msg->id); 512 r_id = ntohl (shorten_msg->id);
@@ -478,6 +527,30 @@ process_message (void *cls, const struct GNUNET_MessageHeader *msg)
478 if (qe) 527 if (qe)
479 process_shorten_reply(qe, shorten_msg); 528 process_shorten_reply(qe, shorten_msg);
480 } 529 }
530 else if (type == GNUNET_MESSAGE_TYPE_GNS_GET_AUTH_RESULT)
531 {
532 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
533 "Got GET_AUTH_RESULT msg\n");
534 get_auth_msg = (struct GNUNET_GNS_ClientGetAuthResultMessage *) msg;
535
536 r_id = ntohl (get_auth_msg->id);
537
538 if (r_id > handle->r_id)
539 {
540 /** no request found */
541 GNUNET_break_op (0);
542 GNUNET_CLIENT_receive (handle->client, &process_message, handle,
543 GNUNET_TIME_UNIT_FOREVER_REL);
544 }
545
546 for (qe = handle->get_auth_head; qe != NULL; qe = qe->next)
547 {
548 if (qe->r_id == r_id)
549 break;
550 }
551 if (qe)
552 process_get_auth_reply(qe, get_auth_msg);
553 }
481 554
482 GNUNET_CLIENT_receive (handle->client, &process_message, handle, 555 GNUNET_CLIENT_receive (handle->client, &process_message, handle,
483 GNUNET_TIME_UNIT_FOREVER_REL); 556 GNUNET_TIME_UNIT_FOREVER_REL);
@@ -651,5 +724,61 @@ GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle,
651} 724}
652 725
653 726
727/**
728 * Perform an authority lookup for a given name.
729 *
730 * @param handle handle to the GNS service
731 * @param name the name to look up authority for
732 * @param proc function to call on result
733 * @param proc_cls closure for processor
734 * @return handle to the operation
735 */
736struct GNUNET_GNS_QueueEntry *
737GNUNET_GNS_get_authority (struct GNUNET_GNS_Handle *handle,
738 const char * name,
739 GNUNET_GNS_GetAuthResultProcessor proc,
740 void *proc_cls)
741{
742 struct GNUNET_GNS_ClientGetAuthMessage *get_auth_msg;
743 struct GNUNET_GNS_QueueEntry *qe;
744 size_t msize;
745 struct PendingMessage *pending;
746
747 if (NULL == name)
748 {
749 return NULL;
750 }
751
752 msize = sizeof (struct GNUNET_GNS_ClientGetAuthMessage) + strlen(name) + 1;
753 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
754 "Trying to look up authority for %s in GNS\n", name);
755
756 qe = GNUNET_malloc(sizeof (struct GNUNET_GNS_QueueEntry));
757 qe->gns_handle = handle;
758 qe->shorten_proc = proc;
759 qe->proc_cls = proc_cls;
760 qe->r_id = get_request_id(handle);
761 GNUNET_CONTAINER_DLL_insert_tail(handle->get_auth_head,
762 handle->get_auth_tail, qe);
763
764 pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
765 memset(pending, 0, (sizeof (struct PendingMessage) + msize));
766
767 pending->size = msize;
768
769 get_auth_msg = (struct GNUNET_GNS_ClientGetAuthMessage *) &pending[1];
770 get_auth_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_GET_AUTH);
771 get_auth_msg->header.size = htons (msize);
772 get_auth_msg->id = htonl(qe->r_id);
773
774 memcpy(&get_auth_msg[1], name, strlen(name));
775
776 GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail,
777 pending);
778
779 process_pending_messages (handle);
780 return qe;
781}
782
654 783
655/* end of gns_api.c */ 784/* end of gns_api.c */