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