/*
This file is part of GNUnet.
- (C) 2012 Christian Grothoff
+ Copyright (C) 2012 Christian Grothoff
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
/**
* @author Christian Grothoff
*
* TODO:
- * - actually collect performance metrics
* - how to signal driver that we're done?
*/
#include "platform.h"
/**
* Task to run the operation.
*/
- GNUNET_SCHEDULER_TaskIdentifier task;
+ struct GNUNET_SCHEDULER_Task * task;
/**
* Secondary task to run the operation.
*/
- GNUNET_SCHEDULER_TaskIdentifier stask;
+ struct GNUNET_SCHEDULER_Task * stask;
/**
* X-value.
/**
- * Parse a pattern string and store the corresponding
+ * Parse a pattern string and store the corresponding
* 'struct Pattern' in the given head/tail.
*
* @param head where to store the head
"(%llu,%llu,%llu)",
&x, &y, &t))
{
- p = GNUNET_malloc (sizeof (struct Pattern));
+ p = GNUNET_new (struct Pattern);
p->x = x;
p->y = y;
- p->delay.rel_value = (uint64_t) t;
+ p->delay.rel_value_us = (uint64_t) t;
GNUNET_CONTAINER_DLL_insert (*head, *tail, p);
pattern = strstr (pattern, ")");
GNUNET_assert (NULL != pattern);
return NULL;
/* initialize data with 'unique' data only depending on 'kval' and 'size',
making sure that blocks do not repeat */
- for (i=0;i<length; i+=8)
+ for (i=0;i<length; i+=8)
{
xor = length ^ kval ^ (uint64_t) (i / 32 / 1024);
- memcpy (&data[i], &xor, GNUNET_MIN (length - i, sizeof (uint64_t)));
+ GNUNET_memcpy (&data[i], &xor, GNUNET_MIN (length - i, sizeof (uint64_t)));
}
bo.expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_DAYS);
bo.anonymity_level = (uint32_t) anonymity_level;
* Task run during shutdown.
*
* @param cls unused
- * @param tc unused
*/
static void
-shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls)
{
struct Pattern *p;
while (NULL != (p = publish_head))
{
- if (GNUNET_SCHEDULER_NO_TASK != p->task)
+ if (NULL != p->task)
GNUNET_SCHEDULER_cancel (p->task);
if (NULL != p->ctx)
GNUNET_FS_publish_stop (p->ctx);
}
while (NULL != (p = download_head))
{
- if (GNUNET_SCHEDULER_NO_TASK != p->task)
+ if (NULL != p->task)
GNUNET_SCHEDULER_cancel (p->task);
- if (GNUNET_SCHEDULER_NO_TASK != p->stask)
+ if (NULL != p->stask)
GNUNET_SCHEDULER_cancel (p->stask);
if (NULL != p->ctx)
GNUNET_FS_download_stop (p->ctx, GNUNET_YES);
* Task run when a publish operation should be stopped.
*
* @param cls the 'struct Pattern' of the publish operation to stop
- * @param tc unused
*/
static void
-publish_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+publish_stop_task (void *cls)
{
struct Pattern *p = cls;
- p->task = GNUNET_SCHEDULER_NO_TASK;
+ p->task = NULL;
GNUNET_FS_publish_stop (p->ctx);
}
* Task run when a download operation should be stopped.
*
* @param cls the 'struct Pattern' of the download operation to stop
- * @param tc unused
*/
static void
-download_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+download_stop_task (void *cls)
{
struct Pattern *p = cls;
- p->task = GNUNET_SCHEDULER_NO_TASK;
+ p->task = NULL;
GNUNET_FS_download_stop (p->ctx, GNUNET_YES);
}
* Task run when a download operation should be stopped.
*
* @param cls the 'struct Pattern' of the download operation to stop
- * @param tc unused
*/
static void
-search_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+search_stop_task (void *cls)
{
struct Pattern *p = cls;
- p->stask = GNUNET_SCHEDULER_NO_TASK;
+ p->stask = NULL;
GNUNET_FS_search_stop (p->sctx);
}
case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
p = info->value.publish.cctx;
return p;
+ case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY:
+ p = info->value.publish.cctx;
+ return p;
case GNUNET_FS_STATUS_PUBLISH_ERROR:
- // FIXME: statistics...
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Publishing failed\n");
+ GNUNET_STATISTICS_update (stats_handle,
+ "# failed publish operations", 1, GNUNET_NO);
p = info->value.publish.cctx;
p->task = GNUNET_SCHEDULER_add_now (&publish_stop_task, p);
return p;
case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
- // FIXME: statistics...
p = info->value.publish.cctx;
+ GNUNET_STATISTICS_update (stats_handle,
+ "# publishing time (ms)",
+ (long long) GNUNET_TIME_absolute_get_duration (p->start_time).rel_value_us / 1000LL,
+ GNUNET_NO);
p->task = GNUNET_SCHEDULER_add_now (&publish_stop_task, p);
return p;
case GNUNET_FS_STATUS_PUBLISH_STOPPED:
p = info->value.download.cctx;
return p;
case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
- // FIXME: statistics
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Download failed\n");
+ GNUNET_STATISTICS_update (stats_handle,
+ "# failed downloads", 1, GNUNET_NO);
p = info->value.download.cctx;
p->task = GNUNET_SCHEDULER_add_now (&download_stop_task, p);
return p;
case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
- // FIXME: statistics
p = info->value.download.cctx;
+ GNUNET_STATISTICS_update (stats_handle,
+ "# download time (ms)",
+ (long long) GNUNET_TIME_absolute_get_duration (p->start_time).rel_value_us / 1000LL,
+ GNUNET_NO);
p->task = GNUNET_SCHEDULER_add_now (&download_stop_task, p);
return p;
case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
return NULL; /* not what we want */
if (p->y != GNUNET_FS_uri_chk_get_file_size (uri))
return NULL; /* not what we want */
+ GNUNET_STATISTICS_update (stats_handle,
+ "# search time (ms)",
+ (long long) GNUNET_TIME_absolute_get_duration (p->start_time).rel_value_us / 1000LL,
+ GNUNET_NO);
+ p->start_time = GNUNET_TIME_absolute_get ();
p->ctx = GNUNET_FS_download_start (fs_handle, uri,
- NULL, NULL, NULL,
+ NULL, NULL, NULL,
0, GNUNET_FS_uri_chk_get_file_size (uri),
anonymity_level,
GNUNET_FS_DOWNLOAD_NO_TEMPORARIES,
case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED:
return NULL; /* don't care */
case GNUNET_FS_STATUS_SEARCH_ERROR:
- // FIXME: statistics
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Search failed\n");
+ GNUNET_STATISTICS_update (stats_handle,
+ "# failed searches", 1, GNUNET_NO);
p = info->value.search.cctx;
p->stask = GNUNET_SCHEDULER_add_now (&search_stop_task, p);
return p;
GNUNET_free (p);
}
return NULL;
- default:
+ default:
/* unexpected event during profiling */
GNUNET_break (0);
return NULL;
* Start publish operation.
*
* @param cls the 'struct Pattern' specifying the operation to perform
- * @param tc scheduler context
*/
-static void
-start_publish (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+static void
+start_publish (void *cls)
{
struct Pattern *p = cls;
struct GNUNET_FS_FileInformation *fi;
- p->task = GNUNET_SCHEDULER_NO_TASK;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
+ p->task = NULL;
fi = make_file (p->x, p->y, p);
+ p->start_time = GNUNET_TIME_absolute_get ();
p->ctx = GNUNET_FS_publish_start (fs_handle,
fi,
NULL, NULL, NULL,
* Start download operation.
*
* @param cls the 'struct Pattern' specifying the operation to perform
- * @param tc scheduler context
*/
-static void
-start_download (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+static void
+start_download (void *cls)
{
struct Pattern *p = cls;
struct GNUNET_FS_Uri *keywords;
- p->task = GNUNET_SCHEDULER_NO_TASK;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
+ p->task = NULL;
keywords = make_keywords (p->x);
+ p->start_time = GNUNET_TIME_absolute_get ();
p->sctx = GNUNET_FS_search_start (fs_handle, keywords,
anonymity_level,
GNUNET_FS_SEARCH_OPTION_NONE,
cfg = cfg_;
/* Scheduled the task to clean up when shutdown is called */
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
+ GNUNET_CONFIGURATION_get_value_number (cfg,
"TESTBED", "PEERID",
&my_peerid))
{
return;
}
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
+ GNUNET_CONFIGURATION_get_value_number (cfg,
"FSPROFILER", "ANONYMITY_LEVEL",
&anonymity_level))
anonymity_level = 1;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
+ GNUNET_CONFIGURATION_get_value_number (cfg,
"FSPROFILER", "REPLICATION_LEVEL",
- &replication_level))
+ &replication_level))
replication_level = 1;
GNUNET_snprintf (myoptname, sizeof (myoptname),
"DOWNLOAD-PATTERN-%u", my_peerid);
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
+ GNUNET_CONFIGURATION_get_value_string (cfg,
"FSPROFILER", myoptname,
- &download_pattern))
+ &download_pattern))
download_pattern = GNUNET_strdup ("");
GNUNET_snprintf (myoptname, sizeof (myoptname),
"PUBLISH-PATTERN-%u", my_peerid);
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
+ GNUNET_CONFIGURATION_get_value_string (cfg,
"FSPROFILER", myoptname,
- &publish_pattern))
+ &publish_pattern))
publish_pattern = GNUNET_strdup ("");
if ( (GNUNET_OK !=
parse_pattern (&download_head,