gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r22134 - in gnunet/src: block fs include mesh namestore


From: gnunet
Subject: [GNUnet-SVN] r22134 - in gnunet/src: block fs include mesh namestore
Date: Wed, 20 Jun 2012 11:36:46 +0200

Author: grothoff
Date: 2012-06-20 11:36:46 +0200 (Wed, 20 Jun 2012)
New Revision: 22134

Modified:
   gnunet/src/block/plugin_block_test.c
   gnunet/src/fs/plugin_block_fs.c
   gnunet/src/include/gnunet_block_lib.h
   gnunet/src/mesh/plugin_block_mesh.c
   gnunet/src/namestore/gnunet-service-namestore.c
Log:
-towards block plugin for mesh

Modified: gnunet/src/block/plugin_block_test.c
===================================================================
--- gnunet/src/block/plugin_block_test.c        2012-06-20 09:25:57 UTC (rev 
22133)
+++ gnunet/src/block/plugin_block_test.c        2012-06-20 09:36:46 UTC (rev 
22134)
@@ -28,9 +28,7 @@
 #include "platform.h"
 #include "gnunet_block_plugin.h"
 
-#define DEBUG_TEST GNUNET_EXTRA_LOGGING
 
-
 /**
  * Number of bits we set per entry in the bloomfilter.
  * Do not change!
@@ -63,9 +61,9 @@
   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;

Modified: gnunet/src/fs/plugin_block_fs.c
===================================================================
--- gnunet/src/fs/plugin_block_fs.c     2012-06-20 09:25:57 UTC (rev 22133)
+++ gnunet/src/fs/plugin_block_fs.c     2012-06-20 09:36:46 UTC (rev 22134)
@@ -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.

Modified: gnunet/src/include/gnunet_block_lib.h
===================================================================
--- gnunet/src/include/gnunet_block_lib.h       2012-06-20 09:25:57 UTC (rev 
22133)
+++ gnunet/src/include/gnunet_block_lib.h       2012-06-20 09:36:46 UTC (rev 
22134)
@@ -103,7 +103,12 @@
     /**
      * 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
 };
 
 

Modified: gnunet/src/mesh/plugin_block_mesh.c
===================================================================
--- gnunet/src/mesh/plugin_block_mesh.c 2012-06-20 09:25:57 UTC (rev 22133)
+++ gnunet/src/mesh/plugin_block_mesh.c 2012-06-20 09:36:46 UTC (rev 22134)
@@ -26,9 +26,15 @@
 
 #include "platform.h"
 #include "gnunet_block_plugin.h"
+#include "block_mesh.h"
 
-#define DEBUG_MESH_BLOCK GNUNET_EXTRA_LOGGING
+/**
+ * Number of bits we set per entry in the bloomfilter.
+ * Do not change!
+ */
+#define BLOOMFILTER_K 16
 
+
 /**
  * Function called to validate a reply or a request.  For
  * request evaluation, simply pass "NULL" for the reply_block.
@@ -55,16 +61,52 @@
                             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)
+  struct GNUNET_HashCode chash;
+  struct GNUNET_HashCode mhash;
+
+  switch (type)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Type MESH PEER\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;
   }
-  else
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Other type\n");
-  }
-  return GNUNET_BLOCK_EVALUATION_OK_LAST;
 }
 
 
@@ -84,8 +126,20 @@
                            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 @@
   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;

Modified: gnunet/src/namestore/gnunet-service-namestore.c
===================================================================
--- gnunet/src/namestore/gnunet-service-namestore.c     2012-06-20 09:25:57 UTC 
(rev 22133)
+++ gnunet/src/namestore/gnunet-service-namestore.c     2012-06-20 09:36:46 UTC 
(rev 22134)
@@ -1137,31 +1137,34 @@
   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 @@
     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 @@
     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 @@
 
   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));




reply via email to

[Prev in Thread] Current Thread [Next in Thread]