2 This file is part of GNUnet.
3 (C) 2012,2013 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @author Bartlomiej Polot
23 * @file regex/regex_block_lib.h
24 * @brief common function to manipulate blocks stored by regex in the DHT
27 #ifndef REGEX_BLOCK_LIB_H_
28 #define REGEX_BLOCK_LIB_H_
34 /* keep Emacsens' auto-indent happy */
40 #include "block_regex.h"
44 * Edge representation.
46 struct REGEX_BLOCK_Edge
49 * Label of the edge. FIXME: might want to not consume exactly multiples of 8 bits, need length!
54 * Destionation of the edge.
56 struct GNUNET_HashCode destination;
61 * Check if the given 'proof' matches the given 'key'.
63 * @param proof partial regex of a state
64 * @param proof_len number of bytes in 'proof'
65 * @param key hash of a state.
67 * @return GNUNET_OK if the proof is valid for the given key.
70 REGEX_INTERNAL_check_proof (const char *proof,
72 const struct GNUNET_HashCode *key);
76 * Check if the regex block is well formed, including all edges.
78 * @param block The start of the block.
79 * @param size The size of the block.
80 * @param xquery String describing the edge we are looking for.
81 * Can be NULL in case this is a put block.
83 * @return GNUNET_OK in case it's fine.
84 * GNUNET_NO in case the xquery exists and is not found (IRRELEVANT).
85 * GNUNET_SYSERR if the block is invalid.
88 REGEX_BLOCK_check (const struct RegexBlock *block,
93 /* FIXME: might want to use 'struct REGEX_BLOCK_Edge' here instead of 3 arguments! */
96 * Iterator over edges in a block.
99 * @param token Token that follows to next state.
100 * @param len Length of token.
101 * @param key Hash of next state.
103 * @return GNUNET_YES if should keep iterating, GNUNET_NO otherwise.
105 typedef int (*REGEX_INTERNAL_EgdeIterator)(void *cls,
108 const struct GNUNET_HashCode *key);
112 * Iterate over all edges of a block of a regex state.
114 * @param block Block to iterate over.
115 * @param size Size of block.
116 * @param iterator Function to call on each edge in the block.
117 * @param iter_cls Closure for the iterator.
119 * @return GNUNET_SYSERR if an error has been encountered.
120 * GNUNET_OK if no error has been encountered.
121 * Note that if the iterator stops the iteration by returning
122 * GNUNET_NO, the block will no longer be checked for further errors.
123 * The return value will be GNUNET_OK meaning that no errors were
124 * found until the edge last notified to the iterator, but there might
125 * be errors in further edges.
128 REGEX_BLOCK_iterate (const struct RegexBlock *block,
130 REGEX_INTERNAL_EgdeIterator iterator,
135 * Construct a regex block to be stored in the DHT.
137 * @param proof proof string for the block
138 * @param num_edges number of edges in the block
139 * @param edges the edges of the block
140 * @return the regex block
143 REGEX_BLOCK_create (const struct GNUNET_HashCode *key,
145 unsigned int num_edges,
146 const struct REGEX_BLOCK_Edge *edges,
151 #if 0 /* keep Emacsens' auto-indent happy */
158 /* ifndef REGEX_BLOCK_LIB_H */
160 /* end of regex_block_lib.h */