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
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file util/speedup.c
23 * @author Matthias Wachs
24 * @brief functions to speedup peer execution by manipulation system time
27 #include "gnunet_util_lib.h"
30 #define LOG(kind,...) GNUNET_log_from (kind, "util-speedup", __VA_ARGS__)
33 static struct GNUNET_TIME_Relative interval;
35 static struct GNUNET_TIME_Relative delta;
37 static struct GNUNET_SCHEDULER_Task *speedup_task;
41 do_speedup (void *cls)
43 static long long current_offset;
46 current_offset += delta.rel_value_us;
47 GNUNET_TIME_set_offset (current_offset);
48 LOG (GNUNET_ERROR_TYPE_DEBUG,
49 "Speeding up execution time by %s\n",
50 GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_NO));
51 speedup_task = GNUNET_SCHEDULER_add_delayed (interval,
58 * Start task that may speed up our system clock artificially
60 * @param cfg configuration to use
61 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the speedup was not configured
64 GNUNET_SPEEDUP_start_ (const struct GNUNET_CONFIGURATION_Handle *cfg)
66 GNUNET_assert (NULL == speedup_task);
68 GNUNET_CONFIGURATION_get_value_time (cfg,
74 GNUNET_CONFIGURATION_get_value_time (cfg,
80 if ( (0 == interval.rel_value_us) ||
81 (0 == delta.rel_value_us) )
83 LOG (GNUNET_ERROR_TYPE_DEBUG,
84 "Speed up disabled\n");
87 LOG (GNUNET_ERROR_TYPE_DEBUG,
88 "Speed up execution by %s\n",
89 GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_NO));
90 LOG (GNUNET_ERROR_TYPE_DEBUG,
91 "Speed up executed every %s\n",
92 GNUNET_STRINGS_relative_time_to_string (interval, GNUNET_NO));
93 speedup_task = GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO,
101 * Stop tasks that modify clock behavior.
104 GNUNET_SPEEDUP_stop_ ()
106 if (NULL != speedup_task)
108 GNUNET_SCHEDULER_cancel (speedup_task);
111 if ( (0 != interval.rel_value_us) &&
112 (0 != delta.rel_value_us) )
113 LOG (GNUNET_ERROR_TYPE_DEBUG,
114 "Stopped execution speed up\n");
117 /* end of speedup.c */