GNUnet 0.21.2
regex_internal_dht.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2012, 2015 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
26#include "platform.h"
27#include "regex_internal_lib.h"
28#include "gnunet_dht_service.h"
30#include "gnunet_constants.h"
31#include "gnunet_signatures.h"
32
33
34#define LOG(kind, ...) GNUNET_log_from (kind, "regex-dht", __VA_ARGS__)
35
39#define DHT_REPLICATION 5
40
44#define DHT_TTL GNUNET_TIME_UNIT_HOURS
45
49#define DHT_OPT GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE
50
51
56{
61
65 const char *regex;
66
71
76
81};
82
83
94static void
95regex_iterator (void *cls,
96 const struct GNUNET_HashCode *key,
97 const char *proof,
98 int accepting,
99 unsigned int num_edges,
100 const struct REGEX_BLOCK_Edge *edges)
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));
134 ab.key = *key;
136 &ab.peer.public_key);
139 &ab.purpose,
140 &ab.signature));
141
142 GNUNET_STATISTICS_update (h->stats, "# regex accepting blocks stored",
143 1, GNUNET_NO);
144 GNUNET_STATISTICS_update (h->stats, "# regex accepting block bytes stored",
145 sizeof(struct RegexAcceptBlock), GNUNET_NO);
146 (void)
147 GNUNET_DHT_put (h->dht, key,
151 size,
152 &ab,
154 NULL, NULL);
155 }
156 block = REGEX_BLOCK_create (proof,
157 num_edges,
158 edges,
159 accepting,
160 &size);
161 if (NULL == block)
162 return;
163 (void) GNUNET_DHT_put (h->dht,
164 key,
166 DHT_OPT,
168 size,
169 block,
171 NULL,
172 NULL);
174 "# regex blocks stored",
175 1,
176 GNUNET_NO);
178 "# regex block bytes stored",
179 size,
180 GNUNET_NO);
181 GNUNET_free (block);
182}
183
184
200 const char *regex,
201 uint16_t compression,
203{
205
206 GNUNET_assert (NULL != dht);
208 h->regex = regex;
209 h->dht = dht;
210 h->stats = stats;
211 h->priv = priv;
212 h->dfa = REGEX_INTERNAL_construct_dfa (regex, strlen (regex), compression);
214 return h;
215}
216
217
218void
220{
221 GNUNET_assert (NULL != h->dfa); /* make sure to call announce first */
223 "REGEX_INTERNAL_reannounce: %s\n",
224 h->regex);
227 h);
228}
229
230
237void
239{
241 GNUNET_free (h);
242}
243
244
245/******************************************************************************/
246
247
253{
258 size_t position;
259
264
269 unsigned int longest_match;
270
275};
276
277
281struct Result
282{
286 size_t size;
287
291 const void *data;
292};
293
294
300{
305
310
315
320
326
331
335 unsigned int n_contexts;
336
341
346};
347
348
356static void
357regex_next_edge (const struct RegexBlock *block,
358 size_t size,
359 struct RegexSearchContext *ctx);
360
361
378static void
380 const struct GNUNET_HashCode *key,
381 const struct GNUNET_PeerIdentity *trunc_peer,
382 const struct GNUNET_DHT_PathElement *get_path,
383 unsigned int get_path_length,
384 const struct GNUNET_DHT_PathElement *put_path,
385 unsigned int put_path_length,
387 size_t size, const void *data)
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}
408
409
417static void
419 struct RegexSearchContext *ctx)
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 get_h = GNUNET_DHT_get_start (ctx->info->dht, /* handle */
428 key, /* key to search */
429 DHT_REPLICATION, /* replication level */
431 NULL, /* xquery */ // FIXME BLOOMFILTER
432 0, /* xquery bits */ // FIXME BLOOMFILTER SIZE
435 GNUNET_CONTAINER_multihashmap_put (ctx->info->dht_get_handles,
436 key,
437 get_h,
439}
440
441
460static void
462 const struct GNUNET_HashCode *key,
463 const struct GNUNET_PeerIdentity *trunc_peer,
464 const struct GNUNET_DHT_PathElement *get_path,
465 unsigned int get_path_length,
466 const struct GNUNET_DHT_PathElement *put_path,
467 unsigned int put_path_length,
469 size_t size, const void *data)
470{
471 const struct RegexBlock *block = data;
472 struct RegexSearchContext *ctx = cls;
473 struct REGEX_INTERNAL_Search *info = ctx->info;
474 size_t len;
475 struct Result *copy;
476
478 "DHT GET result for %s (%s)\n",
479 GNUNET_h2s (key), ctx->info->description);
480 copy = GNUNET_malloc (sizeof(struct Result) + size);
481 copy->size = size;
482 copy->data = &copy[1];
483 GNUNET_memcpy (&copy[1], block, size);
485 GNUNET_CONTAINER_multihashmap_put (info->dht_get_results,
486 key, copy,
488 len = strlen (info->description);
489 if (len == ctx->position) // String processed
490 {
492 {
494 }
495 else
496 {
497 LOG (GNUNET_ERROR_TYPE_INFO, "block not accepting!\n");
498 /* FIXME REGEX this block not successful, wait for more? start timeout? */
499 }
500 return;
501 }
502 regex_next_edge (block, size, ctx);
503}
504
505
514static int
516 const struct GNUNET_HashCode *key,
517 void *value)
518{
519 struct Result *result = value;
520 const struct RegexBlock *block = result->data;
521 struct RegexSearchContext *ctx = cls;
522
523 if ((GNUNET_YES ==
524 GNUNET_BLOCK_is_accepting (block, result->size)) &&
525 (ctx->position == strlen (ctx->info->description)))
526 {
528 "Found accepting known block\n");
530 return GNUNET_YES; // We found an accept state!
531 }
533 "* %llu, %llu, [%u]\n",
534 (unsigned long long) ctx->position,
535 (unsigned long long) strlen (ctx->info->description),
537 result->size));
538 regex_next_edge (block, result->size, ctx);
539
540 GNUNET_STATISTICS_update (ctx->info->stats,
541 "# regex cadet blocks iterated",
542 1, GNUNET_NO);
543
544 return GNUNET_YES;
545}
546
547
557static int
559 const char *token,
560 size_t len,
561 const struct GNUNET_HashCode *key)
562{
563 struct RegexSearchContext *ctx = cls;
564 struct REGEX_INTERNAL_Search *info = ctx->info;
565 const char *current;
566 size_t current_len;
567
568 GNUNET_STATISTICS_update (info->stats, "# regex edges iterated",
569 1, GNUNET_NO);
570 current = &info->description[ctx->position];
571 current_len = strlen (info->description) - ctx->position;
572 if (len > current_len)
573 {
574 LOG (GNUNET_ERROR_TYPE_DEBUG, "Token too long, END\n");
575 return GNUNET_YES;
576 }
577 if (0 != strncmp (current, token, len))
578 {
579 LOG (GNUNET_ERROR_TYPE_DEBUG, "Token doesn't match, END\n");
580 return GNUNET_YES;
581 }
582
583 if (len > ctx->longest_match)
584 {
585 LOG (GNUNET_ERROR_TYPE_DEBUG, "Token is longer, KEEP\n");
586 ctx->longest_match = len;
587 ctx->hash = *key;
588 }
589 else
590 {
591 LOG (GNUNET_ERROR_TYPE_DEBUG, "Token is not longer, IGNORE\n");
592 }
593
594 LOG (GNUNET_ERROR_TYPE_DEBUG, "* End of regex edge iterator\n");
595 return GNUNET_YES;
596}
597
598
606static void
607regex_next_edge (const struct RegexBlock *block,
608 size_t size,
609 struct RegexSearchContext *ctx)
610{
611 struct RegexSearchContext *new_ctx;
612 struct REGEX_INTERNAL_Search *info = ctx->info;
613 struct GNUNET_DHT_GetHandle *get_h;
614 struct GNUNET_HashCode *hash;
615 const char *rest;
616 int result;
617
618 LOG (GNUNET_ERROR_TYPE_DEBUG, "Next edge\n");
619 /* Find the longest match for the current string position,
620 * among tokens in the given block */
621 ctx->longest_match = 0;
625
626 /* Did anything match? */
627 if (0 == ctx->longest_match)
628 {
630 "no match in block\n");
631 return;
632 }
633
634 hash = &ctx->hash;
635 new_ctx = GNUNET_new (struct RegexSearchContext);
636 new_ctx->info = info;
637 new_ctx->position = ctx->position + ctx->longest_match;
638 GNUNET_array_append (info->contexts, info->n_contexts, new_ctx);
639
640 /* Check whether we already have a DHT GET running for it */
641 if (GNUNET_YES ==
642 GNUNET_CONTAINER_multihashmap_contains (info->dht_get_handles, hash))
643 {
645 "GET for %s running, END\n",
646 GNUNET_h2s (hash));
648 hash,
650 new_ctx);
651 return; /* We are already looking for it */
652 }
653
654 GNUNET_STATISTICS_update (info->stats, "# regex nodes traversed",
655 1, GNUNET_NO);
656
658 "Following edges at %s for offset %u in `%s'\n",
659 GNUNET_h2s (hash),
660 (unsigned int) ctx->position,
661 info->description);
662 rest = &new_ctx->info->description[new_ctx->position];
663 get_h =
664 GNUNET_DHT_get_start (info->dht, /* handle */
665 GNUNET_BLOCK_TYPE_REGEX, /* type */
666 hash, /* key to search */
667 DHT_REPLICATION, /* replication level */
668 DHT_OPT,
669 rest, /* xquery */
670 strlen (rest) + 1, /* xquery bits */
671 &dht_get_string_handler, new_ctx);
672 if (GNUNET_OK !=
673 GNUNET_CONTAINER_multihashmap_put (info->dht_get_handles,
674 hash,
675 get_h,
677 {
678 GNUNET_break (0);
679 return;
680 }
681}
682
683
699 const char *string,
701 void *callback_cls,
703{
704 struct REGEX_INTERNAL_Search *h;
705 struct GNUNET_DHT_GetHandle *get_h;
706 struct RegexSearchContext *ctx;
707 struct GNUNET_HashCode key;
708 size_t size;
709 size_t len;
710
711 /* Initialize handle */
712 GNUNET_assert (NULL != dht);
713 GNUNET_assert (NULL != callback);
715 h->dht = dht;
716 h->description = GNUNET_strdup (string);
717 h->callback = callback;
718 h->callback_cls = callback_cls;
719 h->stats = stats;
720 h->dht_get_handles = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
721 h->dht_get_results = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
722
723 /* Initialize context */
724 len = strlen (string);
725 size = REGEX_INTERNAL_get_first_key (string, len, &key);
727 "Initial key for `%s' is %s (based on `%.*s')\n",
728 string,
729 GNUNET_h2s (&key),
730 (int) size,
731 string);
733 ctx->position = size;
734 ctx->info = h;
735 GNUNET_array_append (h->contexts,
736 h->n_contexts,
737 ctx);
738 /* Start search in DHT */
739 get_h = GNUNET_DHT_get_start (h->dht, /* handle */
740 GNUNET_BLOCK_TYPE_REGEX, /* type */
741 &key, /* key to search */
742 DHT_REPLICATION, /* replication level */
743 DHT_OPT,
744 &h->description[size], /* xquery */
745 // FIXME add BLOOMFILTER to exclude filtered peers
746 len + 1 - size, /* xquery bits */
747 // FIXME add BLOOMFILTER SIZE
750 GNUNET_OK ==
751 GNUNET_CONTAINER_multihashmap_put (h->dht_get_handles,
752 &key,
753 get_h,
755 );
756
757 return h;
758}
759
760
771static int
773 const struct GNUNET_HashCode *key,
774 void *value)
775{
776 struct GNUNET_DHT_GetHandle *h = value;
777
779 return GNUNET_YES;
780}
781
782
793static int
795 const struct GNUNET_HashCode *key,
796 void *value)
797{
799 return GNUNET_YES;
800}
801
802
808void
810{
811 unsigned int i;
812
813 GNUNET_free (h->description);
815 &regex_cancel_dht_get, NULL);
817 &regex_free_result, NULL);
818 GNUNET_CONTAINER_multihashmap_destroy (h->dht_get_results);
819 GNUNET_CONTAINER_multihashmap_destroy (h->dht_get_handles);
820 if (0 < h->n_contexts)
821 {
822 for (i = 0; i < h->n_contexts; i++)
823 GNUNET_free (h->contexts[i]);
824 GNUNET_free (h->contexts);
825 }
826 GNUNET_free (h);
827}
828
829
830/* end of regex_internal_dht.c */
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
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 int result
Global testing status.
static uint64_t proof
Definition: gnunet-scrypt.c:49
#define info
static struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
API to the DHT service.
API to create, modify and access statistics.
#define GNUNET_CONSTANTS_DHT_MAX_EXPIRATION
How long do we cache records at most in the DHT?
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:200
enum GNUNET_GenericReturnValue 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:624
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:1088
void GNUNET_DHT_get_stop(struct GNUNET_DHT_GetHandle *get_handle)
Stop async DHT-get.
Definition: dht_api.c:1235
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:1162
@ 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.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
#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
@ GNUNET_ERROR_TYPE_INFO
#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.
Definition: time.c:316
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:638
static unsigned int size
Size of the "table".
Definition: peer.c:68
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 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_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.
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.
#define DHT_REPLICATION
DHT replication level to use.
#define LOG(kind,...)
#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.
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.
#define GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT
Accept state in regex DFA.
Internal representation of the hash map.
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
Private ECC key encoded for transmission.
Handle to a GET request.
Definition: dht_api.c:79
Connection to the DHT service.
Definition: dht_api.c:235
A (signed) path tracking a block's flow through the DHT is represented by an array of path elements,...
A 512-bit hashcode.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Handle for the service.
Time for absolute time used by GNUnet, in microseconds and in network byte order.
Time for absolute times used by GNUnet, in microseconds.
Edge representation.
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.
const struct GNUNET_CRYPTO_EddsaPrivateKey * priv
Our private key.
struct GNUNET_STATISTICS_Handle * stats
Optional statistics handle to report usage.
const char * regex
Regular expression.
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.
Definition: block_regex.h:51
struct GNUNET_HashCode key
The key of the state.
Definition: block_regex.h:66
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does the signature expire?
Definition: block_regex.h:61
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Accept blocks must be signed.
Definition: block_regex.h:56
struct GNUNET_CRYPTO_EddsaSignature signature
The signature.
Definition: block_regex.h:76
struct GNUNET_PeerIdentity peer
Public key of the peer signing.
Definition: block_regex.h:71
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.