From: Nathan S. Evans Date: Mon, 25 Jul 2011 12:36:16 +0000 (+0000) Subject: clockskew code X-Git-Tag: initial-import-from-subversion-38251~17675 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=70a2b635b7107f7554e9ae5c4f3262ee6eaacb83;p=oweals%2Fgnunet.git clockskew code --- 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, char *logfile; int ret; unsigned int cnt; + unsigned long long skew_offset; + unsigned long long skew_variance; + long long clock_offset; struct GNUNET_CONFIGURATION_Handle *cfg; struct GNUNET_GETOPT_CommandLineOption defoptions[] = { GNUNET_GETOPT_OPTION_CFG_FILE (&cc.cfgfile), @@ -229,7 +232,11 @@ GNUNET_PROGRAM_run (int argc, } GNUNET_free (allopts); GNUNET_free (lpfx); - + if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cc.cfg, "testing", "skew_offset", &skew_offset) && + (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cc.cfg, "testing", "skew_variance", &skew_variance))) + { + clock_offset = skew_offset - skew_variance; + } /* run */ cc.args = &argv[ret]; 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 * @param timeout new timeout for activities on the socket */ void -GNUNET_SERVER_client_set_timeout (struct GNUNET_SERVER_Client *client, - struct GNUNET_TIME_Relative timeout) +GNUNET_SERVER_client_set_timeout(struct GNUNET_SERVER_Client *client, + struct GNUNET_TIME_Relative timeout) { client->idle_timeout = timeout; } 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, char *logfile; int do_daemonize; unsigned int i; + unsigned long long skew_offset; + unsigned long long skew_variance; + long long clock_offset; struct GNUNET_SERVICE_Context sctx; struct GNUNET_CONFIGURATION_Handle *cfg; struct GNUNET_GETOPT_CommandLineOption service_options[] = { @@ -1623,6 +1626,14 @@ GNUNET_SERVICE_run (int argc, "Service `%s' runs with configuration from `%s'\n", serviceName, cfg_fn); #endif + if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(sctx.cfg, "testing", "skew_offset", &skew_offset) && + (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(sctx.cfg, "testing", "skew_variance", &skew_variance))) + { + clock_offset = skew_offset - skew_variance; +#if 1 + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Skewing clock by %ll\n", clock_offset); +#endif + } /* actually run service */ GNUNET_SCHEDULER_run (&service_task, &sctx); 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 @@ #include "platform.h" #include "gnunet_time_lib.h" +static long long timestamp_offset; + +/** + * Set the timestamp offset for this instance. + * + * @param offset the offset to skew the locale time by + */ +void +GNUNET_TIME_set_offset(long long offset) +{ + timestamp_offset = offset; +} /** * Get the current time (works just as "time", just that we use the @@ -42,7 +54,7 @@ GNUNET_TIME_absolute_get () GETTIMEOFDAY (&tv, NULL); ret.abs_value = (uint64_t) (((uint64_t) tv.tv_sec * 1000LL) + - ((uint64_t) tv.tv_usec / 1000LL)); + ((uint64_t) tv.tv_usec / 1000LL)) + timestamp_offset; return ret; }