diff options
author | Nathan S. Evans <evans@in.tum.de> | 2011-07-25 12:36:16 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2011-07-25 12:36:16 +0000 |
commit | 70a2b635b7107f7554e9ae5c4f3262ee6eaacb83 (patch) | |
tree | 6773092c3053281f383ec6555e8757bf9387d515 /src | |
parent | 00b0f3c22aab316068326a26f89219eddc7f6ef9 (diff) | |
download | gnunet-70a2b635b7107f7554e9ae5c4f3262ee6eaacb83.tar.gz gnunet-70a2b635b7107f7554e9ae5c4f3262ee6eaacb83.zip |
clockskew code
Diffstat (limited to 'src')
-rw-r--r-- | src/util/program.c | 9 | ||||
-rw-r--r-- | src/util/server.c | 4 | ||||
-rw-r--r-- | src/util/service.c | 11 | ||||
-rw-r--r-- | src/util/time.c | 14 |
4 files changed, 34 insertions, 4 deletions
diff --git a/src/util/program.c b/src/util/program.c index c5fe0b573..d98b388c1 100644 --- a/src/util/program.c +++ b/src/util/program.c | |||
@@ -134,6 +134,9 @@ GNUNET_PROGRAM_run (int argc, | |||
134 | char *logfile; | 134 | char *logfile; |
135 | int ret; | 135 | int ret; |
136 | unsigned int cnt; | 136 | unsigned int cnt; |
137 | unsigned long long skew_offset; | ||
138 | unsigned long long skew_variance; | ||
139 | long long clock_offset; | ||
137 | struct GNUNET_CONFIGURATION_Handle *cfg; | 140 | struct GNUNET_CONFIGURATION_Handle *cfg; |
138 | struct GNUNET_GETOPT_CommandLineOption defoptions[] = { | 141 | struct GNUNET_GETOPT_CommandLineOption defoptions[] = { |
139 | GNUNET_GETOPT_OPTION_CFG_FILE (&cc.cfgfile), | 142 | GNUNET_GETOPT_OPTION_CFG_FILE (&cc.cfgfile), |
@@ -229,7 +232,11 @@ GNUNET_PROGRAM_run (int argc, | |||
229 | } | 232 | } |
230 | GNUNET_free (allopts); | 233 | GNUNET_free (allopts); |
231 | GNUNET_free (lpfx); | 234 | GNUNET_free (lpfx); |
232 | 235 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cc.cfg, "testing", "skew_offset", &skew_offset) && | |
236 | (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cc.cfg, "testing", "skew_variance", &skew_variance))) | ||
237 | { | ||
238 | clock_offset = skew_offset - skew_variance; | ||
239 | } | ||
233 | /* run */ | 240 | /* run */ |
234 | cc.args = &argv[ret]; | 241 | cc.args = &argv[ret]; |
235 | GNUNET_SCHEDULER_run (&program_main, &cc); | 242 | GNUNET_SCHEDULER_run (&program_main, &cc); |
diff --git a/src/util/server.c b/src/util/server.c index 5b9361cfc..6e2dc32cf 100644 --- a/src/util/server.c +++ b/src/util/server.c | |||
@@ -1014,8 +1014,8 @@ GNUNET_SERVER_connect_socket (struct | |||
1014 | * @param timeout new timeout for activities on the socket | 1014 | * @param timeout new timeout for activities on the socket |
1015 | */ | 1015 | */ |
1016 | void | 1016 | void |
1017 | GNUNET_SERVER_client_set_timeout (struct GNUNET_SERVER_Client *client, | 1017 | GNUNET_SERVER_client_set_timeout(struct GNUNET_SERVER_Client *client, |
1018 | struct GNUNET_TIME_Relative timeout) | 1018 | struct GNUNET_TIME_Relative timeout) |
1019 | { | 1019 | { |
1020 | client->idle_timeout = timeout; | 1020 | client->idle_timeout = timeout; |
1021 | } | 1021 | } |
diff --git a/src/util/service.c b/src/util/service.c index 227593b84..abf3b2ab1 100644 --- a/src/util/service.c +++ b/src/util/service.c | |||
@@ -1577,6 +1577,9 @@ GNUNET_SERVICE_run (int argc, | |||
1577 | char *logfile; | 1577 | char *logfile; |
1578 | int do_daemonize; | 1578 | int do_daemonize; |
1579 | unsigned int i; | 1579 | unsigned int i; |
1580 | unsigned long long skew_offset; | ||
1581 | unsigned long long skew_variance; | ||
1582 | long long clock_offset; | ||
1580 | struct GNUNET_SERVICE_Context sctx; | 1583 | struct GNUNET_SERVICE_Context sctx; |
1581 | struct GNUNET_CONFIGURATION_Handle *cfg; | 1584 | struct GNUNET_CONFIGURATION_Handle *cfg; |
1582 | struct GNUNET_GETOPT_CommandLineOption service_options[] = { | 1585 | struct GNUNET_GETOPT_CommandLineOption service_options[] = { |
@@ -1623,6 +1626,14 @@ GNUNET_SERVICE_run (int argc, | |||
1623 | "Service `%s' runs with configuration from `%s'\n", | 1626 | "Service `%s' runs with configuration from `%s'\n", |
1624 | serviceName, cfg_fn); | 1627 | serviceName, cfg_fn); |
1625 | #endif | 1628 | #endif |
1629 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(sctx.cfg, "testing", "skew_offset", &skew_offset) && | ||
1630 | (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(sctx.cfg, "testing", "skew_variance", &skew_variance))) | ||
1631 | { | ||
1632 | clock_offset = skew_offset - skew_variance; | ||
1633 | #if 1 | ||
1634 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Skewing clock by %ll\n", clock_offset); | ||
1635 | #endif | ||
1636 | } | ||
1626 | /* actually run service */ | 1637 | /* actually run service */ |
1627 | GNUNET_SCHEDULER_run (&service_task, &sctx); | 1638 | GNUNET_SCHEDULER_run (&service_task, &sctx); |
1628 | 1639 | ||
diff --git a/src/util/time.c b/src/util/time.c index 10e1e6ffa..5ae05b0d7 100644 --- a/src/util/time.c +++ b/src/util/time.c | |||
@@ -26,6 +26,18 @@ | |||
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_time_lib.h" | 27 | #include "gnunet_time_lib.h" |
28 | 28 | ||
29 | static long long timestamp_offset; | ||
30 | |||
31 | /** | ||
32 | * Set the timestamp offset for this instance. | ||
33 | * | ||
34 | * @param offset the offset to skew the locale time by | ||
35 | */ | ||
36 | void | ||
37 | GNUNET_TIME_set_offset(long long offset) | ||
38 | { | ||
39 | timestamp_offset = offset; | ||
40 | } | ||
29 | 41 | ||
30 | /** | 42 | /** |
31 | * Get the current time (works just as "time", just that we use the | 43 | * Get the current time (works just as "time", just that we use the |
@@ -42,7 +54,7 @@ GNUNET_TIME_absolute_get () | |||
42 | GETTIMEOFDAY (&tv, NULL); | 54 | GETTIMEOFDAY (&tv, NULL); |
43 | ret.abs_value = | 55 | ret.abs_value = |
44 | (uint64_t) (((uint64_t) tv.tv_sec * 1000LL) + | 56 | (uint64_t) (((uint64_t) tv.tv_sec * 1000LL) + |
45 | ((uint64_t) tv.tv_usec / 1000LL)); | 57 | ((uint64_t) tv.tv_usec / 1000LL)) + timestamp_offset; |
46 | return ret; | 58 | return ret; |
47 | } | 59 | } |
48 | 60 | ||