aboutsummaryrefslogtreecommitdiff
path: root/src/regex/gnunet-daemon-regexprofiler.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/regex/gnunet-daemon-regexprofiler.c')
-rw-r--r--src/regex/gnunet-daemon-regexprofiler.c330
1 files changed, 165 insertions, 165 deletions
diff --git a/src/regex/gnunet-daemon-regexprofiler.c b/src/regex/gnunet-daemon-regexprofiler.c
index f1c00a554..b9c32f9c7 100644
--- a/src/regex/gnunet-daemon-regexprofiler.c
+++ b/src/regex/gnunet-daemon-regexprofiler.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file regex/gnunet-daemon-regexprofiler.c 22 * @file regex/gnunet-daemon-regexprofiler.c
@@ -108,31 +108,31 @@ static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
108 * @param cls unused 108 * @param cls unused
109 */ 109 */
110static void 110static void
111shutdown_task (void *cls) 111shutdown_task(void *cls)
112{ 112{
113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shutting down\n"); 113 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "shutting down\n");
114 114
115 if (NULL != announce_handle) 115 if (NULL != announce_handle)
116 { 116 {
117 REGEX_INTERNAL_announce_cancel (announce_handle); 117 REGEX_INTERNAL_announce_cancel(announce_handle);
118 announce_handle = NULL; 118 announce_handle = NULL;
119 } 119 }
120 if (NULL != reannounce_task) 120 if (NULL != reannounce_task)
121 { 121 {
122 GNUNET_free (GNUNET_SCHEDULER_cancel (reannounce_task)); 122 GNUNET_free(GNUNET_SCHEDULER_cancel(reannounce_task));
123 reannounce_task = NULL; 123 reannounce_task = NULL;
124 } 124 }
125 if (NULL != dht_handle) 125 if (NULL != dht_handle)
126 { 126 {
127 GNUNET_DHT_disconnect (dht_handle); 127 GNUNET_DHT_disconnect(dht_handle);
128 dht_handle = NULL; 128 dht_handle = NULL;
129 } 129 }
130 GNUNET_free (my_private_key); 130 GNUNET_free(my_private_key);
131 my_private_key = NULL; 131 my_private_key = NULL;
132 132
133 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 133 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
134 "Daemon for %s shutting down\n", 134 "Daemon for %s shutting down\n",
135 policy_filename); 135 policy_filename);
136} 136}
137 137
138 138
@@ -142,45 +142,45 @@ shutdown_task (void *cls)
142 * @param cls Closure (regex to announce if needed). 142 * @param cls Closure (regex to announce if needed).
143 */ 143 */
144static void 144static void
145reannounce_regex (void *cls) 145reannounce_regex(void *cls)
146{ 146{
147 char *regex = cls; 147 char *regex = cls;
148 struct GNUNET_TIME_Relative random_delay; 148 struct GNUNET_TIME_Relative random_delay;
149 149
150 reannounce_task = NULL; 150 reannounce_task = NULL;
151 if (0 == rounds--) 151 if (0 == rounds--)
152 { 152 {
153 global_ret = 0; 153 global_ret = 0;
154 GNUNET_SCHEDULER_shutdown (); 154 GNUNET_SCHEDULER_shutdown();
155 GNUNET_free (regex); 155 GNUNET_free(regex);
156 return; 156 return;
157 } 157 }
158 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Announcing regex: %s\n", regex); 158 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Announcing regex: %s\n", regex);
159 GNUNET_STATISTICS_update (stats_handle, "# regexes announced", 1, GNUNET_NO); 159 GNUNET_STATISTICS_update(stats_handle, "# regexes announced", 1, GNUNET_NO);
160 if (NULL == announce_handle && NULL != regex) 160 if (NULL == announce_handle && NULL != regex)
161 { 161 {
162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 162 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
163 "First time, creating regex: %s\n", 163 "First time, creating regex: %s\n",
164 regex); 164 regex);
165 announce_handle = REGEX_INTERNAL_announce (dht_handle, 165 announce_handle = REGEX_INTERNAL_announce(dht_handle,
166 my_private_key, 166 my_private_key,
167 regex, 167 regex,
168 (unsigned int) max_path_compression, 168 (unsigned int)max_path_compression,
169 stats_handle); 169 stats_handle);
170 } 170 }
171 else 171 else
172 { 172 {
173 GNUNET_assert (NULL != announce_handle); 173 GNUNET_assert(NULL != announce_handle);
174 REGEX_INTERNAL_reannounce (announce_handle); 174 REGEX_INTERNAL_reannounce(announce_handle);
175 } 175 }
176 176
177 random_delay = 177 random_delay =
178 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 178 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MICROSECONDS,
179 GNUNET_CRYPTO_random_u32 ( 179 GNUNET_CRYPTO_random_u32(
180 GNUNET_CRYPTO_QUALITY_WEAK, 180 GNUNET_CRYPTO_QUALITY_WEAK,
181 reannounce_period_max.rel_value_us)); 181 reannounce_period_max.rel_value_us));
182 reannounce_task = GNUNET_SCHEDULER_add_delayed (random_delay, 182 reannounce_task = GNUNET_SCHEDULER_add_delayed(random_delay,
183 &reannounce_regex, cls); 183 &reannounce_regex, cls);
184} 184}
185 185
186 186
@@ -191,23 +191,23 @@ reannounce_regex (void *cls)
191 * @param regex regular expression to announce on this peer's cadet. 191 * @param regex regular expression to announce on this peer's cadet.
192 */ 192 */
193static void 193static void
194announce_regex (const char *regex) 194announce_regex(const char *regex)
195{ 195{
196 char *copy; 196 char *copy;
197 197
198 if (NULL == regex || 0 == strlen (regex)) 198 if (NULL == regex || 0 == strlen(regex))
199 { 199 {
200 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot announce empty regex\n"); 200 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot announce empty regex\n");
201 return; 201 return;
202 } 202 }
203 203
204 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 204 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
205 "Daemon for %s starting\n", 205 "Daemon for %s starting\n",
206 policy_filename); 206 policy_filename);
207 GNUNET_assert (NULL == reannounce_task); 207 GNUNET_assert(NULL == reannounce_task);
208 copy = GNUNET_strdup (regex); 208 copy = GNUNET_strdup(regex);
209 reannounce_task = GNUNET_SCHEDULER_add_now (&reannounce_regex, 209 reannounce_task = GNUNET_SCHEDULER_add_now(&reannounce_regex,
210 (void *) copy); 210 (void *)copy);
211} 211}
212 212
213 213
@@ -220,16 +220,16 @@ announce_regex (const char *regex)
220 * GNUNET_NO to stop when found 220 * GNUNET_NO to stop when found
221 */ 221 */
222static int 222static int
223scan (void *cls, const char *filename) 223scan(void *cls, const char *filename)
224{ 224{
225 long n = (long) cls; 225 long n = (long)cls;
226 static long c = 0; 226 static long c = 0;
227 227
228 if (c == n) 228 if (c == n)
229 { 229 {
230 policy_filename = GNUNET_strdup (filename); 230 policy_filename = GNUNET_strdup(filename);
231 return GNUNET_NO; 231 return GNUNET_NO;
232 } 232 }
233 c++; 233 c++;
234 return GNUNET_OK; 234 return GNUNET_OK;
235} 235}
@@ -244,9 +244,9 @@ scan (void *cls, const char *filename)
244 * @param cfg_ configuration 244 * @param cfg_ configuration
245 */ 245 */
246static void 246static void
247run (void *cls, char *const *args GNUNET_UNUSED, 247run(void *cls, char *const *args GNUNET_UNUSED,
248 const char *cfgfile GNUNET_UNUSED, 248 const char *cfgfile GNUNET_UNUSED,
249 const struct GNUNET_CONFIGURATION_Handle *cfg_) 249 const struct GNUNET_CONFIGURATION_Handle *cfg_)
250{ 250{
251 char *regex = NULL; 251 char *regex = NULL;
252 char **components; 252 char **components;
@@ -255,106 +255,106 @@ run (void *cls, char *const *args GNUNET_UNUSED,
255 255
256 cfg = cfg_; 256 cfg = cfg_;
257 257
258 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg); 258 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration(cfg);
259 GNUNET_assert (NULL != my_private_key); 259 GNUNET_assert(NULL != my_private_key);
260 if (GNUNET_OK != 260 if (GNUNET_OK !=
261 GNUNET_CONFIGURATION_get_value_number (cfg, "REGEXPROFILER", 261 GNUNET_CONFIGURATION_get_value_number(cfg, "REGEXPROFILER",
262 "MAX_PATH_COMPRESSION", 262 "MAX_PATH_COMPRESSION",
263 &max_path_compression)) 263 &max_path_compression))
264 { 264 {
265 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 265 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
266 _ 266 _
267 ("%s service is lacking key configuration settings (%s). Exiting.\n"), 267 ("%s service is lacking key configuration settings (%s). Exiting.\n"),
268 "regexprofiler", "max_path_compression"); 268 "regexprofiler", "max_path_compression");
269 global_ret = GNUNET_SYSERR; 269 global_ret = GNUNET_SYSERR;
270 GNUNET_SCHEDULER_shutdown (); 270 GNUNET_SCHEDULER_shutdown();
271 return; 271 return;
272 } 272 }
273 if (GNUNET_OK != 273 if (GNUNET_OK !=
274 GNUNET_CONFIGURATION_get_value_string (cfg, "REGEXPROFILER", 274 GNUNET_CONFIGURATION_get_value_string(cfg, "REGEXPROFILER",
275 "POLICY_DIR", &policy_dir)) 275 "POLICY_DIR", &policy_dir))
276 { 276 {
277 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "REGEXPROFILER", "POLICY_DIR"); 277 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "REGEXPROFILER", "POLICY_DIR");
278 global_ret = GNUNET_SYSERR; 278 global_ret = GNUNET_SYSERR;
279 GNUNET_SCHEDULER_shutdown (); 279 GNUNET_SCHEDULER_shutdown();
280 return; 280 return;
281 } 281 }
282 if (GNUNET_OK != 282 if (GNUNET_OK !=
283 GNUNET_CONFIGURATION_get_value_number (cfg, "TESTBED", 283 GNUNET_CONFIGURATION_get_value_number(cfg, "TESTBED",
284 "PEERID", &peer_id)) 284 "PEERID", &peer_id))
285 { 285 {
286 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "TESTBED", "PEERID"); 286 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "TESTBED", "PEERID");
287 global_ret = GNUNET_SYSERR; 287 global_ret = GNUNET_SYSERR;
288 GNUNET_free (policy_dir); 288 GNUNET_free(policy_dir);
289 GNUNET_SCHEDULER_shutdown (); 289 GNUNET_SCHEDULER_shutdown();
290 return; 290 return;
291 } 291 }
292 292
293 if (GNUNET_OK != 293 if (GNUNET_OK !=
294 GNUNET_CONFIGURATION_get_value_string (cfg, "REGEXPROFILER", 294 GNUNET_CONFIGURATION_get_value_string(cfg, "REGEXPROFILER",
295 "REGEX_PREFIX", &regex_prefix)) 295 "REGEX_PREFIX", &regex_prefix))
296 { 296 {
297 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "REGEXPROFILER", "REGEX_PREFIX"); 297 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "REGEXPROFILER", "REGEX_PREFIX");
298 global_ret = GNUNET_SYSERR; 298 global_ret = GNUNET_SYSERR;
299 GNUNET_free (policy_dir); 299 GNUNET_free(policy_dir);
300 GNUNET_SCHEDULER_shutdown (); 300 GNUNET_SCHEDULER_shutdown();
301 return; 301 return;
302 } 302 }
303 303
304 if (GNUNET_OK != 304 if (GNUNET_OK !=
305 GNUNET_CONFIGURATION_get_value_time (cfg, "REGEXPROFILER", 305 GNUNET_CONFIGURATION_get_value_time(cfg, "REGEXPROFILER",
306 "REANNOUNCE_PERIOD_MAX", 306 "REANNOUNCE_PERIOD_MAX",
307 &reannounce_period_max)) 307 &reannounce_period_max))
308 { 308 {
309 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 309 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
310 "reannounce_period_max not given. Using 10 minutes.\n"); 310 "reannounce_period_max not given. Using 10 minutes.\n");
311 reannounce_period_max = 311 reannounce_period_max =
312 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 10); 312 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 10);
313 } 313 }
314 314
315 stats_handle = GNUNET_STATISTICS_create ("regexprofiler", cfg); 315 stats_handle = GNUNET_STATISTICS_create("regexprofiler", cfg);
316 316
317 dht_handle = GNUNET_DHT_connect (cfg, 1); 317 dht_handle = GNUNET_DHT_connect(cfg, 1);
318 318
319 if (NULL == dht_handle) 319 if (NULL == dht_handle)
320 { 320 {
321 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 321 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
322 "Could not acquire dht handle. Exiting.\n"); 322 "Could not acquire dht handle. Exiting.\n");
323 global_ret = GNUNET_SYSERR; 323 global_ret = GNUNET_SYSERR;
324 GNUNET_free (policy_dir); 324 GNUNET_free(policy_dir);
325 GNUNET_SCHEDULER_shutdown (); 325 GNUNET_SCHEDULER_shutdown();
326 return; 326 return;
327 } 327 }
328 328
329 /* Read regexes from policy files */ 329 /* Read regexes from policy files */
330 GNUNET_assert (-1 != GNUNET_DISK_directory_scan (policy_dir, &scan, 330 GNUNET_assert(-1 != GNUNET_DISK_directory_scan(policy_dir, &scan,
331 (void *) (long) peer_id)); 331 (void *)(long)peer_id));
332 if (NULL == (components = REGEX_TEST_read_from_file (policy_filename))) 332 if (NULL == (components = REGEX_TEST_read_from_file(policy_filename)))
333 { 333 {
334 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 334 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
335 "Policy file %s contains no policies. Exiting.\n", 335 "Policy file %s contains no policies. Exiting.\n",
336 policy_filename); 336 policy_filename);
337 global_ret = GNUNET_SYSERR; 337 global_ret = GNUNET_SYSERR;
338 GNUNET_free (policy_dir); 338 GNUNET_free(policy_dir);
339 GNUNET_SCHEDULER_shutdown (); 339 GNUNET_SCHEDULER_shutdown();
340 return; 340 return;
341 } 341 }
342 GNUNET_free (policy_dir); 342 GNUNET_free(policy_dir);
343 regex = REGEX_TEST_combine (components, 16); 343 regex = REGEX_TEST_combine(components, 16);
344 REGEX_TEST_free_from_file (components); 344 REGEX_TEST_free_from_file(components);
345 345
346 /* Announcing regexes from policy_filename */ 346 /* Announcing regexes from policy_filename */
347 GNUNET_asprintf (&rx_with_pfx, 347 GNUNET_asprintf(&rx_with_pfx,
348 "%s(%s)(0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f)*", 348 "%s(%s)(0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f)*",
349 regex_prefix, 349 regex_prefix,
350 regex); 350 regex);
351 announce_regex (rx_with_pfx); 351 announce_regex(rx_with_pfx);
352 GNUNET_free (regex); 352 GNUNET_free(regex);
353 GNUNET_free (rx_with_pfx); 353 GNUNET_free(rx_with_pfx);
354 354
355 /* Scheduled the task to clean up when shutdown is called */ 355 /* Scheduled the task to clean up when shutdown is called */
356 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 356 GNUNET_SCHEDULER_add_shutdown(&shutdown_task,
357 NULL); 357 NULL);
358} 358}
359 359
360 360
@@ -366,19 +366,19 @@ run (void *cls, char *const *args GNUNET_UNUSED,
366 * @return 0 ok, 1 on error 366 * @return 0 ok, 1 on error
367 */ 367 */
368int 368int
369main (int argc, char *const *argv) 369main(int argc, char *const *argv)
370{ 370{
371 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 371 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
372 GNUNET_GETOPT_OPTION_END 372 GNUNET_GETOPT_OPTION_END
373 }; 373 };
374 374
375 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 375 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
376 return 2; 376 return 2;
377 return (GNUNET_OK == 377 return (GNUNET_OK ==
378 GNUNET_PROGRAM_run (argc, argv, "regexprofiler", 378 GNUNET_PROGRAM_run(argc, argv, "regexprofiler",
379 gettext_noop 379 gettext_noop
380 ("Daemon to announce regular expressions for the peer using cadet."), 380 ("Daemon to announce regular expressions for the peer using cadet."),
381 options, &run, NULL)) ? global_ret : 1; 381 options, &run, NULL)) ? global_ret : 1;
382} 382}
383 383
384 384
@@ -388,11 +388,11 @@ main (int argc, char *const *argv)
388/** 388/**
389 * MINIMIZE heap size (way below 128k) since this process doesn't need much. 389 * MINIMIZE heap size (way below 128k) since this process doesn't need much.
390 */ 390 */
391void __attribute__ ((constructor)) GNUNET_ARM_memory_init () 391void __attribute__ ((constructor)) GNUNET_ARM_memory_init()
392{ 392{
393 mallopt (M_TRIM_THRESHOLD, 4 * 1024); 393 mallopt(M_TRIM_THRESHOLD, 4 * 1024);
394 mallopt (M_TOP_PAD, 1 * 1024); 394 mallopt(M_TOP_PAD, 1 * 1024);
395 malloc_trim (0); 395 malloc_trim(0);
396} 396}
397#endif 397#endif
398 398