GNUnet  0.20.0
regex_internal_lib.h File Reference

library to parse regular expressions into dfa More...

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

Functions

struct REGEX_INTERNAL_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_DHT_PathElement *get_path, unsigned int get_path_length, const struct GNUNET_DHT_PathElement *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().

Definition at line 3032 of file regex_internal.c.

3035 {
3036  struct REGEX_INTERNAL_Context ctx;
3037  struct REGEX_INTERNAL_Automaton *dfa;
3038  struct REGEX_INTERNAL_Automaton *nfa;
3039  struct REGEX_INTERNAL_StateSet nfa_start_eps_cls;
3040  struct REGEX_INTERNAL_StateSet singleton_set;
3041 
3043 
3044  /* Create NFA */
3045  nfa = REGEX_INTERNAL_construct_nfa (regex, len);
3046 
3047  if (NULL == nfa)
3048  {
3050  "Could not create DFA, because NFA creation failed\n");
3051  return NULL;
3052  }
3053 
3054  dfa = GNUNET_new (struct REGEX_INTERNAL_Automaton);
3055  dfa->type = DFA;
3056  dfa->regex = GNUNET_strdup (regex);
3057 
3058  /* Create DFA start state from epsilon closure */
3059  memset (&singleton_set, 0, sizeof(struct REGEX_INTERNAL_StateSet));
3060  state_set_append (&singleton_set, nfa->start);
3061  nfa_closure_set_create (&nfa_start_eps_cls, nfa, &singleton_set, NULL);
3062  state_set_clear (&singleton_set);
3063  dfa->start = dfa_state_create (&ctx, &nfa_start_eps_cls);
3064  automaton_add_state (dfa, dfa->start);
3065 
3066  construct_dfa_states (&ctx, nfa, dfa, dfa->start);
3068 
3069  /* Minimize DFA */
3070  if (GNUNET_OK != dfa_minimize (&ctx, dfa))
3071  {
3073  return NULL;
3074  }
3075 
3076  /* Create proofs and hashes for all states */
3077  if (GNUNET_OK != automaton_create_proofs (dfa))
3078  {
3080  return NULL;
3081  }
3082 
3083  /* Compress linear DFA paths */
3084  if (1 != max_path_len)
3085  dfa_compress_paths (&ctx, dfa, max_path_len);
3086 
3087  return dfa;
3088 }
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
@ 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.
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.

Definition at line 3092 of file regex_internal.c.

3093 {
3094  struct REGEX_INTERNAL_State *s;
3095  struct REGEX_INTERNAL_State *next_state;
3096 
3097  if (NULL == a)
3098  return;
3099 
3100  GNUNET_free (a->regex);
3102 
3103  for (s = a->states_head; NULL != s; s = next_state)
3104  {
3105  next_state = s->next;
3108  }
3109 
3110  GNUNET_free (a);
3111 }
#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.

Definition at line 3219 of file regex_internal.c.

3220 {
3221  int result;
3222 
3223  switch (a->type)
3224  {
3225  case DFA:
3226  result = evaluate_dfa (a, string);
3227  break;
3228 
3229  case NFA:
3230  result = evaluate_nfa (a, string);
3231  break;
3232 
3233  default:
3235  "Evaluating regex failed, automaton has no type!\n");
3237  break;
3238  }
3239 
3240  return result;
3241 }
static int result
Global testing status.
@ GNUNET_SYSERR
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 3289 of file regex_internal.c.

3292 {
3293  size_t size;
3294 
3295  size = string_len < GNUNET_REGEX_INITIAL_BYTES ? string_len
3297  if (NULL == input_string)
3298  {
3299  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Given input string was NULL!\n");
3300  return 0;
3301  }
3302  GNUNET_CRYPTO_hash (input_string, size, key);
3303 
3304  return size;
3305 }
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:68

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 3433 of file regex_internal.c.

3436 {
3437  struct REGEX_INTERNAL_State *s;
3438 
3439  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating over starting edges\n");
3442  NULL,
3443  a->start,
3444  iterator,
3445  iterator_cls);
3446  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating over DFA edges\n");
3447  for (s = a->states_head; NULL != s; s = s->next)
3448  {
3449  struct REGEX_BLOCK_Edge edges[s->transition_count];
3450  unsigned int num_edges;
3451 
3452  num_edges = state_get_edges (s, edges);
3453  if (((NULL != s->proof) && (0 < strlen (s->proof))) || s->accepting)
3454  {
3456  "Creating DFA edges at `%s' under key %s\n",
3457  s->proof,
3458  GNUNET_h2s (&s->hash));
3459  iterator (iterator_cls,
3460  &s->hash,
3461  s->proof,
3462  s->accepting,
3463  num_edges,
3464  edges);
3465  }
3466  s->marked = GNUNET_NO;
3467  }
3468 }
static int iterator(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Iterator over hash map entries.
@ GNUNET_NO
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.

Definition at line 3635 of file regex_internal.c.

3638 {
3639  struct GNUNET_CONTAINER_MultiHashMap *hm;
3640  struct client_iterator ci;
3641 
3643  ci.iterator = iterator;
3644  ci.iterator_cls = iterator_cls;
3645 
3649 
3651 }
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the 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.

Definition at line 220 of file regex_internal_dht.c.

221 {
222  GNUNET_assert (NULL != h->dfa); /* make sure to call announce first */
224  "REGEX_INTERNAL_reannounce: %s\n",
225  h->regex);
228  h);
229 }
@ 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 239 of file regex_internal_dht.c.

240 {
242  GNUNET_free (h);
243 }

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 697 of file regex_internal_dht.c.

702 {
703  struct REGEX_INTERNAL_Search *h;
704  struct GNUNET_DHT_GetHandle *get_h;
705  struct RegexSearchContext *ctx;
706  struct GNUNET_HashCode key;
707  size_t size;
708  size_t len;
709 
710  /* Initialize handle */
711  GNUNET_assert (NULL != dht);
712  GNUNET_assert (NULL != callback);
714  h->dht = dht;
715  h->description = GNUNET_strdup (string);
716  h->callback = callback;
717  h->callback_cls = callback_cls;
718  h->stats = stats;
719  h->dht_get_handles = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
720  h->dht_get_results = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
721 
722  /* Initialize context */
723  len = strlen (string);
726  "Initial key for `%s' is %s (based on `%.*s')\n",
727  string,
728  GNUNET_h2s (&key),
729  (int) size,
730  string);
731  ctx = GNUNET_new (struct RegexSearchContext);
732  ctx->position = size;
733  ctx->info = h;
734  GNUNET_array_append (h->contexts,
735  h->n_contexts,
736  ctx);
737  /* Start search in DHT */
738  get_h = GNUNET_DHT_get_start (h->dht, /* handle */
739  GNUNET_BLOCK_TYPE_REGEX, /* type */
740  &key, /* key to search */
741  DHT_REPLICATION, /* replication level */
742  DHT_OPT,
743  &h->description[size], /* xquery */
744  // FIXME add BLOOMFILTER to exclude filtered peers
745  len + 1 - size, /* xquery bits */
746  // FIXME add BLOOMFILTER SIZE
748  GNUNET_break (
749  GNUNET_OK ==
750  GNUNET_CONTAINER_multihashmap_put (h->dht_get_handles,
751  &key,
752  get_h,
754  );
755 
756  return h;
757 }
@ 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:1164
enum GNUNET_GenericReturnValue 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 *trunc_peer, const struct GNUNET_DHT_PathElement *get_path, unsigned int get_path_length, const struct GNUNET_DHT_PathElement *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:81
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 808 of file regex_internal_dht.c.

809 {
810  unsigned int i;
811 
812  GNUNET_free (h->description);
813  GNUNET_CONTAINER_multihashmap_iterate (h->dht_get_handles,
814  &regex_cancel_dht_get, NULL);
815  GNUNET_CONTAINER_multihashmap_iterate (h->dht_get_results,
816  &regex_free_result, NULL);
817  GNUNET_CONTAINER_multihashmap_destroy (h->dht_get_results);
818  GNUNET_CONTAINER_multihashmap_destroy (h->dht_get_handles);
819  if (0 < h->n_contexts)
820  {
821  for (i = 0; i < h->n_contexts; i++)
822  GNUNET_free (h->contexts[i]);
823  GNUNET_free (h->contexts);
824  }
825  GNUNET_free (h);
826 }
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: