#include "platform.h"
#include "regex_internal_lib.h"
#include "gnunet_dht_service.h"
#include "gnunet_statistics_service.h"
#include "gnunet_constants.h"
#include "gnunet_signatures.h"
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. 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_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. 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 *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. 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 *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. 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_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. 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... | |
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "regex-dht", __VA_ARGS__) |
Definition at line 34 of file regex_internal_dht.c.
#define DHT_REPLICATION 5 |
DHT replication level to use.
Definition at line 39 of file regex_internal_dht.c.
#define DHT_TTL GNUNET_TIME_UNIT_HOURS |
DHT record lifetime to use.
Definition at line 44 of file regex_internal_dht.c.
#define DHT_OPT GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE |
DHT options to set.
Definition at line 49 of file regex_internal_dht.c.
|
static |
Regex callback iterator to store own service description in the DHT.
cls | closure. |
key | hash for current state. |
proof | proof for current state. |
accepting | GNUNET_YES if this is an accepting state, GNUNET_NO if not. |
num_edges | number of edges leaving current state. |
edges | edges leaving current state. |
Definition at line 95 of file regex_internal_dht.c.
References 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, proof, GNUNET_PeerIdentity::public_key, RegexAcceptBlock::purpose, GNUNET_CRYPTO_EccSignaturePurpose::purpose, REGEX_BLOCK_create(), RegexAcceptBlock::signature, GNUNET_CRYPTO_EccSignaturePurpose::size, and size.
Referenced by REGEX_INTERNAL_reannounce().
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.
dht | An existing and valid DHT service handle. CANNOT be NULL. |
priv | our private key, must remain valid until the announcement is cancelled |
regex | Regular expression to announce. |
compression | How many characters per edge can we squeeze? |
stats | Optional statistics handle to report usage. Can be NULL. |
Definition at line 198 of file regex_internal_dht.c.
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().
void REGEX_INTERNAL_reannounce | ( | struct REGEX_INTERNAL_Announcement * | h | ) |
Announce again a regular expression previously announced.
Does use caching to speed up process.
h | Handle returned by a previous REGEX_INTERNAL_announce() call. |
Definition at line 219 of file regex_internal_dht.c.
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().
void REGEX_INTERNAL_announce_cancel | ( | struct REGEX_INTERNAL_Announcement * | h | ) |
Clear all cached data used by a regex announce.
Does not close DHT connection.
h | Handle returned by a previous REGEX_INTERNAL_announce() call. |
Definition at line 238 of file regex_internal_dht.c.
References GNUNET_free, h, and REGEX_INTERNAL_automaton_destroy().
Referenced by client_disconnect_cb(), and shutdown_task().
|
static |
Jump to the next edge, with the longest matching token.
block | Block found in the DHT. |
size | Size of the block. |
ctx | Context of the search. |
Definition at line 607 of file regex_internal_dht.c.
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().
|
static |
Function to process DHT string to regex matching.
Called on each result obtained for the DHT search.
cls | Closure (search context). |
exp | When will this value expire. |
trunc_peer | truncated peer, or NULL if none was truncated |
key | Key of the result. |
get_path | Path of the get request. |
get_path_length | Length of get_path. |
put_path | Path of the put request. |
put_path_length | Length of the put_path. |
type | Type of the result. |
size | Number of bytes in data. |
data | Pointer to the result data. |
Definition at line 379 of file regex_internal_dht.c.
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().
|
static |
Find a path to a peer that offers a regex service compatible with a given string.
key | The key of the accepting state. |
ctx | Context containing info about the string, tunnel, etc. |
Definition at line 418 of file regex_internal_dht.c.
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().
|
static |
Function to process DHT string to regex matching.
Called on each result obtained for the DHT search.
cls | closure (search context) |
exp | when will this value expire |
key | key of the result |
trunc_peer | NULL if not truncated |
get_path | path of the get request (not used) |
get_path_length | length of get_path (not used) |
put_path | path of the put request (not used) |
put_path_length | length of the put_path (not used) |
type | type of the result |
size | number of bytes in data |
data | pointer 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, 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().
|
static |
Iterator over found existing cadet regex blocks that match an ongoing search.
cls | Closure (current context)- |
key | Current key code (key for cached block). |
value | Value in the hash map (cached RegexBlock). |
Definition at line 515 of file regex_internal_dht.c.
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().
|
static |
Iterator over edges in a regex block retrieved from the DHT.
cls | Closure (context of the search). |
token | Token that follows to next state. |
len | Length of token. |
key | Hash of next state. |
Definition at line 558 of file regex_internal_dht.c.
References ctx, GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_YES, info, key, and LOG.
Referenced by regex_next_edge().
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.
dht | An existing and valid DHT service handle. |
string | String to match against the regexes in the DHT. |
callback | Callback for found peers. |
callback_cls | Closure for callback . |
stats | Optional statistics handle to report usage. Can be NULL. |
Definition at line 698 of file regex_internal_dht.c.
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().
|
static |
Iterator over hash map entries to cancel DHT GET requests after a successful connect_by_string.
cls | Closure (unused). |
key | Current key code (unused). |
value | Value in the hash map (get handle). |
Definition at line 772 of file regex_internal_dht.c.
References GNUNET_DHT_get_stop(), GNUNET_YES, h, and value.
Referenced by REGEX_INTERNAL_search_cancel().
|
static |
Iterator over hash map entries to free CadetRegexBlocks stored during the search for connect_by_string.
cls | Closure (unused). |
key | Current key code (unused). |
value | CadetRegexBlock in the hash map. |
Definition at line 794 of file regex_internal_dht.c.
References GNUNET_free, GNUNET_YES, and value.
Referenced by 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.
h | the search context. |
Definition at line 809 of file regex_internal_dht.c.
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().