- begin work on enhanced multipart receiving
[oweals/gnunet.git] / src / mesh / plugin_block_mesh.c
index 8c080c48514797cfa375cf766788d3f469999ddb..ae832488531293d9a2fca132de81de7f2b065e24 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet
-     (C) 2012 Christian Grothoff (and other contributing authors)
+     (C) 2012,2013 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
@@ -27,7 +27,6 @@
 #include "platform.h"
 #include "gnunet_block_plugin.h"
 #include "block_mesh.h"
-#include "mesh_block_lib.h"
 
 /**
  * Number of bits we set per entry in the bloomfilter.
@@ -67,108 +66,36 @@ block_plugin_mesh_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
 
   switch (type)
   {
-  case GNUNET_BLOCK_TYPE_MESH_PEER:
-    if (0 != xquery_size)
-    {
-      GNUNET_break_op (0);
-      return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
-    }
-    if (NULL == reply_block)
-      return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
-    if (sizeof (struct PBlock) != reply_block_size)  
-      return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;  
-    return GNUNET_BLOCK_EVALUATION_OK_LAST;
-  case GNUNET_BLOCK_TYPE_MESH_PEER_BY_TYPE:
-    /* FIXME: have an xquery? not sure */
-    if (0 != xquery_size)
-    {
-      GNUNET_break_op (0);
-      return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
-    }
-    if (NULL == reply_block)
-      return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
-    if (sizeof (struct PBlock) != reply_block_size)
-    {
-      GNUNET_break_op(0);
-      return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
-    }
-    if (NULL != bf)
-    {
-      GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash);
-      GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash);
-      if (NULL != *bf)
-      {
-        if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
-          return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
-      }
-      else
-      {
-        *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K);
-      }
-      GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
-    }
-    return GNUNET_BLOCK_EVALUATION_OK_MORE;
-  case GNUNET_BLOCK_TYPE_MESH_REGEX:
-    if (0 != xquery_size)
-    {
-      GNUNET_break_op (0);
-      return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
-    }
-    if (NULL == reply_block)
-      return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
-    if (GNUNET_OK != GNUNET_MESH_regex_block_check (reply_block,
-                                                    reply_block_size))
-    {
-      GNUNET_break_op(0);
-      return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
-    }
-    if (NULL != bf)
-    {
-      GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash);
-      GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash);
-      if (NULL != *bf)
-      {
-        if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
-          return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
-      }
-      else
-      {
-        *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K);
-      }
-      GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
-    }
-    return GNUNET_BLOCK_EVALUATION_OK_MORE;
-  case GNUNET_BLOCK_TYPE_MESH_REGEX_ACCEPT:
-    if (0 != xquery_size)
-    {
-      GNUNET_break_op (0);
-      return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
-    }
-    if (NULL == reply_block)
-      return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
-    if (sizeof (struct MeshRegexAccept) != reply_block_size)
-    {
-      GNUNET_break_op(0);
-      return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
-    }
-    if (NULL != bf)
-    {
-      GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash);
-      GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash);
-      if (NULL != *bf)
+    case GNUNET_BLOCK_TYPE_MESH_PEER:
+      if (0 != xquery_size)
       {
-        if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
-          return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
+        GNUNET_break_op (0);
+        return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
       }
-      else
+      if (NULL == reply_block)
+        return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
+      if (sizeof (struct PBlock) != reply_block_size)
+        return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
+      if (NULL != bf)
       {
-        *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K);
+        GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash);
+        GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash);
+        if (NULL != *bf)
+        {
+          if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
+            return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
+        }
+        else
+        {
+          *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K);
+        }
+        GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
       }
-      GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
-    }
-    return GNUNET_BLOCK_EVALUATION_OK_MORE;
-  default:
-    return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
+      return GNUNET_BLOCK_EVALUATION_OK_LAST;
+
+    default:
+      GNUNET_break(0);
+      return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
   }
 }
 
@@ -179,9 +106,9 @@ block_plugin_mesh_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
  * @param cls closure
  * @param type block type
  * @param block block to get the key for
- * @param block_size number of bytes in block
+ * @param block_size number of bytes in @a block
  * @param key set to the key (query) for the given block
- * @return GNUNET_OK on success, GNUNET_SYSERR if type not supported
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported
  *         (or if extracting a key from a block of this type does not work)
  */
 static int
@@ -197,12 +124,12 @@ block_plugin_mesh_get_key (void *cls, enum GNUNET_BLOCK_Type type,
   case GNUNET_BLOCK_TYPE_MESH_PEER:
     if (sizeof (struct PBlock) != block_size)
       return GNUNET_SYSERR;
-    *key = pb->id.hashPubKey;
-    return GNUNET_OK;
-  case GNUNET_BLOCK_TYPE_MESH_PEER_BY_TYPE:
-    GNUNET_CRYPTO_hash (&pb->type, sizeof(GNUNET_MESH_ApplicationType), key);
+    GNUNET_CRYPTO_hash (&pb->id,
+                       sizeof (struct GNUNET_PeerIdentity),
+                       key);
     return GNUNET_OK;
   default:
+    GNUNET_break (0);
     return GNUNET_SYSERR;
   }
 }
@@ -217,14 +144,11 @@ libgnunet_plugin_block_mesh_init (void *cls)
   static enum GNUNET_BLOCK_Type types[] =
   {
     GNUNET_BLOCK_TYPE_MESH_PEER,
-    GNUNET_BLOCK_TYPE_MESH_PEER_BY_TYPE,
-    GNUNET_BLOCK_TYPE_MESH_REGEX,
-    GNUNET_BLOCK_TYPE_MESH_REGEX_ACCEPT,
     GNUNET_BLOCK_TYPE_ANY       /* end of list */
   };
   struct GNUNET_BLOCK_PluginFunctions *api;
 
-  api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions));
+  api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
   api->evaluate = &block_plugin_mesh_evaluate;
   api->get_key = &block_plugin_mesh_get_key;
   api->types = types;