summaryrefslogtreecommitdiff
path: root/src/gns/gns_api.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-03-08 16:13:47 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-03-08 16:13:47 +0000
commit4803fd2b87550bb34fa8bd88ededb8f73d5d0b4d (patch)
tree7073934e2af4ce78f0b8a97357c2709f88e7f3fb /src/gns/gns_api.c
parent4d055043b4098d07f1900267d35f642bee83bc42 (diff)
downloadgnunet-4803fd2b87550bb34fa8bd88ededb8f73d5d0b4d.tar.gz
gnunet-4803fd2b87550bb34fa8bd88ededb8f73d5d0b4d.zip
-lookup now works in test, removed dns hijack from defaults
Diffstat (limited to 'src/gns/gns_api.c')
-rw-r--r--src/gns/gns_api.c87
1 files changed, 75 insertions, 12 deletions
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c
index 47efe5058..f9aa63335 100644
--- a/src/gns/gns_api.c
+++ b/src/gns/gns_api.c
@@ -35,10 +35,6 @@
35#include "gns.h" 35#include "gns.h"
36#include "gnunet_gns_service.h" 36#include "gnunet_gns_service.h"
37 37
38#define DEBUG_GNS_API GNUNET_EXTRA_LOGGING
39
40#define LOG(kind,...) GNUNET_log_from (kind, "gns-api",__VA_ARGS__)
41
42/* TODO into gnunet_protocols */ 38/* TODO into gnunet_protocols */
43#define GNUNET_MESSAGE_TYPE_GNS_LOOKUP 23 39#define GNUNET_MESSAGE_TYPE_GNS_LOOKUP 23
44#define GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT 24 40#define GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT 24
@@ -67,7 +63,10 @@ struct GNUNET_GNS_QueueEntry
67 struct GNUNET_GNS_Handle *gns_handle; 63 struct GNUNET_GNS_Handle *gns_handle;
68 64
69 /* processor to call on shorten result */ 65 /* processor to call on shorten result */
70 GNUNET_GNS_ShortenResultProcessor proc; 66 GNUNET_GNS_ShortenResultProcessor shorten_proc;
67
68 /* processor to call on lookup result */
69 GNUNET_GNS_LookupResultProcessor lookup_proc;
71 70
72 /* processor closure */ 71 /* processor closure */
73 void *proc_cls; 72 void *proc_cls;
@@ -355,7 +354,7 @@ process_shorten_reply (struct GNUNET_GNS_QueueEntry *qe,
355 "Received shortened reply `%s' from GNS service\n", 354 "Received shortened reply `%s' from GNS service\n",
356 short_name); 355 short_name);
357 356
358 qe->proc(qe->proc_cls, short_name); 357 qe->shorten_proc(qe->proc_cls, short_name);
359 358
360} 359}
361 360
@@ -373,6 +372,31 @@ static void
373process_lookup_reply (struct GNUNET_GNS_QueueEntry *qe, 372process_lookup_reply (struct GNUNET_GNS_QueueEntry *qe,
374 const struct GNUNET_GNS_ClientLookupResultMessage *msg) 373 const struct GNUNET_GNS_ClientLookupResultMessage *msg)
375{ 374{
375 struct GNUNET_GNS_Handle *h = qe->gns_handle;
376 int rd_count = ntohl(msg->rd_count);
377 size_t len = ntohs (((struct GNUNET_MessageHeader*)msg)->size);
378 struct GNUNET_NAMESTORE_RecordData rd[rd_count];
379
380 GNUNET_CONTAINER_DLL_remove(h->lookup_head, h->lookup_tail, qe);
381
382 if (len < sizeof (struct GNUNET_GNS_ClientLookupResultMessage))
383 {
384 GNUNET_break (0);
385 force_reconnect (h);
386 return;
387 }
388
389 len -= sizeof(struct GNUNET_GNS_ClientLookupResultMessage);
390
391 GNUNET_NAMESTORE_records_deserialize (len, (char*)&msg[1],
392 rd_count,
393 rd);
394
395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
396 "Received lookup reply from GNS service (count=%d)\n",
397 ntohl(msg->rd_count));
398
399 qe->lookup_proc(qe->proc_cls, rd_count, rd);
376} 400}
377 401
378/** 402/**
@@ -522,12 +546,51 @@ get_request_id (struct GNUNET_GNS_Handle *h)
522 */ 546 */
523struct GNUNET_GNS_QueueEntry * 547struct GNUNET_GNS_QueueEntry *
524GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, 548GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
525 const char * name, 549 const char * name,
526 enum GNUNET_GNS_RecordType type, 550 enum GNUNET_GNS_RecordType type,
527 GNUNET_GNS_LookupIterator iter, 551 GNUNET_GNS_LookupResultProcessor proc,
528 void *iter_cls) 552 void *proc_cls)
529{ 553{
530 return NULL; 554 /* IPC to shorten gns names, return shorten_handle */
555 struct GNUNET_GNS_ClientLookupMessage *lookup_msg;
556 struct GNUNET_GNS_QueueEntry *qe;
557 size_t msize;
558 struct PendingMessage *pending;
559
560 if (NULL == name)
561 {
562 return NULL;
563 }
564
565 msize = sizeof (struct GNUNET_GNS_ClientLookupMessage) + strlen(name) + 1;
566 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to shorten %s in GNS\n", name);
567
568 qe = GNUNET_malloc(sizeof (struct GNUNET_GNS_QueueEntry));
569 qe->gns_handle = handle;
570 qe->lookup_proc = proc;
571 qe->proc_cls = proc_cls;
572 qe->r_id = get_request_id(handle);
573 GNUNET_CONTAINER_DLL_insert_tail(handle->lookup_head,
574 handle->lookup_tail, qe);
575
576 pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
577 memset(pending, 0, (sizeof (struct PendingMessage) + msize));
578
579 pending->size = msize;
580
581 lookup_msg = (struct GNUNET_GNS_ClientLookupMessage *) &pending[1];
582 lookup_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_LOOKUP);
583 lookup_msg->header.size = htons (msize);
584 lookup_msg->id = htonl(qe->r_id);
585 lookup_msg->type = htonl(type);
586
587 memcpy(&lookup_msg[1], name, strlen(name));
588
589 GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail,
590 pending);
591
592 process_pending_messages (handle);
593 return qe;
531} 594}
532 595
533 596
@@ -562,7 +625,7 @@ GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle,
562 625
563 qe = GNUNET_malloc(sizeof (struct GNUNET_GNS_QueueEntry)); 626 qe = GNUNET_malloc(sizeof (struct GNUNET_GNS_QueueEntry));
564 qe->gns_handle = handle; 627 qe->gns_handle = handle;
565 qe->proc = proc; 628 qe->shorten_proc = proc;
566 qe->proc_cls = proc_cls; 629 qe->proc_cls = proc_cls;
567 qe->r_id = get_request_id(handle); 630 qe->r_id = get_request_id(handle);
568 GNUNET_CONTAINER_DLL_insert_tail(handle->shorten_head, 631 GNUNET_CONTAINER_DLL_insert_tail(handle->shorten_head,