aboutsummaryrefslogtreecommitdiff
path: root/src/lib/util/speedup.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/util/speedup.c')
-rw-r--r--src/lib/util/speedup.c114
1 files changed, 114 insertions, 0 deletions
diff --git a/src/lib/util/speedup.c b/src/lib/util/speedup.c
new file mode 100644
index 000000000..02719e56e
--- /dev/null
+++ b/src/lib/util/speedup.c
@@ -0,0 +1,114 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2011-2013 GNUnet e.V.
4
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.
9
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.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file util/speedup.c
23 * @author Matthias Wachs
24 * @brief functions to speedup peer execution by manipulation system time
25 */
26
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include "speedup.h"
30
31#define LOG(kind, ...) GNUNET_log_from (kind, "util-speedup", __VA_ARGS__)
32
33
34static struct GNUNET_TIME_Relative interval;
35
36static struct GNUNET_TIME_Relative delta;
37
38static struct GNUNET_SCHEDULER_Task *speedup_task;
39
40
41static void
42do_speedup (void *cls)
43{
44 static long long current_offset;
45
46 (void) cls;
47 speedup_task = NULL;
48 current_offset += delta.rel_value_us;
49 GNUNET_TIME_set_offset (current_offset);
50 LOG (GNUNET_ERROR_TYPE_DEBUG,
51 "Speeding up execution time by %s\n",
52 GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_NO));
53 speedup_task = GNUNET_SCHEDULER_add_delayed (interval,
54 &do_speedup,
55 NULL);
56}
57
58
59int
60GNUNET_SPEEDUP_start_ (const struct GNUNET_CONFIGURATION_Handle *cfg)
61{
62 GNUNET_assert (NULL == speedup_task);
63 if (GNUNET_OK !=
64 GNUNET_CONFIGURATION_get_value_time (cfg,
65 "testing",
66 "SPEEDUP_INTERVAL",
67 &interval))
68 return GNUNET_SYSERR;
69 if (GNUNET_OK !=
70 GNUNET_CONFIGURATION_get_value_time (cfg,
71 "testing",
72 "SPEEDUP_DELTA",
73 &delta))
74 return GNUNET_SYSERR;
75
76 if ((0 == interval.rel_value_us) ||
77 (0 == delta.rel_value_us))
78 {
79 LOG (GNUNET_ERROR_TYPE_DEBUG,
80 "Speed up disabled\n");
81 return GNUNET_OK;
82 }
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,
90 &do_speedup,
91 NULL);
92 return GNUNET_OK;
93}
94
95
96/**
97 * Stop tasks that modify clock behavior.
98 */
99void
100GNUNET_SPEEDUP_stop_ ()
101{
102 if (NULL != speedup_task)
103 {
104 GNUNET_SCHEDULER_cancel (speedup_task);
105 speedup_task = NULL;
106 }
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");
111}
112
113
114/* end of speedup.c */