library to parse regular expressions into dfa More...
#include "gnunet_util_lib.h"
#include "gnunet_dht_service.h"
#include "gnunet_statistics_service.h"
#include "../../plugin/regex/regex_block_lib.h"
Go to the source code of this file.
Typedefs | |
typedef void(* | REGEX_INTERNAL_KeyIterator) (void *cls, const struct GNUNET_HashCode *key, const char *proof, int accepting, unsigned int num_edges, const struct REGEX_BLOCK_Edge *edges) |
Iterator callback function. More... | |
typedef void(* | REGEX_INTERNAL_Found) (void *cls, const struct GNUNET_PeerIdentity *id, const struct GNUNET_DHT_PathElement *get_path, unsigned int get_path_length, const struct GNUNET_DHT_PathElement *put_path, unsigned int put_path_length) |
Search callback function. More... | |
Functions | |
struct REGEX_INTERNAL_Automaton * | REGEX_INTERNAL_construct_dfa (const char *regex, const size_t len, unsigned int max_path_len) |
Construct DFA for the given 'regex' of length 'len'. More... | |
void | REGEX_INTERNAL_automaton_destroy (struct REGEX_INTERNAL_Automaton *a) |
Free the memory allocated by constructing the REGEX_INTERNAL_Automaton. More... | |
int | REGEX_INTERNAL_eval (struct REGEX_INTERNAL_Automaton *a, const char *string) |
Evaluates the given 'string' against the given compiled regex. More... | |
size_t | REGEX_INTERNAL_get_first_key (const char *input_string, size_t string_len, struct GNUNET_HashCode *key) |
Get the first key for the given input_string. More... | |
void | REGEX_INTERNAL_iterate_all_edges (struct REGEX_INTERNAL_Automaton *a, REGEX_INTERNAL_KeyIterator iterator, void *iterator_cls) |
Iterate over all edges starting from start state of automaton 'a'. More... | |
void | REGEX_INTERNAL_iterate_reachable_edges (struct REGEX_INTERNAL_Automaton *a, REGEX_INTERNAL_KeyIterator iterator, void *iterator_cls) |
Iterate over all edges of automaton 'a' that are reachable from a state with a proof of at least GNUNET_REGEX_INITIAL_BYTES characters. More... | |
struct REGEX_INTERNAL_Announcement * | REGEX_INTERNAL_announce (struct GNUNET_DHT_Handle *dht, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const char *regex, uint16_t compression, struct GNUNET_STATISTICS_Handle *stats) |
Announce a regular expression: put all states of the automaton in the DHT. More... | |
void | REGEX_INTERNAL_reannounce (struct REGEX_INTERNAL_Announcement *h) |
Announce again a regular expression previously announced. More... | |
void | REGEX_INTERNAL_announce_cancel (struct REGEX_INTERNAL_Announcement *h) |
Clear all cached data used by a regex announce. More... | |
struct REGEX_INTERNAL_Search * | REGEX_INTERNAL_search (struct GNUNET_DHT_Handle *dht, const char *string, REGEX_INTERNAL_Found callback, void *callback_cls, struct GNUNET_STATISTICS_Handle *stats) |
Search for a peer offering a regex matching certain string in the DHT. More... | |
void | REGEX_INTERNAL_search_cancel (struct REGEX_INTERNAL_Search *h) |
Stop search and free all data used by a REGEX_INTERNAL_search() call. More... | |
library to parse regular expressions into dfa
Definition in file regex_internal_lib.h.
typedef void(* REGEX_INTERNAL_KeyIterator) (void *cls, const struct GNUNET_HashCode *key, const char *proof, int accepting, unsigned int num_edges, const struct REGEX_BLOCK_Edge *edges) |
Iterator callback function.
cls | closure. |
key | hash for current state. |
proof | proof for current state |
accepting | GNUNET_YES if this is an accepting state, GNUNET_NO if not. |
num_edges | number of edges leaving current state. |
edges | edges leaving current state. |
Definition at line 121 of file regex_internal_lib.h.
typedef void(* REGEX_INTERNAL_Found) (void *cls, const struct GNUNET_PeerIdentity *id, const struct GNUNET_DHT_PathElement *get_path, unsigned int get_path_length, const struct GNUNET_DHT_PathElement *put_path, unsigned int put_path_length) |
Search callback function.
cls | Closure provided in REGEX_INTERNAL_search(). |
id | Peer providing a regex that matches the string. |
get_path | Path of the get request. |
get_path_length | Length of get_path. |
put_path | Path of the put request. |
put_path_length | Length of the put_path. |
Definition at line 221 of file regex_internal_lib.h.
struct REGEX_INTERNAL_Automaton * REGEX_INTERNAL_construct_dfa | ( | const char * | regex, |
const size_t | len, | ||
unsigned int | max_path_len | ||
) |
Construct DFA for the given 'regex' of length 'len'.
Path compression means, that for example a DFA o -> a -> b -> c -> o will be compressed to o -> abc -> o. Note that this parameter influences the non-determinism of states of the resulting NFA in the DHT (number of outgoing edges with the same label). For example for an application that stores IPv4 addresses as bitstrings it could make sense to limit the path compression to 4 or 8.
regex | regular expression string. |
len | length of the regular expression. |
max_path_len | limit the path compression length to the given value. If set to 1, no path compression is applied. Set to 0 for maximal possible path compression (generally not desirable). |
Definition at line 3037 of file regex_internal.c.
References automaton_add_state(), automaton_create_proofs(), construct_dfa_states(), ctx, DFA, dfa_compress_paths(), dfa_minimize(), dfa_state_create(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_new, GNUNET_OK, GNUNET_strdup, nfa_closure_set_create(), REGEX_INTERNAL_Automaton::regex, REGEX_INTERNAL_automaton_destroy(), REGEX_INTERNAL_construct_nfa(), REGEX_INTERNAL_context_init(), REGEX_INTERNAL_Automaton::start, state_set_append(), state_set_clear(), and REGEX_INTERNAL_Automaton::type.
Referenced by main(), and REGEX_INTERNAL_announce().
void REGEX_INTERNAL_automaton_destroy | ( | struct REGEX_INTERNAL_Automaton * | a | ) |
Free the memory allocated by constructing the REGEX_INTERNAL_Automaton.
data structure.
a | automaton to be destroyed. |
Definition at line 3097 of file regex_internal.c.
References automaton_destroy_state(), REGEX_INTERNAL_Automaton::canonical_regex, GNUNET_CONTAINER_DLL_remove, GNUNET_free, REGEX_INTERNAL_State::next, REGEX_INTERNAL_Automaton::regex, REGEX_INTERNAL_Automaton::states_head, and REGEX_INTERNAL_Automaton::states_tail.
Referenced by main(), REGEX_INTERNAL_announce_cancel(), REGEX_INTERNAL_construct_dfa(), and REGEX_INTERNAL_construct_nfa().
int REGEX_INTERNAL_eval | ( | struct REGEX_INTERNAL_Automaton * | a, |
const char * | string | ||
) |
Evaluates the given 'string' against the given compiled regex.
a | automaton. |
string | string to check. |
Definition at line 3224 of file regex_internal.c.
References DFA, evaluate_dfa(), evaluate_nfa(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_SYSERR, NFA, result, and REGEX_INTERNAL_Automaton::type.
size_t REGEX_INTERNAL_get_first_key | ( | const char * | input_string, |
size_t | string_len, | ||
struct GNUNET_HashCode * | key | ||
) |
Get the first key for the given input_string.
This hashes the first x bits of the input_string.
input_string | string. |
string_len | length of the input_string. |
key | pointer to where to write the hash code. |
Definition at line 3294 of file regex_internal.c.
References GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_REGEX_INITIAL_BYTES, key, and size.
Referenced by REGEX_INTERNAL_search().
void REGEX_INTERNAL_iterate_all_edges | ( | struct REGEX_INTERNAL_Automaton * | a, |
REGEX_INTERNAL_KeyIterator | iterator, | ||
void * | iterator_cls | ||
) |
Iterate over all edges starting from start state of automaton 'a'.
Calling iterator for each edge.
a | automaton. |
iterator | iterator called for each edge. |
iterator_cls | closure. |
Definition at line 3438 of file regex_internal.c.
References GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_NO, GNUNET_REGEX_INITIAL_BYTES, iterate_initial_edge(), REGEX_INTERNAL_State::next, REGEX_INTERNAL_Automaton::start, state_get_edges(), and REGEX_INTERNAL_Automaton::states_head.
Referenced by main(), and REGEX_INTERNAL_iterate_reachable_edges().
void REGEX_INTERNAL_iterate_reachable_edges | ( | struct REGEX_INTERNAL_Automaton * | a, |
REGEX_INTERNAL_KeyIterator | iterator, | ||
void * | iterator_cls | ||
) |
Iterate over all edges of automaton 'a' that are reachable from a state with a proof of at least GNUNET_REGEX_INITIAL_BYTES characters.
Call the iterator for each such edge.
a | automaton. |
iterator | iterator called for each reachable edge. |
iterator_cls | closure. |
Definition at line 3640 of file regex_internal.c.
References GNUNET_CONTAINER_multihashmap_create(), GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_NO, iterate_reachables(), client_iterator::iterator, client_iterator::iterator_cls, reachability_iterator(), REGEX_INTERNAL_iterate_all_edges(), REGEX_INTERNAL_Automaton::state_count, and store_all_states().
Referenced by main(), and REGEX_INTERNAL_reannounce().
struct REGEX_INTERNAL_Announcement * REGEX_INTERNAL_announce | ( | struct GNUNET_DHT_Handle * | dht, |
const struct GNUNET_CRYPTO_EddsaPrivateKey * | priv, | ||
const char * | regex, | ||
uint16_t | compression, | ||
struct GNUNET_STATISTICS_Handle * | stats | ||
) |
Announce a regular expression: put all states of the automaton in the DHT.
Does not free resources, must call REGEX_INTERNAL_announce_cancel() for that.
dht | An existing and valid DHT service handle. CANNOT be NULL. |
priv | our private key, must remain valid until the announcement is cancelled |
regex | Regular expression to announce. |
compression | How many characters per edge can we squeeze? |
stats | Optional statistics handle to report usage. Can be NULL. |
Definition at line 198 of file regex_internal_dht.c.
References dht, GNUNET_assert, GNUNET_new, h, REGEX_INTERNAL_Announcement::priv, REGEX_INTERNAL_Announcement::regex, REGEX_INTERNAL_construct_dfa(), REGEX_INTERNAL_reannounce(), and stats.
Referenced by handle_announce(), and reannounce_regex().
void REGEX_INTERNAL_reannounce | ( | struct REGEX_INTERNAL_Announcement * | h | ) |
Announce again a regular expression previously announced.
Does use caching to speed up process.
h | Handle returned by a previous REGEX_INTERNAL_announce() call. |
Definition at line 219 of file regex_internal_dht.c.
References GNUNET_assert, GNUNET_ERROR_TYPE_INFO, h, LOG, REGEX_INTERNAL_iterate_reachable_edges(), and regex_iterator().
Referenced by reannounce(), reannounce_regex(), and REGEX_INTERNAL_announce().
void REGEX_INTERNAL_announce_cancel | ( | struct REGEX_INTERNAL_Announcement * | h | ) |
Clear all cached data used by a regex announce.
Does not close DHT connection.
h | Handle returned by a previous REGEX_INTERNAL_announce() call. |
Definition at line 238 of file regex_internal_dht.c.
References GNUNET_free, h, and REGEX_INTERNAL_automaton_destroy().
Referenced by client_disconnect_cb(), and shutdown_task().
struct REGEX_INTERNAL_Search * REGEX_INTERNAL_search | ( | struct GNUNET_DHT_Handle * | dht, |
const char * | string, | ||
REGEX_INTERNAL_Found | callback, | ||
void * | callback_cls, | ||
struct GNUNET_STATISTICS_Handle * | stats | ||
) |
Search for a peer offering a regex matching certain string in the DHT.
The search runs until REGEX_INTERNAL_search_cancel() is called, even if results are returned.
dht | An existing and valid DHT service handle. |
string | String to match against the regexes in the DHT. |
callback | Callback for found peers. |
callback_cls | Closure for callback . |
stats | Optional statistics handle to report usage. Can be NULL. |
Definition at line 698 of file regex_internal_dht.c.
References ctx, dht, dht_get_string_handler(), DHT_OPT, DHT_REPLICATION, GNUNET_array_append, GNUNET_assert, GNUNET_BLOCK_TYPE_REGEX, GNUNET_break, GNUNET_CONTAINER_multihashmap_create(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_DHT_get_start(), GNUNET_ERROR_TYPE_INFO, GNUNET_h2s(), GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_strdup, h, key, LOG, REGEX_INTERNAL_get_first_key(), size, and stats.
Referenced by dht_connect_cb(), and handle_search().
void REGEX_INTERNAL_search_cancel | ( | struct REGEX_INTERNAL_Search * | h | ) |
Stop search and free all data used by a REGEX_INTERNAL_search() call.
Does not close DHT connection.
h | Handle returned by a previous REGEX_INTERNAL_search() call. |
Stop search and free all data used by a REGEX_INTERNAL_search() call.
h | the search context. |
Definition at line 809 of file regex_internal_dht.c.
References GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_free, h, regex_cancel_dht_get(), and regex_free_result().
Referenced by client_disconnect_cb(), and dht_da().