2 This file is part of GNUnet.
3 Copyright (C) 2011-2013 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
17 * @file util/speedup.c
18 * @author Matthias Wachs
19 * @brief functions to speedup peer execution by manipulation system time
22 #include "gnunet_util_lib.h"
25 #define LOG(kind,...) GNUNET_log_from (kind, "util-speedup", __VA_ARGS__)
28 static struct GNUNET_TIME_Relative interval;
30 static struct GNUNET_TIME_Relative delta;
32 static struct GNUNET_SCHEDULER_Task *speedup_task;
36 do_speedup (void *cls)
38 static long long current_offset;
42 current_offset += delta.rel_value_us;
43 GNUNET_TIME_set_offset (current_offset);
44 LOG (GNUNET_ERROR_TYPE_DEBUG,
45 "Speeding up execution time by %s\n",
46 GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_NO));
47 speedup_task = GNUNET_SCHEDULER_add_delayed (interval,
54 * Start task that may speed up our system clock artificially
56 * @param cfg configuration to use
57 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the speedup was not configured
60 GNUNET_SPEEDUP_start_ (const struct GNUNET_CONFIGURATION_Handle *cfg)
62 GNUNET_assert (NULL == speedup_task);
64 GNUNET_CONFIGURATION_get_value_time (cfg,
70 GNUNET_CONFIGURATION_get_value_time (cfg,
76 if ( (0 == interval.rel_value_us) ||
77 (0 == delta.rel_value_us) )
79 LOG (GNUNET_ERROR_TYPE_DEBUG,
80 "Speed up disabled\n");
83 LOG (GNUNET_ERROR_TYPE_DEBUG,
84 "Speed up execution by %s\n",
85 GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_NO));
86 LOG (GNUNET_ERROR_TYPE_DEBUG,
87 "Speed up executed every %s\n",
88 GNUNET_STRINGS_relative_time_to_string (interval, GNUNET_NO));
89 speedup_task = GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO,
97 * Stop tasks that modify clock behavior.
100 GNUNET_SPEEDUP_stop_ ()
102 if (NULL != speedup_task)
104 GNUNET_SCHEDULER_cancel (speedup_task);
107 if ( (0 != interval.rel_value_us) &&
108 (0 != delta.rel_value_us) )
109 LOG (GNUNET_ERROR_TYPE_DEBUG,
110 "Stopped execution speed up\n");
113 /* end of speedup.c */