-fixes
authorMartin Schanzenbach <mschanzenbach@posteo.de>
Thu, 23 Feb 2012 16:02:03 +0000 (16:02 +0000)
committerMartin Schanzenbach <mschanzenbach@posteo.de>
Thu, 23 Feb 2012 16:02:03 +0000 (16:02 +0000)
src/gns/gns_api.c
src/gns/gnunet-service-gns.c
src/include/gnunet_gns_service.h

index 00e96a61b9f30b4cd0929af14fff7cec2430abf3..ec9c15979190966e7fa53c8900efdb1db21a9ec7 100644 (file)
@@ -430,7 +430,7 @@ process_reply (void *cls, const GNUNET_HashCode * key, void *value)
   const struct GNUNET_GNS_ClientResultMessage *gns_msg = cls;
   struct GNUNET_GNS_LookupHandle *lookup_handle = value;
   const char *name = (const char*) &lookup_handle[1];
-  const GNUNET_GNS_Record *records;
+  const struct GNUNET_NAMESTORE_RecordData *records;
   uint32_t num_records;
   size_t meta_length;
   size_t msize;
@@ -449,10 +449,10 @@ process_reply (void *cls, const GNUNET_HashCode * key, void *value)
   num_records = ntohl (gns_msg->num_records);
   meta_length =
     sizeof (struct GNUNET_GNS_ClientResultMessage) +
-    sizeof (GNUNET_GNS_Record) * (num_records);
+    sizeof (struct GNUNET_NAMESTORE_RecordData) * (num_records);
   if ((msize < meta_length) ||
       (num_records >
-       GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (GNUNET_GNS_Record)))
+       GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_NAMESTORE_RecordData)))
   {
     GNUNET_break (0);
     return GNUNET_NO;
@@ -461,7 +461,7 @@ process_reply (void *cls, const GNUNET_HashCode * key, void *value)
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Giving %u byte reply for %s to application\n",
        (unsigned int) (msize - meta_length), GNUNET_h2s (key));
 #endif
-  records = (const GNUNET_GNS_Record *) &gns_msg[1];
+  records = (const struct GNUNET_NAMESTORE_RecordData *) &gns_msg[1];
   lookup_handle->iter (lookup_handle->iter_cls, name, records, num_records);
   return GNUNET_YES;
 }
index cb82439c4a8346655effbbf007a649d80b137162..94824eb2124b8f3442b6d4aa3ad4d2ea59ef39cc 100644 (file)
@@ -52,7 +52,7 @@ struct GNUNET_GNS_QueryRecordList
   struct GNUNET_GNS_QueryRecordList * next;
   struct GNUNET_GNS_QueryRecordList * prev;
 
-  GNUNET_GNS_Record * record;
+  struct GNUNET_NAMESTORE_RecordData * record;
 };
 
 /**
@@ -366,16 +366,12 @@ process_authority_lookup(void* cls,
    * We found an authority that may be able to help us
    * move on with query
    */
-  GNUNET_GNS_Record *record 
-    = GNUNET_malloc(sizeof(GNUNET_GNS_Record));
   
-  
-  //FIXME todo
-  //parse_record(rd[0]->data, rd[0]->data_size, 0, record);
-  //FIXME this cast will not work we have to define how a PKEY record looks like
-  //In reality this also returns a pubkey not a hash
-  GNUNET_HashCode *k = (GNUNET_HashCode*)record->data.raw.data;
-  query->authority = k;
+  GNUNET_assert(rd->record_type == GNUNET_GNS_RECORD_PKEY);
+  GNUNET_HashCode *pkey_hash = GNUNET_malloc(sizeof(GNUNET_HashCode));
+  GNUNET_CRYPTO_hash(rd->data, GNUNET_CRYPTO_RSA_KEY_LENGTH, pkey_hash);
+  GNUNET_free_non_null(query->authority);
+  query->authority = pkey_hash;
   resolve_name(query, query->authority);
   
 }
@@ -406,10 +402,11 @@ reply_to_dns(struct GNUNET_GNS_PendingQuery *answer)
   for (i=answer->records_head; i != NULL; i=i->next)
   {
     GNUNET_log(GNUNET_ERROR_TYPE_INFO,
-               "Adding %s to DNS response\n", i->record->name);
-    memcpy(&packet->answers[j], 
-           i->record,
-           sizeof (struct GNUNET_DNSPARSER_Record));
+               "Adding type %d to DNS response\n", i->record->record_type);
+    //FIXME build proper dnsparser record! this will fail!
+    //memcpy(&packet->answers[j], 
+    //       i->record,
+    //       sizeof (struct GNUNET_DNSPARSER_Record));
     GNUNET_free(i->record);
     j++;
   }
@@ -476,7 +473,7 @@ process_authoritative_result(void* cls,
 {
   struct GNUNET_GNS_PendingQuery *query;
   struct GNUNET_GNS_QueryRecordList *qrecord;
-  struct GNUNET_DNSPARSER_Record *record;
+  struct GNUNET_NAMESTORE_RecordData *record;
   GNUNET_HashCode zone;
   query = (struct GNUNET_GNS_PendingQuery *) cls;
   GNUNET_CRYPTO_hash(key, GNUNET_CRYPTO_RSA_KEY_LENGTH, &zone);
@@ -527,7 +524,7 @@ process_authoritative_result(void* cls,
     {
       // A time will come when this has to be freed
       qrecord = GNUNET_malloc(sizeof(struct GNUNET_GNS_QueryRecordList));
-      record = GNUNET_malloc(sizeof(struct GNUNET_DNSPARSER_Record));
+      record = GNUNET_malloc(sizeof(struct GNUNET_NAMESTORE_RecordData));
       qrecord->record = record;
       
       //fixme into gns_util
@@ -580,7 +577,7 @@ is_canonical(char* name)
  * @param name the domain
  * @return the tld
  */
-char* move_up(char* name)
+char* pop_tld(char* name)
 {
   uint32_t len;
 
@@ -627,7 +624,7 @@ resolve_name(struct GNUNET_GNS_PendingQuery *query, GNUNET_HashCode *zone)
   else
   {
     //We have to resolve the authoritative entity
-    char *new_authority = move_up(query->name);
+    char *new_authority = pop_tld(query->name);
     GNUNET_NAMESTORE_lookup_record(namestore_handle,
                                  zone,
                                  new_authority,
@@ -747,19 +744,26 @@ put_some_records(void)
   /* put a few records into namestore */
   char* ipA = "1.2.3.4";
   char* ipB = "5.6.7.8";
-  GNUNET_GNS_Record *alice = GNUNET_malloc(sizeof(GNUNET_GNS_Record));
-  GNUNET_GNS_Record *bob = GNUNET_malloc(sizeof(GNUNET_GNS_Record));
-  struct GNUNET_NAMESTORE_RecordData *rda = NULL;
-  struct GNUNET_NAMESTORE_RecordData *rdb = NULL;
+  struct in_addr *alice = GNUNET_malloc(sizeof(struct in_addr));
+  struct in_addr *bob = GNUNET_malloc(sizeof(struct in_addr));
+  struct GNUNET_NAMESTORE_RecordData *rda;
+  struct GNUNET_NAMESTORE_RecordData *rdb;
+
   rda = GNUNET_malloc(sizeof(struct GNUNET_NAMESTORE_RecordData));
+  rdb = GNUNET_malloc(sizeof(struct GNUNET_NAMESTORE_RecordData));
+  
+  GNUNET_assert(1 == inet_pton (AF_INET, ipA, alice));
+  GNUNET_assert(1 == inet_pton (AF_INET, ipB, bob));
+
+  rda->data_size = sizeof(struct in_addr);
+  rdb->data_size = sizeof(struct in_addr);
+  rda->data = alice;
+  rdb->data = bob;
+  rda->record_type = GNUNET_GNS_RECORD_TYPE_A;
+  rdb->record_type = GNUNET_GNS_RECORD_TYPE_A;
+  rda->expiration = GNUNET_TIME_absolute_get_forever ();
+  rdb->expiration = GNUNET_TIME_absolute_get_forever ();
   
-  //FIXME here we would have to parse the gns record and put it into
-  //the rd struct
-
-  //FIXME this is not enough! but too mucht atm
-  GNUNET_assert(1 == inet_pton (AF_INET, ipA, alice->data.raw.data));
-  GNUNET_assert(1 == inet_pton (AF_INET, ipB, bob->data.raw.data));
-
   GNUNET_NAMESTORE_record_create (namestore_handle,
                                zone_key,
                                "alice",
index 6291ddff853708fe5ebbdc8b0ed93b99fb649e67..7f3fd77d3fae18199aeba4f21966d4312f97abba 100644 (file)
@@ -34,6 +34,7 @@
 #define GNUNET_GNS_SERVICE_H
 
 #include "gnunet_util_lib.h"
+#include "gnunet_namestore_service.h"
 
 #ifdef __cplusplus
 extern "C"
@@ -54,11 +55,6 @@ struct GNUNET_GNS_Handle;
  */
 struct GNUNET_GNS_LookupHandle;
 
-/**
- * A single GNS record.
- */
-struct GNUNET_GNS_Record;
-
 /**
  * Record types
  * Based on GNUNET_DNSPARSER_TYPEs (standard DNS)
@@ -114,7 +110,7 @@ GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle);
  */
 typedef void (*GNUNET_GNS_LookupIterator) (void *cls,
                                         const char * name,
-                                        const struct GNUNET_GNS_Record *record,
+                                        const struct GNUNET_NAMESTORE_RecordData *record,
                                         unsigned int num_records);