GNUnet 0.26.2-114-g7c6b613e3
 
Loading...
Searching...
No Matches
regex_internal_dht.c File Reference
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 initial 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.
 
#define DHT_TTL   GNUNET_TIME_UNIT_HOURS
 DHT record lifetime to use.
 
#define DHT_OPT   GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE
 DHT options to set.
 

Functions

static void sign_accept_block (void *cls, const struct GNUNET_PeerIdentity *pid, const struct GNUNET_CRYPTO_EddsaSignature *sig)
 
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.
 
struct REGEX_INTERNAL_AnnouncementREGEX_INTERNAL_announce (struct GNUNET_DHT_Handle *dht, struct GNUNET_PILS_Handle *pils, const char *regex, uint16_t compression, struct GNUNET_STATISTICS_Handle *stats)
 Announce a regular expression: put all states of the automaton in the DHT.
 
void REGEX_INTERNAL_reannounce (struct REGEX_INTERNAL_Announcement *h)
 Announce again a regular expression previously announced.
 
void REGEX_INTERNAL_announce_cancel (struct REGEX_INTERNAL_Announcement *h)
 Clear all cached data used by a regex announce.
 
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.
 
static void dht_get_string_accept_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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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_string.
 
void REGEX_INTERNAL_search_cancel (struct REGEX_INTERNAL_Search *h)
 Cancel an ongoing regex search in the DHT and free all resources.
 

Macro Definition Documentation

◆ LOG

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

Definition at line 38 of file regex_internal_dht.c.

◆ DHT_REPLICATION

#define DHT_REPLICATION   5

DHT replication level to use.

Definition at line 43 of file regex_internal_dht.c.

◆ DHT_TTL

#define DHT_TTL   GNUNET_TIME_UNIT_HOURS

DHT record lifetime to use.

Definition at line 48 of file regex_internal_dht.c.

◆ DHT_OPT

DHT options to set.

Definition at line 53 of file regex_internal_dht.c.

Function Documentation

◆ sign_accept_block()

static void sign_accept_block ( void *  cls,
const struct GNUNET_PeerIdentity pid,
const struct GNUNET_CRYPTO_EddsaSignature sig 
)
static

Definition at line 99 of file regex_internal_dht.c.

102{
103 struct REGEX_INTERNAL_Announcement *h = cls;
104 size_t size;
105
106 GNUNET_assert ((NULL != h->sign) && (NULL != h->ab));
107
108 h->sign = NULL;
109
110 GNUNET_memcpy (&(h->ab->signature), sig, sizeof (h->ab->signature));
111 size = sizeof(struct RegexAcceptBlock);
112
113 GNUNET_STATISTICS_update (h->stats, "# regex accepting blocks stored",
114 1, GNUNET_NO);
115 GNUNET_STATISTICS_update (h->stats, "# regex accepting block bytes stored",
116 sizeof(struct RegexAcceptBlock), GNUNET_NO);
117 (void)
118 GNUNET_DHT_put (h->dht, &(h->ab->key),
122 size,
123 h->ab,
125 NULL, NULL);
126 GNUNET_free (h->ab);
127 h->ab = NULL;
128}
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition gnunet-arm.c:98
@ GNUNET_BLOCK_TYPE_REGEX_ACCEPT
Block to store a cadet regex accepting state.
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:1087
@ GNUNET_DHT_RO_RECORD_ROUTE
We should keep track of the route that the message took in the P2P network.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
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:316
static unsigned int size
Size of the "table".
Definition peer.c:68
#define DHT_TTL
DHT record lifetime to use.
#define DHT_REPLICATION
DHT replication level to use.
#define DHT_OPT
DHT options to set.
Handle to store cached data about a regex announce.
Block to announce a peer accepting a state.
Definition block_regex.h:51

References DHT_OPT, DHT_REPLICATION, DHT_TTL, GNUNET_assert, GNUNET_BLOCK_TYPE_REGEX_ACCEPT, GNUNET_DHT_put(), GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_free, GNUNET_memcpy, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_relative_to_absolute(), h, and size.

Referenced by regex_iterator().

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

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

148{
149 const struct GNUNET_PeerIdentity *my_identity;
150 struct REGEX_INTERNAL_Announcement *h = cls;
151 struct RegexBlock *block;
152 size_t size;
153 unsigned int i;
154
156 if (NULL == my_identity)
157 return;
158
160 "DHT PUT for state %s with proof `%s' and %u edges:\n",
161 GNUNET_h2s (key),
162 proof,
163 num_edges);
164 for (i = 0; i < num_edges; i++)
165 {
167 "Edge %u `%s' towards %s\n",
168 i,
169 edges[i].label,
170 GNUNET_h2s (&edges[i].destination));
171 }
172 if (GNUNET_YES == accepting)
173 {
174 if (NULL != h->sign)
175 {
176 GNUNET_PILS_cancel (h->sign);
177 h->sign = NULL;
178 }
179 if (NULL != h->ab)
180 GNUNET_free (h->ab);
181 h->ab = GNUNET_new (struct RegexAcceptBlock);
183 "State %s is accepting, putting own id\n",
184 GNUNET_h2s (key));
185 h->ab->purpose.size = ntohl (sizeof(struct GNUNET_CRYPTO_SignaturePurpose)
186 + sizeof(struct GNUNET_TIME_AbsoluteNBO)
187 + sizeof(struct GNUNET_HashCode));
188 h->ab->purpose.purpose = ntohl (GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT);
189 h->ab->expiration_time = GNUNET_TIME_absolute_hton (
191 h->ab->key = *key;
192 GNUNET_memcpy (&(h->ab->peer), my_identity,
193 sizeof (*my_identity));
194 h->sign = GNUNET_PILS_sign_by_peer_identity (h->pils, &(h->ab->purpose),
196 GNUNET_assert (NULL != h->sign);
197 }
198 block = REGEX_BLOCK_create (proof,
199 num_edges,
200 edges,
201 accepting,
202 &size);
203 if (NULL == block)
204 return;
205 (void) GNUNET_DHT_put (h->dht,
206 key,
208 DHT_OPT,
210 size,
211 block,
213 NULL,
214 NULL);
216 "# regex blocks stored",
217 1,
218 GNUNET_NO);
220 "# regex block bytes stored",
221 size,
222 GNUNET_NO);
223 GNUNET_free (block);
224}
struct GNUNET_HashCode key
The key used in the DHT.
static uint64_t proof
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
@ GNUNET_BLOCK_TYPE_REGEX
Block to store a cadet regex state.
void GNUNET_PILS_cancel(struct GNUNET_PILS_Operation *op)
Cancel request.
Definition pils_api.c:623
struct GNUNET_PILS_Operation * GNUNET_PILS_sign_by_peer_identity(struct GNUNET_PILS_Handle *handle, const struct GNUNET_CRYPTO_SignaturePurpose *purpose, GNUNET_PILS_SignResultCallback cb, void *cb_cls)
Sign data with the peer id.
Definition pils_api.c:528
const struct GNUNET_PeerIdentity * GNUNET_PILS_get_identity(const struct GNUNET_PILS_Handle *handle)
Return the current peer identity of a given handle.
Definition pils_api.c:727
#define GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT
Accept state in regex DFA.
#define GNUNET_CONSTANTS_DHT_MAX_EXPIRATION
How long do we cache records at most in the DHT?
@ GNUNET_YES
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition time.c:636
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.
static void sign_accept_block(void *cls, const struct GNUNET_PeerIdentity *pid, const struct GNUNET_CRYPTO_EddsaSignature *sig)
#define LOG(kind,...)
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
A 512-bit hashcode.
The identity of the host (wraps the signing key of the peer).
Time for absolute time used by GNUnet, in microseconds and in network byte order.
Block to announce a regex state.
uint16_t num_edges
Number of edges parting from this state.

References DHT_OPT, DHT_REPLICATION, DHT_TTL, GNUNET_assert, GNUNET_BLOCK_TYPE_REGEX, GNUNET_CONSTANTS_DHT_MAX_EXPIRATION, GNUNET_DHT_put(), GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_h2s(), GNUNET_memcpy, GNUNET_new, GNUNET_NO, GNUNET_PILS_cancel(), GNUNET_PILS_get_identity(), GNUNET_PILS_sign_by_peer_identity(), GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_hton(), GNUNET_TIME_relative_to_absolute(), GNUNET_YES, h, key, LOG, my_identity, RegexBlock::num_edges, proof, REGEX_BLOCK_create(), sign_accept_block(), and size.

Referenced by 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,
struct GNUNET_PILS_Handle pils,
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.
pilsour pils service handle, 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 240 of file regex_internal_dht.c.

245{
247
248 GNUNET_assert ((NULL != dht) && (NULL != pils));
250 h->regex = regex;
251 h->dht = dht;
252 h->stats = stats;
253 h->pils = pils;
256 return h;
257}
static struct GNUNET_DHT_Handle * dht
Handle to the DHT.
static struct GNUNET_PILS_Handle * pils
Handle to PILS.
Definition gnunet-pils.c:44
uint16_t compression
static struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
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.
const char * regex
Regular expression.

References compression, dht, GNUNET_assert, GNUNET_new, h, pils, 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 261 of file regex_internal_dht.c.

262{
263 GNUNET_assert (NULL != h->dfa); /* make sure to call announce first */
265 "REGEX_INTERNAL_reannounce: %s\n",
266 h->regex);
269 h);
270}
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.

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

281{
283 GNUNET_free (h);
284}
void REGEX_INTERNAL_automaton_destroy(struct REGEX_INTERNAL_Automaton *a)
Free the memory allocated by constructing the REGEX_INTERNAL_Automaton.

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

652{
653 struct RegexSearchContext *new_ctx;
654 struct REGEX_INTERNAL_Search *info = ctx->info;
655 struct GNUNET_DHT_GetHandle *get_h;
656 struct GNUNET_HashCode *hash;
657 const char *rest;
658 int result;
659
660 LOG (GNUNET_ERROR_TYPE_DEBUG, "Next edge\n");
661 /* Find the longest match for the current string position,
662 * among tokens in the given block */
663 ctx->longest_match = 0;
667
668 /* Did anything match? */
669 if (0 == ctx->longest_match)
670 {
672 "no match in block\n");
673 return;
674 }
675
676 hash = &ctx->hash;
677 new_ctx = GNUNET_new (struct RegexSearchContext);
678 new_ctx->info = info;
679 new_ctx->position = ctx->position + ctx->longest_match;
680 GNUNET_array_append (info->contexts, info->n_contexts, new_ctx);
681
682 /* Check whether we already have a DHT GET running for it */
683 if (GNUNET_YES ==
684 GNUNET_CONTAINER_multihashmap_contains (info->dht_get_handles, hash))
685 {
687 "GET for %s running, END\n",
688 GNUNET_h2s (hash));
690 hash,
692 new_ctx);
693 return; /* We are already looking for it */
694 }
695
696 GNUNET_STATISTICS_update (info->stats, "# regex nodes traversed",
697 1, GNUNET_NO);
698
700 "Following edges at %s for offset %u in `%s'\n",
701 GNUNET_h2s (hash),
702 (unsigned int) ctx->position,
703 info->description);
704 rest = &new_ctx->info->description[new_ctx->position];
705 get_h =
706 GNUNET_DHT_get_start (info->dht, /* handle */
707 GNUNET_BLOCK_TYPE_REGEX, /* type */
708 hash, /* key to search */
709 DHT_REPLICATION, /* replication level */
710 DHT_OPT,
711 rest, /* xquery */
712 strlen (rest) + 1, /* xquery bits */
713 &dht_get_string_handler, new_ctx);
714 if (GNUNET_OK !=
715 GNUNET_CONTAINER_multihashmap_put (info->dht_get_handles,
716 hash,
717 get_h,
719 {
720 GNUNET_break (0);
721 return;
722 }
723}
static struct GNUNET_FS_Handle * ctx
static int result
Global testing status.
#define info
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:1166
enum GNUNET_GenericReturnValue 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).
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.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_get_multiple(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map that match a particular key.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
@ GNUNET_OK
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
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.
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.
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.
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.
Handle to a GET request.
Definition dht_api.c:79
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.
Struct to keep state of running searches that have consumed a part of the initial string.
size_t position
Part of the description already consumed by this particular search branch.
struct REGEX_INTERNAL_Search * info
Information about the search.

References ctx, REGEX_INTERNAL_Search::description, 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, info, RegexSearchContext::info, LOG, RegexSearchContext::position, REGEX_BLOCK_iterate(), regex_edge_iterator(), regex_result_iterator(), result, and size.

Referenced by dht_get_string_handler(), and regex_result_iterator().

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 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 
)
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.
trunc_peertruncated peer, or NULL if none was truncated
keyKey of the result.
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.
typeType of the result.
sizeNumber of bytes in data.
dataPointer to the result data.

Definition at line 421 of file regex_internal_dht.c.

430{
431 const struct RegexAcceptBlock *block = data;
432 struct RegexSearchContext *ctx = cls;
433 struct REGEX_INTERNAL_Search *info = ctx->info;
434
436 "Regex result accept for %s (key %s)\n",
437 info->description, GNUNET_h2s (key));
438
440 "# regex accepting blocks found",
441 1, GNUNET_NO);
443 "# regex accepting block bytes found",
444 size, GNUNET_NO);
445 info->callback (info->callback_cls,
446 &block->peer,
447 get_path, get_path_length,
448 put_path, put_path_length);
449}
static char * data
The data to insert into the dht.
struct GNUNET_PeerIdentity peer
Public key of the peer signing.
Definition block_regex.h:71

References ctx, data, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_NO, GNUNET_STATISTICS_update(), info, key, LOG, RegexAcceptBlock::peer, and size.

Referenced by regex_find_path().

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

462{
463 struct GNUNET_DHT_GetHandle *get_h;
464
466 "Accept state found, now searching for paths to %s\n",
467 GNUNET_h2s (key));
468 get_h = GNUNET_DHT_get_start (ctx->info->dht, /* handle */
470 key, /* key to search */
471 DHT_REPLICATION, /* replication level */
473 NULL, /* xquery */ // FIXME BLOOMFILTER
474 0, /* xquery bits */ // FIXME BLOOMFILTER SIZE
477 GNUNET_CONTAINER_multihashmap_put (ctx->info->dht_get_handles,
478 key,
479 get_h,
481}
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
static void dht_get_string_accept_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.

References ctx, 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, key, and LOG.

Referenced by dht_get_string_handler(), and regex_result_iterator().

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 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 
)
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
trunc_peerNULL if not truncated
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 503 of file regex_internal_dht.c.

512{
513 const struct RegexBlock *block = data;
514 struct RegexSearchContext *ctx = cls;
515 struct REGEX_INTERNAL_Search *info = ctx->info;
516 size_t len;
517 struct Result *copy;
518
520 "DHT GET result for %s (%s)\n",
521 GNUNET_h2s (key), ctx->info->description);
522 copy = GNUNET_malloc (sizeof(struct Result) + size);
523 copy->size = size;
524 copy->data = &copy[1];
525 GNUNET_memcpy (&copy[1], block, size);
527 GNUNET_CONTAINER_multihashmap_put (info->dht_get_results,
528 key, copy,
530 len = strlen (info->description);
531 if (len == ctx->position) // String processed
532 {
534 {
536 }
537 else
538 {
539 LOG (GNUNET_ERROR_TYPE_INFO, "block not accepting!\n");
540 /* FIXME REGEX this block not successful, wait for more? start timeout? */
541 }
542 return;
543 }
544 regex_next_edge (block, size, ctx);
545}
#define GNUNET_malloc(size)
Wrapper around malloc.
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.
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.
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.
Type of values in dht_get_results.
const void * data
The raw result data.
size_t size
Number of bytes in data.

References ctx, data, Result::data, 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, info, key, LOG, regex_find_path(), regex_next_edge(), size, and Result::size.

Referenced by REGEX_INTERNAL_search(), and regex_next_edge().

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

560{
561 struct Result *result = value;
562 const struct RegexBlock *block = result->data;
563 struct RegexSearchContext *ctx = cls;
564
565 if ((GNUNET_YES ==
566 GNUNET_BLOCK_is_accepting (block, result->size)) &&
567 (ctx->position == strlen (ctx->info->description)))
568 {
570 "Found accepting known block\n");
572 return GNUNET_YES; // We found an accept state!
573 }
575 "* %llu, %llu, [%u]\n",
576 (unsigned long long) ctx->position,
577 (unsigned long long) strlen (ctx->info->description),
579 result->size));
580 regex_next_edge (block, result->size, ctx);
581
582 GNUNET_STATISTICS_update (ctx->info->stats,
583 "# regex cadet blocks iterated",
584 1, GNUNET_NO);
585
586 return GNUNET_YES;
587}
static char * value
Value of the record to add/remove.

References ctx, GNUNET_BLOCK_is_accepting(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_YES, key, LOG, regex_find_path(), regex_next_edge(), result, and value.

Referenced by regex_next_edge().

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.
lenLength of token.
keyHash of next state.
Returns
GNUNET_YES if should keep iterating, GNUNET_NO otherwise.

Definition at line 600 of file regex_internal_dht.c.

604{
605 struct RegexSearchContext *ctx = cls;
606 struct REGEX_INTERNAL_Search *info = ctx->info;
607 const char *current;
608 size_t current_len;
609
610 GNUNET_STATISTICS_update (info->stats, "# regex edges iterated",
611 1, GNUNET_NO);
612 current = &info->description[ctx->position];
613 current_len = strlen (info->description) - ctx->position;
614 if (len > current_len)
615 {
616 LOG (GNUNET_ERROR_TYPE_DEBUG, "Token too long, END\n");
617 return GNUNET_YES;
618 }
619 if (0 != strncmp (current, token, len))
620 {
621 LOG (GNUNET_ERROR_TYPE_DEBUG, "Token doesn't match, END\n");
622 return GNUNET_YES;
623 }
624
625 if (len > ctx->longest_match)
626 {
627 LOG (GNUNET_ERROR_TYPE_DEBUG, "Token is longer, KEEP\n");
628 ctx->longest_match = len;
629 ctx->hash = *key;
630 }
631 else
632 {
633 LOG (GNUNET_ERROR_TYPE_DEBUG, "Token is not longer, IGNORE\n");
634 }
635
636 LOG (GNUNET_ERROR_TYPE_DEBUG, "* End of regex edge iterator\n");
637 return GNUNET_YES;
638}

References ctx, GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_YES, info, key, and LOG.

Referenced by regex_next_edge().

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

745{
746 struct REGEX_INTERNAL_Search *h;
747 struct GNUNET_DHT_GetHandle *get_h;
748 struct RegexSearchContext *ctx;
749 struct GNUNET_HashCode key;
750 size_t size;
751 size_t len;
752
753 /* Initialize handle */
754 GNUNET_assert (NULL != dht);
755 GNUNET_assert (NULL != callback);
757 h->dht = dht;
758 h->description = GNUNET_strdup (string);
759 h->callback = callback;
760 h->callback_cls = callback_cls;
761 h->stats = stats;
762 h->dht_get_handles = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
763 h->dht_get_results = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
764
765 /* Initialize context */
766 len = strlen (string);
767 size = REGEX_INTERNAL_get_first_key (string, len, &key);
769 "Initial key for `%s' is %s (based on `%.*s')\n",
770 string,
771 GNUNET_h2s (&key),
772 (int) size,
773 string);
775 ctx->position = size;
776 ctx->info = h;
777 GNUNET_array_append (h->contexts,
778 h->n_contexts,
779 ctx);
780 /* Start search in DHT */
781 get_h = GNUNET_DHT_get_start (h->dht, /* handle */
782 GNUNET_BLOCK_TYPE_REGEX, /* type */
783 &key, /* key to search */
784 DHT_REPLICATION, /* replication level */
785 DHT_OPT,
786 &h->description[size], /* xquery */
787 // FIXME add BLOOMFILTER to exclude filtered peers
788 len + 1 - size, /* xquery bits */
789 // FIXME add BLOOMFILTER SIZE
792 GNUNET_OK ==
793 GNUNET_CONTAINER_multihashmap_put (h->dht_get_handles,
794 &key,
795 get_h,
797 );
798
799 return h;
800}
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
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.

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, 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_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 814 of file regex_internal_dht.c.

817{
818 struct GNUNET_DHT_GetHandle *h = value;
819
821 return GNUNET_YES;
822}
void GNUNET_DHT_get_stop(struct GNUNET_DHT_GetHandle *get_handle)
Stop async DHT-get.
Definition dht_api.c:1239

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

Referenced by REGEX_INTERNAL_search_cancel().

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

839{
841 return GNUNET_YES;
842}

References GNUNET_free, GNUNET_YES, and value.

Referenced by REGEX_INTERNAL_search_cancel().

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

852{
853 unsigned int i;
854
855 GNUNET_free (h->description);
857 &regex_cancel_dht_get, NULL);
859 &regex_free_result, NULL);
860 GNUNET_CONTAINER_multihashmap_destroy (h->dht_get_results);
861 GNUNET_CONTAINER_multihashmap_destroy (h->dht_get_handles);
862 if (0 < h->n_contexts)
863 {
864 for (i = 0; i < h->n_contexts; i++)
865 GNUNET_free (h->contexts[i]);
866 GNUNET_free (h->contexts);
867 }
868 GNUNET_free (h);
869}
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
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: