GNUnet  0.10.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 122 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 223 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 desireable).
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 desireable).
Returns
DFA, needs to be freed using REGEX_INTERNAL_automaton_destroy.

Definition at line 3056 of file regex_internal.c.

References automaton_add_state(), automaton_create_proofs(), construct_dfa_states(), 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 announce_regex(), main(), and REGEX_INTERNAL_announce().

3059 {
3060  struct REGEX_INTERNAL_Context ctx;
3061  struct REGEX_INTERNAL_Automaton *dfa;
3062  struct REGEX_INTERNAL_Automaton *nfa;
3063  struct REGEX_INTERNAL_StateSet nfa_start_eps_cls;
3064  struct REGEX_INTERNAL_StateSet singleton_set;
3065 
3067 
3068  /* Create NFA */
3069  nfa = REGEX_INTERNAL_construct_nfa (regex, len);
3070 
3071  if (NULL == nfa)
3072  {
3074  "Could not create DFA, because NFA creation failed\n");
3075  return NULL;
3076  }
3077 
3078  dfa = GNUNET_new (struct REGEX_INTERNAL_Automaton);
3079  dfa->type = DFA;
3080  dfa->regex = GNUNET_strdup (regex);
3081 
3082  /* Create DFA start state from epsilon closure */
3083  memset (&singleton_set, 0, sizeof (struct REGEX_INTERNAL_StateSet));
3084  state_set_append (&singleton_set, nfa->start);
3085  nfa_closure_set_create (&nfa_start_eps_cls, nfa, &singleton_set, NULL);
3086  state_set_clear (&singleton_set);
3087  dfa->start = dfa_state_create (&ctx, &nfa_start_eps_cls);
3088  automaton_add_state (dfa, dfa->start);
3089 
3090  construct_dfa_states (&ctx, nfa, dfa, dfa->start);
3092 
3093  /* Minimize DFA */
3094  if (GNUNET_OK != dfa_minimize (&ctx, dfa))
3095  {
3097  return NULL;
3098  }
3099 
3100  /* Create proofs and hashes for all states */
3101  if (GNUNET_OK != automaton_create_proofs (dfa))
3102  {
3104  return NULL;
3105  }
3106 
3107  /* Compress linear DFA paths */
3108  if (1 != max_path_len)
3109  dfa_compress_paths (&ctx, dfa, max_path_len);
3110 
3111  return dfa;
3112 }
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.
enum REGEX_INTERNAL_AutomatonType type
Type of the automaton.
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...
static void state_set_clear(struct REGEX_INTERNAL_StateSet *set)
Clears the given StateSet 'set'.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Automaton representation.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
Context that contains an id counter for states and transitions as well as a DLL of automatons used as...
static void REGEX_INTERNAL_context_init(struct REGEX_INTERNAL_Context *ctx)
Initialize a new context.
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.
struct REGEX_INTERNAL_State * start
First state of the automaton.
static void state_set_append(struct REGEX_INTERNAL_StateSet *set, struct REGEX_INTERNAL_State *state)
Append state to the given StateSet.
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 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...
void REGEX_INTERNAL_automaton_destroy(struct REGEX_INTERNAL_Automaton *a)
Free the memory allocated by constructing the REGEX_INTERNAL_Automaton data structure.
#define GNUNET_log(kind,...)
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'.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
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 3122 of file regex_internal.c.

References automaton_destroy_state(), REGEX_INTERNAL_Automaton::canonical_regex, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_free_non_null, 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().

3123 {
3124  struct REGEX_INTERNAL_State *s;
3125  struct REGEX_INTERNAL_State *next_state;
3126 
3127  if (NULL == a)
3128  return;
3129 
3132 
3133  for (s = a->states_head; NULL != s; s = next_state)
3134  {
3135  next_state = s->next;
3138  }
3139 
3140  GNUNET_free (a);
3141 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct REGEX_INTERNAL_State * states_head
DLL of states.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
static void automaton_destroy_state(struct REGEX_INTERNAL_State *s)
Frees the memory used by State s.
struct REGEX_INTERNAL_State * states_tail
DLL of states.
struct REGEX_INTERNAL_State * next
This is a linked list to keep states in an automaton.
char * canonical_regex
Canonical regex (result of RX->NFA->DFA->RX)
#define GNUNET_free(ptr)
Wrapper around free.
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 3256 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.

3257 {
3258  int result;
3259 
3260  switch (a->type)
3261  {
3262  case DFA:
3263  result = evaluate_dfa (a, string);
3264  break;
3265  case NFA:
3266  result = evaluate_nfa (a, string);
3267  break;
3268  default:
3270  "Evaluating regex failed, automaton has no type!\n");
3271  result = GNUNET_SYSERR;
3272  break;
3273  }
3274 
3275  return result;
3276 }
enum REGEX_INTERNAL_AutomatonType type
Type of the automaton.
static int evaluate_nfa(struct REGEX_INTERNAL_Automaton *a, const char *string)
Evaluates the given string using the given NFA automaton.
static int result
Global testing status.
static int evaluate_dfa(struct REGEX_INTERNAL_Automaton *a, const char *string)
Evaluates the given string using the given DFA automaton.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define GNUNET_log(kind,...)
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 3335 of file regex_internal.c.

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

Referenced by REGEX_INTERNAL_search().

3338 {
3339  size_t size;
3340 
3341  size = string_len < GNUNET_REGEX_INITIAL_BYTES ? string_len
3343  if (NULL == input_string)
3344  {
3345  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Given input string was NULL!\n");
3346  return 0;
3347  }
3348  GNUNET_CRYPTO_hash (input_string, size, key);
3349 
3350  return size;
3351 }
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:44
#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
#define GNUNET_log(kind,...)
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 3479 of file regex_internal.c.

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

3482 {
3483  struct REGEX_INTERNAL_State *s;
3484 
3485  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating over starting edges\n");
3488  NULL,
3489  a->start,
3490  iterator,
3491  iterator_cls);
3492  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating over DFA edges\n");
3493  for (s = a->states_head; NULL != s; s = s->next)
3494  {
3495  struct REGEX_BLOCK_Edge edges[s->transition_count];
3496  unsigned int num_edges;
3497 
3498  num_edges = state_get_edges (s, edges);
3499  if (((NULL != s->proof) && (0 < strlen (s->proof))) || s->accepting)
3500  {
3502  "Creating DFA edges at `%s' under key %s\n",
3503  s->proof,
3504  GNUNET_h2s (&s->hash));
3505  iterator (iterator_cls,
3506  &s->hash,
3507  s->proof,
3508  s->accepting,
3509  num_edges,
3510  edges);
3511  }
3512  s->marked = GNUNET_NO;
3513  }
3514 }
static int iterator(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Iterator over hash map entries.
struct REGEX_INTERNAL_State * states_head
DLL of states.
struct GNUNET_HashCode hash
Hash of the state.
int accepting
If this is an accepting state or not.
#define GNUNET_NO
Definition: gnunet_common.h:81
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
char * proof
Proof for this state.
int marked
Marking of the state.
Edge representation.
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.
#define GNUNET_REGEX_INITIAL_BYTES
Constant for how many bytes the initial string regex should have.
struct REGEX_INTERNAL_State * start
First state of the automaton.
static unsigned int state_get_edges(struct REGEX_INTERNAL_State *s, struct REGEX_BLOCK_Edge *edges)
Get all edges leaving state s.
struct REGEX_INTERNAL_State * next
This is a linked list to keep states in an automaton.
#define GNUNET_log(kind,...)
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 3690 of file regex_internal.c.

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

3693 {
3694  struct GNUNET_CONTAINER_MultiHashMap *hm;
3695  struct client_iterator ci;
3696 
3698  ci.iterator = iterator;
3699  ci.iterator_cls = iterator_cls;
3700 
3704 
3706 }
unsigned int state_count
Number of states in the automaton.
static int iterator(void *cls, const struct GNUNET_PeerIdentity *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 iterate_reachables(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over hash map entries.
#define GNUNET_NO
Definition: gnunet_common.h:81
Internal representation of the hash map.
Store regex iterator and cls in one place to pass to the hashmap iterator.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
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.
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 &#39;a&#39;.
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.
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 198 of file regex_internal_dht.c.

References REGEX_INTERNAL_Announcement::dfa, REGEX_INTERNAL_Announcement::dht, GNUNET_assert, GNUNET_new, h, REGEX_INTERNAL_Announcement::priv, REGEX_INTERNAL_Announcement::regex, REGEX_INTERNAL_construct_dfa(), REGEX_INTERNAL_reannounce(), and REGEX_INTERNAL_Announcement::stats.

Referenced by handle_announce(), and reannounce_regex().

203 {
205 
206  GNUNET_assert (NULL != dht);
208  h->regex = regex;
209  h->dht = dht;
210  h->stats = stats;
211  h->priv = priv;
212  h->dfa = REGEX_INTERNAL_construct_dfa (regex, strlen (regex), compression);
214  return h;
215 }
static struct GNUNET_STATISTICS_Handle * stats
Handle for statistics.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
Handle to store cached data about a regex announce.
void REGEX_INTERNAL_reannounce(struct REGEX_INTERNAL_Announcement *h)
Announce again a regular expression previously announced.
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 &#39;regex&#39; of length &#39;len&#39;.
const char * regex
Regular expression.
struct GNUNET_STATISTICS_Handle * stats
Optional statistics handle to report usage.
struct GNUNET_DHT_Handle * dht
DHT handle to use, must be initialized externally.
const struct GNUNET_CRYPTO_EddsaPrivateKey * priv
Our private key.
static struct GNUNET_DHT_Handle * dht
Handle to the DHT.
struct REGEX_INTERNAL_Automaton * dfa
Automaton representation of the regex (expensive to build).
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 225 of file regex_internal_dht.c.

References REGEX_INTERNAL_Announcement::dfa, GNUNET_assert, GNUNET_ERROR_TYPE_INFO, LOG, REGEX_INTERNAL_Announcement::regex, REGEX_INTERNAL_iterate_reachable_edges(), and regex_iterator().

Referenced by reannounce(), reannounce_regex(), and REGEX_INTERNAL_announce().

226 {
227  GNUNET_assert (NULL != h->dfa); /* make sure to call announce first */
229  "REGEX_INTERNAL_reannounce: %s\n",
230  h->regex);
233  h);
234 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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.
const char * regex
Regular expression.
#define LOG(kind,...)
void REGEX_INTERNAL_iterate_reachable_edges(struct REGEX_INTERNAL_Automaton *a, REGEX_INTERNAL_KeyIterator iterator, void *iterator_cls)
Iterate over all edges of automaton &#39;a&#39; that are reachable from a state with a proof of at least GNUN...
struct REGEX_INTERNAL_Automaton * dfa
Automaton representation of the regex (expensive to build).
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 244 of file regex_internal_dht.c.

References REGEX_INTERNAL_Announcement::dfa, GNUNET_free, and REGEX_INTERNAL_automaton_destroy().

Referenced by client_disconnect_cb(), and shutdown_task().

245 {
247  GNUNET_free (h);
248 }
void REGEX_INTERNAL_automaton_destroy(struct REGEX_INTERNAL_Automaton *a)
Free the memory allocated by constructing the REGEX_INTERNAL_Automaton data structure.
struct REGEX_INTERNAL_Automaton * dfa
Automaton representation of the regex (expensive to build).
#define GNUNET_free(ptr)
Wrapper around free.
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.

References REGEX_INTERNAL_Search::callback, REGEX_INTERNAL_Search::callback_cls, REGEX_INTERNAL_Search::contexts, ctx, REGEX_INTERNAL_Search::description, REGEX_INTERNAL_Announcement::dht, REGEX_INTERNAL_Search::dht, REGEX_INTERNAL_Search::dht_get_handles, REGEX_INTERNAL_Search::dht_get_results, 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, RegexSearchContext::info, len, LOG, REGEX_INTERNAL_Search::n_contexts, RegexSearchContext::position, REGEX_INTERNAL_get_first_key(), size, REGEX_INTERNAL_Announcement::stats, and REGEX_INTERNAL_Search::stats.

Referenced by dht_connect_cb(), and handle_search().

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);
715  h = GNUNET_new (struct REGEX_INTERNAL_Search);
716  h->dht = dht;
717  h->description = GNUNET_strdup (string);
718  h->callback = callback;
719  h->callback_cls = callback_cls;
720  h->stats = stats;
723 
724  /* Initialize context */
725  len = strlen (string);
726  size = REGEX_INTERNAL_get_first_key (string, len, &key);
728  "Initial key for `%s' is %s (based on `%.*s')\n",
729  string,
730  GNUNET_h2s (&key),
731  size,
732  string);
733  ctx = GNUNET_new (struct RegexSearchContext);
734  ctx->position = size;
735  ctx->info = h;
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
749  &dht_get_string_handler, ctx);
750  GNUNET_break (
751  GNUNET_OK ==
753  &key,
754  get_h,
756  );
757 
758  return h;
759 }
static struct GNUNET_STATISTICS_Handle * stats
Handle for statistics.
#define DHT_REPLICATION
DHT replication level to use.
size_t position
Part of the description already consumed by this particular search branch.
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.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Struct to keep state of running searches that have consumed a part of the inital string.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define DHT_OPT
DHT options to set.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
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.
, &#39; bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
struct REGEX_INTERNAL_Search * info
Information about the search.
A 512-bit hashcode.
struct GNUNET_CONTAINER_MultiHashMap * dht_get_results
Results from running DHT GETs, values are of type &#39;struct Result&#39;.
struct GNUNET_HashCode key
The key used in the DHT.
static unsigned int size
Size of the "table".
Definition: peer.c:67
struct GNUNET_DHT_Handle * dht
DHT handle to use, must be initialized externally.
unsigned int n_contexts
Number of contexts (branches/steps in search).
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.
Handle to a GET request.
Definition: dht_api.c:80
struct GNUNET_STATISTICS_Handle * stats
Optional statistics handle to report usage.
Struct to keep information of searches of services described by a regex using a user-provided string ...
#define GNUNET_array_append(arr, size, element)
Append an element to a list (growing the list by one).
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:1072
char * description
User provided description of the searched service.
REGEX_INTERNAL_Found callback
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
#define LOG(kind,...)
Block to store a cadet regex state.
static struct GNUNET_DHT_Handle * dht
Handle to the DHT.
struct GNUNET_CONTAINER_MultiHashMap * dht_get_handles
Running DHT GETs.
struct RegexSearchContext ** contexts
Contexts, for each running DHT GET.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
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.

References REGEX_INTERNAL_Search::contexts, REGEX_INTERNAL_Search::description, REGEX_INTERNAL_Search::dht_get_handles, REGEX_INTERNAL_Search::dht_get_results, GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_free, REGEX_INTERNAL_Search::n_contexts, regex_cancel_dht_get(), and regex_free_result().

Referenced by client_disconnect_cb(), and dht_da().

811 {
812  unsigned int i;
813 
816  &regex_cancel_dht_get, NULL);
818  &regex_free_result, NULL);
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_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...
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
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.
struct GNUNET_CONTAINER_MultiHashMap * dht_get_results
Results from running DHT GETs, values are of type &#39;struct Result&#39;.
unsigned int n_contexts
Number of contexts (branches/steps in search).
char * description
User provided description of the searched service.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
struct GNUNET_CONTAINER_MultiHashMap * dht_get_handles
Running DHT GETs.
struct RegexSearchContext ** contexts
Contexts, for each running DHT GET.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function: