aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-daemon-fsprofiler.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-12-07 16:37:37 +0000
committerChristian Grothoff <christian@grothoff.org>2012-12-07 16:37:37 +0000
commitb90c571bc3811e034d3319c17b1f4fb2496e2d76 (patch)
tree5f4641fa88c1ed8ff426b02e1682fe1f9fc33562 /src/fs/gnunet-daemon-fsprofiler.c
parent8c8c52dd985d5d7aefc72d9ee84c2d3ec66fc915 (diff)
downloadgnunet-b90c571bc3811e034d3319c17b1f4fb2496e2d76.tar.gz
gnunet-b90c571bc3811e034d3319c17b1f4fb2496e2d76.zip
-more work on FS profiler
Diffstat (limited to 'src/fs/gnunet-daemon-fsprofiler.c')
-rw-r--r--src/fs/gnunet-daemon-fsprofiler.c187
1 files changed, 175 insertions, 12 deletions
diff --git a/src/fs/gnunet-daemon-fsprofiler.c b/src/fs/gnunet-daemon-fsprofiler.c
index e83b3e6f2..49583962d 100644
--- a/src/fs/gnunet-daemon-fsprofiler.c
+++ b/src/fs/gnunet-daemon-fsprofiler.c
@@ -22,6 +22,10 @@
22 * @file fs/gnunet-daemon-fsprofiler.c 22 * @file fs/gnunet-daemon-fsprofiler.c
23 * @brief daemon that publishes and downloads (random) files 23 * @brief daemon that publishes and downloads (random) files
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 *
26 * TODO:
27 * - actually collect performance metrics
28 * - how to signal driver that we're done?
25 */ 29 */
26#include "platform.h" 30#include "platform.h"
27#include "gnunet_fs_service.h" 31#include "gnunet_fs_service.h"
@@ -69,6 +73,11 @@ struct Pattern
69 GNUNET_SCHEDULER_TaskIdentifier task; 73 GNUNET_SCHEDULER_TaskIdentifier task;
70 74
71 /** 75 /**
76 * Secondary task to run the operation.
77 */
78 GNUNET_SCHEDULER_TaskIdentifier stask;
79
80 /**
72 * X-value. 81 * X-value.
73 */ 82 */
74 unsigned long long x; 83 unsigned long long x;
@@ -192,6 +201,23 @@ parse_pattern (struct Pattern **head,
192 201
193 202
194/** 203/**
204 * Create a KSK URI from a number.
205 *
206 * @param kval the number
207 * @return corresponding KSK URI
208 */
209static struct GNUNET_FS_Uri *
210make_keywords (uint64_t kval)
211{
212 char kw[128];
213
214 GNUNET_snprintf (kw, sizeof (kw),
215 "%llu", (unsigned long long) kval);
216 return GNUNET_FS_uri_ksk_create (kw, NULL);
217}
218
219
220/**
195 * Create a file of the given length with a deterministic amount 221 * Create a file of the given length with a deterministic amount
196 * of data to be published under keyword 'kval'. 222 * of data to be published under keyword 'kval'.
197 * 223 *
@@ -209,7 +235,6 @@ make_file (uint64_t length,
209 struct GNUNET_FS_BlockOptions bo; 235 struct GNUNET_FS_BlockOptions bo;
210 char *data; 236 char *data;
211 struct GNUNET_FS_Uri *keywords; 237 struct GNUNET_FS_Uri *keywords;
212 char kw[128];
213 unsigned long long i; 238 unsigned long long i;
214 uint64_t xor; 239 uint64_t xor;
215 240
@@ -228,9 +253,7 @@ make_file (uint64_t length,
228 bo.anonymity_level = (uint32_t) anonymity_level; 253 bo.anonymity_level = (uint32_t) anonymity_level;
229 bo.content_priority = 128; 254 bo.content_priority = 128;
230 bo.replication_level = (uint32_t) replication_level; 255 bo.replication_level = (uint32_t) replication_level;
231 GNUNET_snprintf (kw, sizeof (kw), 256 keywords = make_keywords (kval);
232 "%llu", (unsigned long long) kval);
233 keywords = GNUNET_FS_uri_ksk_create (kw, NULL);
234 fi = GNUNET_FS_file_information_create_from_data (fs_handle, 257 fi = GNUNET_FS_file_information_create_from_data (fs_handle,
235 ctx, 258 ctx,
236 length, 259 length,
@@ -265,6 +288,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
265 { 288 {
266 if (GNUNET_SCHEDULER_NO_TASK != p->task) 289 if (GNUNET_SCHEDULER_NO_TASK != p->task)
267 GNUNET_SCHEDULER_cancel (p->task); 290 GNUNET_SCHEDULER_cancel (p->task);
291 if (GNUNET_SCHEDULER_NO_TASK != p->stask)
292 GNUNET_SCHEDULER_cancel (p->stask);
268 if (NULL != p->ctx) 293 if (NULL != p->ctx)
269 GNUNET_FS_download_stop (p->ctx, GNUNET_YES); 294 GNUNET_FS_download_stop (p->ctx, GNUNET_YES);
270 if (NULL != p->sctx) 295 if (NULL != p->sctx)
@@ -286,6 +311,54 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
286 311
287 312
288/** 313/**
314 * Task run when a publish operation should be stopped.
315 *
316 * @param cls the 'struct Pattern' of the publish operation to stop
317 * @param tc unused
318 */
319static void
320publish_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
321{
322 struct Pattern *p = cls;
323
324 p->task = GNUNET_SCHEDULER_NO_TASK;
325 GNUNET_FS_publish_stop (p->ctx);
326}
327
328
329/**
330 * Task run when a download operation should be stopped.
331 *
332 * @param cls the 'struct Pattern' of the download operation to stop
333 * @param tc unused
334 */
335static void
336download_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
337{
338 struct Pattern *p = cls;
339
340 p->task = GNUNET_SCHEDULER_NO_TASK;
341 GNUNET_FS_download_stop (p->ctx, GNUNET_YES);
342}
343
344
345/**
346 * Task run when a download operation should be stopped.
347 *
348 * @param cls the 'struct Pattern' of the download operation to stop
349 * @param tc unused
350 */
351static void
352search_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
353{
354 struct Pattern *p = cls;
355
356 p->stask = GNUNET_SCHEDULER_NO_TASK;
357 GNUNET_FS_search_stop (p->sctx);
358}
359
360
361/**
289 * Notification of FS to a client about the progress of an 362 * Notification of FS to a client about the progress of an
290 * operation. Callbacks of this type will be used for uploads, 363 * operation. Callbacks of this type will be used for uploads,
291 * downloads and searches. Some of the arguments depend a bit 364 * downloads and searches. Some of the arguments depend a bit
@@ -304,13 +377,98 @@ static void *
304progress_cb (void *cls, 377progress_cb (void *cls,
305 const struct GNUNET_FS_ProgressInfo *info) 378 const struct GNUNET_FS_ProgressInfo *info)
306{ 379{
307 // FIXME: 380 struct Pattern *p;
308 // - search result => start download 381 const struct GNUNET_FS_Uri *uri;
309 // - publishing done => staitstic, terminate 'struct Pattern' 382
310 // - download done => statistic, terminate 'struct Pattern' 383 switch (info->status)
311 // => all patterns done => then what!? (how do we tell the 384 {
312 // drive that we are done!?) 385 case GNUNET_FS_STATUS_PUBLISH_START:
313 return NULL; 386 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
387 p = info->value.publish.cctx;
388 return p;
389 case GNUNET_FS_STATUS_PUBLISH_ERROR:
390 // FIXME: statistics...
391 p = info->value.publish.cctx;
392 p->task = GNUNET_SCHEDULER_add_now (&publish_stop_task, p);
393 return p;
394 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
395 // FIXME: statistics...
396 p = info->value.publish.cctx;
397 p->task = GNUNET_SCHEDULER_add_now (&publish_stop_task, p);
398 return p;
399 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
400 p = info->value.publish.cctx;
401 p->ctx = NULL;
402 GNUNET_CONTAINER_DLL_remove (publish_head, publish_tail, p);
403 GNUNET_free (p);
404 return NULL;
405 case GNUNET_FS_STATUS_DOWNLOAD_START:
406 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
407 case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
408 case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
409 p = info->value.download.cctx;
410 return p;
411 case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
412 // FIXME: statistics
413 p = info->value.download.cctx;
414 p->task = GNUNET_SCHEDULER_add_now (&download_stop_task, p);
415 return p;
416 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
417 // FIXME: statistics
418 p = info->value.download.cctx;
419 p->task = GNUNET_SCHEDULER_add_now (&download_stop_task, p);
420 return p;
421 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
422 p = info->value.download.cctx;
423 p->ctx = NULL;
424 if (NULL == p->sctx)
425 {
426 GNUNET_CONTAINER_DLL_remove (download_head, download_tail, p);
427 GNUNET_free (p);
428 }
429 return NULL;
430 case GNUNET_FS_STATUS_SEARCH_START:
431 case GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE:
432 p = info->value.search.cctx;
433 return p;
434 case GNUNET_FS_STATUS_SEARCH_RESULT:
435 p = info->value.search.cctx;
436 uri = info->value.search.specifics.result.uri;
437 if (GNUNET_YES != GNUNET_FS_uri_test_chk (uri))
438 return NULL; /* not what we want */
439 if (p->y != GNUNET_FS_uri_chk_get_file_size (uri))
440 return NULL; /* not what we want */
441 p->ctx = GNUNET_FS_download_start (fs_handle, uri,
442 NULL, NULL, NULL,
443 0, GNUNET_FS_uri_chk_get_file_size (uri),
444 anonymity_level,
445 GNUNET_FS_DOWNLOAD_NO_TEMPORARIES,
446 p,
447 NULL);
448 p->stask = GNUNET_SCHEDULER_add_now (&search_stop_task, p);
449 return NULL;
450 case GNUNET_FS_STATUS_SEARCH_UPDATE:
451 case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED:
452 return NULL; /* don't care */
453 case GNUNET_FS_STATUS_SEARCH_ERROR:
454 // FIXME: statistics
455 p = info->value.search.cctx;
456 p->stask = GNUNET_SCHEDULER_add_now (&search_stop_task, p);
457 return p;
458 case GNUNET_FS_STATUS_SEARCH_STOPPED:
459 p = info->value.search.cctx;
460 p->sctx = NULL;
461 if (NULL == p->ctx)
462 {
463 GNUNET_CONTAINER_DLL_remove (download_head, download_tail, p);
464 GNUNET_free (p);
465 }
466 return NULL;
467 default:
468 /* unexpected event during profiling */
469 GNUNET_break (0);
470 return NULL;
471 }
314} 472}
315 473
316 474
@@ -349,11 +507,16 @@ start_download (void *cls,
349 const struct GNUNET_SCHEDULER_TaskContext *tc) 507 const struct GNUNET_SCHEDULER_TaskContext *tc)
350{ 508{
351 struct Pattern *p = cls; 509 struct Pattern *p = cls;
510 struct GNUNET_FS_Uri *keywords;
352 511
353 p->task = GNUNET_SCHEDULER_NO_TASK; 512 p->task = GNUNET_SCHEDULER_NO_TASK;
354 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 513 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
355 return; 514 return;
356 // FIXME: start search operation 515 keywords = make_keywords (p->x);
516 p->sctx = GNUNET_FS_search_start (fs_handle, keywords,
517 anonymity_level,
518 GNUNET_FS_SEARCH_OPTION_NONE,
519 p);
357} 520}
358 521
359 522