Tell core that we want to have this packet delivered
[oweals/gnunet.git] / src / block / plugin_block_dns.c
index 6fbb9b6f2bd8ad780b4cd7e4c59e8ff78c7d5cd4..4321baf34fe12155ac39fa57e6c3408489dbdd07 100644 (file)
@@ -25,8 +25,9 @@
  */
 
 #include "platform.h"
-#include "plugin_block.h"
-#include "gnunet_block_dns.h"
+#include "gnunet_block_plugin.h"
+#include "block_dns.h"
+#include "gnunet_signatures.h"
 
 #define DEBUG_DHT GNUNET_NO
 
@@ -46,7 +47,7 @@
  * @return characterization of result
  */
 static enum GNUNET_BLOCK_EvaluationResult
-block_plugin_dht_evaluate (void *cls,
+block_plugin_dns_evaluate (void *cls,
                           enum GNUNET_BLOCK_Type type,
                           const GNUNET_HashCode *query,
                           struct GNUNET_CONTAINER_BloomFilter **bf,
@@ -65,11 +66,21 @@ block_plugin_dht_evaluate (void *cls,
     if (reply_block_size == 0)
       return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
 
-    if (reply_block_size < sizeof(struct GNUNET_DNS_Record))
+    if (reply_block_size != sizeof(struct GNUNET_DNS_Record))
       return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
 
     const struct GNUNET_DNS_Record* rec = reply_block;
-    if(reply_block_size != (sizeof(struct GNUNET_DNS_Record) + rec->namelen - 1))
+
+    if (ntohl(rec->purpose.size) != sizeof(struct GNUNET_DNS_Record) - sizeof(struct GNUNET_CRYPTO_RsaSignature))
+      return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
+
+    if (GNUNET_TIME_relative_get_zero().rel_value == GNUNET_TIME_absolute_get_remaining(rec->expiration_time).rel_value)
+      return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
+
+    if (GNUNET_OK != GNUNET_CRYPTO_rsa_verify (htonl(GNUNET_SIGNATURE_PURPOSE_DNS_RECORD),
+                                              &rec->purpose,
+                                              &rec->signature,
+                                              &rec->peer))
       return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
 
     /* How to decide whether there are no more? */
@@ -92,7 +103,7 @@ block_plugin_dht_evaluate (void *cls,
  *         (or if extracting a key from a block of this type does not work)
  */
 static int
-block_plugin_dht_get_key (void *cls,
+block_plugin_dns_get_key (void *cls,
                          enum GNUNET_BLOCK_Type type,
                          const void *block,
                          size_t block_size,
@@ -101,7 +112,7 @@ block_plugin_dht_get_key (void *cls,
   if (type != GNUNET_BLOCK_TYPE_DNS)
     return GNUNET_SYSERR;
   const struct GNUNET_DNS_Record* rec = block;
-  GNUNET_CRYPTO_hash(rec->name, rec->namelen, key);
+  memcpy(key, &rec->service_descriptor, sizeof(GNUNET_HashCode));
   return GNUNET_OK;
 }
 
@@ -109,7 +120,7 @@ block_plugin_dht_get_key (void *cls,
  * Entry point for the plugin.
  */
 void *
-libgnunet_plugin_block_dht_init (void *cls)
+libgnunet_plugin_block_dns_init (void *cls)
 {
   static enum GNUNET_BLOCK_Type types[] = 
     {
@@ -119,8 +130,8 @@ libgnunet_plugin_block_dht_init (void *cls)
   struct GNUNET_BLOCK_PluginFunctions *api;
 
   api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions));
-  api->evaluate = &block_plugin_dht_evaluate;
-  api->get_key = &block_plugin_dht_get_key;
+  api->evaluate = &block_plugin_dns_evaluate;
+  api->get_key = &block_plugin_dns_get_key;
   api->types = types;
   return api;
 }
@@ -130,7 +141,7 @@ libgnunet_plugin_block_dht_init (void *cls)
  * Exit point from the plugin.
  */
 void *
-libgnunet_plugin_block_dht_done (void *cls)
+libgnunet_plugin_block_dns_done (void *cls)
 {
   struct GNUNET_TRANSPORT_PluginFunctions *api = cls;