GNUnet  0.11.x
time.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2001-2013, 2018 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 
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #if __STDC_NO_ATOMICS__
29 #define ATOMIC
30 #else
31 #ifdef HAVE_STDATOMIC_H
32 #include <stdatomic.h>
33 #define ATOMIC _Atomic
34 #else
35 #define __STDC_NO_ATOMICS__ 1
36 #define ATOMIC
37 #endif
38 #endif
39 
40 #define LOG(kind, ...) GNUNET_log_from (kind, "util-time", __VA_ARGS__)
41 
45 static long long timestamp_offset;
46 
47 void
48 GNUNET_TIME_set_offset (long long offset)
49 {
50  timestamp_offset = offset;
51 }
52 
53 
54 long long
56 {
57  return timestamp_offset;
58 }
59 
60 
61 int
63 {
64  if (at->abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us)
65  return GNUNET_OK;
66  if (0 == at->abs_value_us % 1000000)
67  return GNUNET_OK;
68  at->abs_value_us -= at->abs_value_us % 1000000;
69  return GNUNET_NO;
70 }
71 
72 
73 int
75 {
76  if (rt->rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
77  return GNUNET_OK;
78  if (0 == rt->rel_value_us % 1000000)
79  return GNUNET_OK;
80  rt->rel_value_us -= rt->rel_value_us % 1000000;
81  return GNUNET_NO;
82 }
83 
84 
87 {
88  struct GNUNET_TIME_Absolute ret;
89  struct timeval tv;
90 
91  gettimeofday (&tv, NULL);
92  ret.abs_value_us = (uint64_t) (((uint64_t) tv.tv_sec * 1000LL * 1000LL)
93  + ((uint64_t) tv.tv_usec))
95  return ret;
96 }
97 
98 
101 {
102  static struct GNUNET_TIME_Relative zero;
103 
104  return zero;
105 }
106 
107 
110 {
111  static struct GNUNET_TIME_Absolute zero;
112 
113  return zero;
114 }
115 
116 
119 {
120  static struct GNUNET_TIME_Relative one = { 1 };
121 
122  return one;
123 }
124 
125 
128 {
129  static struct GNUNET_TIME_Relative one = { 1000 };
130 
131  return one;
132 }
133 
134 
137 {
138  static struct GNUNET_TIME_Relative one = { 1000 * 1000LL };
139 
140  return one;
141 }
142 
143 
146 {
147  static struct GNUNET_TIME_Relative one = { 60 * 1000 * 1000LL };
148 
149  return one;
150 }
151 
152 
155 {
156  static struct GNUNET_TIME_Relative one = { 60 * 60 * 1000 * 1000LL };
157 
158  return one;
159 }
160 
161 
164 {
165  static struct GNUNET_TIME_Relative forever = { UINT64_MAX };
166 
167  return forever;
168 }
169 
170 
173 {
174  static struct GNUNET_TIME_Absolute forever = { UINT64_MAX };
175 
176  return forever;
177 }
178 
179 
182 {
183  struct GNUNET_TIME_Absolute ret;
184 
185  if (rel.rel_value_us == UINT64_MAX)
188 
189  if (rel.rel_value_us + now.abs_value_us < rel.rel_value_us)
190  {
191  GNUNET_break (0); /* overflow... */
193  }
194  ret.abs_value_us = rel.rel_value_us + now.abs_value_us;
195  return ret;
196 }
197 
198 
201  struct GNUNET_TIME_Relative t2)
202 {
203  return (t1.rel_value_us < t2.rel_value_us) ? t1 : t2;
204 }
205 
206 
209  struct GNUNET_TIME_Relative t2)
210 {
211  return (t1.rel_value_us > t2.rel_value_us) ? t1 : t2;
212 }
213 
214 
217  struct GNUNET_TIME_Absolute t2)
218 {
219  return (t1.abs_value_us < t2.abs_value_us) ? t1 : t2;
220 }
221 
222 
225  struct GNUNET_TIME_Absolute t2)
226 {
227  return (t1.abs_value_us > t2.abs_value_us) ? t1 : t2;
228 }
229 
230 
233 {
234  struct GNUNET_TIME_Relative ret;
235 
236  if (future.abs_value_us == UINT64_MAX)
239 
240  if (now.abs_value_us > future.abs_value_us)
241  return GNUNET_TIME_UNIT_ZERO;
242  ret.rel_value_us = future.abs_value_us - now.abs_value_us;
243  return ret;
244 }
245 
246 
249  struct GNUNET_TIME_Absolute end)
250 {
251  struct GNUNET_TIME_Relative ret;
252 
253  if (end.abs_value_us == UINT64_MAX)
255  if (end.abs_value_us < start.abs_value_us)
256  return GNUNET_TIME_UNIT_ZERO;
257  ret.rel_value_us = end.abs_value_us - start.abs_value_us;
258  return ret;
259 }
260 
261 
264 {
265  struct GNUNET_TIME_Absolute now;
266  struct GNUNET_TIME_Relative ret;
267 
268  now = GNUNET_TIME_absolute_get ();
269  if (whence.abs_value_us > now.abs_value_us)
270  return GNUNET_TIME_UNIT_ZERO;
271  ret.rel_value_us = now.abs_value_us - whence.abs_value_us;
272  return ret;
273 }
274 
275 
279 {
280  struct GNUNET_TIME_Absolute ret;
281 
282  if ((start.abs_value_us == UINT64_MAX) ||
283  (duration.rel_value_us == UINT64_MAX))
285  if (start.abs_value_us + duration.rel_value_us < start.abs_value_us)
286  {
287  GNUNET_break (0);
289  }
290  ret.abs_value_us = start.abs_value_us + duration.rel_value_us;
291  return ret;
292 }
293 
294 
298 {
299  struct GNUNET_TIME_Absolute ret;
300 
301  if (start.abs_value_us <= duration.rel_value_us)
303  if (start.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us)
305  ret.abs_value_us = start.abs_value_us - duration.rel_value_us;
306  return ret;
307 }
308 
309 
312  unsigned long long factor)
313 {
314  struct GNUNET_TIME_Relative ret;
315 
316  if (0 == factor)
317  return GNUNET_TIME_UNIT_ZERO;
318  if (rel.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
320  ret.rel_value_us = rel.rel_value_us * factor;
321  if (ret.rel_value_us / factor != rel.rel_value_us)
322  {
323  GNUNET_break (0);
325  }
326  return ret;
327 }
328 
329 
332 {
333  struct GNUNET_TIME_Relative out;
334  double m;
335 
336  GNUNET_assert (0 <= factor);
337 
338  if (0 == factor)
339  return GNUNET_TIME_UNIT_ZERO;
340  if (rel.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
342 
343  m = ((double) rel.rel_value_us) * factor;
344 
345  if (m >= (double) (GNUNET_TIME_UNIT_FOREVER_REL).rel_value_us)
346  {
347  GNUNET_break (0);
349  }
350 
351  out.rel_value_us = (uint64_t) m;
352  return out;
353 }
354 
355 
358  unsigned long long factor)
359 {
360  struct GNUNET_TIME_Relative ret;
361 
362  if (0 == factor)
363  return GNUNET_TIME_UNIT_ZERO;
364  if (rel.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
366  ret.rel_value_us = rel.rel_value_us * factor;
367  if (ret.rel_value_us / factor != rel.rel_value_us)
368  {
370  }
371  return ret;
372 }
373 
374 
377  unsigned long long factor)
378 {
379  struct GNUNET_TIME_Relative ret;
380 
381  if ((0 == factor) ||
382  (rel.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us))
384  ret.rel_value_us = rel.rel_value_us / factor;
385  return ret;
386 }
387 
388 
391  uint64_t finished,
392  uint64_t total)
393 {
394  struct GNUNET_TIME_Relative due;
395  double exp;
396  struct GNUNET_TIME_Relative ret;
397 
398  GNUNET_break (finished <= total);
399  if (finished >= total)
400  return GNUNET_TIME_UNIT_ZERO;
401  if (0 == finished)
404  exp = ((double) due.rel_value_us) * ((double) total) / ((double) finished);
405  ret.rel_value_us = ((uint64_t) exp) - due.rel_value_us;
406  return ret;
407 }
408 
409 
412  struct GNUNET_TIME_Relative a2)
413 {
414  struct GNUNET_TIME_Relative ret;
415 
416  if ((a1.rel_value_us == UINT64_MAX) || (a2.rel_value_us == UINT64_MAX))
418  if (a1.rel_value_us + a2.rel_value_us < a1.rel_value_us)
419  {
420  GNUNET_break (0);
422  }
423  ret.rel_value_us = a1.rel_value_us + a2.rel_value_us;
424  return ret;
425 }
426 
427 
430  struct GNUNET_TIME_Relative a2)
431 {
432  struct GNUNET_TIME_Relative ret;
433 
434  if (a2.rel_value_us >= a1.rel_value_us)
435  return GNUNET_TIME_UNIT_ZERO;
436  if (a1.rel_value_us == UINT64_MAX)
438  ret.rel_value_us = a1.rel_value_us - a2.rel_value_us;
439  return ret;
440 }
441 
442 
445 {
446  struct GNUNET_TIME_RelativeNBO ret;
447 
448  ret.rel_value_us__ = GNUNET_htonll (a.rel_value_us);
449  return ret;
450 }
451 
452 
455 {
456  struct GNUNET_TIME_Relative ret;
457 
458  ret.rel_value_us = GNUNET_ntohll (a.rel_value_us__);
459  return ret;
460 }
461 
462 
465 {
466  struct GNUNET_TIME_AbsoluteNBO ret;
467 
468  ret.abs_value_us__ = GNUNET_htonll (a.abs_value_us);
469  return ret;
470 }
471 
472 
475 {
476  struct GNUNET_TIME_Absolute ret;
477 
478  ret.abs_value_us = GNUNET_ntohll (a.abs_value_us__);
479  return ret;
480 }
481 
482 
483 unsigned int
485 {
486  time_t tp;
487  struct tm *t;
488 
489  tp = time (NULL);
490  t = gmtime (&tp);
491  if (t == NULL)
492  return 0;
493  return t->tm_year + 1900;
494 }
495 
496 
497 unsigned int
499 {
500  struct tm *t;
501  time_t tp;
502 
503  tp = at.abs_value_us / 1000LL / 1000LL; /* microseconds to seconds */
504  t = gmtime (&tp);
505  if (t == NULL)
506  return 0;
507  return t->tm_year + 1900;
508 }
509 
510 
511 #ifndef HAVE_TIMEGM
512 
515 static time_t
516 my_timegm (struct tm *tm)
517 {
518  time_t ret;
519  char *tz;
520 
521  tz = getenv ("TZ");
522  setenv ("TZ", "", 1);
523  tzset ();
524  ret = mktime (tm);
525  if (tz)
526  setenv ("TZ", tz, 1);
527  else
528  unsetenv ("TZ");
529  tzset ();
530  return ret;
531 }
532 
533 
534 #endif
535 
536 
539 {
540  struct GNUNET_TIME_Absolute ret;
541  time_t tp;
542  struct tm t;
543 
544  memset (&t, 0, sizeof(t));
545  if (year < 1900)
546  {
547  GNUNET_break (0);
548  return GNUNET_TIME_absolute_get (); /* now */
549  }
550  t.tm_year = year - 1900;
551  t.tm_mday = 1;
552  t.tm_mon = 0;
553  t.tm_wday = 1;
554  t.tm_yday = 1;
555 #ifndef HAVE_TIMEGM
556  tp = my_timegm (&t);
557 #else
558  tp = timegm (&t);
559 #endif
560  GNUNET_break (tp != (time_t) -1);
561  ret.abs_value_us = tp * 1000LL * 1000LL; /* seconds to microseconds */
562  return ret;
563 }
564 
565 
569 {
570  double r = (rand () % 500) / 1000.0;
571  struct GNUNET_TIME_Relative t;
572 
575  2 + r);
577 }
578 
579 
582 {
583  double d = ((rand () % 1001) + 500) / 1000.0;
584 
585  return relative_multiply_double (r, d);
586 }
587 
588 
591  const struct GNUNET_CONFIGURATION_Handle *cfg)
592 {
593  static const struct GNUNET_CONFIGURATION_Handle *last_cfg;
594  static struct GNUNET_TIME_Absolute last_time;
595  static struct GNUNET_DISK_MapHandle *map_handle;
596  static ATOMIC volatile uint64_t *map;
597  struct GNUNET_TIME_Absolute now;
598 
599  now = GNUNET_TIME_absolute_get ();
600  if (last_cfg != cfg)
601  {
602  char *filename;
603 
604  if (NULL != map_handle)
605  {
606  GNUNET_DISK_file_unmap (map_handle);
607  map_handle = NULL;
608  }
609  map = NULL;
610 
611  last_cfg = cfg;
612  if ((NULL != cfg) &&
613  (GNUNET_OK ==
615  "util",
616  "MONOTONIC_TIME_FILENAME",
617  &filename)))
618  {
619  struct GNUNET_DISK_FileHandle *fh;
620 
621  fh = GNUNET_DISK_file_open (filename,
628  if (NULL == fh)
629  {
631  _ ("Failed to map `%s', cannot assure monotonic time!\n"),
632  filename);
633  }
634  else
635  {
636  off_t size;
637 
638  size = 0;
640  if (size < (off_t) sizeof(*map))
641  {
642  struct GNUNET_TIME_AbsoluteNBO o;
643 
644  o = GNUNET_TIME_absolute_hton (now);
645  if (sizeof(o) != GNUNET_DISK_file_write (fh, &o, sizeof(o)))
646  size = 0;
647  else
648  size = sizeof(o);
649  }
650  if (size == sizeof(*map))
651  {
652  map = GNUNET_DISK_file_map (fh,
653  &map_handle,
655  sizeof(*map));
656  if (NULL == map)
658  _ (
659  "Failed to map `%s', cannot assure monotonic time!\n"),
660  filename);
661  }
662  else
663  {
664  GNUNET_log (
666  _ (
667  "Failed to setup monotonic time file `%s', cannot assure monotonic time!\n"),
668  filename);
669  }
670  }
672  GNUNET_free (filename);
673  }
674  }
675  if (NULL != map)
676  {
677  struct GNUNET_TIME_AbsoluteNBO mt;
678 
679 #if __STDC_NO_ATOMICS__
680 #if __GNUC__
681  mt.abs_value_us__ = __sync_fetch_and_or (map, 0);
682 #else
683  mt.abs_value_us__ = *map; /* godspeed, pray this is atomic */
684 #endif
685 #else
686  mt.abs_value_us__ = atomic_load (map);
687 #endif
688  last_time =
690  }
691  if (now.abs_value_us <= last_time.abs_value_us)
692  now.abs_value_us = last_time.abs_value_us + 1;
693  last_time = now;
694  if (NULL != map)
695  {
696  uint64_t val = GNUNET_TIME_absolute_hton (now).abs_value_us__;
697 #if __STDC_NO_ATOMICS__
698 #if __GNUC__
699  (void) __sync_lock_test_and_set (map, val);
700 #else
701  *map = val; /* godspeed, pray this is atomic */
702 #endif
703 #else
704  atomic_store (map, val);
705 #endif
706  }
707  return now;
708 }
709 
710 
714 void __attribute__ ((destructor))
715 GNUNET_util_time_fini ()
716 {
718 }
719 
720 
721 /* end of time.c */
struct GNUNET_TIME_Absolute GNUNET_TIME_year_to_time(unsigned int year)
Convert a year to an expiration time of January 1st of that year.
Definition: time.c:538
enum GNUNET_GenericReturnValue GNUNET_DISK_file_handle_size(struct GNUNET_DISK_FileHandle *fh, off_t *size)
Get the size of an open file.
Definition: disk.c:193
static unsigned int threshold
What should the threshold for then key be?
Create file if it doesn&#39;t exist.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_subtract(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Subtract a given relative duration from the given start time.
Definition: time.c:296
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:474
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
uint64_t rel_value_us
The actual value.
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_hour_()
Return relative time of 1 hour.
Definition: time.c:154
static long long timestamp_offset
Variable used to simulate clock skew.
Definition: time.c:45
enum GNUNET_GenericReturnValue GNUNET_DISK_file_unmap(struct GNUNET_DISK_MapHandle *h)
Unmap a file.
Definition: disk.c:1229
struct GNUNET_TIME_Relative GNUNET_TIME_relative_max(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the maximum of two relative time values.
Definition: time.c:208
Read-write memory map.
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_unit_()
Return relative time of 1 microsecond.
Definition: time.c:118
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:181
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1126
void * GNUNET_DISK_file_map(const struct GNUNET_DISK_FileHandle *h, struct GNUNET_DISK_MapHandle **m, enum GNUNET_DISK_MapType access, size_t len)
Map a file into memory.
Definition: disk.c:1198
uint64_t rel_value_us__
The actual value (in network byte order).
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_millisecond_()
Return relative time of 1ms.
Definition: time.c:127
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Add a given relative duration to the given start time.
Definition: time.c:277
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
struct GNUNET_TIME_Relative relative_multiply_double(struct GNUNET_TIME_Relative rel, double factor)
Definition: time.c:331
Time for relative time used by GNUnet, in microseconds and in network byte order. ...
static struct GNUNET_SCHEDULER_Task * t
Main task.
void GNUNET_TIME_set_offset(long long offset)
Set the timestamp offset for this instance.
Definition: time.c:48
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
uint64_t abs_value_us
The actual value.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_CONTAINER_MultiPeerMap * map
Handle to the map used to store old latency values for peers.
void __attribute__((destructor))
Destructor.
Definition: time.c:714
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_forever_()
Return "forever".
Definition: time.c:163
int GNUNET_TIME_round_abs(struct GNUNET_TIME_Absolute *at)
Round a time value so that it is suitable for transmission via JSON encodings.
Definition: time.c:62
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_zero_()
Return relative time of 0ms.
Definition: time.c:100
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_forever_()
Return "forever".
Definition: time.c:172
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:666
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_minute_()
Return relative time of 1 minute.
Definition: time.c:145
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_max(struct GNUNET_TIME_Absolute t1, struct GNUNET_TIME_Absolute t2)
Return the maximum of two absolute time values.
Definition: time.c:224
static char * filename
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_zero_()
Return absolute time of 0ms.
Definition: time.c:109
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:311
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_TIME_Relative GNUNET_TIME_randomize(struct GNUNET_TIME_Relative r)
Return a random time value between 0.5*r and 1.5*r.
Definition: time.c:581
static int fh
Handle to the unique file.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_subtract(struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative a2)
Subtract relative timestamp from the other.
Definition: time.c:429
#define ATOMIC
Definition: time.c:36
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition: time.c:454
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get()
Get the current time.
Definition: time.c:86
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:36
struct GNUNET_TIME_Relative GNUNET_TIME_relative_min(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the minimum of two relative time values.
Definition: time.c:200
static unsigned int size
Size of the "table".
Definition: peer.c:67
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
Definition: time.c:444
int GNUNET_TIME_round_rel(struct GNUNET_TIME_Relative *rt)
Round a time value so that it is suitable for transmission via JSON encodings.
Definition: time.c:74
char * getenv()
long long GNUNET_TIME_get_offset()
Get the timestamp offset for this instance.
Definition: time.c:55
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_monotonic(const struct GNUNET_CONFIGURATION_Handle *cfg)
Obtain the current time and make sure it is monotonically increasing.
Definition: time.c:590
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
static const struct GNUNET_IDENTITY_PrivateKey zero
Public key of all zeros.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_add(struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative a2)
Add relative times together.
Definition: time.c:411
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_second_()
Return relative time of 1s.
Definition: time.c:136
unsigned int GNUNET_TIME_get_current_year()
Return the current year (e.g.
Definition: time.c:484
static time_t my_timegm(struct tm *tm)
As suggested in the timegm() man page.
Definition: time.c:516
configuration data
Definition: configuration.c:84
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_min(struct GNUNET_TIME_Absolute t1, struct GNUNET_TIME_Absolute t2)
Return the minimum of two absolute time values.
Definition: time.c:216
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:263
uint64_t abs_value_us__
The actual value (in network byte order).
#define GNUNET_log(kind,...)
Open the file for both reading and writing.
static struct GNUNET_TIME_Relative duration
How long do we run the test?
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:232
struct GNUNET_TIME_Relative GNUNET_TIME_calculate_eta(struct GNUNET_TIME_Absolute start, uint64_t finished, uint64_t total)
Calculate the estimate time of arrival/completion for an operation.
Definition: time.c:390
struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Divide relative time by a given factor.
Definition: time.c:376
Time for absolute times used by GNUnet, in microseconds.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_difference(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Absolute end)
Compute the time difference between the given start and end times.
Definition: time.c:248
unsigned int GNUNET_TIME_time_to_year(struct GNUNET_TIME_Absolute at)
Convert an expiration time to the respective year (rounds)
Definition: time.c:498
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1055
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:464
Handle used to access files (and pipes).
struct GNUNET_TIME_Relative GNUNET_TIME_relative_saturating_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Saturating multiply relative time by a given factor.
Definition: time.c:357
struct GNUNET_TIME_Relative GNUNET_TIME_randomized_backoff(struct GNUNET_TIME_Relative rt, struct GNUNET_TIME_Relative threshold)
Randomized exponential back-off, starting at 1 ms and going up by a factor of 2+r, where 0 <= r <= 0.5, up to a maximum of the given threshold.
Definition: time.c:567
Handle for a memory-mapping operation.
Definition: disk.c:1178
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:53
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.