gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r27649 - in gnunet/src: include regex


From: gnunet
Subject: [GNUnet-SVN] r27649 - in gnunet/src: include regex
Date: Thu, 27 Jun 2013 13:31:48 +0200

Author: grothoff
Date: 2013-06-27 13:31:48 +0200 (Thu, 27 Jun 2013)
New Revision: 27649

Modified:
   gnunet/src/include/block_regex.h
   gnunet/src/regex/regex_block_lib.c
   gnunet/src/regex/regex_block_lib.h
   gnunet/src/regex/regex_internal_dht.c
Log:
-move struct RegexBlock into regex_block_lib

Modified: gnunet/src/include/block_regex.h
===================================================================
--- gnunet/src/include/block_regex.h    2013-06-27 10:37:55 UTC (rev 27648)
+++ gnunet/src/include/block_regex.h    2013-06-27 11:31:48 UTC (rev 27649)
@@ -43,51 +43,6 @@
 
 
 /**
- * @brief A RegexBlock contains one or more of this struct in the payload.
- */
-struct RegexEdge
-{
-  /**
-   * Destination of this edge.
-   */
-  struct GNUNET_HashCode key;
-  
-  /**
-   * Length of the token towards the new state.
-   */
-  uint32_t n_token GNUNET_PACKED;
-
-  /* char token[n_token] */
-};
-
-
-/**
- * @brief Block to announce a regex state.
- */
-struct RegexBlock
-{
-
-  /**
-   * Length of the proof regex string.
-   */
-  uint16_t proof_len GNUNET_PACKED;
-
-  /**
-   * Is this state an accepting state?
-   */
-  int16_t is_accepting GNUNET_PACKED;
-
-  /**
-   * Numer of edges parting from this state.
-   */
-  uint32_t n_edges GNUNET_PACKED;
-
-  /* char proof[n_proof] */
-  /* struct RegexEdge edges[n_edges] */
-};
-
-
-/**
  * @brief Block to announce a peer accepting a state.
  */
 struct RegexAcceptBlock

Modified: gnunet/src/regex/regex_block_lib.c
===================================================================
--- gnunet/src/regex/regex_block_lib.c  2013-06-27 10:37:55 UTC (rev 27648)
+++ gnunet/src/regex/regex_block_lib.c  2013-06-27 11:31:48 UTC (rev 27649)
@@ -28,8 +28,70 @@
 
 #define LOG(kind,...) GNUNET_log_from (kind,"regex-bck",__VA_ARGS__)
 
+GNUNET_NETWORK_STRUCT_BEGIN
 
 /**
+ * @brief Block to announce a regex state.
+ */
+struct RegexBlock
+{
+
+  /**
+   * Length of the proof regex string.
+   */
+  uint16_t proof_len GNUNET_PACKED;
+
+  /**
+   * Is this state an accepting state?
+   */
+  int16_t is_accepting GNUNET_PACKED;
+
+  /**
+   * Numer of edges parting from this state.
+   */
+  uint32_t n_edges GNUNET_PACKED;
+
+  /* char proof[n_proof] */
+  /* struct RegexEdge edges[n_edges] */
+};
+
+
+/**
+ * @brief A RegexBlock contains one or more of this struct in the payload.
+ */
+struct RegexEdge
+{
+  /**
+   * Destination of this edge.
+   */
+  struct GNUNET_HashCode key;
+  
+  /**
+   * Length of the token towards the new state.
+   */
+  uint32_t n_token GNUNET_PACKED;
+
+  /* char token[n_token] */
+};
+
+
+GNUNET_NETWORK_STRUCT_END
+
+
+/**
+ * Test if this block is marked as being an accept state.
+ *
+ * @param block block to test
+ * @return GNUNET_YES if the block is accepting, GNUNET_NO if not
+ */ 
+int
+GNUNET_BLOCK_is_accepting (const struct RegexBlock *block)
+{
+  return ntohs (block->is_accepting);
+}
+
+
+/**
  * Check if the given 'proof' matches the given 'key'.
  *
  * @param proof partial regex of a state

Modified: gnunet/src/regex/regex_block_lib.h
===================================================================
--- gnunet/src/regex/regex_block_lib.h  2013-06-27 10:37:55 UTC (rev 27648)
+++ gnunet/src/regex/regex_block_lib.h  2013-06-27 11:31:48 UTC (rev 27649)
@@ -41,6 +41,12 @@
 
 
 /**
+ * Representation of a Regex node (and edges) in the DHT.
+ */
+struct RegexBlock;
+
+
+/**
  * Edge representation.
  */
 struct REGEX_BLOCK_Edge
@@ -146,7 +152,16 @@
                     struct GNUNET_HashCode *key);
 
 
+/**
+ * Test if this block is marked as being an accept state.
+ *
+ * @param block block to test
+ * @return GNUNET_YES if the block is accepting, GNUNET_NO if not
+ */ 
+int
+GNUNET_BLOCK_is_accepting (const struct RegexBlock *block);
 
+
 /**
  * Construct a regex block to be stored in the DHT.
  *

Modified: gnunet/src/regex/regex_internal_dht.c
===================================================================
--- gnunet/src/regex/regex_internal_dht.c       2013-06-27 10:37:55 UTC (rev 
27648)
+++ gnunet/src/regex/regex_internal_dht.c       2013-06-27 11:31:48 UTC (rev 
27649)
@@ -107,36 +107,36 @@
        num_edges);
   if (GNUNET_YES == accepting)
   {
-    struct RegexAcceptBlock block;
+    struct RegexAcceptBlock ab;
 
     LOG (GNUNET_ERROR_TYPE_DEBUG,
          "State %s is accepting, putting own id\n",
          GNUNET_h2s(key));
-    size = sizeof (block);
-    block.purpose.size = sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
+    size = sizeof (struct RegexAcceptBlock);
+    ab.purpose.size = sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
       sizeof (struct GNUNET_TIME_AbsoluteNBO) +
       sizeof (struct GNUNET_HashCode);
-    block.purpose.purpose = ntohl (GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT);
-    block.expiration_time = GNUNET_TIME_absolute_hton 
(GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_DHT_MAX_EXPIRATION));
-    block.key = *key;
+    ab.purpose.purpose = ntohl (GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT);
+    ab.expiration_time = GNUNET_TIME_absolute_hton 
(GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_DHT_MAX_EXPIRATION));
+    ab.key = *key;
     GNUNET_CRYPTO_ecc_key_get_public (h->priv,
-                                     &block.public_key);
+                                     &ab.public_key);
     GNUNET_assert (GNUNET_OK ==
                   GNUNET_CRYPTO_ecc_sign (h->priv,
-                                          &block.purpose,
-                                          &block.signature));
+                                          &ab.purpose,
+                                          &ab.signature));
 
     GNUNET_STATISTICS_update (h->stats, "# regex accepting blocks stored",
                               1, GNUNET_NO);
     GNUNET_STATISTICS_update (h->stats, "# regex accepting block bytes stored",
-                              sizeof (block), GNUNET_NO);
+                              sizeof (struct RegexAcceptBlock), GNUNET_NO);
     (void)
     GNUNET_DHT_put (h->dht, key,
                     DHT_REPLICATION,
                     DHT_OPT | GNUNET_DHT_RO_RECORD_ROUTE,
                     GNUNET_BLOCK_TYPE_REGEX_ACCEPT,
                     size,
-                    &block,
+                    &ab,
                     GNUNET_TIME_relative_to_absolute (DHT_TTL),
                     DHT_TTL,
                     NULL, NULL);
@@ -463,7 +463,7 @@
   GNUNET_free (datastore);
 
   copy = GNUNET_malloc (size);
-  memcpy (copy, data, size);
+  memcpy (copy, block, size);
   GNUNET_break (
     GNUNET_OK ==
     GNUNET_CONTAINER_multihashmap_put (info->dht_get_results,
@@ -473,7 +473,7 @@
   len = strlen (info->description);
   if (len == ctx->position) // String processed
   {
-    if (GNUNET_YES == ntohs (block->is_accepting))
+    if (GNUNET_YES == GNUNET_BLOCK_is_accepting (block))
     {
       regex_find_path (key, ctx);
     }
@@ -504,8 +504,9 @@
   struct RegexBlock *block = value;
   struct RegexSearchContext *ctx = cls;
 
-  if (GNUNET_YES == ntohs (block->is_accepting) &&
-      ctx->position == strlen (ctx->info->description))
+  if ( (GNUNET_YES == 
+       GNUNET_BLOCK_is_accepting (block)) &&
+       (ctx->position == strlen (ctx->info->description)) )
   {
     LOG (GNUNET_ERROR_TYPE_INFO, " * Found accepting known block\n");
     regex_find_path (key, ctx);
@@ -513,7 +514,7 @@
   }
   LOG (GNUNET_ERROR_TYPE_DEBUG, "* %u, %u, [%u]\n",
        ctx->position, strlen(ctx->info->description),
-       ntohs (block->is_accepting));
+       GNUNET_BLOCK_is_accepting (block));
 
   regex_next_edge (block, SIZE_MAX, ctx);
 




reply via email to

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