GNUnet  0.11.x
Typedefs | Functions
regex_internal_lib.h File Reference

library to parse regular expressions into dfa More...

#include "gnunet_util_lib.h"
#include "gnunet_dht_service.h"
#include "gnunet_statistics_service.h"
#include "regex_block_lib.h"
Include dependency graph for regex_internal_lib.h:
This graph shows which files directly or indirectly include this file:

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_PeerIdentity *get_path, unsigned int get_path_length, const struct GNUNET_PeerIdentity *put_path, unsigned int put_path_length)
 Search callback function. More...
 

Functions

struct REGEX_INTERNAL_AutomatonREGEX_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_AnnouncementREGEX_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_SearchREGEX_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...
 

Detailed Description

library to parse regular expressions into dfa

Author
Maximilian Szengel

Definition in file regex_internal_lib.h.

Typedef Documentation

◆ REGEX_INTERNAL_KeyIterator

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.

Parameters
clsclosure.
keyhash for current state.
proofproof for current state
acceptingGNUNET_YES if this is an accepting state, GNUNET_NO if not.
num_edgesnumber of edges leaving current state.
edgesedges leaving current state.

Definition at line 121 of file regex_internal_lib.h.

◆ REGEX_INTERNAL_Found

typedef void(* REGEX_INTERNAL_Found) (void *cls, const struct GNUNET_PeerIdentity *id, const struct GNUNET_PeerIdentity *get_path, unsigned int get_path_length, const struct GNUNET_PeerIdentity *put_path, unsigned int put_path_length)

Search callback function.

Parameters
clsClosure provided in REGEX_INTERNAL_search().
idPeer providing a regex that matches the string.
get_pathPath of the get request.
get_path_lengthLength of get_path.
put_pathPath of the put request.
put_path_lengthLength of the put_path.

Definition at line 221 of file regex_internal_lib.h.

Function Documentation

◆ REGEX_INTERNAL_construct_dfa()

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.

Parameters
regexregular expression string.
lenlength of the regular expression.
max_path_lenlimit 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).
Returns
DFA, needs to be freed using REGEX_INTERNAL_automaton_destroy().

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.

Parameters
regexregular expression string.
lenlength of the regular expression.
max_path_lenlimit 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).
Returns
DFA, needs to be freed using REGEX_INTERNAL_automaton_destroy.

Definition at line 3062 of file regex_internal.c.

3065 {
3066  struct REGEX_INTERNAL_Context ctx;
3067  struct REGEX_INTERNAL_Automaton *dfa;
3068  struct REGEX_INTERNAL_Automaton *nfa;
3069  struct REGEX_INTERNAL_StateSet nfa_start_eps_cls;
3070  struct REGEX_INTERNAL_StateSet singleton_set;
3071 
3073 
3074  /* Create NFA */
3075  nfa = REGEX_INTERNAL_construct_nfa (regex, len);
3076 
3077  if (NULL == nfa)
3078  {
3080  "Could not create DFA, because NFA creation failed\n");
3081  return NULL;
3082  }
3083 
3084  dfa = GNUNET_new (struct REGEX_INTERNAL_Automaton);
3085  dfa->type = DFA;
3086  dfa->regex = GNUNET_strdup (regex);
3087 
3088  /* Create DFA start state from epsilon closure */
3089  memset (&singleton_set, 0, sizeof(struct REGEX_INTERNAL_StateSet));
3090  state_set_append (&singleton_set, nfa->start);
3091  nfa_closure_set_create (&nfa_start_eps_cls, nfa, &singleton_set, NULL);
3092  state_set_clear (&singleton_set);
3093  dfa->start = dfa_state_create (&ctx, &nfa_start_eps_cls);
3094  automaton_add_state (dfa, dfa->start);
3095 
3096  construct_dfa_states (&ctx, nfa, dfa, dfa->start);
3098 
3099  /* Minimize DFA */
3100  if (GNUNET_OK != dfa_minimize (&ctx, dfa))
3101  {
3103  return NULL;
3104  }
3105 
3106  /* Create proofs and hashes for all states */
3107  if (GNUNET_OK != automaton_create_proofs (dfa))
3108  {
3110  return NULL;
3111  }
3112 
3113  /* Compress linear DFA paths */
3114  if (1 != max_path_len)
3115  dfa_compress_paths (&ctx, dfa, max_path_len);
3116 
3117  return dfa;
3118 }
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
#define GNUNET_log(kind,...)
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct REGEX_INTERNAL_State * dfa_state_create(struct REGEX_INTERNAL_Context *ctx, struct REGEX_INTERNAL_StateSet *nfa_states)
Creates a new DFA state based on a set of NFA states.
static void construct_dfa_states(struct REGEX_INTERNAL_Context *ctx, struct REGEX_INTERNAL_Automaton *nfa, struct REGEX_INTERNAL_Automaton *dfa, struct REGEX_INTERNAL_State *dfa_state)
Create DFA states based on given 'nfa' and starting with 'dfa_state'.
static void state_set_clear(struct REGEX_INTERNAL_StateSet *set)
Clears the given StateSet 'set'.
static void state_set_append(struct REGEX_INTERNAL_StateSet *set, struct REGEX_INTERNAL_State *state)
Append state to the given StateSet.
static int dfa_minimize(struct REGEX_INTERNAL_Context *ctx, struct REGEX_INTERNAL_Automaton *a)
Minimize the given DFA 'a' by removing all unreachable states, removing all dead states and merging a...
static int automaton_create_proofs(struct REGEX_INTERNAL_Automaton *a)
Create proofs for all states in the given automaton.
static void nfa_closure_set_create(struct REGEX_INTERNAL_StateSet *ret, struct REGEX_INTERNAL_Automaton *nfa, struct REGEX_INTERNAL_StateSet *states, const char *label)
Calculates the closure set for the given set of states.
struct REGEX_INTERNAL_Automaton * REGEX_INTERNAL_construct_nfa(const char *regex, const size_t len)
Construct an NFA by parsing the regex string of length 'len'.
static void automaton_add_state(struct REGEX_INTERNAL_Automaton *a, struct REGEX_INTERNAL_State *s)
Add a state to the automaton 'a', always use this function to alter the states DLL of the automaton.
void REGEX_INTERNAL_automaton_destroy(struct REGEX_INTERNAL_Automaton *a)
Free the memory allocated by constructing the REGEX_INTERNAL_Automaton data structure.
static void dfa_compress_paths(struct REGEX_INTERNAL_Context *regex_ctx, struct REGEX_INTERNAL_Automaton *dfa, unsigned int max_len)
Compress paths in the given 'dfa'.
static void REGEX_INTERNAL_context_init(struct REGEX_INTERNAL_Context *ctx)
Initialize a new context.
@ DFA
Automaton representation.
struct REGEX_INTERNAL_State * start
First state of the automaton.
enum REGEX_INTERNAL_AutomatonType type
Type of the automaton.
Context that contains an id counter for states and transitions as well as a DLL of automatons used as...

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, len, 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 announce_regex(), main(), and REGEX_INTERNAL_announce().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ REGEX_INTERNAL_automaton_destroy()

void REGEX_INTERNAL_automaton_destroy ( struct REGEX_INTERNAL_Automaton a)

Free the memory allocated by constructing the REGEX_INTERNAL_Automaton.

data structure.

Parameters
aautomaton to be destroyed.

Free the memory allocated by constructing the REGEX_INTERNAL_Automaton.

Parameters
aautomaton to be destroyed

Definition at line 3128 of file regex_internal.c.

3129 {
3130  struct REGEX_INTERNAL_State *s;
3131  struct REGEX_INTERNAL_State *next_state;
3132 
3133  if (NULL == a)
3134  return;
3135 
3136  GNUNET_free (a->regex);
3138 
3139  for (s = a->states_head; NULL != s; s = next_state)
3140  {
3141  next_state = s->next;
3144  }
3145 
3146  GNUNET_free (a);
3147 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_free(ptr)
Wrapper around free.
static void automaton_destroy_state(struct REGEX_INTERNAL_State *s)
Frees the memory used by State s.
char * canonical_regex
Canonical regex (result of RX->NFA->DFA->RX)
struct REGEX_INTERNAL_State * states_tail
DLL of states.
struct REGEX_INTERNAL_State * states_head
DLL of states.
struct REGEX_INTERNAL_State * next
This is a linked list to keep states in an automaton.

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 announce_regex(), main(), REGEX_INTERNAL_announce_cancel(), REGEX_INTERNAL_construct_dfa(), and REGEX_INTERNAL_construct_nfa().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ REGEX_INTERNAL_eval()

int REGEX_INTERNAL_eval ( struct REGEX_INTERNAL_Automaton a,
const char *  string 
)

Evaluates the given 'string' against the given compiled regex.

Parameters
aautomaton.
stringstring to check.
Returns
0 if string matches, non 0 otherwise.

Evaluates the given 'string' against the given compiled regex.

Parameters
aautomaton
stringstring to check
Returns
0 if string matches, non-0 otherwise

Definition at line 3262 of file regex_internal.c.

3263 {
3264  int result;
3265 
3266  switch (a->type)
3267  {
3268  case DFA:
3269  result = evaluate_dfa (a, string);
3270  break;
3271 
3272  case NFA:
3273  result = evaluate_nfa (a, string);
3274  break;
3275 
3276  default:
3278  "Evaluating regex failed, automaton has no type!\n");
3280  break;
3281  }
3282 
3283  return result;
3284 }
static int result
Global testing status.
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
static int evaluate_dfa(struct REGEX_INTERNAL_Automaton *a, const char *string)
Evaluates the given string using the given DFA automaton.
static int evaluate_nfa(struct REGEX_INTERNAL_Automaton *a, const char *string)
Evaluates the given string using the given NFA automaton.
@ NFA

References DFA, evaluate_dfa(), evaluate_nfa(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_SYSERR, NFA, result, and REGEX_INTERNAL_Automaton::type.

Here is the call graph for this function:

◆ REGEX_INTERNAL_get_first_key()

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.

Parameters
input_stringstring.
string_lenlength of the input_string.
keypointer to where to write the hash code.
Returns
number of bits of input_string that have been consumed to construct the key

Definition at line 3343 of file regex_internal.c.

3346 {
3347  size_t size;
3348 
3349  size = string_len < GNUNET_REGEX_INITIAL_BYTES ? string_len
3351  if (NULL == input_string)
3352  {
3353  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Given input string was NULL!\n");
3354  return 0;
3355  }
3356  GNUNET_CRYPTO_hash (input_string, size, key);
3357 
3358  return size;
3359 }
struct GNUNET_HashCode key
The key used in the DHT.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
#define GNUNET_REGEX_INITIAL_BYTES
Constant for how many bytes the initial string regex should have.
static unsigned int size
Size of the "table".
Definition: peer.c:67

References GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_REGEX_INITIAL_BYTES, key, and size.

Referenced by REGEX_INTERNAL_search().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ REGEX_INTERNAL_iterate_all_edges()

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.

Parameters
aautomaton.
iteratoriterator called for each edge.
iterator_clsclosure.

Definition at line 3487 of file regex_internal.c.

3490 {
3491  struct REGEX_INTERNAL_State *s;
3492 
3493  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating over starting edges\n");
3496  NULL,
3497  a->start,
3498  iterator,
3499  iterator_cls);
3500  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating over DFA edges\n");
3501  for (s = a->states_head; NULL != s; s = s->next)
3502  {
3503  struct REGEX_BLOCK_Edge edges[s->transition_count];
3504  unsigned int num_edges;
3505 
3506  num_edges = state_get_edges (s, edges);
3507  if (((NULL != s->proof) && (0 < strlen (s->proof))) || s->accepting)
3508  {
3510  "Creating DFA edges at `%s' under key %s\n",
3511  s->proof,
3512  GNUNET_h2s (&s->hash));
3513  iterator (iterator_cls,
3514  &s->hash,
3515  s->proof,
3516  s->accepting,
3517  num_edges,
3518  edges);
3519  }
3520  s->marked = GNUNET_NO;
3521  }
3522 }
@ GNUNET_NO
Definition: gnunet_common.h:94
static int iterator(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Iterator over hash map entries.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
static unsigned int state_get_edges(struct REGEX_INTERNAL_State *s, struct REGEX_BLOCK_Edge *edges)
Get all edges leaving state s.
static void iterate_initial_edge(unsigned int min_len, unsigned int max_len, char *consumed_string, struct REGEX_INTERNAL_State *state, REGEX_INTERNAL_KeyIterator iterator, void *iterator_cls)
Recursive function that calls the iterator for each synthetic start state.
Edge representation.
char * proof
Proof for this state.
int marked
Marking of the state.
int accepting
If this is an accepting state or not.
struct GNUNET_HashCode hash
Hash of the state.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_NO, GNUNET_REGEX_INITIAL_BYTES, iterate_initial_edge(), iterator(), REGEX_INTERNAL_State::next, REGEX_INTERNAL_Automaton::start, state_get_edges(), and REGEX_INTERNAL_Automaton::states_head.

Referenced by announce_regex(), main(), and REGEX_INTERNAL_iterate_reachable_edges().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Parameters
aautomaton.
iteratoriterator called for each reachable edge.
iterator_clsclosure.

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.

Parameters
aautomaton.
iteratoriterator called for each reachable edge.
iterator_clsclosure.

Definition at line 3699 of file regex_internal.c.

3702 {
3703  struct GNUNET_CONTAINER_MultiHashMap *hm;
3704  struct client_iterator ci;
3705 
3707  ci.iterator = iterator;
3708  ci.iterator_cls = iterator_cls;
3709 
3713 
3715 }
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
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'.
static int iterate_reachables(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over hash map entries.
static void store_all_states(void *cls, const struct GNUNET_HashCode *key, const char *proof, int accepting, unsigned int num_edges, const struct REGEX_BLOCK_Edge *edges)
Iterator over all edges of a dfa.
static int reachability_iterator(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over hash map entries to mark the ones that are reachable.
Internal representation of the hash map.
unsigned int state_count
Number of states in the automaton.
Store regex iterator and cls in one place to pass to the hashmap iterator.

References GNUNET_CONTAINER_multihashmap_create(), GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_NO, iterate_reachables(), client_iterator::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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ REGEX_INTERNAL_announce()

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.

Parameters
dhtAn existing and valid DHT service handle. CANNOT be NULL.
privour private key, must remain valid until the announcement is cancelled
regexRegular expression to announce.
compressionHow many characters per edge can we squeeze?
statsOptional statistics handle to report usage. Can be NULL.
Returns
Handle to reuse o free cached resources. Must be freed by calling REGEX_INTERNAL_announce_cancel().

Definition at line 199 of file regex_internal_dht.c.

204 {
206 
207  GNUNET_assert (NULL != dht);
209  h->regex = regex;
210  h->dht = dht;
211  h->stats = stats;
212  h->priv = priv;
213  h->dfa = REGEX_INTERNAL_construct_dfa (regex, strlen (regex), compression);
215  return h;
216 }
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static struct GNUNET_DHT_Handle * dht
Handle to the DHT.
struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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'.
void REGEX_INTERNAL_reannounce(struct REGEX_INTERNAL_Announcement *h)
Announce again a regular expression previously announced.
Handle to store cached data about a regex announce.
const struct GNUNET_CRYPTO_EddsaPrivateKey * priv
Our private key.
const char * regex
Regular expression.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ REGEX_INTERNAL_reannounce()

void REGEX_INTERNAL_reannounce ( struct REGEX_INTERNAL_Announcement h)

Announce again a regular expression previously announced.

Does use caching to speed up process.

Parameters
hHandle returned by a previous REGEX_INTERNAL_announce() call.

Does use caching to speed up process.

Parameters
hHandle returned by a previous REGEX_INTERNAL_announce call().

Definition at line 226 of file regex_internal_dht.c.

227 {
228  GNUNET_assert (NULL != h->dfa); /* make sure to call announce first */
230  "REGEX_INTERNAL_reannounce: %s\n",
231  h->regex);
234  h);
235 }
@ GNUNET_ERROR_TYPE_INFO
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 GNUN...
static void regex_iterator(void *cls, const struct GNUNET_HashCode *key, const char *proof, int accepting, unsigned int num_edges, const struct REGEX_BLOCK_Edge *edges)
Regex callback iterator to store own service description in the DHT.
#define LOG(kind,...)

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ REGEX_INTERNAL_announce_cancel()

void REGEX_INTERNAL_announce_cancel ( struct REGEX_INTERNAL_Announcement h)

Clear all cached data used by a regex announce.

Does not close DHT connection.

Parameters
hHandle returned by a previous REGEX_INTERNAL_announce() call.

Definition at line 245 of file regex_internal_dht.c.

246 {
248  GNUNET_free (h);
249 }

References GNUNET_free, h, and REGEX_INTERNAL_automaton_destroy().

Referenced by client_disconnect_cb(), and shutdown_task().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ REGEX_INTERNAL_search()

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.

Parameters
dhtAn existing and valid DHT service handle.
stringString to match against the regexes in the DHT.
callbackCallback for found peers.
callback_clsClosure for callback.
statsOptional statistics handle to report usage. Can be NULL.
Returns
Handle to stop search and free resources. Must be freed by calling REGEX_INTERNAL_search_cancel().

Definition at line 699 of file regex_internal_dht.c.

704 {
705  struct REGEX_INTERNAL_Search *h;
706  struct GNUNET_DHT_GetHandle *get_h;
707  struct RegexSearchContext *ctx;
708  struct GNUNET_HashCode key;
709  size_t size;
710  size_t len;
711 
712  /* Initialize handle */
713  GNUNET_assert (NULL != dht);
714  GNUNET_assert (NULL != callback);
716  h->dht = dht;
717  h->description = GNUNET_strdup (string);
718  h->callback = callback;
719  h->callback_cls = callback_cls;
720  h->stats = stats;
721  h->dht_get_handles = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
722  h->dht_get_results = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
723 
724  /* Initialize context */
725  len = strlen (string);
728  "Initial key for `%s' is %s (based on `%.*s')\n",
729  string,
730  GNUNET_h2s (&key),
731  (int) size,
732  string);
733  ctx = GNUNET_new (struct RegexSearchContext);
734  ctx->position = size;
735  ctx->info = h;
736  GNUNET_array_append (h->contexts,
737  h->n_contexts,
738  ctx);
739  /* Start search in DHT */
740  get_h = GNUNET_DHT_get_start (h->dht, /* handle */
741  GNUNET_BLOCK_TYPE_REGEX, /* type */
742  &key, /* key to search */
743  DHT_REPLICATION, /* replication level */
744  DHT_OPT,
745  &h->description[size], /* xquery */
746  // FIXME add BLOOMFILTER to exclude filtered peers
747  len + 1 - size, /* xquery bits */
748  // FIXME add BLOOMFILTER SIZE
750  GNUNET_break (
751  GNUNET_OK ==
752  GNUNET_CONTAINER_multihashmap_put (h->dht_get_handles,
753  &key,
754  get_h,
756  );
757 
758  return h;
759 }
@ GNUNET_BLOCK_TYPE_REGEX
Block to store a cadet regex state.
struct GNUNET_DHT_GetHandle * GNUNET_DHT_get_start(struct GNUNET_DHT_Handle *handle, enum GNUNET_BLOCK_Type type, const struct GNUNET_HashCode *key, uint32_t desired_replication_level, enum GNUNET_DHT_RouteOption options, const void *xquery, size_t xquery_size, GNUNET_DHT_GetIterator iter, void *iter_cls)
Perform an asynchronous GET operation on the DHT identified.
Definition: dht_api.c:1067
int GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
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.
static void dht_get_string_handler(void *cls, struct GNUNET_TIME_Absolute exp, const struct GNUNET_HashCode *key, const struct GNUNET_PeerIdentity *get_path, unsigned int get_path_length, const struct GNUNET_PeerIdentity *put_path, unsigned int put_path_length, enum GNUNET_BLOCK_Type type, size_t size, const void *data)
Function to process DHT string to regex matching.
#define DHT_REPLICATION
DHT replication level to use.
#define DHT_OPT
DHT options to set.
Handle to a GET request.
Definition: dht_api.c:80
A 512-bit hashcode.
Struct to keep information of searches of services described by a regex using a user-provided string ...
Struct to keep state of running searches that have consumed a part of the initial string.

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, len, LOG, REGEX_INTERNAL_get_first_key(), size, and stats.

Referenced by dht_connect_cb(), and handle_search().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ REGEX_INTERNAL_search_cancel()

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.

Parameters
hHandle returned by a previous REGEX_INTERNAL_search() call.

Stop search and free all data used by a REGEX_INTERNAL_search() call.

Parameters
hthe search context.

Definition at line 810 of file regex_internal_dht.c.

811 {
812  unsigned int i;
813 
814  GNUNET_free (h->description);
815  GNUNET_CONTAINER_multihashmap_iterate (h->dht_get_handles,
816  &regex_cancel_dht_get, NULL);
817  GNUNET_CONTAINER_multihashmap_iterate (h->dht_get_results,
818  &regex_free_result, NULL);
819  GNUNET_CONTAINER_multihashmap_destroy (h->dht_get_results);
820  GNUNET_CONTAINER_multihashmap_destroy (h->dht_get_handles);
821  if (0 < h->n_contexts)
822  {
823  for (i = 0; i < h->n_contexts; i++)
824  GNUNET_free (h->contexts[i]);
825  GNUNET_free (h->contexts);
826  }
827  GNUNET_free (h);
828 }
static int regex_cancel_dht_get(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over hash map entries to cancel DHT GET requests after a successful connect_by_string.
static int regex_free_result(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over hash map entries to free CadetRegexBlocks stored during the search for connect_by_strin...

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().

Here is the call graph for this function:
Here is the caller graph for this function: