- add framework for mesh2 mutipeer tests
[oweals/gnunet.git] / src / mesh / plugin_block_mesh.c
index 7c5b9fbeb58280e1b4a6ce140d32a167b6264b9f..3d99201f7877c2e6bfc91bc85e538d99eba1ce21 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
@@ -66,46 +66,68 @@ 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)  
-      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;
+
+
+    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;
+
+    default:
+      return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
   }
 }
 
@@ -127,6 +149,7 @@ block_plugin_mesh_get_key (void *cls, enum GNUNET_BLOCK_Type type,
                            struct GNUNET_HashCode * key)
 {
   const struct PBlock *pb;
+  GNUNET_MESH_ApplicationType app_type;
   pb = block;
 
   switch (type)
@@ -137,9 +160,11 @@ block_plugin_mesh_get_key (void *cls, enum GNUNET_BLOCK_Type type,
     *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);
+    app_type = ntohl (pb->type);
+    GNUNET_CRYPTO_hash (&app_type, sizeof(GNUNET_MESH_ApplicationType), key);
     return GNUNET_OK;
   default:
+    GNUNET_break (0);
     return GNUNET_SYSERR;
   }
 }