38#define LOG(kind, ...) GNUNET_log_from (kind, "regex-dht", __VA_ARGS__)
43#define DHT_REPLICATION 5
48#define DHT_TTL GNUNET_TIME_UNIT_HOURS
53#define DHT_OPT GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE
146 unsigned int num_edges,
160 "DHT PUT for state %s with proof `%s' and %u edges:\n",
167 "Edge %u `%s' towards %s\n",
183 "State %s is accepting, putting own id\n",
216 "# regex blocks stored",
220 "# regex block bytes stored",
265 "REGEX_INTERNAL_reannounce: %s\n",
425 unsigned int get_path_length,
427 unsigned int put_path_length,
436 "Regex result accept for %s (key %s)\n",
440 "# regex accepting blocks found",
443 "# regex accepting block bytes found",
447 get_path, get_path_length,
448 put_path, put_path_length);
466 "Accept state found, now searching for paths to %s\n",
507 unsigned int get_path_length,
509 unsigned int put_path_length,
520 "DHT GET result for %s (%s)\n",
524 copy->
data = ©[1];
530 len = strlen (
info->description);
531 if (len ==
ctx->position)
567 (
ctx->position == strlen (
ctx->info->description)))
570 "Found accepting known block\n");
575 "* %llu, %llu, [%u]\n",
576 (
unsigned long long)
ctx->position,
577 (
unsigned long long) strlen (
ctx->info->description),
583 "# regex cadet blocks iterated",
612 current = &
info->description[
ctx->position];
613 current_len = strlen (
info->description) -
ctx->position;
614 if (len > current_len)
619 if (0 != strncmp (current, token, len))
625 if (len >
ctx->longest_match)
628 ctx->longest_match = len;
663 ctx->longest_match = 0;
669 if (0 ==
ctx->longest_match)
672 "no match in block\n");
687 "GET for %s running, END\n",
700 "Following edges at %s for offset %u in `%s'\n",
702 (
unsigned int)
ctx->position,
759 h->callback = callback;
760 h->callback_cls = callback_cls;
766 len = strlen (
string);
769 "Initial key for `%s' is %s (based on `%.*s')\n",
786 &
h->description[
size],
862 if (0 <
h->n_contexts)
864 for (i = 0; i <
h->n_contexts; i++)
static struct GNUNET_ARM_Handle * h
Connection with ARM.
static struct GNUNET_DHT_Handle * dht
Handle to the DHT.
static char * data
The data to insert into the dht.
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_FS_Handle * ctx
static char * value
Value of the record to add/remove.
static uint32_t type
Type string converted to DNS type value.
static struct GNUNET_PILS_Handle * pils
Handle to PILS.
static int result
Global testing status.
Information we track per peer.
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
static struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
GNUNET_BLOCK_Type
WARNING: This header is generated! In order to add DHT block types, you must register them in GANA,...
@ GNUNET_BLOCK_TYPE_REGEX_ACCEPT
Block to store a cadet regex accepting state.
@ GNUNET_BLOCK_TYPE_REGEX
Block to store a cadet regex state.
void GNUNET_PILS_cancel(struct GNUNET_PILS_Operation *op)
Cancel request.
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.
const struct GNUNET_PeerIdentity * GNUNET_PILS_get_identity(const struct GNUNET_PILS_Handle *handle)
Return the current peer identity of a given handle.
#define GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT
Accept state in regex DFA.
API to create, modify and access statistics.
#define GNUNET_CONSTANTS_DHT_MAX_EXPIRATION
How long do we cache records at most 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.
void GNUNET_DHT_get_stop(struct GNUNET_DHT_GetHandle *get_handle)
Stop async DHT-get.
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.
@ GNUNET_DHT_RO_RECORD_ROUTE
We should keep track of the route that the message took in the P2P network.
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).
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
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.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash 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_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
#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.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
static unsigned int size
Size of the "table".
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 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.
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.
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.
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_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...
void REGEX_INTERNAL_automaton_destroy(struct REGEX_INTERNAL_Automaton *a)
Free the memory allocated by constructing the REGEX_INTERNAL_Automaton.
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.
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.
#define DHT_TTL
DHT record lifetime to use.
void REGEX_INTERNAL_search_cancel(struct REGEX_INTERNAL_Search *h)
Cancel an ongoing regex search in the DHT and free all resources.
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_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 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 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 void sign_accept_block(void *cls, const struct GNUNET_PeerIdentity *pid, const struct GNUNET_CRYPTO_EddsaSignature *sig)
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.
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.
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.
void REGEX_INTERNAL_announce_cancel(struct REGEX_INTERNAL_Announcement *h)
Clear all cached data used by a regex announce.
void REGEX_INTERNAL_reannounce(struct REGEX_INTERNAL_Announcement *h)
Announce again a regular expression previously announced.
#define DHT_REPLICATION
DHT replication level to use.
#define DHT_OPT
DHT options to set.
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...
library to parse regular expressions into dfa
void(* REGEX_INTERNAL_Found)(void *cls, const struct GNUNET_PeerIdentity *id, const struct GNUNET_DHT_PathElement *get_path, unsigned int get_path_length, const struct GNUNET_DHT_PathElement *put_path, unsigned int put_path_length)
Search callback function.
Internal representation of the hash map.
an ECC signature using EdDSA.
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
Connection to the DHT service.
A (signed) path tracking a block's flow through the DHT is represented by an array of path elements,...
A handle for the PILS service.
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.
Time for absolute times used by GNUnet, in microseconds.
Handle to store cached data about a regex announce.
struct REGEX_INTERNAL_Automaton * dfa
Automaton representation of the regex (expensive to build).
struct GNUNET_DHT_Handle * dht
DHT handle to use, must be initialized externally.
struct GNUNET_STATISTICS_Handle * stats
Optional statistics handle to report usage.
struct GNUNET_PILS_Handle * pils
Our PILS service handle.
struct RegexAcceptBlock * ab
Accepting block in memory during signature operation.
const char * regex
Regular expression.
struct GNUNET_PILS_Operation * sign
Signature operation.
Automaton representation.
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 RegexSearchContext ** contexts
Contexts, for each running DHT GET.
struct GNUNET_CONTAINER_MultiHashMap * dht_get_results
Results from running DHT GETs, values are of type 'struct Result'.
struct GNUNET_CONTAINER_MultiHashMap * dht_get_handles
Running DHT GETs.
struct GNUNET_DHT_Handle * dht
DHT handle to use, must be initialized externally.
struct GNUNET_STATISTICS_Handle * stats
Optional statistics handle to report usage.
unsigned int n_contexts
Number of contexts (branches/steps in search).
REGEX_INTERNAL_Found callback
Block to announce a peer accepting a state.
struct GNUNET_PeerIdentity peer
Public key of the peer signing.
Block to announce a regex state.
uint16_t num_edges
Number of edges parting from this state.
Struct to keep state of running searches that have consumed a part of the initial string.
struct GNUNET_HashCode hash
Destination hash of the longest match.
unsigned int longest_match
We just want to look for one edge, the longer the better.
size_t position
Part of the description already consumed by this particular search branch.
struct REGEX_INTERNAL_Search * info
Information about the search.
Type of values in dht_get_results.
const void * data
The raw result data.
size_t size
Number of bytes in data.