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 {
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 
331 relative_multiply_double (struct GNUNET_TIME_Relative rel, double factor)
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 {
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 {
467 
468  ret.abs_value_us__ = GNUNET_htonll (a.abs_value_us);
469  return ret;
470 }
471 
472 
473 bool
475 {
476  return GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us == abs.abs_value_us;
477 }
478 
479 
480 bool
482 {
483  return GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == rel.rel_value_us;
484 }
485 
486 
487 bool
489 {
490  return 0 == rel.rel_value_us;
491 }
492 
493 
494 bool
496 {
497  struct GNUNET_TIME_Absolute now;
498 
499  now = GNUNET_TIME_absolute_get ();
500  return abs.abs_value_us < now.abs_value_us;
501 }
502 
503 
504 bool
506 {
507  struct GNUNET_TIME_Absolute now;
508 
509  now = GNUNET_TIME_absolute_get ();
510  return abs.abs_value_us > now.abs_value_us;
511 }
512 
513 
515 GNUNET_TIME_absolute_from_ms (uint64_t ms_after_epoch)
516 {
517  struct GNUNET_TIME_Absolute ret;
518 
519  ret.abs_value_us = GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us
520  * ms_after_epoch;
521  if (ret.abs_value_us / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us !=
522  ms_after_epoch)
524  return ret;
525 }
526 
527 
529 GNUNET_TIME_absolute_from_s (uint64_t s_after_epoch)
530 {
531  struct GNUNET_TIME_Absolute ret;
532 
533  ret.abs_value_us = GNUNET_TIME_UNIT_SECONDS.rel_value_us * s_after_epoch;
534  if (ret.abs_value_us / GNUNET_TIME_UNIT_SECONDS.rel_value_us !=
535  s_after_epoch)
537  return ret;
538 }
539 
540 
543 {
544  struct GNUNET_TIME_Absolute ret;
545 
546  ret.abs_value_us = GNUNET_ntohll (a.abs_value_us__);
547  return ret;
548 }
549 
550 
551 unsigned int
553 {
554  time_t tp;
555  struct tm *t;
556 
557  tp = time (NULL);
558  t = gmtime (&tp);
559  if (t == NULL)
560  return 0;
561  return t->tm_year + 1900;
562 }
563 
564 
565 unsigned int
567 {
568  struct tm *t;
569  time_t tp;
570 
571  tp = at.abs_value_us / 1000LL / 1000LL; /* microseconds to seconds */
572  t = gmtime (&tp);
573  if (t == NULL)
574  return 0;
575  return t->tm_year + 1900;
576 }
577 
578 
579 #ifndef HAVE_TIMEGM
583 static time_t
584 my_timegm (struct tm *tm)
585 {
586  time_t ret;
587  char *tz;
588 
589  tz = getenv ("TZ");
590  setenv ("TZ", "", 1);
591  tzset ();
592  ret = mktime (tm);
593  if (tz)
594  setenv ("TZ", tz, 1);
595  else
596  unsetenv ("TZ");
597  tzset ();
598  return ret;
599 }
600 
601 
602 #endif
603 
604 
606 GNUNET_TIME_year_to_time (unsigned int year)
607 {
608  struct GNUNET_TIME_Absolute ret;
609  time_t tp;
610  struct tm t;
611 
612  memset (&t, 0, sizeof(t));
613  if (year < 1900)
614  {
615  GNUNET_break (0);
616  return GNUNET_TIME_absolute_get (); /* now */
617  }
618  t.tm_year = year - 1900;
619  t.tm_mday = 1;
620  t.tm_mon = 0;
621  t.tm_wday = 1;
622  t.tm_yday = 1;
623 #ifndef HAVE_TIMEGM
624  tp = my_timegm (&t);
625 #else
626  tp = timegm (&t);
627 #endif
628  GNUNET_break (tp != (time_t) -1);
629  ret.abs_value_us = tp * 1000LL * 1000LL; /* seconds to microseconds */
630  return ret;
631 }
632 
633 
637 {
638  double r = (rand () % 500) / 1000.0;
639  struct GNUNET_TIME_Relative t;
640 
643  2 + r);
645 }
646 
647 
650 {
651  double d = ((rand () % 1001) + 500) / 1000.0;
652 
653  return relative_multiply_double (r, d);
654 }
655 
656 
659  const struct GNUNET_CONFIGURATION_Handle *cfg)
660 {
661  static const struct GNUNET_CONFIGURATION_Handle *last_cfg;
662  static struct GNUNET_TIME_Absolute last_time;
663  static struct GNUNET_DISK_MapHandle *map_handle;
664  static ATOMIC volatile uint64_t *map;
665  struct GNUNET_TIME_Absolute now;
666 
667  now = GNUNET_TIME_absolute_get ();
668  if (last_cfg != cfg)
669  {
670  char *filename;
671 
672  if (NULL != map_handle)
673  {
674  GNUNET_DISK_file_unmap (map_handle);
675  map_handle = NULL;
676  }
677  map = NULL;
678 
679  last_cfg = cfg;
680  if ((NULL != cfg) &&
681  (GNUNET_OK ==
683  "util",
684  "MONOTONIC_TIME_FILENAME",
685  &filename)))
686  {
687  struct GNUNET_DISK_FileHandle *fh;
688 
696  if (NULL == fh)
697  {
699  _ ("Failed to map `%s', cannot assure monotonic time!\n"),
700  filename);
701  }
702  else
703  {
704  off_t size;
705 
706  size = 0;
708  if (size < (off_t) sizeof(*map))
709  {
710  struct GNUNET_TIME_AbsoluteNBO o;
711 
712  o = GNUNET_TIME_absolute_hton (now);
713  if (sizeof(o) != GNUNET_DISK_file_write (fh, &o, sizeof(o)))
714  size = 0;
715  else
716  size = sizeof(o);
717  }
718  if (size == sizeof(*map))
719  {
721  &map_handle,
723  sizeof(*map));
724  if (NULL == map)
726  _ (
727  "Failed to map `%s', cannot assure monotonic time!\n"),
728  filename);
729  }
730  else
731  {
732  GNUNET_log (
734  _ (
735  "Failed to setup monotonic time file `%s', cannot assure monotonic time!\n"),
736  filename);
737  }
738  }
741  }
742  }
743  if (NULL != map)
744  {
745  struct GNUNET_TIME_AbsoluteNBO mt;
746 
747 #if __STDC_NO_ATOMICS__
748 #if __GNUC__
749  mt.abs_value_us__ = __sync_fetch_and_or (map, 0);
750 #else
751  mt.abs_value_us__ = *map; /* godspeed, pray this is atomic */
752 #endif
753 #else
754  mt.abs_value_us__ = atomic_load (map);
755 #endif
756  last_time =
758  }
759  if (now.abs_value_us <= last_time.abs_value_us)
760  now.abs_value_us = last_time.abs_value_us + 1;
761  last_time = now;
762  if (NULL != map)
763  {
764  uint64_t val = GNUNET_TIME_absolute_hton (now).abs_value_us__;
765 #if __STDC_NO_ATOMICS__
766 #if __GNUC__
767  (void) __sync_lock_test_and_set (map, val);
768 #else
769  *map = val; /* godspeed, pray this is atomic */
770 #endif
771 #else
772  atomic_store (map, val);
773 #endif
774  }
775  return now;
776 }
777 
778 
782 void __attribute__ ((destructor))
783 GNUNET_util_time_fini ()
784 {
786 }
787 
788 
789 /* end of time.c */
char * getenv()
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
static struct GNUNET_CONTAINER_MultiPeerMap * map
Handle to the map used to store old latency values for peers.
static char * filename
static struct GNUNET_TIME_Relative duration
How long do we run the test?
static unsigned int threshold
What should the threshold for then key be?
static const struct GNUNET_IDENTITY_PrivateKey zero
Public key of all zeros.
static struct GNUNET_DISK_FileHandle * fh
File handle to STDIN, for reading restart/quit commands.
static struct GNUNET_SCHEDULER_Task * t
Main task.
#define GNUNET_log(kind,...)
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:53
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:36
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_NO
Definition: gnunet_common.h:94
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_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:1235
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:686
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:1378
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1306
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
enum GNUNET_GenericReturnValue GNUNET_DISK_file_unmap(struct GNUNET_DISK_MapHandle *h)
Unmap a file.
Definition: disk.c:1409
@ GNUNET_DISK_OPEN_CREATE
Create file if it doesn't exist.
@ GNUNET_DISK_OPEN_READWRITE
Open the file for both reading and writing.
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_GROUP_READ
Group can read.
@ GNUNET_DISK_PERM_GROUP_WRITE
Group can write.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
@ GNUNET_DISK_MAP_TYPE_READWRITE
Read-write memory map.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
#define GNUNET_free(ptr)
Wrapper around free.
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:606
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
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_zero_()
Return relative time of 0ms.
Definition: time.c:100
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_hour_()
Return relative time of 1 hour.
Definition: time.c:154
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_from_s(uint64_t s_after_epoch)
Convert seconds after the UNIX epoch to absolute time.
Definition: time.c:529
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition: time.c:454
bool GNUNET_TIME_absolute_is_future(struct GNUNET_TIME_Absolute abs)
Test if abs is truly in the future (excluding now).
Definition: time.c:505
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_millisecond_()
Return relative time of 1ms.
Definition: time.c:127
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
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_relative_max(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the maximum of two relative time values.
Definition: time.c:208
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_get_zero_()
Return absolute time of 0ms.
Definition: time.c:109
#define GNUNET_TIME_UNIT_SECONDS
One second.
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_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
unsigned int GNUNET_TIME_get_current_year()
Return the current year (e.g.
Definition: time.c:552
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_from_ms(uint64_t ms_after_epoch)
Convert milliseconds after the UNIX epoch to absolute time.
Definition: time.c:515
bool GNUNET_TIME_relative_is_zero(struct GNUNET_TIME_Relative rel)
Test if rel is zero.
Definition: time.c:488
bool GNUNET_TIME_absolute_is_never(struct GNUNET_TIME_Absolute abs)
Test if abs is never.
Definition: time.c:474
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
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,...
Definition: time.c:635
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
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_forever_()
Return "forever".
Definition: time.c:172
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get()
Get the current time.
Definition: time.c:86
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_forever_()
Return "forever".
Definition: time.c:163
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
bool GNUNET_TIME_relative_is_forever(struct GNUNET_TIME_Relative rel)
Test if rel is forever.
Definition: time.c:481
long long GNUNET_TIME_get_offset()
Get the timestamp offset for this instance.
Definition: time.c:55
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:542
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
void GNUNET_TIME_set_offset(long long offset)
Set the timestamp offset for this instance.
Definition: time.c:48
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:649
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
unsigned int GNUNET_TIME_time_to_year(struct GNUNET_TIME_Absolute at)
Convert an expiration time to the respective year (rounds)
Definition: time.c:566
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_second_()
Return relative time of 1s.
Definition: time.c:136
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
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
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
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
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_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_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
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
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:658
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
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
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:464
bool GNUNET_TIME_absolute_is_past(struct GNUNET_TIME_Absolute abs)
Test if abs is truly in the past (excluding now).
Definition: time.c:495
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
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
static unsigned int size
Size of the "table".
Definition: peer.c:67
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
Handle used to access files (and pipes).
Handle for a memory-mapping operation.
Definition: disk.c:1359
Time for absolute time used by GNUnet, in microseconds and in network byte order.
uint64_t abs_value_us__
The actual value (in network byte order).
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
Time for relative time used by GNUnet, in microseconds and in network byte order.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
static long long timestamp_offset
Variable used to simulate clock skew.
Definition: time.c:45
#define ATOMIC
Definition: time.c:36
struct GNUNET_TIME_Relative relative_multiply_double(struct GNUNET_TIME_Relative rel, double factor)
Definition: time.c:331
static time_t my_timegm(struct tm *tm)
As suggested in the timegm() man page.
Definition: time.c:584
void __attribute__((destructor))
Destructor.
Definition: time.c:782