-adding block duplicating detection to template for block plugins
authorChristian Grothoff <christian@grothoff.org>
Tue, 12 Jun 2012 19:02:54 +0000 (19:02 +0000)
committerChristian Grothoff <christian@grothoff.org>
Tue, 12 Jun 2012 19:02:54 +0000 (19:02 +0000)
src/block/plugin_block_template.c

index 6ed675dc9a6624bfaf3f3b86fe555aeb3e78a968..ca5b8744f46b2d3220c8f6cc3e7b3c875ea7a88f 100644 (file)
@@ -53,6 +53,27 @@ block_plugin_template_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
                                 size_t xquery_size, const void *reply_block,
                                 size_t reply_block_size)
 {
+  struct GNUNET_HashCode chash;
+  struct GNUNET_HashCode mhash;
+  /* FIXME: check validity first... */
+     
+  /* mandatory duplicate-detection code... */
+  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, 64 /* BLOOMFILTER_K */);
+    }
+    GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
+  }
+  /* FIXME: other stuff here... */
   return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
 }