diff options
Diffstat (limited to 'src/fs/gnunet-daemon-fsprofiler.c')
-rw-r--r-- | src/fs/gnunet-daemon-fsprofiler.c | 565 |
1 files changed, 289 insertions, 276 deletions
diff --git a/src/fs/gnunet-daemon-fsprofiler.c b/src/fs/gnunet-daemon-fsprofiler.c index 0202dde9c..524475c40 100644 --- a/src/fs/gnunet-daemon-fsprofiler.c +++ b/src/fs/gnunet-daemon-fsprofiler.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 fs/gnunet-daemon-fsprofiler.c | 22 | * @file fs/gnunet-daemon-fsprofiler.c |
@@ -34,8 +34,7 @@ | |||
34 | * We use 'patterns' of the form (x,y,t) to specify desired download/publish | 34 | * We use 'patterns' of the form (x,y,t) to specify desired download/publish |
35 | * activities of a peer. They are stored in a DLL. | 35 | * activities of a peer. They are stored in a DLL. |
36 | */ | 36 | */ |
37 | struct Pattern | 37 | struct Pattern { |
38 | { | ||
39 | /** | 38 | /** |
40 | * Kept in a DLL. | 39 | * Kept in a DLL. |
41 | */ | 40 | */ |
@@ -173,29 +172,29 @@ static struct Pattern *download_tail; | |||
173 | * @return GNUNET_OK on success | 172 | * @return GNUNET_OK on success |
174 | */ | 173 | */ |
175 | static int | 174 | static int |
176 | parse_pattern (struct Pattern **head, | 175 | parse_pattern(struct Pattern **head, |
177 | struct Pattern **tail, | 176 | struct Pattern **tail, |
178 | const char *pattern) | 177 | const char *pattern) |
179 | { | 178 | { |
180 | struct Pattern *p; | 179 | struct Pattern *p; |
181 | unsigned long long x; | 180 | unsigned long long x; |
182 | unsigned long long y; | 181 | unsigned long long y; |
183 | unsigned long long t; | 182 | unsigned long long t; |
184 | 183 | ||
185 | while (3 == sscanf (pattern, | 184 | while (3 == sscanf(pattern, |
186 | "(%llu,%llu,%llu)", | 185 | "(%llu,%llu,%llu)", |
187 | &x, &y, &t)) | 186 | &x, &y, &t)) |
188 | { | 187 | { |
189 | p = GNUNET_new (struct Pattern); | 188 | p = GNUNET_new(struct Pattern); |
190 | p->x = x; | 189 | p->x = x; |
191 | p->y = y; | 190 | p->y = y; |
192 | p->delay.rel_value_us = (uint64_t) t; | 191 | p->delay.rel_value_us = (uint64_t)t; |
193 | GNUNET_CONTAINER_DLL_insert (*head, *tail, p); | 192 | GNUNET_CONTAINER_DLL_insert(*head, *tail, p); |
194 | pattern = strstr (pattern, ")"); | 193 | pattern = strstr(pattern, ")"); |
195 | GNUNET_assert (NULL != pattern); | 194 | GNUNET_assert(NULL != pattern); |
196 | pattern++; | 195 | pattern++; |
197 | } | 196 | } |
198 | return (0 == strlen (pattern)) ? GNUNET_OK : GNUNET_SYSERR; | 197 | return (0 == strlen(pattern)) ? GNUNET_OK : GNUNET_SYSERR; |
199 | } | 198 | } |
200 | 199 | ||
201 | 200 | ||
@@ -206,13 +205,13 @@ parse_pattern (struct Pattern **head, | |||
206 | * @return corresponding KSK URI | 205 | * @return corresponding KSK URI |
207 | */ | 206 | */ |
208 | static struct GNUNET_FS_Uri * | 207 | static struct GNUNET_FS_Uri * |
209 | make_keywords (uint64_t kval) | 208 | make_keywords(uint64_t kval) |
210 | { | 209 | { |
211 | char kw[128]; | 210 | char kw[128]; |
212 | 211 | ||
213 | GNUNET_snprintf (kw, sizeof (kw), | 212 | GNUNET_snprintf(kw, sizeof(kw), |
214 | "%llu", (unsigned long long) kval); | 213 | "%llu", (unsigned long long)kval); |
215 | return GNUNET_FS_uri_ksk_create (kw, NULL); | 214 | return GNUNET_FS_uri_ksk_create(kw, NULL); |
216 | } | 215 | } |
217 | 216 | ||
218 | 217 | ||
@@ -226,9 +225,9 @@ make_keywords (uint64_t kval) | |||
226 | * @return file information handle for the file | 225 | * @return file information handle for the file |
227 | */ | 226 | */ |
228 | static struct GNUNET_FS_FileInformation * | 227 | static struct GNUNET_FS_FileInformation * |
229 | make_file (uint64_t length, | 228 | make_file(uint64_t length, |
230 | uint64_t kval, | 229 | uint64_t kval, |
231 | void *ctx) | 230 | void *ctx) |
232 | { | 231 | { |
233 | struct GNUNET_FS_FileInformation *fi; | 232 | struct GNUNET_FS_FileInformation *fi; |
234 | struct GNUNET_FS_BlockOptions bo; | 233 | struct GNUNET_FS_BlockOptions bo; |
@@ -238,27 +237,27 @@ make_file (uint64_t length, | |||
238 | uint64_t xor; | 237 | uint64_t xor; |
239 | 238 | ||
240 | data = NULL; /* to make compilers happy */ | 239 | data = NULL; /* to make compilers happy */ |
241 | if ( (0 != length) && | 240 | if ((0 != length) && |
242 | (NULL == (data = GNUNET_malloc_large ((size_t) length))) ) | 241 | (NULL == (data = GNUNET_malloc_large((size_t)length)))) |
243 | return NULL; | 242 | return NULL; |
244 | /* initialize data with 'unique' data only depending on 'kval' and 'size', | 243 | /* initialize data with 'unique' data only depending on 'kval' and 'size', |
245 | making sure that blocks do not repeat */ | 244 | making sure that blocks do not repeat */ |
246 | for (i=0;i<length; i+=8) | 245 | for (i = 0; i < length; i += 8) |
247 | { | 246 | { |
248 | xor = length ^ kval ^ (uint64_t) (i / 32 / 1024); | 247 | xor = length ^ kval ^ (uint64_t)(i / 32 / 1024); |
249 | GNUNET_memcpy (&data[i], &xor, GNUNET_MIN (length - i, sizeof (uint64_t))); | 248 | GNUNET_memcpy(&data[i], &xor, GNUNET_MIN(length - i, sizeof(uint64_t))); |
250 | } | 249 | } |
251 | bo.expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_DAYS); | 250 | bo.expiration_time = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_DAYS); |
252 | bo.anonymity_level = (uint32_t) anonymity_level; | 251 | bo.anonymity_level = (uint32_t)anonymity_level; |
253 | bo.content_priority = 128; | 252 | bo.content_priority = 128; |
254 | bo.replication_level = (uint32_t) replication_level; | 253 | bo.replication_level = (uint32_t)replication_level; |
255 | keywords = make_keywords (kval); | 254 | keywords = make_keywords(kval); |
256 | fi = GNUNET_FS_file_information_create_from_data (fs_handle, | 255 | fi = GNUNET_FS_file_information_create_from_data(fs_handle, |
257 | ctx, | 256 | ctx, |
258 | length, | 257 | length, |
259 | data, keywords, | 258 | data, keywords, |
260 | NULL, GNUNET_NO, &bo); | 259 | NULL, GNUNET_NO, &bo); |
261 | GNUNET_FS_uri_destroy (keywords); | 260 | GNUNET_FS_uri_destroy(keywords); |
262 | return fi; | 261 | return fi; |
263 | } | 262 | } |
264 | 263 | ||
@@ -269,42 +268,42 @@ make_file (uint64_t length, | |||
269 | * @param cls unused | 268 | * @param cls unused |
270 | */ | 269 | */ |
271 | static void | 270 | static void |
272 | shutdown_task (void *cls) | 271 | shutdown_task(void *cls) |
273 | { | 272 | { |
274 | struct Pattern *p; | 273 | struct Pattern *p; |
275 | 274 | ||
276 | while (NULL != (p = publish_head)) | 275 | while (NULL != (p = publish_head)) |
277 | { | 276 | { |
278 | if (NULL != p->task) | 277 | if (NULL != p->task) |
279 | GNUNET_SCHEDULER_cancel (p->task); | 278 | GNUNET_SCHEDULER_cancel(p->task); |
280 | if (NULL != p->ctx) | 279 | if (NULL != p->ctx) |
281 | GNUNET_FS_publish_stop (p->ctx); | 280 | GNUNET_FS_publish_stop(p->ctx); |
282 | GNUNET_CONTAINER_DLL_remove (publish_head, publish_tail, p); | 281 | GNUNET_CONTAINER_DLL_remove(publish_head, publish_tail, p); |
283 | GNUNET_free (p); | 282 | GNUNET_free(p); |
284 | } | 283 | } |
285 | while (NULL != (p = download_head)) | 284 | while (NULL != (p = download_head)) |
286 | { | 285 | { |
287 | if (NULL != p->task) | 286 | if (NULL != p->task) |
288 | GNUNET_SCHEDULER_cancel (p->task); | 287 | GNUNET_SCHEDULER_cancel(p->task); |
289 | if (NULL != p->stask) | 288 | if (NULL != p->stask) |
290 | GNUNET_SCHEDULER_cancel (p->stask); | 289 | GNUNET_SCHEDULER_cancel(p->stask); |
291 | if (NULL != p->ctx) | 290 | if (NULL != p->ctx) |
292 | GNUNET_FS_download_stop (p->ctx, GNUNET_YES); | 291 | GNUNET_FS_download_stop(p->ctx, GNUNET_YES); |
293 | if (NULL != p->sctx) | 292 | if (NULL != p->sctx) |
294 | GNUNET_FS_search_stop (p->sctx); | 293 | GNUNET_FS_search_stop(p->sctx); |
295 | GNUNET_CONTAINER_DLL_remove (download_head, download_tail, p); | 294 | GNUNET_CONTAINER_DLL_remove(download_head, download_tail, p); |
296 | GNUNET_free (p); | 295 | GNUNET_free(p); |
297 | } | 296 | } |
298 | if (NULL != fs_handle) | 297 | if (NULL != fs_handle) |
299 | { | 298 | { |
300 | GNUNET_FS_stop (fs_handle); | 299 | GNUNET_FS_stop(fs_handle); |
301 | fs_handle = NULL; | 300 | fs_handle = NULL; |
302 | } | 301 | } |
303 | if (NULL != stats_handle) | 302 | if (NULL != stats_handle) |
304 | { | 303 | { |
305 | GNUNET_STATISTICS_destroy (stats_handle, GNUNET_YES); | 304 | GNUNET_STATISTICS_destroy(stats_handle, GNUNET_YES); |
306 | stats_handle = NULL; | 305 | stats_handle = NULL; |
307 | } | 306 | } |
308 | } | 307 | } |
309 | 308 | ||
310 | 309 | ||
@@ -314,12 +313,12 @@ shutdown_task (void *cls) | |||
314 | * @param cls the 'struct Pattern' of the publish operation to stop | 313 | * @param cls the 'struct Pattern' of the publish operation to stop |
315 | */ | 314 | */ |
316 | static void | 315 | static void |
317 | publish_stop_task (void *cls) | 316 | publish_stop_task(void *cls) |
318 | { | 317 | { |
319 | struct Pattern *p = cls; | 318 | struct Pattern *p = cls; |
320 | 319 | ||
321 | p->task = NULL; | 320 | p->task = NULL; |
322 | GNUNET_FS_publish_stop (p->ctx); | 321 | GNUNET_FS_publish_stop(p->ctx); |
323 | } | 322 | } |
324 | 323 | ||
325 | 324 | ||
@@ -329,12 +328,12 @@ publish_stop_task (void *cls) | |||
329 | * @param cls the 'struct Pattern' of the download operation to stop | 328 | * @param cls the 'struct Pattern' of the download operation to stop |
330 | */ | 329 | */ |
331 | static void | 330 | static void |
332 | download_stop_task (void *cls) | 331 | download_stop_task(void *cls) |
333 | { | 332 | { |
334 | struct Pattern *p = cls; | 333 | struct Pattern *p = cls; |
335 | 334 | ||
336 | p->task = NULL; | 335 | p->task = NULL; |
337 | GNUNET_FS_download_stop (p->ctx, GNUNET_YES); | 336 | GNUNET_FS_download_stop(p->ctx, GNUNET_YES); |
338 | } | 337 | } |
339 | 338 | ||
340 | 339 | ||
@@ -344,12 +343,12 @@ download_stop_task (void *cls) | |||
344 | * @param cls the 'struct Pattern' of the download operation to stop | 343 | * @param cls the 'struct Pattern' of the download operation to stop |
345 | */ | 344 | */ |
346 | static void | 345 | static void |
347 | search_stop_task (void *cls) | 346 | search_stop_task(void *cls) |
348 | { | 347 | { |
349 | struct Pattern *p = cls; | 348 | struct Pattern *p = cls; |
350 | 349 | ||
351 | p->stask = NULL; | 350 | p->stask = NULL; |
352 | GNUNET_FS_search_stop (p->sctx); | 351 | GNUNET_FS_search_stop(p->sctx); |
353 | } | 352 | } |
354 | 353 | ||
355 | 354 | ||
@@ -369,124 +368,138 @@ search_stop_task (void *cls) | |||
369 | * field in the GNUNET_FS_ProgressInfo struct. | 368 | * field in the GNUNET_FS_ProgressInfo struct. |
370 | */ | 369 | */ |
371 | static void * | 370 | static void * |
372 | progress_cb (void *cls, | 371 | progress_cb(void *cls, |
373 | const struct GNUNET_FS_ProgressInfo *info) | 372 | const struct GNUNET_FS_ProgressInfo *info) |
374 | { | 373 | { |
375 | struct Pattern *p; | 374 | struct Pattern *p; |
376 | const struct GNUNET_FS_Uri *uri; | 375 | const struct GNUNET_FS_Uri *uri; |
377 | 376 | ||
378 | switch (info->status) | 377 | switch (info->status) |
379 | { | ||
380 | case GNUNET_FS_STATUS_PUBLISH_START: | ||
381 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | ||
382 | p = info->value.publish.cctx; | ||
383 | return p; | ||
384 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | ||
385 | p = info->value.publish.cctx; | ||
386 | return p; | ||
387 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | ||
388 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
389 | "Publishing failed\n"); | ||
390 | GNUNET_STATISTICS_update (stats_handle, | ||
391 | "# failed publish operations", 1, GNUNET_NO); | ||
392 | p = info->value.publish.cctx; | ||
393 | p->task = GNUNET_SCHEDULER_add_now (&publish_stop_task, p); | ||
394 | return p; | ||
395 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | ||
396 | p = info->value.publish.cctx; | ||
397 | GNUNET_STATISTICS_update (stats_handle, | ||
398 | "# publishing time (ms)", | ||
399 | (long long) GNUNET_TIME_absolute_get_duration (p->start_time).rel_value_us / 1000LL, | ||
400 | GNUNET_NO); | ||
401 | p->task = GNUNET_SCHEDULER_add_now (&publish_stop_task, p); | ||
402 | return p; | ||
403 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
404 | p = info->value.publish.cctx; | ||
405 | p->ctx = NULL; | ||
406 | GNUNET_CONTAINER_DLL_remove (publish_head, publish_tail, p); | ||
407 | GNUNET_free (p); | ||
408 | return NULL; | ||
409 | case GNUNET_FS_STATUS_DOWNLOAD_START: | ||
410 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | ||
411 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: | ||
412 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: | ||
413 | p = info->value.download.cctx; | ||
414 | return p; | ||
415 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: | ||
416 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
417 | "Download failed\n"); | ||
418 | GNUNET_STATISTICS_update (stats_handle, | ||
419 | "# failed downloads", 1, GNUNET_NO); | ||
420 | p = info->value.download.cctx; | ||
421 | p->task = GNUNET_SCHEDULER_add_now (&download_stop_task, p); | ||
422 | return p; | ||
423 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: | ||
424 | p = info->value.download.cctx; | ||
425 | GNUNET_STATISTICS_update (stats_handle, | ||
426 | "# download time (ms)", | ||
427 | (long long) GNUNET_TIME_absolute_get_duration (p->start_time).rel_value_us / 1000LL, | ||
428 | GNUNET_NO); | ||
429 | p->task = GNUNET_SCHEDULER_add_now (&download_stop_task, p); | ||
430 | return p; | ||
431 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: | ||
432 | p = info->value.download.cctx; | ||
433 | p->ctx = NULL; | ||
434 | if (NULL == p->sctx) | ||
435 | { | ||
436 | GNUNET_CONTAINER_DLL_remove (download_head, download_tail, p); | ||
437 | GNUNET_free (p); | ||
438 | } | ||
439 | return NULL; | ||
440 | case GNUNET_FS_STATUS_SEARCH_START: | ||
441 | case GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE: | ||
442 | p = info->value.search.cctx; | ||
443 | return p; | ||
444 | case GNUNET_FS_STATUS_SEARCH_RESULT: | ||
445 | p = info->value.search.cctx; | ||
446 | uri = info->value.search.specifics.result.uri; | ||
447 | if (GNUNET_YES != GNUNET_FS_uri_test_chk (uri)) | ||
448 | return NULL; /* not what we want */ | ||
449 | if (p->y != GNUNET_FS_uri_chk_get_file_size (uri)) | ||
450 | return NULL; /* not what we want */ | ||
451 | GNUNET_STATISTICS_update (stats_handle, | ||
452 | "# search time (ms)", | ||
453 | (long long) GNUNET_TIME_absolute_get_duration (p->start_time).rel_value_us / 1000LL, | ||
454 | GNUNET_NO); | ||
455 | p->start_time = GNUNET_TIME_absolute_get (); | ||
456 | p->ctx = GNUNET_FS_download_start (fs_handle, uri, | ||
457 | NULL, NULL, NULL, | ||
458 | 0, GNUNET_FS_uri_chk_get_file_size (uri), | ||
459 | anonymity_level, | ||
460 | GNUNET_FS_DOWNLOAD_NO_TEMPORARIES, | ||
461 | p, | ||
462 | NULL); | ||
463 | p->stask = GNUNET_SCHEDULER_add_now (&search_stop_task, p); | ||
464 | return NULL; | ||
465 | case GNUNET_FS_STATUS_SEARCH_UPDATE: | ||
466 | case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: | ||
467 | return NULL; /* don't care */ | ||
468 | case GNUNET_FS_STATUS_SEARCH_ERROR: | ||
469 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
470 | "Search failed\n"); | ||
471 | GNUNET_STATISTICS_update (stats_handle, | ||
472 | "# failed searches", 1, GNUNET_NO); | ||
473 | p = info->value.search.cctx; | ||
474 | p->stask = GNUNET_SCHEDULER_add_now (&search_stop_task, p); | ||
475 | return p; | ||
476 | case GNUNET_FS_STATUS_SEARCH_STOPPED: | ||
477 | p = info->value.search.cctx; | ||
478 | p->sctx = NULL; | ||
479 | if (NULL == p->ctx) | ||
480 | { | 378 | { |
481 | GNUNET_CONTAINER_DLL_remove (download_head, download_tail, p); | 379 | case GNUNET_FS_STATUS_PUBLISH_START: |
482 | GNUNET_free (p); | 380 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
381 | p = info->value.publish.cctx; | ||
382 | return p; | ||
383 | |||
384 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | ||
385 | p = info->value.publish.cctx; | ||
386 | return p; | ||
387 | |||
388 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | ||
389 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
390 | "Publishing failed\n"); | ||
391 | GNUNET_STATISTICS_update(stats_handle, | ||
392 | "# failed publish operations", 1, GNUNET_NO); | ||
393 | p = info->value.publish.cctx; | ||
394 | p->task = GNUNET_SCHEDULER_add_now(&publish_stop_task, p); | ||
395 | return p; | ||
396 | |||
397 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | ||
398 | p = info->value.publish.cctx; | ||
399 | GNUNET_STATISTICS_update(stats_handle, | ||
400 | "# publishing time (ms)", | ||
401 | (long long)GNUNET_TIME_absolute_get_duration(p->start_time).rel_value_us / 1000LL, | ||
402 | GNUNET_NO); | ||
403 | p->task = GNUNET_SCHEDULER_add_now(&publish_stop_task, p); | ||
404 | return p; | ||
405 | |||
406 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
407 | p = info->value.publish.cctx; | ||
408 | p->ctx = NULL; | ||
409 | GNUNET_CONTAINER_DLL_remove(publish_head, publish_tail, p); | ||
410 | GNUNET_free(p); | ||
411 | return NULL; | ||
412 | |||
413 | case GNUNET_FS_STATUS_DOWNLOAD_START: | ||
414 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | ||
415 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: | ||
416 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: | ||
417 | p = info->value.download.cctx; | ||
418 | return p; | ||
419 | |||
420 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: | ||
421 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
422 | "Download failed\n"); | ||
423 | GNUNET_STATISTICS_update(stats_handle, | ||
424 | "# failed downloads", 1, GNUNET_NO); | ||
425 | p = info->value.download.cctx; | ||
426 | p->task = GNUNET_SCHEDULER_add_now(&download_stop_task, p); | ||
427 | return p; | ||
428 | |||
429 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: | ||
430 | p = info->value.download.cctx; | ||
431 | GNUNET_STATISTICS_update(stats_handle, | ||
432 | "# download time (ms)", | ||
433 | (long long)GNUNET_TIME_absolute_get_duration(p->start_time).rel_value_us / 1000LL, | ||
434 | GNUNET_NO); | ||
435 | p->task = GNUNET_SCHEDULER_add_now(&download_stop_task, p); | ||
436 | return p; | ||
437 | |||
438 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: | ||
439 | p = info->value.download.cctx; | ||
440 | p->ctx = NULL; | ||
441 | if (NULL == p->sctx) | ||
442 | { | ||
443 | GNUNET_CONTAINER_DLL_remove(download_head, download_tail, p); | ||
444 | GNUNET_free(p); | ||
445 | } | ||
446 | return NULL; | ||
447 | |||
448 | case GNUNET_FS_STATUS_SEARCH_START: | ||
449 | case GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE: | ||
450 | p = info->value.search.cctx; | ||
451 | return p; | ||
452 | |||
453 | case GNUNET_FS_STATUS_SEARCH_RESULT: | ||
454 | p = info->value.search.cctx; | ||
455 | uri = info->value.search.specifics.result.uri; | ||
456 | if (GNUNET_YES != GNUNET_FS_uri_test_chk(uri)) | ||
457 | return NULL; /* not what we want */ | ||
458 | if (p->y != GNUNET_FS_uri_chk_get_file_size(uri)) | ||
459 | return NULL; /* not what we want */ | ||
460 | GNUNET_STATISTICS_update(stats_handle, | ||
461 | "# search time (ms)", | ||
462 | (long long)GNUNET_TIME_absolute_get_duration(p->start_time).rel_value_us / 1000LL, | ||
463 | GNUNET_NO); | ||
464 | p->start_time = GNUNET_TIME_absolute_get(); | ||
465 | p->ctx = GNUNET_FS_download_start(fs_handle, uri, | ||
466 | NULL, NULL, NULL, | ||
467 | 0, GNUNET_FS_uri_chk_get_file_size(uri), | ||
468 | anonymity_level, | ||
469 | GNUNET_FS_DOWNLOAD_NO_TEMPORARIES, | ||
470 | p, | ||
471 | NULL); | ||
472 | p->stask = GNUNET_SCHEDULER_add_now(&search_stop_task, p); | ||
473 | return NULL; | ||
474 | |||
475 | case GNUNET_FS_STATUS_SEARCH_UPDATE: | ||
476 | case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: | ||
477 | return NULL; /* don't care */ | ||
478 | |||
479 | case GNUNET_FS_STATUS_SEARCH_ERROR: | ||
480 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
481 | "Search failed\n"); | ||
482 | GNUNET_STATISTICS_update(stats_handle, | ||
483 | "# failed searches", 1, GNUNET_NO); | ||
484 | p = info->value.search.cctx; | ||
485 | p->stask = GNUNET_SCHEDULER_add_now(&search_stop_task, p); | ||
486 | return p; | ||
487 | |||
488 | case GNUNET_FS_STATUS_SEARCH_STOPPED: | ||
489 | p = info->value.search.cctx; | ||
490 | p->sctx = NULL; | ||
491 | if (NULL == p->ctx) | ||
492 | { | ||
493 | GNUNET_CONTAINER_DLL_remove(download_head, download_tail, p); | ||
494 | GNUNET_free(p); | ||
495 | } | ||
496 | return NULL; | ||
497 | |||
498 | default: | ||
499 | /* unexpected event during profiling */ | ||
500 | GNUNET_break(0); | ||
501 | return NULL; | ||
483 | } | 502 | } |
484 | return NULL; | ||
485 | default: | ||
486 | /* unexpected event during profiling */ | ||
487 | GNUNET_break (0); | ||
488 | return NULL; | ||
489 | } | ||
490 | } | 503 | } |
491 | 504 | ||
492 | 505 | ||
@@ -496,18 +509,18 @@ progress_cb (void *cls, | |||
496 | * @param cls the 'struct Pattern' specifying the operation to perform | 509 | * @param cls the 'struct Pattern' specifying the operation to perform |
497 | */ | 510 | */ |
498 | static void | 511 | static void |
499 | start_publish (void *cls) | 512 | start_publish(void *cls) |
500 | { | 513 | { |
501 | struct Pattern *p = cls; | 514 | struct Pattern *p = cls; |
502 | struct GNUNET_FS_FileInformation *fi; | 515 | struct GNUNET_FS_FileInformation *fi; |
503 | 516 | ||
504 | p->task = NULL; | 517 | p->task = NULL; |
505 | fi = make_file (p->x, p->y, p); | 518 | fi = make_file(p->x, p->y, p); |
506 | p->start_time = GNUNET_TIME_absolute_get (); | 519 | p->start_time = GNUNET_TIME_absolute_get(); |
507 | p->ctx = GNUNET_FS_publish_start (fs_handle, | 520 | p->ctx = GNUNET_FS_publish_start(fs_handle, |
508 | fi, | 521 | fi, |
509 | NULL, NULL, NULL, | 522 | NULL, NULL, NULL, |
510 | GNUNET_FS_PUBLISH_OPTION_NONE); | 523 | GNUNET_FS_PUBLISH_OPTION_NONE); |
511 | } | 524 | } |
512 | 525 | ||
513 | 526 | ||
@@ -517,18 +530,18 @@ start_publish (void *cls) | |||
517 | * @param cls the 'struct Pattern' specifying the operation to perform | 530 | * @param cls the 'struct Pattern' specifying the operation to perform |
518 | */ | 531 | */ |
519 | static void | 532 | static void |
520 | start_download (void *cls) | 533 | start_download(void *cls) |
521 | { | 534 | { |
522 | struct Pattern *p = cls; | 535 | struct Pattern *p = cls; |
523 | struct GNUNET_FS_Uri *keywords; | 536 | struct GNUNET_FS_Uri *keywords; |
524 | 537 | ||
525 | p->task = NULL; | 538 | p->task = NULL; |
526 | keywords = make_keywords (p->x); | 539 | keywords = make_keywords(p->x); |
527 | p->start_time = GNUNET_TIME_absolute_get (); | 540 | p->start_time = GNUNET_TIME_absolute_get(); |
528 | p->sctx = GNUNET_FS_search_start (fs_handle, keywords, | 541 | p->sctx = GNUNET_FS_search_start(fs_handle, keywords, |
529 | anonymity_level, | 542 | anonymity_level, |
530 | GNUNET_FS_SEARCH_OPTION_NONE, | 543 | GNUNET_FS_SEARCH_OPTION_NONE, |
531 | p); | 544 | p); |
532 | } | 545 | } |
533 | 546 | ||
534 | 547 | ||
@@ -541,88 +554,88 @@ start_download (void *cls) | |||
541 | * @param cfg_ configuration | 554 | * @param cfg_ configuration |
542 | */ | 555 | */ |
543 | static void | 556 | static void |
544 | run (void *cls, char *const *args GNUNET_UNUSED, | 557 | run(void *cls, char *const *args GNUNET_UNUSED, |
545 | const char *cfgfile GNUNET_UNUSED, | 558 | const char *cfgfile GNUNET_UNUSED, |
546 | const struct GNUNET_CONFIGURATION_Handle *cfg_) | 559 | const struct GNUNET_CONFIGURATION_Handle *cfg_) |
547 | { | 560 | { |
548 | char myoptname[128]; | 561 | char myoptname[128]; |
549 | struct Pattern *p; | 562 | struct Pattern *p; |
550 | 563 | ||
551 | cfg = cfg_; | 564 | cfg = cfg_; |
552 | /* Scheduled the task to clean up when shutdown is called */ | 565 | /* Scheduled the task to clean up when shutdown is called */ |
553 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 566 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, |
554 | NULL); | 567 | NULL); |
555 | 568 | ||
556 | if (GNUNET_OK != | 569 | if (GNUNET_OK != |
557 | GNUNET_CONFIGURATION_get_value_number (cfg, | 570 | GNUNET_CONFIGURATION_get_value_number(cfg, |
558 | "TESTBED", "PEERID", | 571 | "TESTBED", "PEERID", |
559 | &my_peerid)) | 572 | &my_peerid)) |
560 | { | 573 | { |
561 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 574 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
562 | "TESTBED", "PEERID"); | 575 | "TESTBED", "PEERID"); |
563 | global_ret = GNUNET_SYSERR; | 576 | global_ret = GNUNET_SYSERR; |
564 | GNUNET_SCHEDULER_shutdown (); | 577 | GNUNET_SCHEDULER_shutdown(); |
565 | return; | 578 | return; |
566 | } | 579 | } |
567 | if (GNUNET_OK != | 580 | if (GNUNET_OK != |
568 | GNUNET_CONFIGURATION_get_value_number (cfg, | 581 | GNUNET_CONFIGURATION_get_value_number(cfg, |
569 | "FSPROFILER", "ANONYMITY_LEVEL", | 582 | "FSPROFILER", "ANONYMITY_LEVEL", |
570 | &anonymity_level)) | 583 | &anonymity_level)) |
571 | anonymity_level = 1; | 584 | anonymity_level = 1; |
572 | if (GNUNET_OK != | 585 | if (GNUNET_OK != |
573 | GNUNET_CONFIGURATION_get_value_number (cfg, | 586 | GNUNET_CONFIGURATION_get_value_number(cfg, |
574 | "FSPROFILER", "REPLICATION_LEVEL", | 587 | "FSPROFILER", "REPLICATION_LEVEL", |
575 | &replication_level)) | 588 | &replication_level)) |
576 | replication_level = 1; | 589 | replication_level = 1; |
577 | GNUNET_snprintf (myoptname, sizeof (myoptname), | 590 | GNUNET_snprintf(myoptname, sizeof(myoptname), |
578 | "DOWNLOAD-PATTERN-%u", my_peerid); | 591 | "DOWNLOAD-PATTERN-%u", my_peerid); |
579 | if (GNUNET_OK != | 592 | if (GNUNET_OK != |
580 | GNUNET_CONFIGURATION_get_value_string (cfg, | 593 | GNUNET_CONFIGURATION_get_value_string(cfg, |
581 | "FSPROFILER", myoptname, | 594 | "FSPROFILER", myoptname, |
582 | &download_pattern)) | 595 | &download_pattern)) |
583 | download_pattern = GNUNET_strdup (""); | 596 | download_pattern = GNUNET_strdup(""); |
584 | GNUNET_snprintf (myoptname, sizeof (myoptname), | 597 | GNUNET_snprintf(myoptname, sizeof(myoptname), |
585 | "PUBLISH-PATTERN-%u", my_peerid); | 598 | "PUBLISH-PATTERN-%u", my_peerid); |
586 | if (GNUNET_OK != | 599 | if (GNUNET_OK != |
587 | GNUNET_CONFIGURATION_get_value_string (cfg, | 600 | GNUNET_CONFIGURATION_get_value_string(cfg, |
588 | "FSPROFILER", myoptname, | 601 | "FSPROFILER", myoptname, |
589 | &publish_pattern)) | 602 | &publish_pattern)) |
590 | publish_pattern = GNUNET_strdup (""); | 603 | publish_pattern = GNUNET_strdup(""); |
591 | if ( (GNUNET_OK != | 604 | if ((GNUNET_OK != |
592 | parse_pattern (&download_head, | 605 | parse_pattern(&download_head, |
593 | &download_tail, | 606 | &download_tail, |
594 | download_pattern)) || | 607 | download_pattern)) || |
595 | (GNUNET_OK != | 608 | (GNUNET_OK != |
596 | parse_pattern (&publish_head, | 609 | parse_pattern(&publish_head, |
597 | &publish_tail, | 610 | &publish_tail, |
598 | publish_pattern)) ) | 611 | publish_pattern))) |
599 | { | 612 | { |
600 | GNUNET_SCHEDULER_shutdown (); | 613 | GNUNET_SCHEDULER_shutdown(); |
601 | return; | 614 | return; |
602 | } | 615 | } |
603 | 616 | ||
604 | stats_handle = GNUNET_STATISTICS_create ("fsprofiler", cfg); | 617 | stats_handle = GNUNET_STATISTICS_create("fsprofiler", cfg); |
605 | fs_handle = | 618 | fs_handle = |
606 | GNUNET_FS_start (cfg, | 619 | GNUNET_FS_start(cfg, |
607 | "fsprofiler", | 620 | "fsprofiler", |
608 | &progress_cb, NULL, | 621 | &progress_cb, NULL, |
609 | GNUNET_FS_FLAGS_NONE, | 622 | GNUNET_FS_FLAGS_NONE, |
610 | GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, 1, | 623 | GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, 1, |
611 | GNUNET_FS_OPTIONS_REQUEST_PARALLELISM, 1, | 624 | GNUNET_FS_OPTIONS_REQUEST_PARALLELISM, 1, |
612 | GNUNET_FS_OPTIONS_END); | 625 | GNUNET_FS_OPTIONS_END); |
613 | if (NULL == fs_handle) | 626 | if (NULL == fs_handle) |
614 | { | 627 | { |
615 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not acquire FS handle. Exiting.\n"); | 628 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not acquire FS handle. Exiting.\n"); |
616 | global_ret = GNUNET_SYSERR; | 629 | global_ret = GNUNET_SYSERR; |
617 | GNUNET_SCHEDULER_shutdown (); | 630 | GNUNET_SCHEDULER_shutdown(); |
618 | return; | 631 | return; |
619 | } | 632 | } |
620 | for (p = publish_head; NULL != p; p = p->next) | 633 | for (p = publish_head; NULL != p; p = p->next) |
621 | p->task = GNUNET_SCHEDULER_add_delayed (p->delay, | 634 | p->task = GNUNET_SCHEDULER_add_delayed(p->delay, |
622 | &start_publish, p); | 635 | &start_publish, p); |
623 | for (p = download_head; NULL != p; p = p->next) | 636 | for (p = download_head; NULL != p; p = p->next) |
624 | p->task = GNUNET_SCHEDULER_add_delayed (p->delay, | 637 | p->task = GNUNET_SCHEDULER_add_delayed(p->delay, |
625 | &start_download, p); | 638 | &start_download, p); |
626 | } | 639 | } |
627 | 640 | ||
628 | 641 | ||
@@ -634,19 +647,19 @@ run (void *cls, char *const *args GNUNET_UNUSED, | |||
634 | * @return 0 ok, 1 on error | 647 | * @return 0 ok, 1 on error |
635 | */ | 648 | */ |
636 | int | 649 | int |
637 | main (int argc, char *const *argv) | 650 | main(int argc, char *const *argv) |
638 | { | 651 | { |
639 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 652 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
640 | GNUNET_GETOPT_OPTION_END | 653 | GNUNET_GETOPT_OPTION_END |
641 | }; | 654 | }; |
642 | 655 | ||
643 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 656 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) |
644 | return 2; | 657 | return 2; |
645 | return (GNUNET_OK == | 658 | return (GNUNET_OK == |
646 | GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-fsprofiler", | 659 | GNUNET_PROGRAM_run(argc, argv, "gnunet-daemon-fsprofiler", |
647 | gettext_noop | 660 | gettext_noop |
648 | ("Daemon to use file-sharing to measure its performance."), | 661 | ("Daemon to use file-sharing to measure its performance."), |
649 | options, &run, NULL)) ? global_ret : 1; | 662 | options, &run, NULL)) ? global_ret : 1; |
650 | } | 663 | } |
651 | 664 | ||
652 | /* end of gnunet-daemon-fsprofiler.c */ | 665 | /* end of gnunet-daemon-fsprofiler.c */ |