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

3062 {
3063  struct REGEX_INTERNAL_Context ctx;
3064  struct REGEX_INTERNAL_Automaton *dfa;
3065  struct REGEX_INTERNAL_Automaton *nfa;
3066  struct REGEX_INTERNAL_StateSet nfa_start_eps_cls;
3067  struct REGEX_INTERNAL_StateSet singleton_set;
3068 
3070 
3071  /* Create NFA */
3072  nfa = REGEX_INTERNAL_construct_nfa(regex, len);
3073 
3074  if (NULL == nfa)
3075  {
3077  "Could not create DFA, because NFA creation failed\n");
3078  return NULL;
3079  }
3080 
3081  dfa = GNUNET_new(struct REGEX_INTERNAL_Automaton);
3082  dfa->type = DFA;
3083  dfa->regex = GNUNET_strdup(regex);
3084 
3085  /* Create DFA start state from epsilon closure */
3086  memset(&singleton_set, 0, sizeof(struct REGEX_INTERNAL_StateSet));
3087  state_set_append(&singleton_set, nfa->start);
3088  nfa_closure_set_create(&nfa_start_eps_cls, nfa, &singleton_set, NULL);
3089  state_set_clear(&singleton_set);
3090  dfa->start = dfa_state_create(&ctx, &nfa_start_eps_cls);
3091  automaton_add_state(dfa, dfa->start);
3092 
3093  construct_dfa_states(&ctx, nfa, dfa, dfa->start);
3095 
3096  /* Minimize DFA */
3097  if (GNUNET_OK != dfa_minimize(&ctx, dfa))
3098  {
3100  return NULL;
3101  }
3102 
3103  /* Create proofs and hashes for all states */
3104  if (GNUNET_OK != automaton_create_proofs(dfa))
3105  {
3107  return NULL;
3108  }
3109 
3110  /* Compress linear DFA paths */
3111  if (1 != max_path_len)
3112  dfa_compress_paths(&ctx, dfa, max_path_len);
3113 
3114  return dfa;
3115 }
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:75
#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 3125 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().

3126 {
3127  struct REGEX_INTERNAL_State *s;
3128  struct REGEX_INTERNAL_State *next_state;
3129 
3130  if (NULL == a)
3131  return;
3132 
3135 
3136  for (s = a->states_head; NULL != s; s = next_state)
3137  {
3138  next_state = s->next;
3141  }
3142 
3143  GNUNET_free(a);
3144 }
#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 3259 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.

3260 {
3261  int result;
3262 
3263  switch (a->type)
3264  {
3265  case DFA:
3266  result = evaluate_dfa(a, string);
3267  break;
3268 
3269  case NFA:
3270  result = evaluate_nfa(a, string);
3271  break;
3272 
3273  default:
3275  "Evaluating regex failed, automaton has no type!\n");
3276  result = GNUNET_SYSERR;
3277  break;
3278  }
3279 
3280  return result;
3281 }
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:76
#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 3340 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().

3343 {
3344  size_t size;
3345 
3346  size = string_len < GNUNET_REGEX_INITIAL_BYTES ? string_len
3348  if (NULL == input_string)
3349  {
3350  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Given input string was NULL!\n");
3351  return 0;
3352  }
3353  GNUNET_CRYPTO_hash(input_string, size, key);
3354 
3355  return size;
3356 }
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:66
#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 3484 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().

3487 {
3488  struct REGEX_INTERNAL_State *s;
3489 
3490  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Iterating over starting edges\n");
3493  NULL,
3494  a->start,
3495  iterator,
3496  iterator_cls);
3497  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Iterating over DFA edges\n");
3498  for (s = a->states_head; NULL != s; s = s->next)
3499  {
3500  struct REGEX_BLOCK_Edge edges[s->transition_count];
3501  unsigned int num_edges;
3502 
3503  num_edges = state_get_edges(s, edges);
3504  if (((NULL != s->proof) && (0 < strlen(s->proof))) || s->accepting)
3505  {
3507  "Creating DFA edges at `%s' under key %s\n",
3508  s->proof,
3509  GNUNET_h2s(&s->hash));
3510  iterator(iterator_cls,
3511  &s->hash,
3512  s->proof,
3513  s->accepting,
3514  num_edges,
3515  edges);
3516  }
3517  s->marked = GNUNET_NO;
3518  }
3519 }
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:78
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 3693 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().

3696 {
3697  struct GNUNET_CONTAINER_MultiHashMap *hm;
3698  struct client_iterator ci;
3699 
3701  ci.iterator = iterator;
3702  ci.iterator_cls = iterator_cls;
3703 
3707 
3709 }
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:78
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 197 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().

202 {
204 
205  GNUNET_assert(NULL != dht);
207  h->regex = regex;
208  h->dht = dht;
209  h->stats = stats;
210  h->priv = priv;
211  h->dfa = REGEX_INTERNAL_construct_dfa(regex, strlen(regex), compression);
213  return h;
214 }
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 224 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().

225 {
226  GNUNET_assert(NULL != h->dfa); /* make sure to call announce first */
228  "REGEX_INTERNAL_reannounce: %s\n",
229  h->regex);
232  h);
233 }
#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 243 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().

244 {
246  GNUNET_free(h);
247 }
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 695 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().

700 {
701  struct REGEX_INTERNAL_Search *h;
702  struct GNUNET_DHT_GetHandle *get_h;
703  struct RegexSearchContext *ctx;
704  struct GNUNET_HashCode key;
705  size_t size;
706  size_t len;
707 
708  /* Initialize handle */
709  GNUNET_assert(NULL != dht);
710  GNUNET_assert(NULL != callback);
711  h = GNUNET_new(struct REGEX_INTERNAL_Search);
712  h->dht = dht;
713  h->description = GNUNET_strdup(string);
714  h->callback = callback;
715  h->callback_cls = callback_cls;
716  h->stats = stats;
719 
720  /* Initialize context */
721  len = strlen(string);
722  size = REGEX_INTERNAL_get_first_key(string, len, &key);
724  "Initial key for `%s' is %s (based on `%.*s')\n",
725  string,
726  GNUNET_h2s(&key),
727  size,
728  string);
729  ctx = GNUNET_new(struct RegexSearchContext);
730  ctx->position = size;
731  ctx->info = h;
733  h->n_contexts,
734  ctx);
735  /* Start search in DHT */
736  get_h = GNUNET_DHT_get_start(h->dht, /* handle */
737  GNUNET_BLOCK_TYPE_REGEX, /* type */
738  &key, /* key to search */
739  DHT_REPLICATION, /* replication level */
740  DHT_OPT,
741  &h->description[size], /* xquery */
742  // FIXME add BLOOMFILTER to exclude filtered peers
743  len + 1 - size, /* xquery bits */
744  // FIXME add BLOOMFILTER SIZE
745  &dht_get_string_handler, ctx);
746  GNUNET_break(
747  GNUNET_OK ==
749  &key,
750  get_h,
752  );
753 
754  return h;
755 }
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:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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:66
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:78
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:1062
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 806 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().

807 {
808  unsigned int i;
809 
812  &regex_cancel_dht_get, NULL);
814  &regex_free_result, NULL);
817  if (0 < h->n_contexts)
818  {
819  for (i = 0; i < h->n_contexts; i++)
820  GNUNET_free(h->contexts[i]);
821  GNUNET_free(h->contexts);
822  }
823  GNUNET_free(h);
824 }
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: