[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r27626 - gnunet/src/regex
From: |
gnunet |
Subject: |
[GNUnet-SVN] r27626 - gnunet/src/regex |
Date: |
Wed, 26 Jun 2013 14:16:12 +0200 |
Author: grothoff
Date: 2013-06-26 14:16:12 +0200 (Wed, 26 Jun 2013)
New Revision: 27626
Modified:
gnunet/src/regex/Makefile.am
gnunet/src/regex/regex_block_lib.c
gnunet/src/regex/regex_block_lib.h
gnunet/src/regex/regex_internal.c
gnunet/src/regex/regex_internal_dht.c
gnunet/src/regex/regex_internal_lib.h
gnunet/src/regex/test_regex_iterate_api.c
Log:
-moving REGEX_INTERNAL_check_proof to libgnunetregexblock, integrating proof
check into block plugin
Modified: gnunet/src/regex/Makefile.am
===================================================================
--- gnunet/src/regex/Makefile.am 2013-06-26 11:58:56 UTC (rev 27625)
+++ gnunet/src/regex/Makefile.am 2013-06-26 12:16:12 UTC (rev 27626)
@@ -183,8 +183,8 @@
test_regex_iterate_api.c
test_regex_iterate_api_LDADD = -lm \
$(top_builddir)/src/regex/libgnunetregex_internal.a \
+ $(top_builddir)/src/regex/libgnunetregexblock.la \
$(top_builddir)/src/dht/libgnunetdht.la \
- $(top_builddir)/src/regex/libgnunetregexblock.la \
$(top_builddir)/src/util/libgnunetutil.la
test_regex_proofs_SOURCES = \
Modified: gnunet/src/regex/regex_block_lib.c
===================================================================
--- gnunet/src/regex/regex_block_lib.c 2013-06-26 11:58:56 UTC (rev 27625)
+++ gnunet/src/regex/regex_block_lib.c 2013-06-26 12:16:12 UTC (rev 27626)
@@ -28,7 +28,36 @@
#define LOG(kind,...) GNUNET_log_from (kind,"regex-bck",__VA_ARGS__)
+
/**
+ * Check if the given 'proof' matches the given 'key'.
+ *
+ * @param proof partial regex of a state
+ * @param proof_len number of bytes in 'proof'
+ * @param key hash of a state.
+ *
+ * @return GNUNET_OK if the proof is valid for the given key.
+ */
+int
+REGEX_INTERNAL_check_proof (const char *proof,
+ size_t proof_len,
+ const struct GNUNET_HashCode *key)
+{
+ struct GNUNET_HashCode key_check;
+
+ if ( (NULL == proof) || (NULL == key))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Proof check failed, was NULL.\n");
+ return GNUNET_NO;
+ }
+
+ GNUNET_CRYPTO_hash (proof, proof_len, &key_check);
+ return (0 ==
+ GNUNET_CRYPTO_hash_cmp (key, &key_check)) ? GNUNET_OK : GNUNET_NO;
+}
+
+
+/**
* Struct to keep track of the xquery while iterating all the edges in a block.
*/
struct CheckEdgeContext
@@ -100,11 +129,22 @@
{
struct CheckEdgeContext ctx;
int res;
+ uint32_t len;
- // FIXME: fails to check the proof!
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Checking block with xquery `%s'\n",
NULL != xquery ? xquery : "NULL");
+ len = ntohl (block->n_proof);
+ if (size < sizeof (struct RegexBlock) + len)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK != REGEX_INTERNAL_check_proof ((const char *) &block[1], len,
&block->key))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
if ( (GNUNET_YES == ntohl (block->accepting)) &&
( (NULL == xquery) || ('\0' == xquery[0]) ) )
return GNUNET_OK;
Modified: gnunet/src/regex/regex_block_lib.h
===================================================================
--- gnunet/src/regex/regex_block_lib.h 2013-06-26 11:58:56 UTC (rev 27625)
+++ gnunet/src/regex/regex_block_lib.h 2013-06-26 12:16:12 UTC (rev 27626)
@@ -58,6 +58,21 @@
/**
+ * Check if the given 'proof' matches the given 'key'.
+ *
+ * @param proof partial regex of a state
+ * @param proof_len number of bytes in 'proof'
+ * @param key hash of a state.
+ *
+ * @return GNUNET_OK if the proof is valid for the given key.
+ */
+int
+REGEX_INTERNAL_check_proof (const char *proof,
+ size_t proof_len,
+ const struct GNUNET_HashCode *key);
+
+
+/**
* Check if the regex block is well formed, including all edges.
*
* @param block The start of the block.
@@ -71,8 +86,8 @@
*/
int
REGEX_BLOCK_check (const struct RegexBlock *block,
- size_t size,
- const char *xquery);
+ size_t size,
+ const char *xquery);
/* FIXME: might want to use 'struct REGEX_BLOCK_Edge' here instead of 3
arguments! */
@@ -88,9 +103,9 @@
* @return GNUNET_YES if should keep iterating, GNUNET_NO otherwise.
*/
typedef int (*REGEX_INTERNAL_EgdeIterator)(void *cls,
- const char *token,
- size_t len,
- const struct GNUNET_HashCode *key);
+ const char *token,
+ size_t len,
+ const struct GNUNET_HashCode *key);
/**
Modified: gnunet/src/regex/regex_internal.c
===================================================================
--- gnunet/src/regex/regex_internal.c 2013-06-26 11:58:56 UTC (rev 27625)
+++ gnunet/src/regex/regex_internal.c 2013-06-26 12:16:12 UTC (rev 27626)
@@ -3329,31 +3329,6 @@
/**
- * Check if the given 'proof' matches the given 'key'.
- *
- * @param proof partial regex of a state.
- * @param key hash of a state.
- *
- * @return GNUNET_OK if the proof is valid for the given key.
- */
-int
-REGEX_INTERNAL_check_proof (const char *proof, const struct GNUNET_HashCode
*key)
-{
- struct GNUNET_HashCode key_check;
-
- if (NULL == proof || NULL == key)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Proof check failed, was NULL.\n");
- return GNUNET_NO;
- }
-
- GNUNET_CRYPTO_hash (proof, strlen (proof), &key_check);
- return (0 ==
- GNUNET_CRYPTO_hash_cmp (key, &key_check)) ? GNUNET_OK : GNUNET_NO;
-}
-
-
-/**
* Recursive function that calls the iterator for each synthetic start state.
*
* @param min_len minimum length of the path in the graph.
Modified: gnunet/src/regex/regex_internal_dht.c
===================================================================
--- gnunet/src/regex/regex_internal_dht.c 2013-06-26 11:58:56 UTC (rev
27625)
+++ gnunet/src/regex/regex_internal_dht.c 2013-06-26 12:16:12 UTC (rev
27626)
@@ -423,18 +423,6 @@
&((struct RegexBlock *)copy)->key, copy,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)
);
- len = ntohl (block->n_proof);
- {
- char proof[len + 1];
-
- memcpy (proof, &block[1], len);
- proof[len] = '\0';
- if (GNUNET_OK != REGEX_INTERNAL_check_proof (proof, key))
- {
- GNUNET_break_op (0);
- return;
- }
- }
len = strlen (info->description);
if (len == ctx->position) // String processed
{
Modified: gnunet/src/regex/regex_internal_lib.h
===================================================================
--- gnunet/src/regex/regex_internal_lib.h 2013-06-26 11:58:56 UTC (rev
27625)
+++ gnunet/src/regex/regex_internal_lib.h 2013-06-26 12:16:12 UTC (rev
27626)
@@ -108,24 +108,11 @@
/**
- * Check if the given 'proof' matches the given 'key'.
- *
- * @param proof partial regex of a state.
- * @param key hash of a state.
- *
- * @return GNUNET_OK if the proof is valid for the given key.
- */
-int
-REGEX_INTERNAL_check_proof (const char *proof,
- const struct GNUNET_HashCode *key);
-
-
-/**
* Iterator callback function.
*
* @param cls closure.
* @param key hash for current state.
- * @param proof proof for current state.
+ * @param proof proof for current state
* @param accepting GNUNET_YES if this is an accepting state, GNUNET_NO if not.
* @param num_edges number of edges leaving current state.
* @param edges edges leaving current state.
Modified: gnunet/src/regex/test_regex_iterate_api.c
===================================================================
--- gnunet/src/regex/test_regex_iterate_api.c 2013-06-26 11:58:56 UTC (rev
27625)
+++ gnunet/src/regex/test_regex_iterate_api.c 2013-06-26 12:16:12 UTC (rev
27626)
@@ -26,6 +26,7 @@
#include <time.h>
#include "platform.h"
#include "regex_internal_lib.h"
+#include "regex_block_lib.h"
#include "regex_internal.h"
/**
@@ -59,7 +60,8 @@
static void
-key_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof,
+key_iterator (void *cls, const struct GNUNET_HashCode *key,
+ const char *proof,
int accepting, unsigned int num_edges,
const struct REGEX_BLOCK_Edge *edges)
{
@@ -101,7 +103,7 @@
ctx->match_count++;
}
- if (GNUNET_OK != REGEX_INTERNAL_check_proof (proof, key))
+ if (GNUNET_OK != REGEX_INTERNAL_check_proof (proof, strlen (proof), key))
{
ctx->error++;
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r27626 - gnunet/src/regex,
gnunet <=