clockskew code
authorNathan S. Evans <evans@in.tum.de>
Mon, 25 Jul 2011 12:36:16 +0000 (12:36 +0000)
committerNathan S. Evans <evans@in.tum.de>
Mon, 25 Jul 2011 12:36:16 +0000 (12:36 +0000)
src/util/program.c
src/util/server.c
src/util/service.c
src/util/time.c

index c5fe0b5737a2268aac87dd9297f4c5163e894710..d98b388c12c3577e517e13a92bdf3b7ac610a655 100644 (file)
@@ -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);
index 5b9361cfcf2aa99b302d8567f0c5ba7b92d80f08..6e2dc32cf20fdb0420c7fdd1f5e370f8848e99ed 100644 (file)
@@ -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;
 }
index 227593b849c4509c7209f88f409271da3e429169..abf3b2ab15c48d9cb6cb5d4c4363311df6e28c99 100644 (file)
@@ -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);
 
index 10e1e6ffa853b462a88a3e100d2a033a3f8372ff..5ae05b0d7d80d38e8399a5a571b62da10c58696d 100644 (file)
 #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;
 }