-doxygen, more block plugin
authorMartin Schanzenbach <mschanzenbach@posteo.de>
Sun, 26 Feb 2012 14:34:56 +0000 (14:34 +0000)
committerMartin Schanzenbach <mschanzenbach@posteo.de>
Sun, 26 Feb 2012 14:34:56 +0000 (14:34 +0000)
src/gns/block_gns.h [deleted file]
src/gns/gnunet-gns-lookup.c
src/gns/gnunet-service-gns.c
src/gns/plugin_block_gns.c
src/include/block_gns.h [new file with mode: 0644]
src/include/gnunet_gns_service.h

diff --git a/src/gns/block_gns.h b/src/gns/block_gns.h
deleted file mode 100644 (file)
index d34e33c..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
-     This file is part of GNUnet.
-     (C) 2012 Christian Grothoff (and other contributing authors)
-
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
-
-     GNUnet is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
-*/
-
-/**
- * @file include/block_gns.h
- * @brief fs block formats (shared between fs and block)
- * @author Martin Schanzenbach
- */
-#ifndef BLOCK_GNS_H
-#define BLOCK_GNS_H
-
-#include "gnunet_util_lib.h"
-
-GNUNET_NETWORK_STRUCT_BEGIN
-
-/**
- * @brief a simgle record inside a record block
- */
-struct GNSRecordBlock
-{
-  /**
-   * the record type
-   */
-  uint32_t type GNUNET_PACKED;
-
-  /**
-   * expiration time of the record
-   */
-  struct GNUNET_TIME_AbsoluteNBO expiration;
-
-  /**
-   * length of the data
-   */
-  uint32_t data_length GNUNET_PACKED;
-  
-  /* record flags */
-  uint32_t flags GNUNET_PACKED;
-
-  //Class of the record?
-
-  /* followed by the record data */
-}
-
-/**
- * @brief a record block for a given name of a single authority
- */
-struct GNSNameRecordBlock
-{
-
-  /**
-   * GNUNET_RSA_Signature using RSA-key generated from the records.
-   */
-  struct GNUNET_CRYPTO_RsaSignature signature;
-
-  /**
-   * What is being signed and why?
-   */
-  struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
-
-  /**
-   * The public key of the authority
-   */
-  struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
-
-  /* 0-terminated name here */
-
-  /* number of records that follow */
-  uint32_t rd_num GNUNET_PACKED;
-
-  /* variable-size GNSRecordBlocks follows here */
-
-
-};
-
-GNUNET_NETWORK_STRUCT_END
-#endif
index 5adb4064e6a68f41b3116d2be5a0513edd7e164e..f33264f61d2f8bec74cb86e16329c74a6a0c138d 100644 (file)
@@ -104,15 +104,9 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * operation that expects a reply
  *
  * @param cls closure
- * @param exp when will this value expire
- * @param key key of the result
- * @param get_path peers on reply path (or NULL if not recorded)
- * @param get_path_length number of entries in get_path
- * @param put_path peers on the PUT path (or NULL if not recorded)
- * @param put_path_length number of entries in get_path
- * @param type type of the result
- * @param size number of bytes in data
- * @param data pointer to the result data
+ * @param name name
+ * @param record a record
+ * @param num_records number of records
  */
 static void
 lookup_result_iterator (void *cls,
index e4e28c14b94c0a8b604844ce40321fb37c2b6482..d2cb477f6355b572c5f5e8a577f6ecf5b813db5e 100644 (file)
@@ -303,7 +303,7 @@ process_authority_dht_result(void* cls,
  * Start DHT lookup for a name -> PKEY (compare NS) record in
  * query->authority's zone
  *
- * @param query the pending gns query
+ * @param rh the pending gns query
  * @param name the name of the PKEY record
  */
 void
@@ -459,7 +459,7 @@ process_name_dht_result(void* cls,
  * Start DHT lookup for a (name -> query->record_type) record in
  * query->authority's zone
  *
- * @param query the pending gns query
+ * @param rh the pending gns query context
  * @param name the name to query record
  */
 void
@@ -501,7 +501,7 @@ resolve_name(struct GNUNET_GNS_ResolverHandle *query, GNUNET_HashCode *zone);
  * @param expiration expiration date of the record data set in the namestore
  * @param name the name for which we need an authority
  * @param rd_count the number of records with 'name'
- * @param data the record data
+ * @param rd the record data
  * @param signature the signature of the authority for the record data
  */
 void
@@ -697,7 +697,7 @@ reply_to_dns(struct GNUNET_GNS_ResolverHandle *rh, uint32_t rd_count,
  * @param expiration expiration date of the namestore entry
  * @param name the name for which we need an authority
  * @param rd_count the number of records with 'name'
- * @param data the record data
+ * @param rd the record data
  * @param signature the signature of the authority for the record data
  */
 static void
@@ -854,7 +854,7 @@ char* pop_tld(char* name)
  * If it is then try to resolve directly.
  * If not then first have to resolve the authoritative entities.
  *
- * @param query the pending lookup
+ * @param rh the pending lookup
  * @param zone the zone we are currently resolving in
  */
 void
@@ -889,7 +889,7 @@ resolve_name(struct GNUNET_GNS_ResolverHandle *rh, GNUNET_HashCode *zone)
  *
  * Setup a new query and try to resolve
  *
- * @param rh the request handle of the DNS request from a client
+ * @param request the request handle of the DNS request from a client
  * @param p the DNS query packet we received
  * @param q the DNS query we received parsed from p
  */
index 33699a32ce5c94883534416c3f3fc31962ccebf8..1a33b2d1a180ed8c7f96c89ae1c6592223cfba7c 100644 (file)
@@ -61,10 +61,86 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
                           size_t xquery_size, const void *reply_block,
                           size_t reply_block_size)
 {
-  if (type != GNUNET_BLOCK_TYPE_GNS_RECORD)
+  if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD)
     return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
+
+  struct GNUNET_CRYPTO_RsaSignature *signature;
+  struct GNUNET_CRYPTO_RsaSignaturePurpose *purpose;
+  struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key;
+  char* name;
+  GNUNET_HashCode pkey_hash;
+  GNUNET_HashCode query_pkey;
+  GNUNET_HashCode name_hash;
+
+  uint32_t rd_num;
+  uint32_t type;
+  struct GNUNET_TIME_AbsoluteNBO;
+  uint32_t data_length;
+  uint32_t flags;
+
+  char* pos = (char*) reply_block;
+  signature = pos;
+  pos += sizeof(struct GNUNET_CRYPTO_RsaSignature);
+  pos += sizeof(struct GNUNET_CRYPTO_RsaSignaturePurpose);
+
+  public_key = pos;
+  pos += sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded);
+  name = pos;
+  pos += namelen(name); //Off by 1?
+
+  GNUNET_CRYPTO_hash(public_key,
+                     sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+                     &pkey_hash);
+
+  GNUNET_CRYPTO_hash(name, strlen(name), &name_hash);
+
+  GNUNET_CRYPTO_hash_xor(query, &name_hash, &query_pkey);
   
-  //FIXME check signatures here
+  //Check query key against public key
+  if (0 != GNUNET_CRYPTO_hash_cmp(&query_pkey, &pkey_hash))
+    return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
+
+  rd_count = ntohl(*pos);
+  pos += sizeof(uint32_t);
+
+  struct GNUNET_NAMESTORE_RecordData rd[rd_count];
+  int i = 0;
+
+  for (i=0; i<rd_count; i++)
+  {
+    rd[i].type = ntohl(*pos);
+    pos += sizeof(uint32_t);
+    rd[i].expiration =
+      GNUNET_TIME_relative_ntoh(*((struct GNUNET_TIME_AbsoluteNBO*)pos));
+    pos += sizeof(struct GNUNET_TIME_AbsoluteNBO);
+    rd[i].data_length = ntohl(*pos);
+    pos += sizeof(uint32_t);
+    rd[i].flags = ntohl(*pos);
+    pos += sizeof(uint32_t);
+    rd[i].data = pos;
+    pos += rd[i].data_length;
+  }
+
+  if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature (public_key,
+                                                      name,
+                                                      rd_count,
+                                                      rd,
+                                                      signature))
+  {
+    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Signature invalid\n");
+    return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
+  }
+
+  //Cache
+  GNUNET_NAMESTORE_record_put (handle, //FIXME where do i get this from?
+                               &pkey_hash,
+                               name,
+                               expiration, //FIXME uh where do i get this from?
+                               rd_count,
+                               rd,
+                               signature,
+                               NULL, //cont
+                               NULL); //cls
   return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
 }
 
diff --git a/src/include/block_gns.h b/src/include/block_gns.h
new file mode 100644 (file)
index 0000000..d34e33c
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+     This file is part of GNUnet.
+     (C) 2012 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file include/block_gns.h
+ * @brief fs block formats (shared between fs and block)
+ * @author Martin Schanzenbach
+ */
+#ifndef BLOCK_GNS_H
+#define BLOCK_GNS_H
+
+#include "gnunet_util_lib.h"
+
+GNUNET_NETWORK_STRUCT_BEGIN
+
+/**
+ * @brief a simgle record inside a record block
+ */
+struct GNSRecordBlock
+{
+  /**
+   * the record type
+   */
+  uint32_t type GNUNET_PACKED;
+
+  /**
+   * expiration time of the record
+   */
+  struct GNUNET_TIME_AbsoluteNBO expiration;
+
+  /**
+   * length of the data
+   */
+  uint32_t data_length GNUNET_PACKED;
+  
+  /* record flags */
+  uint32_t flags GNUNET_PACKED;
+
+  //Class of the record?
+
+  /* followed by the record data */
+}
+
+/**
+ * @brief a record block for a given name of a single authority
+ */
+struct GNSNameRecordBlock
+{
+
+  /**
+   * GNUNET_RSA_Signature using RSA-key generated from the records.
+   */
+  struct GNUNET_CRYPTO_RsaSignature signature;
+
+  /**
+   * What is being signed and why?
+   */
+  struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
+
+  /**
+   * The public key of the authority
+   */
+  struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
+
+  /* 0-terminated name here */
+
+  /* number of records that follow */
+  uint32_t rd_num GNUNET_PACKED;
+
+  /* variable-size GNSRecordBlocks follows here */
+
+
+};
+
+GNUNET_NETWORK_STRUCT_END
+#endif
index 7f3fd77d3fae18199aeba4f21966d4312f97abba..2422178660d1689e765a730a8de9253f11c573e8 100644 (file)
@@ -121,13 +121,14 @@ typedef void (*GNUNET_GNS_LookupIterator) (void *cls,
  * @param handle handle to the GNS service
  * @param timeout how long to wait for transmission of this request to the service
  * // FIXME: what happens afterwards?
- * @param type expected type of the response object
+ * @param handle handle to the GNS service
+ * @param timeout timeout of request
  * @param name the name to look up
  * @param type the GNUNET_GNS_RecordType to look for
  * @param iter function to call on each result
  * @param iter_cls closure for iter
  *
- * @return handle to stop the async get
+ * @return handle to stop the async lookup
  */
 struct GNUNET_GNS_LookupHandle *
 GNUNET_GNS_lookup_start (struct GNUNET_GNS_Handle *handle,