GNUnet  0.10.x
Data Structures | Macros | Functions
regex_internal_dht.c File Reference

library to announce regexes in the network and match strings against published regexes. More...

#include "platform.h"
#include "regex_internal_lib.h"
#include "regex_block_lib.h"
#include "gnunet_dht_service.h"
#include "gnunet_statistics_service.h"
#include "gnunet_constants.h"
#include "gnunet_signatures.h"
Include dependency graph for regex_internal_dht.c:

Go to the source code of this file.

Data Structures

struct  REGEX_INTERNAL_Announcement
 Handle to store cached data about a regex announce. More...
 
struct  RegexSearchContext
 Struct to keep state of running searches that have consumed a part of the inital string. More...
 
struct  Result
 Type of values in dht_get_results. More...
 
struct  REGEX_INTERNAL_Search
 Struct to keep information of searches of services described by a regex using a user-provided string service description. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from(kind, "regex-dht", __VA_ARGS__)
 
#define DHT_REPLICATION   5
 DHT replication level to use. More...
 
#define DHT_TTL   GNUNET_TIME_UNIT_HOURS
 DHT record lifetime to use. More...
 
#define DHT_OPT   GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE
 DHT options to set. More...
 

Functions

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. 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...
 
static void regex_next_edge (const struct RegexBlock *block, size_t size, struct RegexSearchContext *ctx)
 Jump to the next edge, with the longest matching token. More...
 
static void dht_get_string_accept_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. More...
 
static void regex_find_path (const struct GNUNET_HashCode *key, struct RegexSearchContext *ctx)
 Find a path to a peer that offers a regex service compatible with a given string. More...
 
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. More...
 
static int regex_result_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
 Iterator over found existing cadet regex blocks that match an ongoing search. More...
 
static int regex_edge_iterator (void *cls, const char *token, size_t len, const struct GNUNET_HashCode *key)
 Iterator over edges in a regex block retrieved from the DHT. 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...
 
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. More...
 
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_string. More...
 
void REGEX_INTERNAL_search_cancel (struct REGEX_INTERNAL_Search *h)
 Cancel an ongoing regex search in the DHT and free all resources. More...
 

Detailed Description

library to announce regexes in the network and match strings against published regexes.

Author
Bartlomiej Polot

Definition in file regex_internal_dht.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from(kind, "regex-dht", __VA_ARGS__)

◆ DHT_REPLICATION

#define DHT_REPLICATION   5

DHT replication level to use.

Definition at line 40 of file regex_internal_dht.c.

Referenced by regex_find_path(), REGEX_INTERNAL_search(), regex_iterator(), and regex_next_edge().

◆ DHT_TTL

#define DHT_TTL   GNUNET_TIME_UNIT_HOURS

DHT record lifetime to use.

Definition at line 45 of file regex_internal_dht.c.

Referenced by regex_iterator().

◆ DHT_OPT

DHT options to set.

Definition at line 50 of file regex_internal_dht.c.

Referenced by regex_find_path(), REGEX_INTERNAL_search(), regex_iterator(), and regex_next_edge().

Function Documentation

◆ regex_iterator()

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 
)
static

Regex callback iterator to store own service description in the DHT.

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

References REGEX_INTERNAL_Announcement::dht, DHT_OPT, DHT_REPLICATION, DHT_TTL, RegexAcceptBlock::expiration_time, GNUNET_assert, GNUNET_BLOCK_TYPE_REGEX, GNUNET_BLOCK_TYPE_REGEX_ACCEPT, GNUNET_CONSTANTS_DHT_MAX_EXPIRATION, GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_CRYPTO_eddsa_sign(), GNUNET_DHT_put(), GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_h2s(), GNUNET_NO, GNUNET_OK, GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_hton(), GNUNET_TIME_relative_to_absolute(), GNUNET_YES, h, key, RegexAcceptBlock::key, LOG, RegexBlock::num_edges, RegexAcceptBlock::peer, REGEX_INTERNAL_Announcement::priv, GNUNET_PeerIdentity::public_key, RegexAcceptBlock::purpose, GNUNET_CRYPTO_EccSignaturePurpose::purpose, REGEX_BLOCK_create(), RegexAcceptBlock::signature, size, GNUNET_CRYPTO_EccSignaturePurpose::size, and REGEX_INTERNAL_Announcement::stats.

Referenced by REGEX_INTERNAL_reannounce().

101 {
102  struct REGEX_INTERNAL_Announcement *h = cls;
103  struct RegexBlock *block;
104  size_t size;
105  unsigned int i;
106 
108  "DHT PUT for state %s with proof `%s' and %u edges:\n",
109  GNUNET_h2s(key),
110  proof,
111  num_edges);
112  for (i = 0; i < num_edges; i++)
113  {
115  "Edge %u `%s' towards %s\n",
116  i,
117  edges[i].label,
118  GNUNET_h2s(&edges[i].destination));
119  }
120  if (GNUNET_YES == accepting)
121  {
122  struct RegexAcceptBlock ab;
123 
125  "State %s is accepting, putting own id\n",
126  GNUNET_h2s(key));
127  size = sizeof(struct RegexAcceptBlock);
128  ab.purpose.size = ntohl(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) +
129  sizeof(struct GNUNET_TIME_AbsoluteNBO) +
130  sizeof(struct GNUNET_HashCode));
131  ab.purpose.purpose = ntohl(GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT);
133  ab.key = *key;
135  &ab.peer.public_key);
138  &ab.purpose,
139  &ab.signature));
140 
141  GNUNET_STATISTICS_update(h->stats, "# regex accepting blocks stored",
142  1, GNUNET_NO);
143  GNUNET_STATISTICS_update(h->stats, "# regex accepting block bytes stored",
144  sizeof(struct RegexAcceptBlock), GNUNET_NO);
145  (void)
146  GNUNET_DHT_put(h->dht, key,
150  size,
151  &ab,
153  NULL, NULL);
154  }
155  block = REGEX_BLOCK_create(proof,
156  num_edges,
157  edges,
158  accepting,
159  &size);
160  if (NULL == block)
161  return;
162  (void)GNUNET_DHT_put(h->dht,
163  key,
165  DHT_OPT,
167  size,
168  block,
170  NULL,
171  NULL);
173  "# regex blocks stored",
174  1,
175  GNUNET_NO);
177  "# regex block bytes stored",
178  size,
179  GNUNET_NO);
180  GNUNET_free(block);
181 }
#define GNUNET_CONSTANTS_DHT_MAX_EXPIRATION
How long do we cache records at most in the DHT?
Block to store a cadet regex accepting state.
#define DHT_REPLICATION
DHT replication level to use.
We should keep track of the route that the message took in the P2P network.
uint16_t num_edges
Number of edges parting from this state.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:246
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Block to announce a regex state.
int GNUNET_CRYPTO_eddsa_sign(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
EdDSA sign a given block.
Definition: crypto_ecc.c:989
#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).
Block to announce a peer accepting a state.
Definition: block_regex.h:49
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
#define DHT_OPT
DHT options to set.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
#define DHT_TTL
DHT record lifetime to use.
static uint64_t proof
Definition: gnunet-scrypt.c:41
Handle to store cached data about a regex announce.
A 512-bit hashcode.
struct RegexBlock * REGEX_BLOCK_create(const char *proof, unsigned int num_edges, const struct REGEX_BLOCK_Edge *edges, int accepting, size_t *rsize)
Construct a regex block to be stored in the DHT.
struct GNUNET_HashCode key
The key used in the DHT.
struct GNUNET_DHT_PutHandle * GNUNET_DHT_put(struct GNUNET_DHT_Handle *handle, const struct GNUNET_HashCode *key, uint32_t desired_replication_level, enum GNUNET_DHT_RouteOption options, enum GNUNET_BLOCK_Type type, size_t size, const void *data, struct GNUNET_TIME_Absolute exp, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
Perform a PUT operation storing data in the DHT.
Definition: dht_api.c:961
static unsigned int size
Size of the "table".
Definition: peer.c:66
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:272
#define GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT
Accept state in regex DFA.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_STATISTICS_Handle * stats
Optional statistics handle to report usage.
#define LOG(kind,...)
struct GNUNET_DHT_Handle * dht
DHT handle to use, must be initialized externally.
const struct GNUNET_CRYPTO_EddsaPrivateKey * priv
Our private key.
Block to store a cadet regex state.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:655
#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_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().

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

static void regex_next_edge ( const struct RegexBlock block,
size_t  size,
struct RegexSearchContext ctx 
)
static

Jump to the next edge, with the longest matching token.

Parameters
blockBlock found in the DHT.
sizeSize of the block.
ctxContext of the search.

Definition at line 604 of file regex_internal_dht.c.

References REGEX_INTERNAL_Search::contexts, REGEX_INTERNAL_Search::description, 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_BLOCK_TYPE_REGEX, GNUNET_break, GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CONTAINER_multihashmap_get_multiple(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_DHT_get_start(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_YES, RegexSearchContext::hash, RegexSearchContext::info, LOG, RegexSearchContext::longest_match, REGEX_INTERNAL_Search::n_contexts, RegexSearchContext::position, REGEX_BLOCK_iterate(), regex_edge_iterator(), regex_result_iterator(), result, and REGEX_INTERNAL_Search::stats.

Referenced by dht_get_string_handler(), and regex_result_iterator().

607 {
608  struct RegexSearchContext *new_ctx;
609  struct REGEX_INTERNAL_Search *info = ctx->info;
610  struct GNUNET_DHT_GetHandle *get_h;
611  struct GNUNET_HashCode *hash;
612  const char *rest;
613  int result;
614 
615  LOG(GNUNET_ERROR_TYPE_DEBUG, "Next edge\n");
616  /* Find the longest match for the current string position,
617  * among tokens in the given block */
618  ctx->longest_match = 0;
619  result = REGEX_BLOCK_iterate(block, size,
620  &regex_edge_iterator, ctx);
621  GNUNET_break(GNUNET_OK == result);
622 
623  /* Did anything match? */
624  if (0 == ctx->longest_match)
625  {
627  "no match in block\n");
628  return;
629  }
630 
631  hash = &ctx->hash;
632  new_ctx = GNUNET_new(struct RegexSearchContext);
633  new_ctx->info = info;
634  new_ctx->position = ctx->position + ctx->longest_match;
635  GNUNET_array_append(info->contexts, info->n_contexts, new_ctx);
636 
637  /* Check whether we already have a DHT GET running for it */
638  if (GNUNET_YES ==
640  {
642  "GET for %s running, END\n",
643  GNUNET_h2s(hash));
645  hash,
647  new_ctx);
648  return; /* We are already looking for it */
649  }
650 
651  GNUNET_STATISTICS_update(info->stats, "# regex nodes traversed",
652  1, GNUNET_NO);
653 
655  "Following edges at %s for offset %u in `%s'\n",
656  GNUNET_h2s(hash),
657  (unsigned int)ctx->position,
658  info->description);
659  rest = &new_ctx->info->description[new_ctx->position];
660  get_h =
661  GNUNET_DHT_get_start(info->dht, /* handle */
662  GNUNET_BLOCK_TYPE_REGEX, /* type */
663  hash, /* key to search */
664  DHT_REPLICATION, /* replication level */
665  DHT_OPT,
666  rest, /* xquery */
667  strlen(rest) + 1, /* xquery bits */
668  &dht_get_string_handler, new_ctx);
669  if (GNUNET_OK !=
671  hash,
672  get_h,
674  {
675  GNUNET_break(0);
676  return;
677  }
678 }
#define DHT_REPLICATION
DHT replication level to use.
size_t position
Part of the description already consumed by this particular search branch.
int REGEX_BLOCK_iterate(const struct RegexBlock *block, size_t size, REGEX_INTERNAL_EgdeIterator iterator, void *iter_cls)
Iterate over all edges of a block of a regex state.
Struct to keep state of running searches that have consumed a part of the inital string.
#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).
#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.
int GNUNET_CONTAINER_multihashmap_contains(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Check if the map contains any value under the given key (including values that are NULL)...
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#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...
struct GNUNET_HashCode hash
Destination hash of the longest match.
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.
static int result
Global testing status.
A 512-bit hashcode.
struct GNUNET_CONTAINER_MultiHashMap * dht_get_results
Results from running DHT GETs, values are of type &#39;struct Result&#39;.
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).
static int regex_edge_iterator(void *cls, const char *token, size_t len, const struct GNUNET_HashCode *key)
Iterator over edges in a regex block retrieved from the DHT.
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).
int GNUNET_CONTAINER_multihashmap_get_multiple(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map that match a particular key.
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.
#define GNUNET_YES
Definition: gnunet_common.h:77
#define LOG(kind,...)
Block to store a cadet regex state.
struct GNUNET_CONTAINER_MultiHashMap * dht_get_handles
Running DHT GETs.
unsigned int longest_match
We just want to look for one edge, the longer the better.
struct RegexSearchContext ** contexts
Contexts, for each running DHT GET.
static int regex_result_iterator(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over found existing cadet regex blocks that match an ongoing search.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dht_get_string_accept_handler()

static void dht_get_string_accept_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 
)
static

Function to process DHT string to regex matching.

Called on each result obtained for the DHT search.

Parameters
clsClosure (search context).
expWhen will this value expire.
keyKey of the result.
get_pathPath of the get request.
get_path_lengthLenght of get_path.
put_pathPath of the put request.
put_path_lengthLength of the put_path.
typeType of the result.
sizeNumber of bytes in data.
dataPointer to the result data.

Definition at line 380 of file regex_internal_dht.c.

References REGEX_INTERNAL_Search::callback, REGEX_INTERNAL_Search::callback_cls, ctx, data, REGEX_INTERNAL_Search::description, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_NO, GNUNET_STATISTICS_update(), RegexSearchContext::info, LOG, RegexAcceptBlock::peer, and REGEX_INTERNAL_Search::stats.

Referenced by regex_find_path().

388 {
389  const struct RegexAcceptBlock *block = data;
390  struct RegexSearchContext *ctx = cls;
391  struct REGEX_INTERNAL_Search *info = ctx->info;
392 
394  "Regex result accept for %s (key %s)\n",
395  info->description, GNUNET_h2s(key));
396 
398  "# regex accepting blocks found",
399  1, GNUNET_NO);
401  "# regex accepting block bytes found",
402  size, GNUNET_NO);
403  info->callback(info->callback_cls,
404  &block->peer,
405  get_path, get_path_length,
406  put_path, put_path_length);
407 }
Struct to keep state of running searches that have consumed a part of the inital string.
#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).
Block to announce a peer accepting a state.
Definition: block_regex.h:49
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
struct GNUNET_PeerIdentity peer
Public key of the peer signing.
Definition: block_regex.h:69
struct REGEX_INTERNAL_Search * info
Information about the search.
static unsigned int size
Size of the "table".
Definition: peer.c:66
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 ...
char * description
User provided description of the searched service.
REGEX_INTERNAL_Found callback
#define LOG(kind,...)
uint32_t data
The data value.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ regex_find_path()

static void regex_find_path ( const struct GNUNET_HashCode key,
struct RegexSearchContext ctx 
)
static

Find a path to a peer that offers a regex service compatible with a given string.

Parameters
keyThe key of the accepting state.
ctxContext containing info about the string, tunnel, etc.

Definition at line 418 of file regex_internal_dht.c.

References REGEX_INTERNAL_Search::dht, REGEX_INTERNAL_Search::dht_get_handles, dht_get_string_accept_handler(), DHT_OPT, DHT_REPLICATION, GNUNET_BLOCK_TYPE_REGEX_ACCEPT, GNUNET_break, GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_DHT_get_start(), GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_OK, RegexSearchContext::info, LOG, and RegexSearchContext::position.

Referenced by dht_get_string_handler(), and regex_result_iterator().

420 {
421  struct GNUNET_DHT_GetHandle *get_h;
422 
424  "Accept state found, now searching for paths to %s\n",
425  GNUNET_h2s(key),
426  (unsigned int)ctx->position);
427  get_h = GNUNET_DHT_get_start(ctx->info->dht, /* handle */
429  key, /* key to search */
430  DHT_REPLICATION, /* replication level */
432  NULL, /* xquery */ // FIXME BLOOMFILTER
433  0, /* xquery bits */ // FIXME BLOOMFILTER SIZE
437  key,
438  get_h,
440 }
Block to store a cadet regex accepting state.
#define DHT_REPLICATION
DHT replication level to use.
We should keep track of the route that the message took in the P2P network.
size_t position
Part of the description already consumed by this particular search branch.
static void dht_get_string_accept_handler(void *cls, struct GNUNET_TIME_Absolute exp, const struct GNUNET_HashCode *key, const struct GNUNET_PeerIdentity *get_path, unsigned int get_path_length, const struct GNUNET_PeerIdentity *put_path, unsigned int put_path_length, enum GNUNET_BLOCK_Type type, size_t size, const void *data)
Function to process DHT string to regex matching.
#define 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 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...
struct REGEX_INTERNAL_Search * info
Information about the search.
struct GNUNET_DHT_Handle * dht
DHT handle to use, must be initialized externally.
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
Allow multiple values with the same key.
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
#define LOG(kind,...)
struct GNUNET_CONTAINER_MultiHashMap * dht_get_handles
Running DHT GETs.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dht_get_string_handler()

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 
)
static

Function to process DHT string to regex matching.

Called on each result obtained for the DHT search.

Parameters
clsclosure (search context)
expwhen will this value expire
keykey of the result
get_pathpath of the get request (not used)
get_path_lengthlength of get_path (not used)
put_pathpath of the put request (not used)
put_path_lengthlength of the put_path (not used)
typetype of the result
sizenumber of bytes in data
datapointer to the result data

TODO: re-issue the request after certain time? cancel after X results?

Definition at line 461 of file regex_internal_dht.c.

References ctx, data, Result::data, REGEX_INTERNAL_Search::description, REGEX_INTERNAL_Search::dht_get_results, GNUNET_BLOCK_is_accepting(), GNUNET_break, GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_ERROR_TYPE_INFO, GNUNET_h2s(), GNUNET_malloc, GNUNET_memcpy, GNUNET_OK, GNUNET_YES, RegexSearchContext::info, len, LOG, RegexSearchContext::position, regex_find_path(), regex_next_edge(), size, and Result::size.

Referenced by REGEX_INTERNAL_search(), and regex_next_edge().

469 {
470  const struct RegexBlock *block = data;
471  struct RegexSearchContext *ctx = cls;
472  struct REGEX_INTERNAL_Search *info = ctx->info;
473  size_t len;
474  struct Result *copy;
475 
477  "DHT GET result for %s (%s)\n",
478  GNUNET_h2s(key), ctx->info->description);
479  copy = GNUNET_malloc(sizeof(struct Result) + size);
480  copy->size = size;
481  copy->data = &copy[1];
482  GNUNET_memcpy(&copy[1], block, size);
485  key, copy,
487  len = strlen(info->description);
488  if (len == ctx->position) // String processed
489  {
491  {
492  regex_find_path(key, ctx);
493  }
494  else
495  {
496  LOG(GNUNET_ERROR_TYPE_INFO, "block not accepting!\n");
497  /* FIXME REGEX this block not successful, wait for more? start timeout? */
498  }
499  return;
500  }
501  regex_next_edge(block, size, ctx);
502 }
GNUNET_NETWORK_STRUCT_END int GNUNET_BLOCK_is_accepting(const struct RegexBlock *block, size_t size)
Test if this block is marked as being an accept state.
const void * data
The raw result data.
size_t position
Part of the description already consumed by this particular search branch.
Block to announce a regex state.
Struct to keep state of running searches that have consumed a part of the inital string.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#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_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.
struct REGEX_INTERNAL_Search * info
Information about the search.
Type of values in dht_get_results.
struct GNUNET_CONTAINER_MultiHashMap * dht_get_results
Results from running DHT GETs, values are of type &#39;struct Result&#39;.
static unsigned int size
Size of the "table".
Definition: peer.c:66
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.
Struct to keep information of searches of services described by a regex using a user-provided string ...
Allow multiple values with the same key.
char * description
User provided description of the searched service.
#define GNUNET_YES
Definition: gnunet_common.h:77
static void regex_next_edge(const struct RegexBlock *block, size_t size, struct RegexSearchContext *ctx)
Jump to the next edge, with the longest matching token.
#define LOG(kind,...)
uint32_t data
The data value.
#define GNUNET_malloc(size)
Wrapper around malloc.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
size_t size
Number of bytes in data.
static void regex_find_path(const struct GNUNET_HashCode *key, struct RegexSearchContext *ctx)
Find a path to a peer that offers a regex service compatible with a given string. ...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ regex_result_iterator()

static int regex_result_iterator ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Iterator over found existing cadet regex blocks that match an ongoing search.

Parameters
clsClosure (current context)-
keyCurrent key code (key for cached block).
valueValue in the hash map (cached RegexBlock).
Returns
GNUNET_YES: we should always continue to iterate.

Definition at line 514 of file regex_internal_dht.c.

References ctx, Result::data, REGEX_INTERNAL_Search::description, GNUNET_BLOCK_is_accepting(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_YES, RegexSearchContext::info, LOG, RegexSearchContext::position, regex_find_path(), regex_next_edge(), result, Result::size, REGEX_INTERNAL_Search::stats, and value.

Referenced by regex_next_edge().

517 {
518  struct Result *result = value;
519  const struct RegexBlock *block = result->data;
520  struct RegexSearchContext *ctx = cls;
521 
522  if ((GNUNET_YES ==
523  GNUNET_BLOCK_is_accepting(block, result->size)) &&
524  (ctx->position == strlen(ctx->info->description)))
525  {
527  "Found accepting known block\n");
528  regex_find_path(key, ctx);
529  return GNUNET_YES; // We found an accept state!
530  }
532  "* %u, %u, [%u]\n",
533  ctx->position,
534  strlen(ctx->info->description),
535  GNUNET_BLOCK_is_accepting(block, result->size));
536  regex_next_edge(block, result->size, ctx);
537 
538  GNUNET_STATISTICS_update(ctx->info->stats, "# regex cadet blocks iterated",
539  1, GNUNET_NO);
540 
541  return GNUNET_YES;
542 }
GNUNET_NETWORK_STRUCT_END int GNUNET_BLOCK_is_accepting(const struct RegexBlock *block, size_t size)
Test if this block is marked as being an accept state.
const void * data
The raw result data.
size_t position
Part of the description already consumed by this particular search branch.
Block to announce a regex state.
Struct to keep state of running searches that have consumed a part of the inital string.
#define GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
static char * value
Value of the record to add/remove.
struct REGEX_INTERNAL_Search * info
Information about the search.
static int result
Global testing status.
Type of values in dht_get_results.
struct GNUNET_STATISTICS_Handle * stats
Optional statistics handle to report usage.
char * description
User provided description of the searched service.
#define GNUNET_YES
Definition: gnunet_common.h:77
static void regex_next_edge(const struct RegexBlock *block, size_t size, struct RegexSearchContext *ctx)
Jump to the next edge, with the longest matching token.
#define LOG(kind,...)
size_t size
Number of bytes in data.
static void regex_find_path(const struct GNUNET_HashCode *key, struct RegexSearchContext *ctx)
Find a path to a peer that offers a regex service compatible with a given string. ...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ regex_edge_iterator()

static int regex_edge_iterator ( void *  cls,
const char *  token,
size_t  len,
const struct GNUNET_HashCode key 
)
static

Iterator over edges in a regex block retrieved from the DHT.

Parameters
clsClosure (context of the search).
tokenToken that follows to next state.
lenLenght of token.
keyHash of next state.
Returns
GNUNET_YES if should keep iterating, GNUNET_NO otherwise.

Definition at line 555 of file regex_internal_dht.c.

References ctx, REGEX_INTERNAL_Search::description, GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_YES, RegexSearchContext::hash, RegexSearchContext::info, key, len, LOG, RegexSearchContext::longest_match, RegexSearchContext::position, and REGEX_INTERNAL_Search::stats.

Referenced by regex_next_edge().

559 {
560  struct RegexSearchContext *ctx = cls;
561  struct REGEX_INTERNAL_Search *info = ctx->info;
562  const char *current;
563  size_t current_len;
564 
565  GNUNET_STATISTICS_update(info->stats, "# regex edges iterated",
566  1, GNUNET_NO);
567  current = &info->description[ctx->position];
568  current_len = strlen(info->description) - ctx->position;
569  if (len > current_len)
570  {
571  LOG(GNUNET_ERROR_TYPE_DEBUG, "Token too long, END\n");
572  return GNUNET_YES;
573  }
574  if (0 != strncmp(current, token, len))
575  {
576  LOG(GNUNET_ERROR_TYPE_DEBUG, "Token doesn't match, END\n");
577  return GNUNET_YES;
578  }
579 
580  if (len > ctx->longest_match)
581  {
582  LOG(GNUNET_ERROR_TYPE_DEBUG, "Token is longer, KEEP\n");
583  ctx->longest_match = len;
584  ctx->hash = *key;
585  }
586  else
587  {
588  LOG(GNUNET_ERROR_TYPE_DEBUG, "Token is not longer, IGNORE\n");
589  }
590 
591  LOG(GNUNET_ERROR_TYPE_DEBUG, "* End of regex edge iterator\n");
592  return GNUNET_YES;
593 }
size_t position
Part of the description already consumed by this particular search branch.
Struct to keep state of running searches that have consumed a part of the inital string.
#define GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
struct GNUNET_HashCode hash
Destination hash of the longest match.
struct REGEX_INTERNAL_Search * info
Information about the search.
struct GNUNET_HashCode key
The key used in the DHT.
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 ...
char * description
User provided description of the searched service.
#define GNUNET_YES
Definition: gnunet_common.h:77
#define LOG(kind,...)
unsigned int longest_match
We just want to look for one edge, the longer the better.
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()

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

static int regex_cancel_dht_get ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Iterator over hash map entries to cancel DHT GET requests after a successful connect_by_string.

Parameters
clsClosure (unused).
keyCurrent key code (unused).
valueValue in the hash map (get handle).
Returns
GNUNET_YES if we should continue to iterate, GNUNET_NO if not.

Definition at line 769 of file regex_internal_dht.c.

References GNUNET_DHT_get_stop(), GNUNET_YES, h, and value.

Referenced by REGEX_INTERNAL_search_cancel().

772 {
773  struct GNUNET_DHT_GetHandle *h = value;
774 
776  return GNUNET_YES;
777 }
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
static char * value
Value of the record to add/remove.
void GNUNET_DHT_get_stop(struct GNUNET_DHT_GetHandle *get_handle)
Stop async DHT-get.
Definition: dht_api.c:1150
Handle to a GET request.
Definition: dht_api.c:78
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the call graph for this function:
Here is the caller graph for this function:

◆ regex_free_result()

static int regex_free_result ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Iterator over hash map entries to free CadetRegexBlocks stored during the search for connect_by_string.

Parameters
clsClosure (unused).
keyCurrent key code (unused).
valueCadetRegexBlock in the hash map.
Returns
GNUNET_YES if we should continue to iterate, GNUNET_NO if not.

Definition at line 791 of file regex_internal_dht.c.

References GNUNET_free, and GNUNET_YES.

Referenced by REGEX_INTERNAL_search_cancel().

794 {
796  return GNUNET_YES;
797 }
static char * value
Value of the record to add/remove.
#define GNUNET_YES
Definition: gnunet_common.h:77
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ REGEX_INTERNAL_search_cancel()

void REGEX_INTERNAL_search_cancel ( struct REGEX_INTERNAL_Search h)

Cancel an ongoing regex search in the DHT and free all resources.

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: