GNUnet 0.26.2-114-g7c6b613e3
 
Loading...
Searching...
No Matches
regex_internal_dht.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2012, 2015, 2026 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 "gnunet_common.h"
27#include "gnunet_util_lib.h"
28#include "platform.h"
29#include "regex_internal_lib.h"
30#include "gnunet_dht_service.h"
31#include "gnunet_pils_service.h"
33#include "gnunet_constants.h"
34#include "gnunet_signatures.h"
36
37
38#define LOG(kind, ...) GNUNET_log_from (kind, "regex-dht", __VA_ARGS__)
39
43#define DHT_REPLICATION 5
44
48#define DHT_TTL GNUNET_TIME_UNIT_HOURS
49
53#define DHT_OPT GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE
54
55
96
97
98static void
100 const struct GNUNET_PeerIdentity *pid,
101 const struct GNUNET_CRYPTO_EddsaSignature *sig)
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}
129
130
141static void
142regex_iterator (void *cls,
143 const struct GNUNET_HashCode *key,
144 const char *proof,
145 int accepting,
146 unsigned int num_edges,
147 const struct REGEX_BLOCK_Edge *edges)
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}
225
226
241 struct GNUNET_PILS_Handle *pils,
242 const char *regex,
243 uint16_t compression,
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}
258
259
260void
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}
271
272
279void
285
286
287/******************************************************************************/
288
289
295{
300 size_t position;
301
306
311 unsigned int longest_match;
312
317};
318
319
323struct Result
324{
328 size_t size;
329
333 const void *data;
334};
335
336
389
390
398static void
399regex_next_edge (const struct RegexBlock *block,
400 size_t size,
401 struct RegexSearchContext *ctx);
402
403
420static void
422 const struct GNUNET_HashCode *key,
423 const struct GNUNET_PeerIdentity *trunc_peer,
424 const struct GNUNET_DHT_PathElement *get_path,
425 unsigned int get_path_length,
426 const struct GNUNET_DHT_PathElement *put_path,
427 unsigned int put_path_length,
429 size_t size, const void *data)
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}
450
451
459static void
461 struct RegexSearchContext *ctx)
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}
482
483
502static void
504 const struct GNUNET_HashCode *key,
505 const struct GNUNET_PeerIdentity *trunc_peer,
506 const struct GNUNET_DHT_PathElement *get_path,
507 unsigned int get_path_length,
508 const struct GNUNET_DHT_PathElement *put_path,
509 unsigned int put_path_length,
511 size_t size, const void *data)
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}
546
547
556static int
558 const struct GNUNET_HashCode *key,
559 void *value)
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}
588
589
599static int
601 const char *token,
602 size_t len,
603 const struct GNUNET_HashCode *key)
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}
639
640
648static void
649regex_next_edge (const struct RegexBlock *block,
650 size_t size,
651 struct RegexSearchContext *ctx)
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}
724
725
741 const char *string,
743 void *callback_cls,
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}
801
802
813static int
815 const struct GNUNET_HashCode *key,
816 void *value)
817{
818 struct GNUNET_DHT_GetHandle *h = value;
819
821 return GNUNET_YES;
822}
823
824
835static int
837 const struct GNUNET_HashCode *key,
838 void *value)
839{
841 return GNUNET_YES;
842}
843
844
850void
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}
870
871
872/* end of regex_internal_dht.c */
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition gnunet-arm.c:98
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.
Definition gnunet-pils.c:44
static int result
Global testing status.
uint16_t compression
static uint64_t proof
#define info
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.
API to the DHT service.
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.
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.
Definition dht_api.c:1087
void GNUNET_DHT_get_stop(struct GNUNET_DHT_GetHandle *get_handle)
Stop async DHT-get.
Definition dht_api.c:1239
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
@ 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:636
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 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 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.
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 ...
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.
A handle for the PILS service.
Definition pils_api.c:82
The identity of the host (wraps the signing key of the peer).
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.
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.
Definition block_regex.h:51
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.