GNUnet 0.26.2-98-gb402d9955
 
Loading...
Searching...
No Matches
gnunet-regex.c File Reference

Use regex service from terminal. More...

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "gnunet_common.h"
#include "gnunet_regex_service.h"
#include "gnunet_scheduler_lib.h"
#include "gnunet_time_lib.h"
#include "gnunet_util_lib.h"
Include dependency graph for gnunet-regex.c:

Go to the source code of this file.

Functions

static void shutdown_hook (void *cls)
 
static void regex_found (void *cls, const struct GNUNET_PeerIdentity *id, const struct GNUNET_PeerIdentity *get_path, unsigned int get_path_length, const struct GNUNET_PeerIdentity *put_path, unsigned int put_path_length)
 Search callback function, invoked for every result that was found.
 
static void print_announcement (void *cls)
 
static void drop_announcement (void *cls)
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Main function that will be run by the scheduler.
 
int main (int argc, char **argv)
 The main function to announce regular expressions or observe announcing peers.
 

Variables

struct GNUNET_REGEX_Announcementannouncement
 
struct GNUNET_REGEX_Searchsearch
 
int announcing
 
struct GNUNET_TIME_Relative refresh_delay
 
uint16_t compression
 
struct GNUNET_CONTAINER_MultiHashMapmatches
 
struct GNUNET_SCHEDULER_Taskshutdown_task
 
struct GNUNET_SCHEDULER_Taskdelay_task
 
char * expression
 

Detailed Description

Use regex service from terminal.

Author
Tobias Frisch

Definition in file gnunet-regex.c.

Function Documentation

◆ shutdown_hook()

static void shutdown_hook ( void *  cls)
static

Definition at line 52 of file gnunet-regex.c.

53{
54 shutdown_task = NULL;
55
56 if (search)
58
59 if (announcement)
61
62 if (delay_task)
64
65 if (matches)
67
68 if (expression)
70}
struct GNUNET_REGEX_Search * search
struct GNUNET_CONTAINER_MultiHashMap * matches
char * expression
struct GNUNET_SCHEDULER_Task * shutdown_task
struct GNUNET_REGEX_Announcement * announcement
struct GNUNET_SCHEDULER_Task * delay_task
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_REGEX_announce_cancel(struct GNUNET_REGEX_Announcement *a)
Stop announcing the regex specified by the given handle.
void GNUNET_REGEX_search_cancel(struct GNUNET_REGEX_Search *s)
Stop search and free all data used by a GNUNET_REGEX_search call.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986

References announcement, delay_task, expression, GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_free, GNUNET_REGEX_announce_cancel(), GNUNET_REGEX_search_cancel(), GNUNET_SCHEDULER_cancel(), matches, search, and shutdown_task.

Referenced by run().

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

◆ regex_found()

static void regex_found ( void *  cls,
const struct GNUNET_PeerIdentity id,
const struct GNUNET_PeerIdentity get_path,
unsigned int  get_path_length,
const struct GNUNET_PeerIdentity put_path,
unsigned int  put_path_length 
)
static

Search callback function, invoked for every result that was found.

Parameters
clsClosure provided in GNUNET_REGEX_search.
idPeer providing a regex that matches the string.
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.

Definition at line 84 of file gnunet-regex.c.

90{
91 struct GNUNET_HashCode hash;
92 size_t get_path_size, put_path_size;
93 unsigned int i;
94
95 get_path_size = sizeof (struct GNUNET_PeerIdentity) * get_path_length;
96 put_path_size = sizeof (struct GNUNET_PeerIdentity) * put_path_length;
97
99 &hash, sizeof (hash),
100 "regex_match", 11,
101 id, sizeof (*id),
102 GNUNET_CRYPTO_kdf_arg (get_path, get_path_size),
103 GNUNET_CRYPTO_kdf_arg (put_path, put_path_size)))
104 return;
105
107 return;
108
109 printf ("%s ( get: %u, put: %u )\n", GNUNET_i2s_full (id), get_path_length,
110 put_path_length);
111
112 for (i = 0; i < get_path_length; i++)
113 printf (" - get: %s\n", GNUNET_i2s_full (&(get_path[i])));
114
115 for (i = 0; i < put_path_length; i++)
116 printf (" - put: %s\n", GNUNET_i2s_full (&(put_path[i])));
117
119 matches, &hash, NULL,
121}
#define GNUNET_CRYPTO_hkdf_gnunet(result, out_len, xts, xts_len, skm, skm_len,...)
A peculiar HKDF instantiation that tried to mimic Truncated NMAC.
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.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
#define GNUNET_CRYPTO_kdf_arg(d, s)
@ GNUNET_YES
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
A 512-bit hashcode.
The identity of the host (wraps the signing key of the peer).

References GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CRYPTO_hkdf_gnunet, GNUNET_CRYPTO_kdf_arg, GNUNET_i2s_full(), GNUNET_YES, and matches.

Referenced by run().

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

◆ print_announcement()

static void print_announcement ( void *  cls)
static

Definition at line 125 of file gnunet-regex.c.

126{
127 delay_task = NULL;
128
129 printf ("> %s\n", expression);
130
131 if (cls)
134 cls);
135}
struct GNUNET_TIME_Relative refresh_delay
static void print_announcement(void *cls)
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition scheduler.c:1283

References delay_task, expression, GNUNET_SCHEDULER_add_delayed(), print_announcement(), and refresh_delay.

Referenced by drop_announcement(), print_announcement(), and run().

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

◆ drop_announcement()

static void drop_announcement ( void *  cls)
static

Definition at line 139 of file gnunet-regex.c.

140{
141 delay_task = NULL;
142
143 print_announcement (NULL);
144
145 if (announcement)
146 {
148 announcement = NULL;
149 }
150
152}
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition scheduler.c:572

References announcement, delay_task, GNUNET_REGEX_announce_cancel(), GNUNET_SCHEDULER_shutdown(), and print_announcement().

Referenced by run().

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

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle cfg 
)
static

Main function that will be run by the scheduler.

Parameters
[in/out]cls closure
[in]argsremaining command-line arguments
[in]cfgfilename of the configuration file used (for saving, can be NULL!)
[in]cfgconfiguration

Definition at line 164 of file gnunet-regex.c.

168{
169 int argc;
170 size_t len, pos;
171 unsigned int i;
172
173 for (argc = 0; NULL != args[argc]; argc++)
174 ;
175
176 len = 0;
177 for (i = 0; i < argc; i++)
178 len += strlen (args[i]);
179
180 if (argc > 0)
181 len += (argc - 1);
182
183 expression = GNUNET_malloc (len + 1);
185 expression[len] = '\0';
186 pos = 0;
187 for (i = 0; i < argc; i++)
188 {
189 size_t s;
190 s = strlen (args[i]);
191 GNUNET_memcpy (expression + pos, args[i], s);
192 pos += s;
193
194 if (i + 1 < argc)
195 {
196 expression[pos] = ' ';
197 pos++;
198 }
199 }
200
203
204 GNUNET_assert (pos == len);
205 if (announcing)
206 {
207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Announcing regular expression: %s\n",
208 expression);
209
212
215 else
217 }
218 else
219 {
221 "Observing peers that announced matching regular expressions to: %s\n",
222 expression);
223
225 }
226}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
int announcing
uint16_t compression
static void regex_found(void *cls, const struct GNUNET_PeerIdentity *id, const struct GNUNET_PeerIdentity *get_path, unsigned int get_path_length, const struct GNUNET_PeerIdentity *put_path, unsigned int put_path_length)
Search callback function, invoked for every result that was found.
static void shutdown_hook(void *cls)
static void drop_announcement(void *cls)
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
#define GNUNET_log(kind,...)
#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.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_malloc(size)
Wrapper around malloc.
struct GNUNET_REGEX_Search * GNUNET_REGEX_search(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *string, GNUNET_REGEX_Found callback, void *callback_cls)
Search for a peer offering a regex matching certain string in the DHT.
struct GNUNET_REGEX_Announcement * GNUNET_REGEX_announce(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *regex, struct GNUNET_TIME_Relative refresh_delay, uint16_t compression)
Announce this peer under the given regular expression.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition scheduler.c:1345
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition scheduler.c:1310
bool GNUNET_TIME_relative_is_zero(struct GNUNET_TIME_Relative rel)
Test if rel is zero.
Definition time.c:660

References announcement, announcing, cfg, compression, delay_task, drop_announcement(), expression, GNUNET_assert, GNUNET_CONTAINER_multihashmap_create(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_NO, GNUNET_REGEX_announce(), GNUNET_REGEX_search(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_TIME_relative_is_zero(), matches, print_announcement(), refresh_delay, regex_found(), search, shutdown_hook(), and shutdown_task.

Referenced by main().

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

◆ main()

int main ( int  argc,
char **  argv 
)

The main function to announce regular expressions or observe announcing peers.

Parameters
[in]argcnumber of arguments from the command line
[in]argvcommand line arguments
Returns
#EXIT_SUCCESS ok, #EXIT_FAILURE on error

Definition at line 237 of file gnunet-regex.c.

239{
240 const char *description =
241 "Announce regular expressions and observe announcing peers.";
242
244 GNUNET_GETOPT_option_flag ('a', "announce",
245 "flag to announce an expression",
246 &announcing),
247 GNUNET_GETOPT_option_relative_time ('r', "refresh", "DELAY",
248 "refresh delay of announcement",
250 GNUNET_GETOPT_option_uint16 ('c', "compression", "AMOUNT",
251 "amount of characters per edge to squeeze",
252 &compression),
254 };
255
256 return (GNUNET_OK ==
258 argc,
259 argv,
260 "gnunet-regex [OPTIONS] EXPRESSION\0",
262 &run,
263 NULL) ? EXIT_SUCCESS : EXIT_FAILURE);
264}
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
#define gettext_noop(String)
Definition gettext.h:74
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run by the scheduler.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_relative_time(char shortName, const char *name, const char *argumentHelp, const char *description, struct GNUNET_TIME_Relative *val)
Allow user to specify a struct GNUNET_TIME_Relative (using human-readable "fancy" time).
#define GNUNET_GETOPT_OPTION_END
Marker for the end of the list of options.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_uint16(char shortName, const char *name, const char *argumentHelp, const char *description, uint16_t *val)
Allow user to specify an uint16_t.
@ GNUNET_OK
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition program.c:407
Definition of a command line option.
const char * description
Help text for the option (description)

References announcing, compression, GNUNET_GETOPT_CommandLineOption::description, gettext_noop, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_flag(), GNUNET_GETOPT_option_relative_time(), GNUNET_GETOPT_option_uint16(), GNUNET_OK, GNUNET_OS_project_data_gnunet(), GNUNET_PROGRAM_run(), options, refresh_delay, and run().

Here is the call graph for this function:

Variable Documentation

◆ announcement

struct GNUNET_REGEX_Announcement* announcement

Definition at line 36 of file gnunet-regex.c.

Referenced by confirm_epoch_announcement_member(), cont_write_epoch_announcement_record(), create_epoch_announcement(), derive_epoch_announcement_key(), destroy_epoch_announcement(), drop_announcement(), generate_room_epoch_announcement(), get_epoch_announcement(), get_epoch_announcement_key(), get_epoch_announcement_member_hash(), get_epoch_announcement_members_count(), get_epoch_announcement_size(), get_epoch_membership_member_hash(), get_epoch_previous_announcement(), handle_access_message(), handle_announcement_message(), handle_appeal_message(), handle_authorization_message(), handle_epoch_announcement(), handle_epoch_announcement_access(), handle_epoch_announcement_delay(), handle_epoch_announcement_message(), handle_revolution_message(), handle_room_delayed_announcement(), handle_room_delayed_appeal(), handle_room_delayed_deletion(), handle_secret_message(), handle_secret_message_with_key(), handle_secret_messages_with_key(), invalidate_epoch_announcement(), is_epoch_announcement_announced(), is_epoch_announcement_appealed(), is_epoch_announcement_completed(), is_epoch_announcement_key_derived_from(), is_epoch_announcement_member(), is_epoch_group_missing_announcement(), is_other_epoch_announcement_better(), it_announcement_store_key(), it_find_announcement_with_most_members(), it_find_valid_announcement_with_most_members(), it_handle_secret_message(), iterate_destroy_announcement(), iterate_epoch_announcement_invalidation(), read_handle_epoch_key(), revoke_epoch_announcement_member(), run(), send_epoch_announcement(), send_epoch_announcement_access(), send_epoch_announcement_appeal(), send_epoch_announcement_authorization(), send_epoch_announcement_revolution(), send_message_to_room(), set_epoch_announcement_appeal(), set_epoch_announcement_key(), shutdown_hook(), task_epoch_announcement_appeal(), update_epoch_announcement(), and write_epoch_announcement_record().

◆ search

◆ announcing

int announcing

Definition at line 39 of file gnunet-regex.c.

Referenced by main(), and run().

◆ refresh_delay

struct GNUNET_TIME_Relative refresh_delay

Definition at line 41 of file gnunet-regex.c.

Referenced by GNUNET_REGEX_announce(), main(), print_announcement(), and run().

◆ compression

uint16_t compression

Definition at line 42 of file gnunet-regex.c.

Referenced by GNUNET_REGEX_announce(), main(), main(), REGEX_INTERNAL_announce(), and run().

◆ matches

Definition at line 44 of file gnunet-regex.c.

Referenced by abd_string_to_value(), regex_found(), run(), and shutdown_hook().

◆ shutdown_task

struct GNUNET_SCHEDULER_Task* shutdown_task

Definition at line 45 of file gnunet-regex.c.

Referenced by run(), and shutdown_hook().

◆ delay_task

struct GNUNET_SCHEDULER_Task* delay_task

Definition at line 46 of file gnunet-regex.c.

Referenced by drop_announcement(), print_announcement(), run(), and shutdown_hook().

◆ expression

char* expression

Definition at line 48 of file gnunet-regex.c.

Referenced by print_announcement(), run(), and shutdown_hook().