[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r27621 - gnunet/src/regex
From: |
gnunet |
Subject: |
[GNUnet-SVN] r27621 - gnunet/src/regex |
Date: |
Wed, 26 Jun 2013 13:50:17 +0200 |
Author: grothoff
Date: 2013-06-26 13:50:16 +0200 (Wed, 26 Jun 2013)
New Revision: 27621
Modified:
gnunet/src/regex/plugin_block_regex.c
gnunet/src/regex/regex_block_lib.c
gnunet/src/regex/regex_block_lib.h
gnunet/src/regex/regex_internal_dht.c
gnunet/src/regex/regex_internal_lib.h
Log:
-cleaning up block code, moving all of the block logic into the block library
Modified: gnunet/src/regex/plugin_block_regex.c
===================================================================
--- gnunet/src/regex/plugin_block_regex.c 2013-06-26 11:25:29 UTC (rev
27620)
+++ gnunet/src/regex/plugin_block_regex.c 2013-06-26 11:50:16 UTC (rev
27621)
@@ -48,11 +48,12 @@
*/
static int
rdebug (void *cls,
- const char *token,
- size_t len,
- const struct GNUNET_HashCode *key)
+ const char *token,
+ size_t len,
+ const struct GNUNET_HashCode *key)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %s: %.*s\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s: %.*s\n",
GNUNET_h2s (key), len, token);
return GNUNET_YES;
}
@@ -92,7 +93,7 @@
const char *query;
query = (const char *) xquery;
- if ('\0' != query[xquery_size - 1]) /* must be valid string */
+ if ('\0' != query[xquery_size - 1]) /* must be valid 0-terminated string */
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Block xquery not a valid string\n");
@@ -111,8 +112,8 @@
return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
}
switch (REGEX_INTERNAL_block_check (reply_block,
- reply_block_size,
- xquery))
+ reply_block_size,
+ xquery))
{
case GNUNET_SYSERR:
GNUNET_break_op(0);
Modified: gnunet/src/regex/regex_block_lib.c
===================================================================
--- gnunet/src/regex/regex_block_lib.c 2013-06-26 11:25:29 UTC (rev 27620)
+++ gnunet/src/regex/regex_block_lib.c 2013-06-26 11:50:16 UTC (rev 27621)
@@ -20,6 +20,8 @@
/**
* @author Bartlomiej Polot
* @file regex/regex_block_lib.c
+ * @brief functions for manipulating non-accept blocks stored for
+ * regex in the DHT
*/
#include "platform.h"
#include "regex_block_lib.h"
@@ -66,45 +68,32 @@
{
struct regex_block_xquery_ctx *ctx = cls;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " edge %.*s [%u]: %s->%s\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "edge %.*s [%u]: %s->%s\n",
(int) len, token, len, ctx->key, GNUNET_h2s(key));
-
if (NULL == ctx->xquery)
return GNUNET_YES;
if (strlen (ctx->xquery) < len)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " too long!\n");
- return GNUNET_YES;
- }
+ return GNUNET_YES; /* too long */
if (0 == strncmp (ctx->xquery, token, len))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " OK!\n");
ctx->found = GNUNET_OK;
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " KO!\n");
- }
-
return GNUNET_YES; /* keep checking for malformed data! */
}
int
REGEX_INTERNAL_block_check (const struct RegexBlock *block,
- size_t size,
- const char *xquery)
+ size_t size,
+ const char *xquery)
{
int res;
struct regex_block_xquery_ctx ctx;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "* Checking block with xquery \"%s\"\n",
+ "Checking block with xquery `%s'\n",
NULL != xquery ? xquery : "NULL");
if ( (GNUNET_YES == ntohl (block->accepting)) &&
- ( (NULL == xquery) || ('\0' == xquery[0]) )
- )
+ ( (NULL == xquery) || ('\0' == xquery[0]) ) )
return GNUNET_OK;
ctx.xquery = xquery;
ctx.found = GNUNET_NO;
@@ -133,31 +122,24 @@
char *aux;
offset = sizeof (struct RegexBlock);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "* Start iterating block of size %u, off %u\n",
- size, offset);
if (offset >= size) /* Is it safe to access the regex block? */
{
- LOG (GNUNET_ERROR_TYPE_WARNING,
- "* Block is smaller than struct RegexBlock, END\n");
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
n = ntohl (block->n_proof);
offset += n;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "* Proof length: %u, off %u\n", n, offset);
if (offset >= size) /* Is it safe to access the regex proof? */
{
- LOG (GNUNET_ERROR_TYPE_WARNING,
- "* Block is smaller than Block + proof, END\n");
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
aux = (char *) &block[1]; /* Skip regex block */
aux = &aux[n]; /* Skip regex proof */
n = ntohl (block->n_edges);
- LOG (GNUNET_ERROR_TYPE_DEBUG, "* Edges: %u\n", n);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Start iterating block of size %u, proof %u, off %u edges %u\n",
+ size, ntohl (block->n_proof), offset, n);
/* aux always points at the end of the previous block */
for (i = 0; i < n; i++)
{
@@ -191,15 +173,74 @@
/* The total size should be exactly the size of (regex + all edges) blocks
* If size == -1, block is from cache and therefore previously checked and
* assumed correct. */
- if (offset == size || SIZE_MAX == size)
+ if ( (offset != size) && (SIZE_MAX != size) )
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "* Block processed, END OK\n");
- return GNUNET_OK;
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
}
- LOG (GNUNET_ERROR_TYPE_WARNING,
- "* Size %u (%d), read %u END KO\n", size, size, offset);
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
+ return GNUNET_OK;
}
+
+/**
+ * Construct a regex block to be stored in the DHT.
+ *
+ * @param proof proof string for the block
+ * @param num_edges number of edges in the block
+ * @param edges the edges of the block
+ * @return the regex block
+ */
+struct RegexBlock *
+REGEX_INTERNAL_block_create (const struct GNUNET_HashCode *key,
+ const char *proof,
+ unsigned int num_edges,
+ const struct REGEX_INTERNAL_Edge *edges,
+ int accepting,
+ size_t *rsize)
+{
+ struct RegexBlock *block;
+ struct RegexEdge *block_edge;
+ size_t size;
+ size_t len;
+ unsigned int i;
+ unsigned int offset;
+ char *aux;
+
+ len = strlen(proof);
+ size = sizeof (struct RegexBlock) + len;
+ block = GNUNET_malloc (size);
+ block->key = *key;
+ block->n_proof = htonl (len);
+ block->n_edges = htonl (num_edges);
+ block->accepting = htonl (accepting);
+
+ /* Store the proof at the end of the block. */
+ aux = (char *) &block[1];
+ memcpy (aux, proof, len);
+ aux = &aux[len];
+
+ /* Store each edge in a variable length MeshEdge struct at the
+ * very end of the MeshRegexBlock structure.
+ */
+ for (i = 0; i < num_edges; i++)
+ {
+ /* aux points at the end of the last block */
+ len = strlen (edges[i].label);
+ size += sizeof (struct RegexEdge) + len;
+ // Calculate offset FIXME is this ok? use size instead?
+ offset = aux - (char *) block;
+ block = GNUNET_realloc (block, size);
+ aux = &((char *) block)[offset];
+ block_edge = (struct RegexEdge *) aux;
+ block_edge->key = edges[i].destination;
+ block_edge->n_token = htonl (len);
+ aux = (char *) &block_edge[1];
+ memcpy (aux, edges[i].label, len);
+ aux = &aux[len];
+ }
+ *rsize = size;
+ return block;
+}
+
+
/* end of regex_block_lib.c */
Modified: gnunet/src/regex/regex_block_lib.h
===================================================================
--- gnunet/src/regex/regex_block_lib.h 2013-06-26 11:25:29 UTC (rev 27620)
+++ gnunet/src/regex/regex_block_lib.h 2013-06-26 11:50:16 UTC (rev 27621)
@@ -39,7 +39,25 @@
#include "platform.h"
#include "block_regex.h"
+
/**
+ * Edge representation.
+ */
+struct REGEX_INTERNAL_Edge
+{
+ /**
+ * Label of the edge. FIXME: might want to not consume exactly multiples of
8 bits, need length!
+ */
+ const char *label;
+
+ /**
+ * Destionation of the edge.
+ */
+ struct GNUNET_HashCode destination;
+};
+
+
+/**
* Check if the regex block is well formed, including all edges.
*
* @param block The start of the block.
@@ -53,16 +71,19 @@
*/
int
REGEX_INTERNAL_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_INTERNAL_Edge' here instead of 3
arguments! */
+
/**
* Iterator over edges in a block.
*
* @param cls Closure.
* @param token Token that follows to next state.
* @param len Length of token.
- * @param key Hash of next state.
+ * @param key Hash of next state.
*
* @return GNUNET_YES if should keep iterating, GNUNET_NO otherwise.
*/
@@ -94,6 +115,24 @@
REGEX_INTERNAL_EgdeIterator iterator,
void *iter_cls);
+
+/**
+ * Construct a regex block to be stored in the DHT.
+ *
+ * @param proof proof string for the block
+ * @param num_edges number of edges in the block
+ * @param edges the edges of the block
+ * @return the regex block
+ */
+struct RegexBlock *
+REGEX_INTERNAL_block_create (const struct GNUNET_HashCode *key,
+ const char *proof,
+ unsigned int num_edges,
+ const struct REGEX_INTERNAL_Edge *edges,
+ int accepting,
+ size_t *rsize);
+
+
#if 0 /* keep Emacsens' auto-indent happy */
{
#endif
Modified: gnunet/src/regex/regex_internal_dht.c
===================================================================
--- gnunet/src/regex/regex_internal_dht.c 2013-06-26 11:25:29 UTC (rev
27620)
+++ gnunet/src/regex/regex_internal_dht.c 2013-06-26 11:50:16 UTC (rev
27621)
@@ -91,25 +91,19 @@
{
struct REGEX_INTERNAL_Announcement *h = cls;
struct RegexBlock *block;
- struct RegexEdge *block_edge;
size_t size;
- size_t len;
- unsigned int i;
- unsigned int offset;
- char *aux;
LOG (GNUNET_ERROR_TYPE_DEBUG,
- " regex dht put for state %s\n",
- GNUNET_h2s (key));
- LOG (GNUNET_ERROR_TYPE_DEBUG, " proof: %s\n", proof);
- LOG (GNUNET_ERROR_TYPE_DEBUG, " num edges: %u\n", num_edges);
-
+ "DHT PUT for state %s with proof `%s' and %u edges\n",
+ GNUNET_h2s (key),
+ proof,
+ num_edges);
if (GNUNET_YES == accepting)
{
struct RegexAccept block;
LOG (GNUNET_ERROR_TYPE_DEBUG,
- " state %s is accepting, putting own id\n",
+ "State %s is accepting, putting own id\n",
GNUNET_h2s(key));
size = sizeof (block);
block.key = *key;
@@ -124,53 +118,21 @@
DHT_OPT | GNUNET_DHT_RO_RECORD_ROUTE,
GNUNET_BLOCK_TYPE_REGEX_ACCEPT,
size,
- (char *) &block,
+ &block,
GNUNET_TIME_relative_to_absolute (DHT_TTL),
DHT_TTL,
NULL, NULL);
}
- len = strlen(proof);
- size = sizeof (struct RegexBlock) + len;
- block = GNUNET_malloc (size);
-
- block->key = *key;
- block->n_proof = htonl (len);
- block->n_edges = htonl (num_edges);
- block->accepting = htonl (accepting);
-
- /* Store the proof at the end of the block. */
- aux = (char *) &block[1];
- memcpy (aux, proof, len);
- aux = &aux[len];
-
- /* Store each edge in a variable length MeshEdge struct at the
- * very end of the MeshRegexBlock structure.
- */
- for (i = 0; i < num_edges; i++)
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG, " edge %s towards %s\n",
- edges[i].label, GNUNET_h2s(&edges[i].destination));
-
- /* aux points at the end of the last block */
- len = strlen (edges[i].label);
- size += sizeof (struct RegexEdge) + len;
- // Calculate offset FIXME is this ok? use size instead?
- offset = aux - (char *) block;
- block = GNUNET_realloc (block, size);
- aux = &((char *) block)[offset];
- block_edge = (struct RegexEdge *) aux;
- block_edge->key = edges[i].destination;
- block_edge->n_token = htonl (len);
- aux = (char *) &block_edge[1];
- memcpy (aux, edges[i].label, len);
- aux = &aux[len];
- }
+ block = REGEX_INTERNAL_block_create (key, proof,
+ num_edges, edges,
+ accepting,
+ &size);
(void)
GNUNET_DHT_put (h->dht, key,
DHT_REPLICATION,
DHT_OPT,
- GNUNET_BLOCK_TYPE_REGEX, size,
- (char *) block,
+ GNUNET_BLOCK_TYPE_REGEX,
+ size, block,
GNUNET_TIME_relative_to_absolute (DHT_TTL),
DHT_TTL,
NULL, NULL);
Modified: gnunet/src/regex/regex_internal_lib.h
===================================================================
--- gnunet/src/regex/regex_internal_lib.h 2013-06-26 11:25:29 UTC (rev
27620)
+++ gnunet/src/regex/regex_internal_lib.h 2013-06-26 11:50:16 UTC (rev
27621)
@@ -29,6 +29,7 @@
#include "gnunet_util_lib.h"
#include "gnunet_dht_service.h"
#include "gnunet_statistics_service.h"
+#include "regex_block_lib.h"
#ifdef __cplusplus
extern "C"
@@ -46,23 +47,6 @@
/**
- * Edge representation.
- */
-struct REGEX_INTERNAL_Edge
-{
- /**
- * Label of the edge. FIXME: might want to not consume exactly multiples of
8 bits, need length?
- */
- const char *label;
-
- /**
- * Destionation of the edge.
- */
- struct GNUNET_HashCode destination;
-};
-
-
-/**
* Construct DFA for the given 'regex' of length 'len'.
*
* Path compression means, that for example a DFA o -> a -> b -> c -> o will be
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r27621 - gnunet/src/regex,
gnunet <=