-improve UDP logging
[oweals/gnunet.git] / src / regex / regex_block_lib.h
index ad4884f4d70f0b29989803aef9c9543a74f9765a..e5685ba9a238522987ef9554227d77df0e7675f7 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2012,2013 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2012,2013 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -40,10 +40,16 @@ extern "C"
 #include "block_regex.h"
 
 
+/**
+ * Representation of a Regex node (and edges) in the DHT.
+ */
+struct RegexBlock;
+
+
 /**
  * Edge representation.
  */
-struct REGEX_INTERNAL_Edge
+struct REGEX_BLOCK_Edge
 {
   /**
    * Label of the edge.  FIXME: might want to not consume exactly multiples of 8 bits, need length!
@@ -57,11 +63,27 @@ struct REGEX_INTERNAL_Edge
 };
 
 
+/**
+ * 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_BLOCK_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.
  * @param size The size of the block.
+ * @param query the query for the block
  * @param xquery String describing the edge we are looking for.
  *               Can be NULL in case this is a put block.
  *
@@ -70,12 +92,13 @@ struct REGEX_INTERNAL_Edge
  *         GNUNET_SYSERR if the block is invalid.
  */
 int
-REGEX_INTERNAL_block_check (const struct RegexBlock *block,
-                           size_t size,
-                           const char *xquery);
+REGEX_BLOCK_check (const struct RegexBlock *block,
+                  size_t size,
+                  const struct GNUNET_HashCode *query,
+                  const char *xquery);
 
 
-/* FIXME: might want to use 'struct REGEX_INTERNAL_Edge' here instead of 3 arguments! */
+/* FIXME: might want to use 'struct REGEX_BLOCK_Edge' here instead of 3 arguments! */
 
 /**
  * Iterator over edges in a block.
@@ -83,14 +106,14 @@ REGEX_INTERNAL_block_check (const struct RegexBlock *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.
  */
 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);
 
 
 /**
@@ -110,11 +133,36 @@ typedef int (*REGEX_INTERNAL_EgdeIterator)(void *cls,
  *         be errors in further edges.
  */
 int
-REGEX_INTERNAL_block_iterate (const struct RegexBlock *block,
+REGEX_BLOCK_iterate (const struct RegexBlock *block,
                             size_t size,
                             REGEX_INTERNAL_EgdeIterator iterator,
                             void *iter_cls);
 
+/**
+ * Obtain the key that a particular block is to be stored under.
+ *
+ * @param block block to get the key from
+ * @param block_len number of bytes in block
+ * @param key where to store the key
+ * @return GNUNET_OK on success, GNUNET_SYSERR if the block is malformed
+ */
+int
+REGEX_BLOCK_get_key (const struct RegexBlock *block,
+                    size_t block_len,
+                    struct GNUNET_HashCode *key);
+
+
+/**
+ * Test if this block is marked as being an accept state.
+ *
+ * @param block block to test
+ * @param size number of bytes in block
+ * @return GNUNET_YES if the block is accepting, GNUNET_NO if not
+ */
+int
+GNUNET_BLOCK_is_accepting (const struct RegexBlock *block,
+                          size_t block_len);
+
 
 /**
  * Construct a regex block to be stored in the DHT.
@@ -122,15 +170,16 @@ REGEX_INTERNAL_block_iterate (const struct RegexBlock *block,
  * @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
+ * @param accepting is this an accepting state
+ * @param rsize set to the size of the returned block (OUT-only)
+ * @return the regex block, NULL on error
  */
 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);
+REGEX_BLOCK_create (const char *proof,
+                   unsigned int num_edges,
+                   const struct REGEX_BLOCK_Edge *edges,
+                   int accepting,
+                   size_t *rsize);
 
 
 #if 0                           /* keep Emacsens' auto-indent happy */