gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r19973 - gnunet/src/gns
Date: Thu, 23 Feb 2012 16:03:53 +0100

Author: schanzen
Date: 2012-02-23 16:03:53 +0100 (Thu, 23 Feb 2012)
New Revision: 19973

Added:
   gnunet/src/gns/gns_util.c
Modified:
   gnunet/src/gns/gns.h
   gnunet/src/gns/gns_api.c
   gnunet/src/gns/gnunet-service-gns.c
   gnunet/src/gns/namestore_stub_api.c
Log:
-make it compile against new api, added parser utils borrowed from dnsparser


Modified: gnunet/src/gns/gns.h
===================================================================
--- gnunet/src/gns/gns.h        2012-02-23 15:03:44 UTC (rev 19972)
+++ gnunet/src/gns/gns.h        2012-02-23 15:03:53 UTC (rev 19973)
@@ -29,19 +29,6 @@
 GNUNET_NETWORK_STRUCT_BEGIN
 
 /**
- * Equivalent to GNUNET_DNSPARSER_Record
- * FIXME typedef?
- */
-struct GNUNET_GNS_Record
-{
-  //struct GNUNET_DNSPARSER_Record record;
-
-  //enum GNUNET_NAMESTORE_RecordFlags flags;
-
-  const struct GNUNET_NAMESTORE_SignatureLocation *sig_loc;
-
-};
-/**
  * Message from client to GNS service to lookup records.
  */
 struct GNUNET_GNS_ClientLookupMessage

Modified: gnunet/src/gns/gns_api.c
===================================================================
--- gnunet/src/gns/gns_api.c    2012-02-23 15:03:44 UTC (rev 19972)
+++ gnunet/src/gns/gns_api.c    2012-02-23 15:03:53 UTC (rev 19973)
@@ -430,7 +430,7 @@
   const struct GNUNET_GNS_ClientResultMessage *gns_msg = cls;
   struct GNUNET_GNS_LookupHandle *lookup_handle = value;
   const char *name = (const char*) &lookup_handle[1];
-  const struct GNUNET_GNS_Record *records;
+  const GNUNET_GNS_Record *records;
   uint32_t num_records;
   size_t meta_length;
   size_t msize;
@@ -449,10 +449,10 @@
   num_records = ntohl (gns_msg->num_records);
   meta_length =
     sizeof (struct GNUNET_GNS_ClientResultMessage) +
-    sizeof (struct GNUNET_GNS_Record) * (num_records);
+    sizeof (GNUNET_GNS_Record) * (num_records);
   if ((msize < meta_length) ||
       (num_records >
-       GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_GNS_Record)))
+       GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (GNUNET_GNS_Record)))
   {
     GNUNET_break (0);
     return GNUNET_NO;
@@ -461,7 +461,7 @@
   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 struct GNUNET_GNS_Record *) &gns_msg[1];
+  records = (const GNUNET_GNS_Record *) &gns_msg[1];
   lookup_handle->iter (lookup_handle->iter_cls, name, records, num_records);
   return GNUNET_YES;
 }

Added: gnunet/src/gns/gns_util.c
===================================================================
--- gnunet/src/gns/gns_util.c                           (rev 0)
+++ gnunet/src/gns/gns_util.c   2012-02-23 15:03:53 UTC (rev 19973)
@@ -0,0 +1,196 @@
+#include "gns.h"
+
+/**
+ * Add a DNS name to the buffer at the given location.
+ *
+ * @param dst where to write the name
+ * @param dst_len number of bytes in dst
+ * @param off pointer to offset where to write the name (increment by bytes 
used)
+ *            must not be changed if there is an error
+ * @param name name to write
+ * @return GNUNET_SYSERR if 'name' is invalid
+ *         GNUNET_NO if 'name' did not fit
+ *         GNUNET_OK if 'name' was added to 'dst'
+ */
+static int
+add_name (char *dst,
+         size_t dst_len,
+         size_t *off,
+         const char *name)
+{
+  const char *dot;
+  size_t start;
+  size_t pos;
+  size_t len;
+
+  if (NULL == name)
+    return GNUNET_SYSERR;
+  start = *off;
+  if (start + strlen (name) + 2 > dst_len)
+    return GNUNET_NO;
+  pos = start;
+  do
+  {
+    dot = strchr (name, '.');
+    if (NULL == dot)
+      len = strlen (name);
+    else
+      len = dot - name;
+    if ( (len >= 64) || (len == 0) )
+      return GNUNET_NO; /* segment too long or empty */
+    dst[pos++] = (char) (uint8_t) len;
+    memcpy (&dst[pos], name, len);
+    pos += len;
+    name += len + 1; /* also skip dot */
+  }
+  while (NULL != dot);
+  dst[pos++] = '\0'; /* terminator */
+  *off = pos;
+  return GNUNET_OK;
+}
+
+/**
+ * Add an MX record to the buffer at the given location.
+ *
+ * @param dst where to write the mx record
+ * @param dst_len number of bytes in dst
+ * @param off pointer to offset where to write the mx information (increment 
by bytes used);
+ *            can also change if there was an error
+ * @param mx mx information to write
+ * @return GNUNET_SYSERR if 'mx' is invalid
+ *         GNUNET_NO if 'mx' did not fit
+ *         GNUNET_OK if 'mx' was added to 'dst'
+ */
+static int
+add_mx (char *dst,
+       size_t dst_len,
+       size_t *off,
+       const struct GNUNET_DNSPARSER_MxRecord *mx)
+{
+  uint16_t mxpref;
+
+  if (*off + sizeof (uint16_t) > dst_len)
+    return GNUNET_NO;
+  mxpref = htons (mx->preference);
+  memcpy (&dst[*off], &mxpref, sizeof (mxpref));
+  (*off) += sizeof (mxpref);
+  return add_name (dst, dst_len, off, mx->mxhost);
+}
+
+
+/**
+ * Add an SOA record to the buffer at the given location.
+ *
+ * @param dst where to write the SOA record
+ * @param dst_len number of bytes in dst
+ * @param off pointer to offset where to write the SOA information (increment 
by bytes used)
+ *            can also change if there was an error
+ * @param soa SOA information to write
+ * @return GNUNET_SYSERR if 'soa' is invalid
+ *         GNUNET_NO if 'soa' did not fit
+ *         GNUNET_OK if 'soa' was added to 'dst'
+ */
+static int
+add_soa (char *dst,
+        size_t dst_len,
+        size_t *off,
+        const struct GNUNET_DNSPARSER_SoaRecord *soa)
+{
+  struct soa_data sd;
+  int ret;
+
+  if ( (GNUNET_OK != (ret = add_name (dst,
+                                     dst_len,
+                                     off,
+                                     soa->mname))) ||
+       (GNUNET_OK != (ret = add_name (dst,
+                                     dst_len,
+                                     off,
+                                     soa->rname)) ) )
+    return ret;
+  if (*off + sizeof (struct soa_data) > dst_len)
+    return GNUNET_NO;
+  sd.serial = htonl (soa->serial);
+  sd.refresh = htonl (soa->refresh);
+  sd.retry = htonl (soa->retry);
+  sd.expire = htonl (soa->expire);
+  sd.minimum = htonl (soa->minimum_ttl);
+  memcpy (&dst[*off], &sd, sizeof (sd));
+  (*off) += sizeof (sd);
+  return GNUNET_OK;
+}
+
+/**
+ * Add a DNS record to the buffer at the given location.
+ *
+ * @param dst where to write the record
+ * @param dst_len number of bytes in dst
+ * @param off pointer to offset where to write the query (increment by bytes 
used)
+ *            must not be changed if there is an error
+ * @param record record to write
+ * @return GNUNET_SYSERR if 'record' is invalid
+ *         GNUNET_NO if 'record' did not fit
+ *         GNUNET_OK if 'record' was added to 'dst'
+ */
+static int
+parse_record (char *dst,
+           size_t dst_len,
+           size_t *off,
+           const struct GNUNET_GNS_Record *record)
+{
+  int ret;
+  size_t start;
+  size_t pos;
+  struct record_line rl;
+
+  start = *off;
+  ret = add_name (dst, dst_len - sizeof (struct record_line), off, 
record->name);
+  if (ret != GNUNET_OK)
+    return ret;
+  /* '*off' is now the position where we will need to write the record line */
+
+  pos = *off + sizeof (struct record_line);
+  switch (record->type)
+  { 
+  case GNUNET_DNSPARSER_TYPE_MX:
+    ret = add_mx (dst, dst_len, &pos, record->data.mx);    
+    break;
+  case GNUNET_DNSPARSER_TYPE_SOA:
+    ret = add_soa (dst, dst_len, &pos, record->data.soa);
+    break;
+  case GNUNET_DNSPARSER_TYPE_NS:
+  case GNUNET_DNSPARSER_TYPE_CNAME:
+  case GNUNET_DNSPARSER_TYPE_PTR:
+    ret = add_name (dst, dst_len, &pos, record->data.hostname);
+    break;
+  default:
+    if (pos + record->data.raw.data_len > dst_len)
+    {
+      ret = GNUNET_NO;
+      break;
+    }
+    memcpy (&dst[pos], record->data.raw.data, record->data.raw.data_len);
+    pos += record->data.raw.data_len;
+    ret = GNUNET_OK;
+    break;
+  }
+  if (ret != GNUNET_OK)
+  {
+    *off = start;
+    return GNUNET_NO;
+  }
+
+  if (pos - (*off + sizeof (struct record_line)) > UINT16_MAX)
+  {
+    /* record data too long */
+    *off = start;
+    return GNUNET_NO;
+  }
+  rl.type = htons (record->type);
+  rl.class = htons (record->class);
+  rl.ttl = htonl (GNUNET_TIME_absolute_get_remaining 
(record->expiration_time).rel_value / 1000); /* in seconds */
+  rl.data_len = htons ((uint16_t) (pos - (*off + sizeof (struct 
record_line))));
+  memcpy (&dst[*off], &rl, sizeof (struct record_line));
+  *off = pos;
+  return GNUNET_OK;  
+}

Modified: gnunet/src/gns/gnunet-service-gns.c
===================================================================
--- gnunet/src/gns/gnunet-service-gns.c 2012-02-23 15:03:44 UTC (rev 19972)
+++ gnunet/src/gns/gnunet-service-gns.c 2012-02-23 15:03:53 UTC (rev 19973)
@@ -52,7 +52,7 @@
   struct GNUNET_GNS_QueryRecordList * next;
   struct GNUNET_GNS_QueryRecordList * prev;
 
-  struct GNUNET_DNSPARSER_Record * record;
+  GNUNET_GNS_Record * record;
 };
 
 /**
@@ -103,8 +103,6 @@
  */
 struct GNUNET_DHT_Handle *dht_handle;
 
-struct GNUNET_TIME_Relative dht_update_interval;
-
 /**
  * Our zone's private key
  */
@@ -115,6 +113,8 @@
  */
 struct GNUNET_NAMESTORE_Handle *namestore_handle;
 
+struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter;
+
 /**
  * The configuration the GNS service is running with
  */
@@ -136,6 +136,12 @@
 const char* gnunet_tld = ".gnunet";
 
 /**
+ * Useful for zone update for DHT put
+ */
+static int num_public_records =  3600;
+struct GNUNET_TIME_Relative dht_update_interval;
+
+/**
  * Task run during shutdown.
  *
  * @param cls unused
@@ -313,20 +319,24 @@
  * @param data the record data
  */
 void
-process_authority_lookup(void* cls, const GNUNET_HashCode *zone,
-                   const char *name, uint32_t record_type,
+process_authority_lookup(void* cls,
+                   const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
                    struct GNUNET_TIME_Absolute expiration,
-                   enum GNUNET_NAMESTORE_RecordFlags flags,
-                   size_t size, const void *data)
+                   const char *name,
+                   unsigned int rd_count,
+                   const struct GNUNET_NAMESTORE_RecordData *rd,
+                   const struct GNUNET_CRYPTO_RsaSignature *signature)
 {
   struct GNUNET_GNS_PendingQuery *query;
+  GNUNET_HashCode zone;
 
   query = (struct GNUNET_GNS_PendingQuery *)cls;
+  GNUNET_CRYPTO_hash(key, GNUNET_CRYPTO_RSA_KEY_LENGTH, &zone);
   
   /**
    * No authority found in namestore.
    */
-  if (NULL == data)
+  if (rd_count == 0)
   {
     if (query->authority_found)
     {
@@ -337,11 +347,10 @@
 
     /**
      * We did not find an authority in the namestore
-     * _IF_ the current authoritative zone is us.
-     * we cannot resolve
-     * _ELSE_ we cannot still check the dht
+     * _IF_ the current authoritative zone is us we cannot resolve
+     * _ELSE_ we can still check the dht
      */
-    if (GNUNET_CRYPTO_hash_cmp(zone, &zone_hash))
+    if (GNUNET_CRYPTO_hash_cmp(&zone, &zone_hash))
     {
       GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Authority unknown\n");
       //FIXME return NX answer
@@ -351,15 +360,24 @@
     resolve_authority_dht(query, name);
     return;
   }
-  
+
+  //Note only 1 pkey should have been returned.. anything else would be strange
   /**
    * We found an authority that may be able to help us
    * move on with query
    */
-  query->authority_found = 1;
-  GNUNET_HashCode *key = (GNUNET_HashCode*) data; //FIXME i assume this works
-  query->authority = key;
+  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;
+  resolve_name(query, query->authority);
+  
 }
 
 
@@ -449,40 +467,38 @@
  * @param data the record data
  */
 static void
-process_authoritative_result(void* cls, const GNUNET_HashCode *zone,
-                  const char *name, uint32_t record_type,
+process_authoritative_result(void* cls,
+                  const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
                   struct GNUNET_TIME_Absolute expiration,
-                  enum GNUNET_NAMESTORE_RecordFlags flags,
-                  size_t size, const void *data)
+                  const char *name, unsigned int rd_count,
+                  const struct GNUNET_NAMESTORE_RecordData *rd,
+                  const struct GNUNET_CRYPTO_RsaSignature *signature)
 {
   struct GNUNET_GNS_PendingQuery *query;
   struct GNUNET_GNS_QueryRecordList *qrecord;
   struct GNUNET_DNSPARSER_Record *record;
+  GNUNET_HashCode zone;
   query = (struct GNUNET_GNS_PendingQuery *) cls;
+  GNUNET_CRYPTO_hash(key, GNUNET_CRYPTO_RSA_KEY_LENGTH, &zone);
 
+  //FIXME Handle results in rd
 
-  if (NULL == data)
+  if (rd_count == 0)
   {
     /**
      * FIXME
-     * Lookup terminated
-     * Do we have what we need to answer?
-     * If not -> DHT Phase
+     * Lookup terminated and no results
+     * -> DHT Phase unless data is recent
      * if full_name == next_name and not anwered we cannot resolve
      */
     GNUNET_log(GNUNET_ERROR_TYPE_INFO,
-               "Namestore lookup terminated. (answered=%d)", query->answered);
-    if (query->answered)
-    {
-      reply_to_dns(query);
-      return;
-    }
-
+               "Namestore lookup terminated. without results\n");
+    
     /**
      * if this is not our zone we cannot rely on the namestore to be
      * complete. -> Query DHT
      */
-    if (!GNUNET_CRYPTO_hash_cmp(zone, &zone_hash))
+    if (!GNUNET_CRYPTO_hash_cmp(&zone, &zone_hash))
     {
       //FIXME todo
       resolve_name_dht(query, name);
@@ -500,54 +516,36 @@
   {
     /**
      * Record found
+     *
+     * FIXME Check record expiration and dht expiration
+     * consult dht if necessary
      */
     GNUNET_log(GNUNET_ERROR_TYPE_INFO,
                "Processing additional result for %s from namestore\n", name);
-
-    qrecord = GNUNET_malloc(sizeof(struct GNUNET_GNS_QueryRecordList));
-    record = GNUNET_malloc(sizeof(struct GNUNET_DNSPARSER_Record));
-    qrecord->record = record;
-
-    record->name = (char*)query->original_name;
-
-    /**
-     * FIXME for gns records this requires the dnsparser to be modified!
-     * or use RAW. But RAW data need serialization!
-     * maybe store record data appropriately in namestore to avoid a
-     * huge switch statement?
-     */
-    if (record_type == GNUNET_DNSPARSER_TYPE_A)
+    int i;
+    for (i=0; i<rd_count;i++)
     {
-      record->data.raw.data = (char*)data;
-      record->data.raw.data_len = size;
+      // 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));
+      qrecord->record = record;
+      
+      //fixme into gns_util
+      //parse_record(rd[i]->data, rd[i]->data_size, 0, record);
+      GNUNET_CONTAINER_DLL_insert(query->records_head,
+                                  query->records_tail,
+                                  qrecord);
+      query->num_records++;
+
+      //TODO really?
+      //we need to resolve to the original name in the end though...
+      //record->name = (char*)query->original_name;
     }
-    record->expiration_time = expiration;
-    record->type = record_type;
-    record->class = GNUNET_DNSPARSER_CLASS_INTERNET; /* srsly? */
-    
-    //FIXME authoritative answer if we find a result in namestore
-    if (flags == GNUNET_NAMESTORE_RF_AUTHORITY)
-    {
-      //query->num_authority_records++;
-    }
-    
-    /**
-     * This seems to take into account that the result could
-     * be different in name and or record type...
-     * but to me this does not make sense
-     */
+
     GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Found answer to query!\n");
     query->answered = 1;
 
-    query->num_records++;
-
-    /**
-     * FIXME watch for leaks
-     * properly free pendingquery when the time comes
-     */
-    GNUNET_CONTAINER_DLL_insert(query->records_head,
-                                query->records_tail,
-                                qrecord);
+    reply_to_dns(query);
   }
 }
 
@@ -749,40 +747,41 @@
   /* put a few records into namestore */
   char* ipA = "1.2.3.4";
   char* ipB = "5.6.7.8";
-  struct in_addr *alice = GNUNET_malloc(sizeof(struct in_addr));
-  struct in_addr *bob = GNUNET_malloc(sizeof(struct in_addr));
-  GNUNET_assert(1 == inet_pton (AF_INET, ipA, alice));
-  GNUNET_assert(1 == inet_pton (AF_INET, ipB, bob));
-  GNUNET_NAMESTORE_record_put (namestore_handle,
-                               &zone_hash,
+  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;
+  rda = GNUNET_malloc(sizeof(struct GNUNET_NAMESTORE_RecordData));
+  
+  //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",
-                               GNUNET_GNS_RECORD_TYPE_A,
-                               GNUNET_TIME_absolute_get_forever(),
-                               GNUNET_NAMESTORE_RF_AUTHORITY,
-                               sizeof(struct in_addr),
-                               alice,
+                               rda,
                                NULL,
                                NULL);
-  GNUNET_NAMESTORE_record_put (namestore_handle,
-                               &zone_hash,
+  GNUNET_NAMESTORE_record_create (namestore_handle,
+                               zone_key,
                                "bob",
-                               GNUNET_GNS_RECORD_TYPE_A,
-                               GNUNET_TIME_absolute_get_forever(),
-                               GNUNET_NAMESTORE_RF_AUTHORITY,
-                               sizeof(struct in_addr),
-                               bob,
+                               rdb,
                                NULL,
                                NULL);
 }
 
-//Prototype... needed in put function
-static void
-update_zone_dht(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
+void
+update_zone_dht_next(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  GNUNET_NAMESTORE_zone_iterator_next(namestore_iter);
+}
 
 /**
  * Function used to put all records successively into the DHT.
- * FIXME also serializes records. maybe do this somewhere else...
- * FIXME don't store private records (maybe zone transfer does this)
  *
  * @param cls the closure (NULL)
  * @param zone our root zone hash
@@ -795,77 +794,37 @@
  * @param record_data the record data
  */
 void
-put_gns_record(void *cls, const GNUNET_HashCode *zone, const char *name,
-               uint32_t record_type, struct GNUNET_TIME_Absolute expiration,
-               enum GNUNET_NAMESTORE_RecordFlags flags,
-               size_t size, const void *record_data)
+put_gns_record(void *cls,
+                const const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded 
*key,
+                struct GNUNET_TIME_Absolute expiration,
+                const char *name,
+                unsigned int rd_count,
+                const struct GNUNET_NAMESTORE_RecordData *rd,
+                const struct GNUNET_CRYPTO_RsaSignature *signature)
 {
-  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Putting a record into the DHT\n");
+  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Putting records into the DHT\n");
   struct GNUNET_TIME_Relative timeout;
-
-  char* data;
-  char* data_ptr;
-  struct GNUNET_TIME_AbsoluteNBO exp_nbo;
-  exp_nbo = GNUNET_TIME_absolute_hton (expiration);
-  uint32_t namelen = htonl(strlen(name));
-  uint16_t flags_nbo = htons(flags);
   GNUNET_HashCode name_hash;
   GNUNET_HashCode xor_hash;
 
+  if (NULL == name) //We're done
+  {
+    GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
+    return;
+  }
   /**
-   * I guess this can be done prettier
-   * FIXME extract into function, maybe even into different file
-   */
-  size_t record_len = sizeof(size_t) + sizeof(uint32_t) +
-    sizeof(uint16_t) +
-    sizeof(uint32_t) + strlen(name) + size;
-  
-  record_type = htonl(record_type);
-
-  data = GNUNET_malloc(record_len);
-  
-  /* -_- */
-  data_ptr = data;
-  memcpy(data_ptr, &namelen, sizeof(size_t));
-  data_ptr += sizeof(size_t);
-
-  memcpy(data_ptr, name, namelen);
-  data_ptr += namelen;
-  
-  memcpy(data_ptr, &record_type, sizeof(uint32_t));
-  data_ptr += sizeof(uint32_t);
-
-  memcpy(data_ptr, &exp_nbo, sizeof(struct GNUNET_TIME_AbsoluteNBO));
-  data_ptr += sizeof(struct GNUNET_TIME_AbsoluteNBO);
-
-  memcpy(data_ptr, &flags_nbo, sizeof(uint16_t));
-  data_ptr += sizeof(uint16_t);
-
-  memcpy(data_ptr, &size, sizeof(uint32_t));
-  data_ptr += sizeof(uint32_t);
-
-  /**
-   * FIXME note that this only works with raw data in nbo
-   * write helper function that converts properly and returns buffer
-   */
-  memcpy(data_ptr, record_data, size);
-  data_ptr += size;
-  /*Doing this made me sad...*/
-
-  /**
    * FIXME magic number 20 move to config file
    */
   timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20);
-
   GNUNET_CRYPTO_hash(name, strlen(name), &name_hash);
   GNUNET_CRYPTO_hash_xor(&zone_hash, &name_hash, &xor_hash);
   GNUNET_DHT_put (dht_handle, &xor_hash,
                   5, //replication level
                   GNUNET_DHT_RO_NONE,
                   GNUNET_BLOCK_TYPE_TEST, //FIXME todo block plugin
-                  (data_ptr-data),
-                  data,
-                  expiration, //FIXME from record makes sense? is absolute?
+                  rd->data_size,
+                  rd->data,
+                  expiration,
                   timeout,
                   NULL, //FIXME continuation needed? success check? yes ofc
                   NULL); //cls for cont
@@ -874,7 +833,7 @@
    * Reschedule periodic put
    */
   GNUNET_SCHEDULER_add_delayed (dht_update_interval,
-                                &update_zone_dht,
+                                &update_zone_dht_next,
                                 NULL);
 
 }
@@ -886,12 +845,17 @@
  * @param tc task context
  */
 static void
-update_zone_dht(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Update zone!\n");
-  GNUNET_NAMESTORE_zone_transfer (namestore_handle, &zone_hash,
-                                  &put_gns_record,
-                                  NULL);
+  dht_update_interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
+                                                     
(3600/num_public_records));
+  namestore_iter = GNUNET_NAMESTORE_zone_iteration_start (namestore_handle,
+                                                          &zone_hash,
+                                                          
GNUNET_NAMESTORE_RF_AUTHORITY,
+                                                          
GNUNET_NAMESTORE_RF_PRIVATE,
+                                                          &put_gns_record,
+                                                          NULL);
 }
 
 /**
@@ -960,11 +924,12 @@
   /**
    * Schedule periodic put
    * for our records
+   * We have roughly an hour for all records;
    */
   dht_update_interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
                                                       60); //FIXME from cfg
   GNUNET_SCHEDULER_add_delayed (dht_update_interval,
-                                &update_zone_dht,
+                                &update_zone_dht_start,
                                 NULL);
   GNUNET_log(GNUNET_ERROR_TYPE_INFO, "GNS Init done!\n");
 

Modified: gnunet/src/gns/namestore_stub_api.c
===================================================================
--- gnunet/src/gns/namestore_stub_api.c 2012-02-23 15:03:44 UTC (rev 19972)
+++ gnunet/src/gns/namestore_stub_api.c 2012-02-23 15:03:53 UTC (rev 19973)
@@ -146,56 +146,40 @@
 GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h,
                             const GNUNET_HashCode *zone,
                             const char *name,
-                            uint32_t record_type,
                             struct GNUNET_TIME_Absolute expiration,
-                            enum GNUNET_NAMESTORE_RecordFlags flags,
-                            size_t data_size,
-                            const void *data, 
-                            GNUNET_NAMESTORE_ContinuationWithStatus cont,
+                            unsigned int rd_count,
+           const struct GNUNET_NAMESTORE_RecordData *rd,
+           const struct GNUNET_CRYPTO_RsaSignature *signature,
+           GNUNET_NAMESTORE_ContinuationWithStatus cont,
                             void *cont_cls)
 {
   struct GNUNET_NAMESTORE_QueueEntry *qe;
   qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
-
-  struct GNUNET_NAMESTORE_SimpleRecord *sr;
-  sr = GNUNET_malloc(sizeof(struct GNUNET_NAMESTORE_SimpleRecord));
-  sr->name = name;
-  sr->record_type = record_type;
-  sr->expiration = expiration;
-  sr->flags = flags;
-  sr->data_size = data_size;
-  sr->data = data;
-  GNUNET_CONTAINER_DLL_insert(h->records_head, h->records_tail, sr);
+  //FIXME
   return qe;
 }
 
-/**
- * Store a signature in the namestore. 
- *
- * @param h handle to the namestore
- * @param zone hash of the public key of the zone
- * @param name name that is being mapped (at most 255 characters long)
- * @param record_type type of the record (A, AAAA, PKEY, etc.)
- * @param expiration expiration time for the content
- * @param flags flags for the content
- * @param data_size number of bytes in data
- * @param data value, semantics depend on 'record_type' (see RFCs for DNS and 
- *             GNS specification for GNS extensions)
- * @param cont continuation to call when done
- * @param cont_cls closure for cont
- * @return handle to abort the request
- */
+int
+GNUNET_NAMESTORE_verify_signature (const struct 
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key,
+                                   const char *name,
+                                   unsigned int rd_count,
+                                   const struct GNUNET_NAMESTORE_RecordData 
*rd,
+                                   const struct GNUNET_CRYPTO_RsaSignature 
*signature)
+{
+  return GNUNET_OK;
+}
+
 struct GNUNET_NAMESTORE_QueueEntry *
-GNUNET_NAMESTORE_signature_put (struct GNUNET_NAMESTORE_Handle *h,
-                            const GNUNET_HashCode *zone,
+GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h,
+                            const struct GNUNET_CRYPTO_RsaPrivateKey *pkey,
                             const char *name,
-           struct GNUNET_CRYPTO_RsaSignature sig,
-                            GNUNET_NAMESTORE_ContinuationWithStatus cont,
+           const struct GNUNET_NAMESTORE_RecordData *rd,
+           GNUNET_NAMESTORE_ContinuationWithStatus cont,
                             void *cont_cls)
 {
   struct GNUNET_NAMESTORE_QueueEntry *qe;
   qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
-
+  //FIXME
   return qe;
 }
 
@@ -217,30 +201,16 @@
  */
 struct GNUNET_NAMESTORE_QueueEntry *
 GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h,
-                               const GNUNET_HashCode *zone, 
+                               const struct GNUNET_CRYPTO_RsaPrivateKey *pkey,
                                const char *name,
-                               uint32_t record_type,
-                               size_t size,
-                               const void *data, 
-                               GNUNET_NAMESTORE_ContinuationWithStatus cont,
+                               const struct GNUNET_NAMESTORE_RecordData *rd,
+        GNUNET_NAMESTORE_ContinuationWithStatus cont,
                                void *cont_cls)
 {
   struct GNUNET_NAMESTORE_QueueEntry *qe;
   qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
   
-  struct GNUNET_NAMESTORE_SimpleRecord *iter;
-  for (iter=h->records_head; iter != NULL; iter=iter->next)
-  {
-    if (strcmp ( iter->name, name ) &&
-        iter->record_type == record_type &&
-        GNUNET_CRYPTO_hash_cmp (iter->zone, zone))
-      break;
-  }
-  if (iter)
-    GNUNET_CONTAINER_DLL_remove(h->records_head,
-                                h->records_tail,
-                                iter);
-  
+  //FIXME
   return qe;
 }
 
@@ -268,107 +238,33 @@
   struct GNUNET_NAMESTORE_QueueEntry *qe;
   qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
 
-  struct GNUNET_NAMESTORE_SimpleRecord *iter;
-  for (iter=h->records_head; iter != NULL; iter=iter->next)
-  {
-    if (strcmp(iter->name, name))
-      continue;
-
-    if (iter->record_type != record_type)
-      continue;
-
-    proc(proc_cls, iter->zone, iter->name, iter->record_type,
-       iter->expiration,
-       iter->flags,
-       iter->data_size /*size*/,
-       iter->data /* data */);
-  }
-  proc(proc_cls, zone, name, record_type,
-       GNUNET_TIME_absolute_get_forever(), 0, 0, NULL); /*TERMINATE*/
-
+  //FIXME
   return qe;
 }
 
-struct GNUNET_NAMESTORE_QueueEntry *
-GNUNET_NAMESTORE_lookup_signature (struct GNUNET_NAMESTORE_Handle *h,
-                                   const GNUNET_HashCode *zone,
-                                   const char* name,
-                                   GNUNET_NAMESTORE_SignatureProcessor proc,
-                                   void *proc_cls)
+struct GNUNET_NAMESTORE_ZoneIterator *
+GNUNET_NAMESTORE_zone_iteration_start(struct GNUNET_NAMESTORE_Handle *h,
+                                      const GNUNET_HashCode *zone,
+                                      enum GNUNET_NAMESTORE_RecordFlags 
must_have_flags,
+                                      enum GNUNET_NAMESTORE_RecordFlags 
must_not_have_flags,
+                                      GNUNET_NAMESTORE_RecordProcessor proc,
+                                      void *proc_cls)
 {
-  return NULL;
+  struct GNUNET_NAMESTORE_ZoneIterator *it;
+  it = GNUNET_malloc(sizeof(struct GNUNET_NAMESTORE_ZoneIterator));
+  return it;
 }
 
-
-/**
- * Get the hash of a record (what will be signed in the Stree for
- * the record).
- *
- * @param zone hash of the public key of the zone
- * @param name name that is being mapped (at most 255 characters long)
- * @param record_type type of the record (A, AAAA, PKEY, etc.)
- * @param expiration expiration time for the content
- * @param flags flags for the content
- * @param data_size number of bytes in data
- * @param data value, semantics depend on 'record_type' (see RFCs for DNS and.
- *             GNS specification for GNS extensions)
- * @param record_hash hash of the record (set)
- */
 void
-GNUNET_NAMESTORE_record_hash (struct GNUNET_NAMESTORE_Handle *h,
-                              const GNUNET_HashCode *zone,
-                              const char *name,
-                              uint32_t record_type,
-                              struct GNUNET_TIME_Absolute expiration,
-                              enum GNUNET_NAMESTORE_RecordFlags flags,
-                              size_t data_size,
-                              const void *data,
-                              GNUNET_HashCode *record_hash)
+GNUNET_NAMESTORE_zone_iterator_next(struct GNUNET_NAMESTORE_ZoneIterator *it)
 {
-  char* teststring = "namestore-stub";
-  GNUNET_CRYPTO_hash(teststring, strlen(teststring), record_hash);
 }
 
-
-/**
- * Get all records of a zone.
- *
- * @param h handle to the namestore
- * @param zone zone to access
- * @param proc function to call on a random value; it
- *        will be called repeatedly with a value (if available)
- *        and always once at the end with a zone and name of NULL.
- * @param proc_cls closure for proc
- * @return a handle that can be used to
- *         cancel
- */
-struct GNUNET_NAMESTORE_QueueEntry *
-GNUNET_NAMESTORE_zone_transfer (struct GNUNET_NAMESTORE_Handle *h,
-                                const GNUNET_HashCode *zone,
-                                GNUNET_NAMESTORE_RecordProcessor proc,
-                                void *proc_cls)
+void
+GNUNET_NAMESTORE_zone_iteration_stop(struct GNUNET_NAMESTORE_ZoneIterator *it)
 {
-  struct GNUNET_NAMESTORE_QueueEntry *qe;
-  qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
-  return qe;
 }
 
-struct GNUNET_NAMESTORE_ZoneIterator *
-GNUNET_NAMESTORE_zone_iteration_start(struct GNUNET_NAMESTORE_Handle *h,
-                                      const GNUNET_HashCode *zone,
-                                      GNUNET_NAMESTORE_RecordProcessor proc,
-                                      void *proc_cls);
-
-int
-GNUNET_NAMESTORE_zone_iterator_next(struct GNUNET_NAMESTORE_ZoneIterator *it);
-
-void
-GNUNET_NAMESTORE_zone_iteration_stop(struct GNUNET_NAMESTORE_ZoneIterator *it);
-
-void
-GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
-
-
 /**
  * Cancel a namestore operation.  The final callback from the
  * operation must not have been done yet.




reply via email to

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