aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mesh/gnunet-daemon-regexprofiler.c77
1 files changed, 13 insertions, 64 deletions
diff --git a/src/mesh/gnunet-daemon-regexprofiler.c b/src/mesh/gnunet-daemon-regexprofiler.c
index 384da9c83..09725b15e 100644
--- a/src/mesh/gnunet-daemon-regexprofiler.c
+++ b/src/mesh/gnunet-daemon-regexprofiler.c
@@ -72,22 +72,6 @@ static char * policy_filename;
72static char * regex_prefix; 72static char * regex_prefix;
73 73
74/** 74/**
75 * Time to wait between announcing regexes.
76 */
77static struct GNUNET_TIME_Relative announce_delay = { 500 };
78
79/**
80 * Regexes to announce read from 'policy_filename'.
81 */
82static char **regexes;
83
84/**
85 * Number of regexes read from 'policy_filename'.
86 */
87static unsigned int num_regexes;
88
89
90/**
91 * Task run during shutdown. 75 * Task run during shutdown.
92 * 76 *
93 * @param cls unused 77 * @param cls unused
@@ -136,28 +120,6 @@ announce_regex (const char * regex)
136 120
137 121
138/** 122/**
139 * Task run to iterate over all policies and announce them using mesh.
140 *
141 * @param cls unused
142 * @param tc unused
143 */
144static void
145do_announce_policies (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
146{
147 static unsigned int num_rx_announced;
148
149 announce_regex (regexes[num_rx_announced]);
150
151 if (++num_rx_announced < num_regexes)
152 {
153 GNUNET_SCHEDULER_add_delayed (announce_delay, &do_announce_policies, NULL);
154 return;
155 }
156
157 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "All regexes announced.\n");
158}
159
160/**
161 * Load regular expressions from filename into 'rxes' array. Array needs to be freed. 123 * Load regular expressions from filename into 'rxes' array. Array needs to be freed.
162 * 124 *
163 * @param filename filename of the file containing the regexes, one per line. 125 * @param filename filename of the file containing the regexes, one per line.
@@ -165,14 +127,13 @@ do_announce_policies (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
165 * @return number of regular expressions read from filename and in rxes array. 127 * @return number of regular expressions read from filename and in rxes array.
166 */ 128 */
167static unsigned int 129static unsigned int
168load_regexes (const char *filename, char ***rxes) 130load_regexes (const char *filename, char **rx)
169{ 131{
170 char *data; 132 char *data;
171 char *buf; 133 char *buf;
172 uint64_t filesize; 134 uint64_t filesize;
173 unsigned int offset; 135 unsigned int offset;
174 unsigned int rx_cnt; 136 unsigned int rx_cnt;
175 unsigned int i;
176 137
177 if (GNUNET_YES != GNUNET_DISK_file_test (policy_filename)) 138 if (GNUNET_YES != GNUNET_DISK_file_test (policy_filename))
178 { 139 {
@@ -203,22 +164,16 @@ load_regexes (const char *filename, char ***rxes)
203 offset++; 164 offset++;
204 if (((data[offset] == '\n')) && (buf != &data[offset])) 165 if (((data[offset] == '\n')) && (buf != &data[offset]))
205 { 166 {
206 data[offset] = '\0'; 167 data[offset] = '|';
207 rx_cnt++;
208 buf = &data[offset + 1]; 168 buf = &data[offset + 1];
169 rx_cnt++;
209 } 170 }
210 else if ((data[offset] == '\n') || (data[offset] == '\0')) 171 else if ((data[offset] == '\n') || (data[offset] == '\0'))
211 buf = &data[offset + 1]; 172 buf = &data[offset + 1];
212 } 173 }
213 *rxes = GNUNET_malloc (sizeof (char *) * rx_cnt); 174 data[offset] = '\0';
214 offset = 0; 175 *rx = data;
215 for (i = 0; i < rx_cnt; i++) 176
216 {
217 GNUNET_asprintf (&(*rxes)[i], "%s%s", regex_prefix, &data[offset]);
218 offset += strlen (&data[offset]) + 1;
219 }
220 GNUNET_free (data);
221
222 return rx_cnt; 177 return rx_cnt;
223} 178}
224 179
@@ -236,6 +191,8 @@ run (void *cls, char *const *args GNUNET_UNUSED,
236 const char *cfgfile GNUNET_UNUSED, 191 const char *cfgfile GNUNET_UNUSED,
237 const struct GNUNET_CONFIGURATION_Handle *cfg_) 192 const struct GNUNET_CONFIGURATION_Handle *cfg_)
238{ 193{
194 char *regex = NULL;
195 char *rx_with_pfx;
239 const GNUNET_MESH_ApplicationType app = (GNUNET_MESH_ApplicationType)0; 196 const GNUNET_MESH_ApplicationType app = (GNUNET_MESH_ApplicationType)0;
240 static struct GNUNET_MESH_MessageHandler handlers[] = { 197 static struct GNUNET_MESH_MessageHandler handlers[] = {
241 {NULL, 0, 0} 198 {NULL, 0, 0}
@@ -282,17 +239,6 @@ run (void *cls, char *const *args GNUNET_UNUSED,
282 return; 239 return;
283 } 240 }
284 241
285 if (GNUNET_OK !=
286 GNUNET_CONFIGURATION_get_value_time (cfg, "REGEXPROFILER", "ANNOUNCE_DELAY",
287 &announce_delay))
288 {
289 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
290 _
291 ("%s service is lacking key configuration settings (%s). Using default value: %s.\n"),
292 "regexprofiler", "announce_delay",
293 GNUNET_STRINGS_relative_time_to_string (announce_delay, GNUNET_NO));
294 }
295
296 stats_handle = GNUNET_STATISTICS_create ("regexprofiler", cfg); 242 stats_handle = GNUNET_STATISTICS_create ("regexprofiler", cfg);
297 243
298 mesh_handle = 244 mesh_handle =
@@ -307,7 +253,7 @@ run (void *cls, char *const *args GNUNET_UNUSED,
307 } 253 }
308 254
309 /* Read regexes from policy files */ 255 /* Read regexes from policy files */
310 if ((num_regexes = load_regexes (policy_filename, &regexes)) == 0) 256 if (0 == load_regexes (policy_filename, &regex))
311 { 257 {
312 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 258 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
313 "Policy file %s contains no policies. Exiting.\n", 259 "Policy file %s contains no policies. Exiting.\n",
@@ -318,7 +264,10 @@ run (void *cls, char *const *args GNUNET_UNUSED,
318 } 264 }
319 265
320 /* Announcing regexes from policy_filename */ 266 /* Announcing regexes from policy_filename */
321 GNUNET_SCHEDULER_add_delayed (announce_delay, &do_announce_policies, NULL); 267 GNUNET_asprintf (&rx_with_pfx, "%s(%s)", regex_prefix, regex);
268 announce_regex (rx_with_pfx);
269 GNUNET_free (rx_with_pfx);
270 GNUNET_free (regex);
322 271
323 /* Scheduled the task to clean up when shutdown is called */ 272 /* Scheduled the task to clean up when shutdown is called */
324 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, 273 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,