GNUnet 0.26.2-117-g4aaa958f8
 
Loading...
Searching...
No Matches
gnunet-daemon-regexprofiler.c File Reference

daemon that uses cadet to announce a regular expression. More...

Include dependency graph for gnunet-daemon-regexprofiler.c:

Go to the source code of this file.

Functions

static void shutdown_task (void *cls)
 Task run during shutdown.
 
static void reannounce_regex (void *cls)
 Announce a previously announced regex reusing cached data.
 
static void announce_regex (const char *regex)
 Announce the given regular expression using regex and the path compression length read from config.
 
static int scan (void *cls, const char *filename)
 Scan through the policy_dir looking for the n-th filename.
 
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 *const *argv)
 The main function of the regexprofiler service.
 

Variables

static int global_ret
 Return value from 'main'.
 
static const struct GNUNET_CONFIGURATION_Handlecfg
 Configuration we use.
 
static struct GNUNET_PILS_Handlepils_handle
 Handle to the pils service.
 
static struct GNUNET_STATISTICS_Handlestats_handle
 Handle to the statistics service.
 
static struct GNUNET_DHT_Handledht_handle
 Peer's dht handle.
 
static struct REGEX_INTERNAL_Announcementannounce_handle
 Peer's regex announce handle.
 
static struct GNUNET_SCHEDULER_Taskreannounce_task
 Periodically reannounce regex.
 
static struct GNUNET_TIME_Relative reannounce_period_max
 What's the maximum reannounce period.
 
static unsigned long long max_path_compression
 Maximal path compression length for regex announcing.
 
static char * policy_filename
 Name of the file containing policies that this peer should announce.
 
static char * regex_prefix
 Prefix to add before every regex we're announcing.
 
static char * rx_with_pfx
 Regex with prefix.
 
static unsigned int rounds = 3
 How many put rounds should we do.
 

Detailed Description

daemon that uses cadet to announce a regular expression.

Used in conjunction with gnunet-regex-profiler to announce regexes on several peers without the need to explicitly connect to the cadet service running on the peer from within the profiler.

Author
Maximilian Szengel
Bartlomiej Polot

Definition in file gnunet-daemon-regexprofiler.c.

Function Documentation

◆ shutdown_task()

static void shutdown_task ( void *  cls)
static

Task run during shutdown.

Parameters
clsunused

Definition at line 111 of file gnunet-daemon-regexprofiler.c.

112{
113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shutting down\n");
114
115 if (NULL != announce_handle)
116 {
118 announce_handle = NULL;
119 }
120 if (NULL != reannounce_task)
121 {
123 reannounce_task = NULL;
124 }
125 if (NULL != dht_handle)
126 {
128 dht_handle = NULL;
129 }
130 if (NULL != pils_handle)
131 {
133 pils_handle = NULL;
134 }
135
137 "Daemon for %s shutting down\n",
139}
static struct REGEX_INTERNAL_Announcement * announce_handle
Peer's regex announce handle.
static struct GNUNET_PILS_Handle * pils_handle
Handle to the pils service.
static struct GNUNET_DHT_Handle * dht_handle
Peer's dht handle.
static char * policy_filename
Name of the file containing policies that this peer should announce.
static struct GNUNET_SCHEDULER_Task * reannounce_task
Periodically reannounce regex.
void GNUNET_PILS_disconnect(struct GNUNET_PILS_Handle *handle)
Disconnect from the PILS service.
Definition pils_api.c:488
void GNUNET_DHT_disconnect(struct GNUNET_DHT_Handle *handle)
Shutdown connection with the DHT service.
Definition dht_api.c:1059
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_free_nz(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986
void REGEX_INTERNAL_announce_cancel(struct REGEX_INTERNAL_Announcement *h)
Clear all cached data used by a regex announce.

References announce_handle, dht_handle, GNUNET_DHT_disconnect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_free_nz, GNUNET_log, GNUNET_PILS_disconnect(), GNUNET_SCHEDULER_cancel(), pils_handle, policy_filename, reannounce_task, and REGEX_INTERNAL_announce_cancel().

Here is the call graph for this function:

◆ reannounce_regex()

static void reannounce_regex ( void *  cls)
static

Announce a previously announced regex reusing cached data.

Parameters
clsClosure (regex to announce if needed).

Definition at line 148 of file gnunet-daemon-regexprofiler.c.

149{
150 char *regex = cls;
151 struct GNUNET_TIME_Relative random_delay;
152
153 reannounce_task = NULL;
154 if (0 == rounds--)
155 {
156 global_ret = 0;
158 GNUNET_free (regex);
159 return;
160 }
161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Announcing regex: %s\n", regex);
162 GNUNET_STATISTICS_update (stats_handle, "# regexes announced", 1, GNUNET_NO);
163 if ((NULL == announce_handle) && (NULL != regex))
164 {
166 "First time, creating regex: %s\n",
167 regex);
170 regex,
171 (unsigned
174 }
175 else
176 {
179 }
180
181 random_delay =
187 &reannounce_regex, cls);
188}
static void reannounce_regex(void *cls)
Announce a previously announced regex reusing cached data.
static int global_ret
Return value from 'main'.
static struct GNUNET_TIME_Relative reannounce_period_max
What's the maximum reannounce period.
static struct GNUNET_STATISTICS_Handle * stats_handle
Handle to the statistics service.
static unsigned int rounds
How many put rounds should we do.
static unsigned long long max_path_compression
Maximal path compression length for regex announcing.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition scheduler.c:572
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
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_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition time.c:486
#define GNUNET_TIME_UNIT_MICROSECONDS
One microsecond, our basic time unit.
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.
void REGEX_INTERNAL_reannounce(struct REGEX_INTERNAL_Announcement *h)
Announce again a regular expression previously announced.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.

References announce_handle, dht_handle, global_ret, GNUNET_assert, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_shutdown(), GNUNET_STATISTICS_update(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_MICROSECONDS, max_path_compression, pils_handle, reannounce_period_max, reannounce_regex(), reannounce_task, REGEX_INTERNAL_announce(), REGEX_INTERNAL_reannounce(), GNUNET_TIME_Relative::rel_value_us, rounds, and stats_handle.

Referenced by announce_regex(), and reannounce_regex().

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

◆ announce_regex()

static void announce_regex ( const char *  regex)
static

Announce the given regular expression using regex and the path compression length read from config.

Parameters
regexregular expression to announce on this peer's cadet.

Definition at line 198 of file gnunet-daemon-regexprofiler.c.

199{
200 char *copy;
201
202 if ((NULL == regex) || (0 == strlen (regex)))
203 {
204 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot announce empty regex\n");
205 return;
206 }
207
209 "Daemon for %s starting\n",
212 copy = GNUNET_strdup (regex);
214 (void *) copy);
215}
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
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

References GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, policy_filename, reannounce_regex(), and reannounce_task.

Referenced by run().

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

◆ scan()

static int scan ( void *  cls,
const char *  filename 
)
static

Scan through the policy_dir looking for the n-th filename.

Parameters
clsClosure (target number n).
filenamecomplete filename (absolute path).
Returns
GNUNET_OK to continue to iterate, GNUNET_NO to stop when found

Definition at line 227 of file gnunet-daemon-regexprofiler.c.

228{
229 long n = (long) cls;
230 static long c = 0;
231
232 if (c == n)
233 {
235 return GNUNET_NO;
236 }
237 c++;
238 return GNUNET_OK;
239}
static char * filename
@ GNUNET_OK

References filename, GNUNET_NO, GNUNET_OK, GNUNET_strdup, and policy_filename.

Referenced by run().

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
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cfg_configuration

Definition at line 251 of file gnunet-daemon-regexprofiler.c.

254{
255 char *regex = NULL;
256 char **components;
257 char *policy_dir;
258 long long unsigned int peer_id;
259
260 cfg = cfg_;
261
262 if (GNUNET_OK !=
264 "MAX_PATH_COMPRESSION",
266 {
268 _
269 (
270 "%s service is lacking key configuration settings (%s). Exiting.\n"),
271 "regexprofiler", "max_path_compression");
274 return;
275 }
276 if (GNUNET_OK !=
278 "POLICY_DIR", &policy_dir))
279 {
281 "POLICY_DIR");
284 return;
285 }
286 if (GNUNET_OK !=
288 "PEERID", &peer_id))
289 {
294 return;
295 }
296
297 if (GNUNET_OK !=
299 "REGEX_PREFIX", &regex_prefix))
300 {
302 "REGEX_PREFIX");
306 return;
307 }
308
309 if (GNUNET_OK !=
311 "REANNOUNCE_PERIOD_MAX",
313 {
315 "reannounce_period_max not given. Using 10 minutes.\n");
318 }
319
320 pils_handle = GNUNET_PILS_connect (cfg, NULL, NULL);
321 stats_handle = GNUNET_STATISTICS_create ("regexprofiler", cfg);
323
324 if (NULL == dht_handle)
325 {
327 "Could not acquire dht handle. Exiting.\n");
331 return;
332 }
333
334 /* Read regexes from policy files */
336 (void *) (long) peer_id));
337 if (NULL == (components = REGEX_TEST_read_from_file (policy_filename)))
338 {
340 "Policy file %s contains no policies. Exiting.\n",
345 return;
346 }
348 regex = REGEX_TEST_combine (components, 16);
349 REGEX_TEST_free_from_file (components);
350
351 /* Announcing regexes from policy_filename */
353 "%s(%s)(0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f)*",
355 regex);
357 GNUNET_free (regex);
359
360 /* Scheduled the task to clean up when shutdown is called */
362 NULL);
363}
static char * peer_id
Option –peer.
static char * rx_with_pfx
Regex with prefix.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we use.
static void announce_regex(const char *regex)
Announce the given regular expression using regex and the path compression length read from config.
static int scan(void *cls, const char *filename)
Scan through the policy_dir looking for the n-th filename.
static char * regex_prefix
Prefix to add before every regex we're announcing.
struct GNUNET_SCHEDULER_Task * shutdown_task
static char * policy_dir
Folder where policy files are stored.
struct GNUNET_PILS_Handle * GNUNET_PILS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_PILS_PidChangeCallback pid_change_cb, void *cls)
Connect to the PILS service.
Definition pils_api.c:465
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_time(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
Get a configuration value that should be a relative time.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
struct GNUNET_DHT_Handle * GNUNET_DHT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned int ht_len)
Initialize the connection with the DHT service.
Definition dht_api.c:1036
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition disk.c:881
@ GNUNET_SYSERR
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
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_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
#define GNUNET_TIME_UNIT_MINUTES
One minute.
#define _(String)
GNU gettext support macro.
Definition platform.h:179
void REGEX_TEST_free_from_file(char **regexes)
Free all memory reserved for a set of regexes created by read_from_file.
char * REGEX_TEST_combine(char *const regexes[], unsigned int alphabet_size)
Combine an array of regexes into a single prefix-shared regex.
char ** REGEX_TEST_read_from_file(const char *filename)
Read a set of regexes from a file, one per line and return them in an array suitable for REGEX_TEST_c...

References _, announce_regex(), cfg, dht_handle, global_ret, GNUNET_asprintf(), GNUNET_assert, GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_get_value_time(), GNUNET_DHT_connect(), GNUNET_DISK_directory_scan(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_log_config_missing(), GNUNET_OK, GNUNET_PILS_connect(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), GNUNET_STATISTICS_create(), GNUNET_SYSERR, GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_MINUTES, max_path_compression, peer_id, pils_handle, policy_dir, policy_filename, reannounce_period_max, regex_prefix, REGEX_TEST_combine(), REGEX_TEST_free_from_file(), REGEX_TEST_read_from_file(), rx_with_pfx, scan(), shutdown_task, and stats_handle.

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 *const *  argv 
)

The main function of the regexprofiler service.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

Definition at line 374 of file gnunet-daemon-regexprofiler.c.

375{
376 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
378 };
379
380 return (GNUNET_OK ==
382 argc, argv, "regexprofiler",
384 (
385 "Daemon to announce regular expressions for the peer using cadet."),
386 options, &run, NULL)) ? global_ret : 1;
387}
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.
#define GNUNET_GETOPT_OPTION_END
Marker for the end of the list of options.
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.

References gettext_noop, global_ret, GNUNET_GETOPT_OPTION_END, GNUNET_OK, GNUNET_OS_project_data_gnunet(), GNUNET_PROGRAM_run(), options, and run().

Here is the call graph for this function:

Variable Documentation

◆ global_ret

int global_ret
static

Return value from 'main'.

Definition at line 41 of file gnunet-daemon-regexprofiler.c.

Referenced by main(), reannounce_regex(), and run().

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

Configuration we use.

Definition at line 46 of file gnunet-daemon-regexprofiler.c.

Referenced by run().

◆ pils_handle

struct GNUNET_PILS_Handle* pils_handle
static

Handle to the pils service.

Definition at line 51 of file gnunet-daemon-regexprofiler.c.

Referenced by reannounce_regex(), run(), and shutdown_task().

◆ stats_handle

struct GNUNET_STATISTICS_Handle* stats_handle
static

Handle to the statistics service.

Definition at line 56 of file gnunet-daemon-regexprofiler.c.

Referenced by reannounce_regex(), and run().

◆ dht_handle

struct GNUNET_DHT_Handle* dht_handle
static

Peer's dht handle.

Definition at line 61 of file gnunet-daemon-regexprofiler.c.

Referenced by reannounce_regex(), run(), and shutdown_task().

◆ announce_handle

struct REGEX_INTERNAL_Announcement* announce_handle
static

Peer's regex announce handle.

Definition at line 66 of file gnunet-daemon-regexprofiler.c.

Referenced by reannounce_regex(), and shutdown_task().

◆ reannounce_task

struct GNUNET_SCHEDULER_Task* reannounce_task
static

Periodically reannounce regex.

Definition at line 71 of file gnunet-daemon-regexprofiler.c.

Referenced by announce_regex(), reannounce_regex(), and shutdown_task().

◆ reannounce_period_max

struct GNUNET_TIME_Relative reannounce_period_max
static

What's the maximum reannounce period.

Definition at line 76 of file gnunet-daemon-regexprofiler.c.

Referenced by reannounce_regex(), and run().

◆ max_path_compression

unsigned long long max_path_compression
static

Maximal path compression length for regex announcing.

Definition at line 81 of file gnunet-daemon-regexprofiler.c.

Referenced by reannounce_regex(), and run().

◆ policy_filename

char* policy_filename
static

Name of the file containing policies that this peer should announce.

One policy per line.

Definition at line 87 of file gnunet-daemon-regexprofiler.c.

Referenced by announce_regex(), run(), scan(), and shutdown_task().

◆ regex_prefix

char* regex_prefix
static

Prefix to add before every regex we're announcing.

Definition at line 92 of file gnunet-daemon-regexprofiler.c.

Referenced by run().

◆ rx_with_pfx

char* rx_with_pfx
static

Regex with prefix.

Definition at line 97 of file gnunet-daemon-regexprofiler.c.

Referenced by run().

◆ rounds

unsigned int rounds = 3
static

How many put rounds should we do.

Definition at line 102 of file gnunet-daemon-regexprofiler.c.

Referenced by reannounce_regex().