gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r19982 - gnunet/src/gns


From: gnunet
Subject: [GNUnet-SVN] r19982 - gnunet/src/gns
Date: Thu, 23 Feb 2012 18:31:14 +0100

Author: schanzen
Date: 2012-02-23 18:31:14 +0100 (Thu, 23 Feb 2012)
New Revision: 19982

Modified:
   gnunet/src/gns/gnunet-service-gns.c
Log:
-more dht


Modified: gnunet/src/gns/gnunet-service-gns.c
===================================================================
--- gnunet/src/gns/gnunet-service-gns.c 2012-02-23 17:27:42 UTC (rev 19981)
+++ gnunet/src/gns/gnunet-service-gns.c 2012-02-23 17:31:14 UTC (rev 19982)
@@ -141,6 +141,11 @@
 static int num_public_records =  3600;
 struct GNUNET_TIME_Relative dht_update_interval;
 
+
+void reply_to_dns(struct GNUNET_GNS_PendingQuery *answer);
+void resolve_name(struct GNUNET_GNS_PendingQuery *query,
+                  GNUNET_HashCode *zone);
+
 /**
  * Task run during shutdown.
  *
@@ -181,9 +186,88 @@
                  enum GNUNET_BLOCK_Type type,
                  size_t size, const void *data)
 {
+  struct GNUNET_GNS_PendingQuery *query;
+  uint32_t num_records;
+  uint16_t namelen;
+  char* name = NULL;
+  struct GNUNET_CRYPTO_RsaSignature *signature;
+  int i;
+  char* pos;
+  GNUNET_HashCode zone, name_hash;
+
   if (data == NULL)
     return;
+  
+  query = (struct GNUNET_GNS_PendingQuery *)cls;
+  pos = (char*)data;
+  
+  num_records = ntohl(*pos);
+  struct GNUNET_NAMESTORE_RecordData rd[num_records];
 
+  pos += sizeof(uint32_t);
+  
+  for (i=0; i<num_records; i++)
+  {
+    namelen = ntohs(*pos);
+    pos += sizeof(uint16_t);
+    
+    //name must be 0 terminated
+    name = pos;
+    pos += namelen;
+  
+    rd[i].record_type = ntohl(*pos);
+    pos += sizeof(uint32_t);
+  
+    rd[i].data_size = ntohl(*pos);
+    pos += sizeof(uint32_t);
+  
+    rd[i].data = pos;
+    pos += rd[i].data_size;
+
+    rd[i].expiration = GNUNET_TIME_absolute_ntoh(
+                              *((struct GNUNET_TIME_AbsoluteNBO*)pos));
+    pos += sizeof(struct GNUNET_TIME_AbsoluteNBO);
+
+    rd[i].flags = ntohs(*pos);
+    pos += sizeof(uint16_t);
+    //FIXME class?
+    //
+    if (strcmp(name, query->name) && rd[i].record_type == query->type)
+    {
+      query->answered = 1;
+    }
+
+  }
+
+  if ((((char*)data)-pos) < sizeof(struct GNUNET_CRYPTO_RsaSignature))
+  {
+    GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+               "Cannot parse signature in DHT response. Corrupted or Missing");
+    return;
+  }
+
+  signature = (struct GNUNET_CRYPTO_RsaSignature*)pos;
+
+  GNUNET_CRYPTO_hash(name, strlen(name), &name_hash);
+  GNUNET_CRYPTO_hash_xor(key, &name_hash, &zone);
+
+  //Save to namestore
+  GNUNET_NAMESTORE_record_put (namestore_handle,
+                               &zone,
+                               name,
+                               exp,
+                               num_records,
+                               rd,
+                               signature,
+                               NULL, //cont
+                               NULL); //cls
+  
+  if (query->answered)
+  {
+    query->answered = 0;
+    memcpy(query->authority, &zone, sizeof(GNUNET_HashCode));
+    resolve_name(query, query->authority);
+  }
   /**
    * data is a serialized PKEY record (probably)
    * parse, put into namestore
@@ -255,6 +339,7 @@
                  enum GNUNET_BLOCK_Type type,
                  size_t size, const void *data)
 {
+  struct GNUNET_GNS_PendingQuery *query;
   uint32_t num_records;
   uint16_t namelen;
   char* name = NULL;
@@ -266,6 +351,7 @@
   if (data == NULL)
     return;
   
+  query = (struct GNUNET_GNS_PendingQuery *)cls;
   pos = (char*)data;
   
   num_records = ntohl(*pos);
@@ -298,6 +384,12 @@
     rd[i].flags = ntohs(*pos);
     pos += sizeof(uint16_t);
     //FIXME class?
+    //
+    if (strcmp(name, query->name) && rd[i].record_type == query->type)
+    {
+      query->answered = 1;
+    }
+
   }
 
   if ((((char*)data)-pos) < sizeof(struct GNUNET_CRYPTO_RsaSignature))
@@ -322,6 +414,14 @@
                                signature,
                                NULL, //cont
                                NULL); //cls
+  
+  if (query->answered)
+  {
+    //FIXME: add records to query handle, but on stack!
+    //do we need records in query handle? can't we just
+    //pass them to reply_to_dns?
+    reply_to_dns(query);
+  }
 
   /**
    * data is a serialized GNS record of type
@@ -401,13 +501,6 @@
    */
   if (rd_count == 0)
   {
-    if (query->authority_found)
-    {
-      query->authority_found = 0;
-      resolve_name(query, query->authority);
-      return;
-    }
-
     /**
      * We did not find an authority in the namestore
      * _IF_ the current authoritative zone is us we cannot resolve
@@ -419,7 +512,10 @@
       //FIXME return NX answer
       return;
     }
-
+    
+    /**
+     * Last hope
+     */
     resolve_authority_dht(query, name);
     return;
   }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]