30 #define LOG(kind, ...) GNUNET_log_from (kind, "regex-bck", __VA_ARGS__) 128 if ((NULL == proof) || (NULL == key))
175 "edge %.*s [%u]: %s\n",
182 if (strlen (ctx->
xquery) < len)
184 if (0 == strncmp (ctx->
xquery, token, len))
221 if ((NULL != query) &&
229 ((NULL == xquery) || (
'\0' == xquery[0])))
232 " out! Is accepting: %u, xquery %p\n",
265 uint16_t num_destinations;
278 edges = (
const struct EdgeInfo *) &destinations[num_destinations];
279 total =
sizeof(
struct RegexBlock) + num_destinations *
sizeof(
struct 282 if (block_len < total)
317 uint16_t num_destinations;
333 edges = (
const struct EdgeInfo *) &destinations[num_destinations];
334 aux = (
const char *) &edges[num_edges];
335 total =
sizeof(
struct RegexBlock) + num_destinations *
sizeof(
struct 347 fprintf (stderr,
"Expected %u, got %u\n",
349 (
unsigned int) total);
355 "Start iterating block of size %lu, proof %u, off %lu edges %u\n",
356 (
unsigned long) size, len, (
unsigned long) off, n);
361 "Edge %u/%u, off %lu tokenlen %u (%.*s)\n",
362 n + 1, num_edges, (
unsigned long) off,
363 ntohs (edges[n].token_length), ntohs (edges[n].token_length),
365 if (NULL != iterator)
368 ntohs (edges[n].token_length),
369 &destinations[ntohs (
372 off += ntohs (edges[n].token_length);
397 uint16_t destination_indices[num_edges];
404 unsigned int unique_destinations;
409 len = strlen (proof);
410 if (len > UINT16_MAX)
415 unique_destinations = 0;
419 slen = strlen (edges[i].label);
420 if (slen > UINT16_MAX)
426 for (j = 0; j < unique_destinations; j++)
427 if (0 == memcmp (&destinations[j],
428 &edges[i].destination,
436 destination_indices[i] = j;
437 if (j == unique_destinations)
438 destinations[unique_destinations++] = edges[i].
destination;
440 total += num_edges *
sizeof(
struct EdgeInfo) + unique_destinations
454 * unique_destinations);
455 edgeinfos = (
struct EdgeInfo *) &dests[unique_destinations];
456 aux = (
char *) &edgeinfos[num_edges];
459 for (i = 0; i < num_edges; i++)
461 slen = strlen (edges[i].label);
static int iterator(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Iterator over hash map entries.
GNUNET_NETWORK_STRUCT_END int GNUNET_BLOCK_is_accepting(const struct RegexBlock *block, size_t size)
Test if this block is marked as being an accept state.
int(* REGEX_INTERNAL_EgdeIterator)(void *cls, const char *token, size_t len, const struct GNUNET_HashCode *key)
Iterator over edges in a block.
struct GNUNET_HashCode destination
Destionation of the edge.
uint16_t destination_index
Index of the destination of this edge in the unique destinations array.
Struct to keep track of the xquery while iterating all the edges in a block.
uint16_t num_edges
Number of edges parting from this state.
int REGEX_BLOCK_get_key(const struct RegexBlock *block, size_t block_len, struct GNUNET_HashCode *key)
Obtain the key that a particular block is to be stored under.
int REGEX_BLOCK_iterate(const struct RegexBlock *block, size_t size, REGEX_INTERNAL_EgdeIterator iterator, void *iter_cls)
Iterate over all edges of a block of a regex state.
Block to announce a regex state.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
int found
Has any edge matched the xquery so far? (GNUNET_OK / GNUNET_NO)
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
uint16_t num_destinations
Nubmer of unique destinations reachable from this state.
uint16_t proof_len
Length of the proof regex string.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
uint16_t token_length
Number of bytes the token for this edge takes in the token area.
Information for each edge.
struct RegexBlock * REGEX_BLOCK_create(const char *proof, unsigned int num_edges, const struct REGEX_BLOCK_Edge *edges, int accepting, size_t *rsize)
Construct a regex block to be stored in the DHT.
struct GNUNET_HashCode key
The key used in the DHT.
static unsigned int size
Size of the "table".
#define GNUNET_CONSTANTS_MAX_BLOCK_SIZE
Largest block that can be stored in the DHT.
int REGEX_BLOCK_check_proof(const char *proof, size_t proof_len, const struct GNUNET_HashCode *key)
Check if the given 'proof' matches the given 'key'.
const char * xquery
Xquery: string we are looking for.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.
#define GNUNET_PACKED
gcc-ism to get packed structs.
int GNUNET_CRYPTO_hash_cmp(const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2)
Compare function for HashCodes, producing a total ordering of all hashcodes.
common function to manipulate blocks stored by regex in the DHT
static int check_edge(void *cls, const char *token, size_t len, const struct GNUNET_HashCode *key)
Iterator over all edges in a block, checking for a presence of a given query.
#define GNUNET_log(kind,...)
int16_t is_accepting
Is this state an accepting state?
int REGEX_BLOCK_check(const struct RegexBlock *block, size_t size, const struct GNUNET_HashCode *query, const char *xquery)
Check if the regex block is well formed, including all edges.
#define GNUNET_malloc(size)
Wrapper around malloc.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...