-towards block plugin for mesh
authorChristian Grothoff <christian@grothoff.org>
Wed, 20 Jun 2012 09:36:46 +0000 (09:36 +0000)
committerChristian Grothoff <christian@grothoff.org>
Wed, 20 Jun 2012 09:36:46 +0000 (09:36 +0000)
src/block/plugin_block_test.c
src/fs/plugin_block_fs.c
src/include/gnunet_block_lib.h
src/mesh/plugin_block_mesh.c
src/namestore/gnunet-service-namestore.c

index e6b4f496007885934c7178b3a80da769a0ac150d..dacf0453522f582efe3b6e934ef758521bdf3ac1 100644 (file)
@@ -28,8 +28,6 @@
 #include "platform.h"
 #include "gnunet_block_plugin.h"
 
-#define DEBUG_TEST GNUNET_EXTRA_LOGGING
-
 
 /**
  * Number of bits we set per entry in the bloomfilter.
@@ -63,9 +61,9 @@ block_plugin_test_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
   struct GNUNET_HashCode chash;
   struct GNUNET_HashCode mhash;
 
-  if (type != GNUNET_BLOCK_TYPE_TEST)
+  if ( GNUNET_BLOCK_TYPE_TEST != type)
     return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
-  if (xquery_size != 0)
+  if (0 != xquery_size)
   {
     GNUNET_break_op (0);
     return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
index c43a5de5ed5d57652dbb22be7263d7cde0da2c7e..2e4f7ef873047ef32d2a6fad5001dbb9fe8abe8e 100644 (file)
@@ -29,7 +29,6 @@
 #include "block_fs.h"
 #include "gnunet_signatures.h"
 
-#define DEBUG_FS_BLOCK GNUNET_EXTRA_LOGGING
 
 /**
  * Number of bits we set per entry in the bloomfilter.
index d651476a8a0a43d9839c292cce2940eb2dc26f5b..5498fe74d536f66be90bd15c070708e27975ce90 100644 (file)
@@ -103,7 +103,12 @@ enum GNUNET_BLOCK_Type
     /**
      * Block for storing mesh peers
      */
-  GNUNET_BLOCK_TYPE_MESH_PEER = 20
+  GNUNET_BLOCK_TYPE_MESH_PEER = 20,
+
+    /**
+     * Block for finding peers by type
+     */
+  GNUNET_BLOCK_TYPE_MESH_PEER_BY_TYPE = 21
 };
 
 
index c5bb458bd3410caa5d28d18c4fffb66f7cbe1378..8b601652fa116d82971f29fb86e4f936728333e3 100644 (file)
 
 #include "platform.h"
 #include "gnunet_block_plugin.h"
+#include "block_mesh.h"
+
+/**
+ * Number of bits we set per entry in the bloomfilter.
+ * Do not change!
+ */
+#define BLOOMFILTER_K 16
 
-#define DEBUG_MESH_BLOCK GNUNET_EXTRA_LOGGING
 
 /**
  * Function called to validate a reply or a request.  For
@@ -55,16 +61,52 @@ block_plugin_mesh_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
                             size_t xquery_size, const void *reply_block,
                             size_t reply_block_size)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Evaluate called\n");
-  if (GNUNET_BLOCK_TYPE_MESH_PEER == type)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Type MESH PEER\n");
-  }
-  else
+  struct GNUNET_HashCode chash;
+  struct GNUNET_HashCode mhash;
+
+  switch (type)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Other type\n");
+  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)
+      {
+       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;
   }
-  return GNUNET_BLOCK_EVALUATION_OK_LAST;
 }
 
 
@@ -84,8 +126,20 @@ block_plugin_mesh_get_key (void *cls, enum GNUNET_BLOCK_Type type,
                            const void *block, size_t block_size,
                            struct GNUNET_HashCode * key)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Get key called\n");
-  return GNUNET_SYSERR;
+  const struct PBlock *pb;
+
+  switch (type)
+  {
+  case GNUNET_BLOCK_TYPE_MESH_PEER:
+    if (sizeof (struct PBlock) != block_size)
+      return GNUNET_SYSERR;
+    pb = block;
+    *key = pb->id.hashPubKey;
+    return GNUNET_OK;
+    // FIXME: other types...
+  default:
+    return GNUNET_SYSERR;
+  }
 }
 
 
@@ -98,6 +152,7 @@ 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_ANY       /* end of list */
   };
   struct GNUNET_BLOCK_PluginFunctions *api;
index e67ffaa653645c2b1082e9866581686787cfe5c3..250e2b812b4194c068710ed1abf5534fef6b52ab 100644 (file)
@@ -1137,31 +1137,34 @@ handle_record_remove_it (void *cls,
   rrc->op_res = 0;
 }
 
-static void handle_record_remove (void *cls,
-                          struct GNUNET_SERVER_Client * client,
-                          const struct GNUNET_MessageHeader * message)
+
+static void
+handle_record_remove (void *cls,
+                     struct GNUNET_SERVER_Client * client,
+                     const struct GNUNET_MessageHeader * message)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_REMOVE");
   struct GNUNET_NAMESTORE_Client *nc;
+  const struct RecordRemoveMessage * rr_msg;
   struct RecordRemoveResponseMessage rrr_msg;
   struct GNUNET_CRYPTO_RsaPrivateKey *pkey;
-  struct GNUNET_NAMESTORE_CryptoContainer *cc = NULL;
+  struct GNUNET_NAMESTORE_CryptoContainer *cc;
   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub;
   struct GNUNET_CRYPTO_ShortHashCode pubkey_hash;
   struct GNUNET_HashCode long_hash;
-  char * pkey_tmp = NULL;
-  char * name_tmp = NULL;
-  char * rd_ser = NULL;
-  size_t key_len = 0;
-  size_t name_len = 0;
-  size_t rd_ser_len = 0;
-  size_t msg_size = 0;
+  const char * pkey_tmp;
+  const char * name_tmp;
+  const char * rd_ser;
+  size_t key_len;
+  size_t name_len;
+  size_t rd_ser_len;
+  size_t msg_size;
   size_t msg_size_exp = 0;
   uint32_t rd_count;
-  uint32_t rid = 0;
+  uint32_t rid;
 
   int res = GNUNET_SYSERR;
 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_REMOVE");
   if (ntohs (message->size) < sizeof (struct RecordRemoveMessage))
   {
     GNUNET_break_op (0);
@@ -1177,7 +1180,7 @@ static void handle_record_remove (void *cls,
     return;
   }
 
-  struct RecordRemoveMessage * rr_msg = (struct RecordRemoveMessage *) message;
+  rr_msg = (const struct RecordRemoveMessage *) message;
   rid = ntohl (rr_msg->gns_header.r_id);
   name_len = ntohs (rr_msg->name_len);
   rd_ser_len = ntohs (rr_msg->rd_len);
@@ -1208,7 +1211,7 @@ static void handle_record_remove (void *cls,
     return;
   }
 
-  pkey_tmp = (char *) &rr_msg[1];
+  pkey_tmp = (const char *) &rr_msg[1];
   name_tmp = &pkey_tmp[key_len];
   rd_ser = &name_tmp[name_len];
 
@@ -1236,7 +1239,9 @@ static void handle_record_remove (void *cls,
 
   if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(zonekeys, &long_hash))
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received new private key for zone `%s'\n",GNUNET_short_h2s(&pubkey_hash));
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
+               "Received new private key for zone `%s'\n",
+               GNUNET_short_h2s(&pubkey_hash));
     cc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer));
     cc->privkey = GNUNET_CRYPTO_rsa_decode_key((char *) pkey_tmp, key_len);
     cc->pubkey = GNUNET_malloc(sizeof (pub));