GNUnet  0.17.6
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 bool
63  struct GNUNET_TIME_Absolute a2,
64  struct GNUNET_TIME_Relative t)
65 {
67 
72  <=,
73  t);
74 }
75 
76 
79 {
80  struct GNUNET_TIME_Timestamp ts;
81 
84  ts.abs_time.abs_value_us = at.abs_value_us - at.abs_value_us % 1000000;
85  return ts;
86 }
87 
88 
91 {
92  struct GNUNET_TIME_TimestampNBO tn;
93 
95  return tn;
96 }
97 
98 
101 {
102  struct GNUNET_TIME_Timestamp t;
103 
104  t.abs_time = GNUNET_TIME_absolute_ntoh (tn.abs_time_nbo);
105  return t;
106 }
107 
108 
111 {
112  struct GNUNET_TIME_Absolute ret;
113  struct timeval tv;
114 
115  gettimeofday (&tv, NULL);
116  ret.abs_value_us = (uint64_t) (((uint64_t) tv.tv_sec * 1000LL * 1000LL)
117  + ((uint64_t) tv.tv_usec))
119  return ret;
120 }
121 
122 
125 {
128 }
129 
130 
133 {
134  static struct GNUNET_TIME_Relative zero;
135 
136  return zero;
137 }
138 
139 
142 {
143  static struct GNUNET_TIME_Absolute zero;
144 
145  return zero;
146 }
147 
148 
151 {
152  static struct GNUNET_TIME_Relative one = { 1 };
153 
154  return one;
155 }
156 
157 
160 {
161  static struct GNUNET_TIME_Relative one = { 1000 };
162 
163  return one;
164 }
165 
166 
169 {
170  static struct GNUNET_TIME_Relative one = { 1000 * 1000LL };
171 
172  return one;
173 }
174 
175 
178 {
179  static struct GNUNET_TIME_Relative one = { 60 * 1000 * 1000LL };
180 
181  return one;
182 }
183 
184 
187 {
188  static struct GNUNET_TIME_Relative one = { 60 * 60 * 1000 * 1000LL };
189 
190  return one;
191 }
192 
193 
196 {
197  static struct GNUNET_TIME_Relative forever = { UINT64_MAX };
198 
199  return forever;
200 }
201 
202 
205 {
206  static struct GNUNET_TIME_Absolute forever = { UINT64_MAX };
207 
208  return forever;
209 }
210 
211 
212 const char *
214 {
215  static GNUNET_THREAD_LOCAL char buf[255];
216  time_t tt;
217  struct tm *tp;
218 
220  return "end of time";
221  tt = ts.abs_time.abs_value_us / 1000LL / 1000LL;
222  tp = localtime (&tt);
223  /* This is hacky, but i don't know a way to detect libc character encoding.
224  * Just expect utf8 from glibc these days.
225  * As for msvcrt, use the wide variant, which always returns utf16
226  * (otherwise we'd have to detect current codepage or use W32API character
227  * set conversion routines to convert to UTF8).
228  */
229  strftime (buf,
230  sizeof(buf),
231  "%a %b %d %H:%M:%S %Y",
232  tp);
233  return buf;
234 }
235 
236 
237 const char *
239 {
240  static GNUNET_THREAD_LOCAL char buf[255];
241  time_t tt;
242  struct tm *tp;
243 
245  return "end of time";
246  tt = t.abs_value_us / 1000LL / 1000LL;
247  tp = localtime (&tt);
248  /* This is hacky, but i don't know a way to detect libc character encoding.
249  * Just expect utf8 from glibc these days.
250  * As for msvcrt, use the wide variant, which always returns utf16
251  * (otherwise we'd have to detect current codepage or use W32API character
252  * set conversion routines to convert to UTF8).
253  */
254  strftime (buf,
255  sizeof(buf),
256  "%a %b %d %H:%M:%S %Y",
257  tp);
258  return buf;
259 }
260 
261 
262 const char *
264  bool do_round)
265 {
266  static GNUNET_THREAD_LOCAL char buf[128];
267  const char *unit = /* time unit */ "┬Ás";
268  uint64_t dval = delta.rel_value_us;
269 
271  return "forever";
272  if (0 == delta.rel_value_us)
273  return "0 ms";
274  if ( ((GNUNET_YES == do_round) &&
275  (dval > 5 * 1000)) ||
276  (0 == (dval % 1000)))
277  {
278  dval = dval / 1000;
279  unit = /* time unit */ "ms";
280  if (((GNUNET_YES == do_round) && (dval > 5 * 1000)) || (0 == (dval % 1000)))
281  {
282  dval = dval / 1000;
283  unit = /* time unit */ "s";
284  if (((GNUNET_YES == do_round) && (dval > 5 * 60)) || (0 == (dval % 60)))
285  {
286  dval = dval / 60;
287  unit = /* time unit */ "m";
288  if (((GNUNET_YES == do_round) && (dval > 5 * 60)) || (0 == (dval % 60)))
289  {
290  dval = dval / 60;
291  unit = /* time unit */ "h";
292  if (((GNUNET_YES == do_round) && (dval > 5 * 24)) ||
293  (0 == (dval % 24)))
294  {
295  dval = dval / 24;
296  if (1 == dval)
297  unit = /* time unit */ "day";
298  else
299  unit = /* time unit */ "days";
300  }
301  }
302  }
303  }
304  }
306  sizeof(buf),
307  "%llu %s",
308  (unsigned long long) dval,
309  unit);
310  return buf;
311 }
312 
313 
316 {
317  struct GNUNET_TIME_Absolute ret;
318 
322 
323  if (rel.rel_value_us + now.abs_value_us < rel.rel_value_us)
324  {
325  GNUNET_break (0); /* overflow... */
327  }
328  ret.abs_value_us = rel.rel_value_us + now.abs_value_us;
329  return ret;
330 }
331 
332 
335 {
338 }
339 
340 
343  struct GNUNET_TIME_Relative t2)
344 {
345  return (t1.rel_value_us < t2.rel_value_us) ? t1 : t2;
346 }
347 
348 
351  struct GNUNET_TIME_Relative t2)
352 {
353  return (t1.rel_value_us > t2.rel_value_us) ? t1 : t2;
354 }
355 
356 
359  struct GNUNET_TIME_Absolute t2)
360 {
361  return (t1.abs_value_us < t2.abs_value_us) ? t1 : t2;
362 }
363 
364 
367  struct GNUNET_TIME_Absolute t2)
368 {
369  return (t1.abs_value_us > t2.abs_value_us) ? t1 : t2;
370 }
371 
372 
375  struct GNUNET_TIME_Timestamp t2)
376 {
377  return (t1.abs_time.abs_value_us > t2.abs_time.abs_value_us) ? t1 : t2;
378 }
379 
380 
383  struct GNUNET_TIME_Timestamp t2)
384 {
385  return (t1.abs_time.abs_value_us < t2.abs_time.abs_value_us) ? t1 : t2;
386 }
387 
388 
391  struct GNUNET_TIME_Relative rt)
392 {
393  struct GNUNET_TIME_Absolute ret;
394 
396  ret.abs_value_us
397  = at.abs_value_us
398  - at.abs_value_us % rt.rel_value_us;
399  return ret;
400 }
401 
402 
405 {
406  struct GNUNET_TIME_Relative ret;
407 
408  if (GNUNET_TIME_absolute_is_never (future))
411 
412  if (now.abs_value_us > future.abs_value_us)
413  return GNUNET_TIME_UNIT_ZERO;
414  ret.rel_value_us = future.abs_value_us - now.abs_value_us;
415  return ret;
416 }
417 
418 
421  struct GNUNET_TIME_Absolute end)
422 {
423  struct GNUNET_TIME_Relative ret;
424 
427  if (end.abs_value_us < start.abs_value_us)
428  return GNUNET_TIME_UNIT_ZERO;
429  ret.rel_value_us = end.abs_value_us - start.abs_value_us;
430  return ret;
431 }
432 
433 
436 {
437  struct GNUNET_TIME_Absolute now;
438  struct GNUNET_TIME_Relative ret;
439 
440  now = GNUNET_TIME_absolute_get ();
441  if (whence.abs_value_us > now.abs_value_us)
442  return GNUNET_TIME_UNIT_ZERO;
443  ret.rel_value_us = now.abs_value_us - whence.abs_value_us;
444  return ret;
445 }
446 
447 
451 {
452  struct GNUNET_TIME_Absolute ret;
453 
457  if (start.abs_value_us + duration.rel_value_us < start.abs_value_us)
458  {
459  GNUNET_break (0);
461  }
462  ret.abs_value_us = start.abs_value_us + duration.rel_value_us;
463  return ret;
464 }
465 
466 
470 {
471  struct GNUNET_TIME_Absolute ret;
472 
473  if (start.abs_value_us <= duration.rel_value_us)
477  ret.abs_value_us = start.abs_value_us - duration.rel_value_us;
478  return ret;
479 }
480 
481 
484  unsigned long long factor)
485 {
486  struct GNUNET_TIME_Relative ret;
487 
488  if (0 == factor)
489  return GNUNET_TIME_UNIT_ZERO;
492  ret.rel_value_us = rel.rel_value_us * factor;
493  if (ret.rel_value_us / factor != rel.rel_value_us)
494  {
495  GNUNET_break (0);
497  }
498  return ret;
499 }
500 
501 
504  double factor)
505 {
506  struct GNUNET_TIME_Relative out;
507  double m;
508 
509  GNUNET_assert (0 <= factor);
510 
511  if (0 == factor)
512  return GNUNET_TIME_UNIT_ZERO;
515 
516  m = ((double) rel.rel_value_us) * factor;
517 
518  if (m >= (double) (GNUNET_TIME_UNIT_FOREVER_REL).rel_value_us)
519  {
520  GNUNET_break (0);
522  }
523 
524  out.rel_value_us = (uint64_t) m;
525  return out;
526 }
527 
528 
531  unsigned long long factor)
532 {
533  struct GNUNET_TIME_Relative ret;
534 
535  if (0 == factor)
536  return GNUNET_TIME_UNIT_ZERO;
539  ret.rel_value_us = rel.rel_value_us * factor;
540  if (ret.rel_value_us / factor != rel.rel_value_us)
541  {
543  }
544  return ret;
545 }
546 
547 
550  unsigned long long factor)
551 {
552  struct GNUNET_TIME_Relative ret;
553 
554  if ((0 == factor) ||
557  ret.rel_value_us = rel.rel_value_us / factor;
558  return ret;
559 }
560 
561 
564  uint64_t finished,
565  uint64_t total)
566 {
567  struct GNUNET_TIME_Relative due;
568  double exp;
569  struct GNUNET_TIME_Relative ret;
570 
571  GNUNET_break (finished <= total);
572  if (finished >= total)
573  return GNUNET_TIME_UNIT_ZERO;
574  if (0 == finished)
577  exp = ((double) due.rel_value_us) * ((double) total) / ((double) finished);
578  ret.rel_value_us = ((uint64_t) exp) - due.rel_value_us;
579  return ret;
580 }
581 
582 
585  struct GNUNET_TIME_Relative a2)
586 {
587  struct GNUNET_TIME_Relative ret;
588 
589  if ((a1.rel_value_us == UINT64_MAX) || (a2.rel_value_us == UINT64_MAX))
591  if (a1.rel_value_us + a2.rel_value_us < a1.rel_value_us)
592  {
593  GNUNET_break (0);
595  }
596  ret.rel_value_us = a1.rel_value_us + a2.rel_value_us;
597  return ret;
598 }
599 
600 
603  struct GNUNET_TIME_Relative a2)
604 {
605  struct GNUNET_TIME_Relative ret;
606 
607  if (a2.rel_value_us >= a1.rel_value_us)
608  return GNUNET_TIME_UNIT_ZERO;
609  if (a1.rel_value_us == UINT64_MAX)
611  ret.rel_value_us = a1.rel_value_us - a2.rel_value_us;
612  return ret;
613 }
614 
615 
618 {
620 
621  ret.rel_value_us__ = GNUNET_htonll (a.rel_value_us);
622  return ret;
623 }
624 
625 
628 {
629  struct GNUNET_TIME_Relative ret;
630 
631  ret.rel_value_us = GNUNET_ntohll (a.rel_value_us__);
632  return ret;
633 }
634 
635 
638 {
640 
641  ret.abs_value_us__ = GNUNET_htonll (a.abs_value_us);
642  return ret;
643 }
644 
645 
646 bool
648 {
649  return GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us == abs.abs_value_us;
650 }
651 
652 
653 bool
655 {
656  return GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == rel.rel_value_us;
657 }
658 
659 
660 bool
662 {
663  return 0 == rel.rel_value_us;
664 }
665 
666 
667 bool
669 {
670  struct GNUNET_TIME_Absolute now;
671 
672  now = GNUNET_TIME_absolute_get ();
673  return abs.abs_value_us < now.abs_value_us;
674 }
675 
676 
677 bool
679 {
680  struct GNUNET_TIME_Absolute now;
681 
682  now = GNUNET_TIME_absolute_get ();
683  return abs.abs_value_us > now.abs_value_us;
684 }
685 
686 
688 GNUNET_TIME_absolute_from_ms (uint64_t ms_after_epoch)
689 {
690  struct GNUNET_TIME_Absolute ret;
691 
692  ret.abs_value_us = GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us
693  * ms_after_epoch;
694  if (ret.abs_value_us / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us !=
695  ms_after_epoch)
697  return ret;
698 }
699 
700 
702 GNUNET_TIME_absolute_from_s (uint64_t s_after_epoch)
703 {
704  struct GNUNET_TIME_Absolute ret;
705 
706  ret.abs_value_us = GNUNET_TIME_UNIT_SECONDS.rel_value_us * s_after_epoch;
707  if (ret.abs_value_us / GNUNET_TIME_UNIT_SECONDS.rel_value_us !=
708  s_after_epoch)
710  return ret;
711 }
712 
713 
715 GNUNET_TIME_timestamp_from_s (uint64_t s_after_epoch)
716 {
717  struct GNUNET_TIME_Timestamp ret;
718 
719  ret.abs_time.abs_value_us
720  = GNUNET_TIME_UNIT_SECONDS.rel_value_us * s_after_epoch;
721  if (ret.abs_time.abs_value_us / GNUNET_TIME_UNIT_SECONDS.rel_value_us
722  != s_after_epoch)
724  return ret;
725 }
726 
727 
728 uint64_t
730 {
731  return ts.abs_time.abs_value_us / GNUNET_TIME_UNIT_SECONDS.rel_value_us;
732 }
733 
734 
737 {
738  struct GNUNET_TIME_Absolute ret;
739 
740  ret.abs_value_us = GNUNET_ntohll (a.abs_value_us__);
741  return ret;
742 }
743 
744 
745 unsigned int
747 {
748  time_t tp;
749  struct tm *t;
750 
751  tp = time (NULL);
752  t = gmtime (&tp);
753  if (t == NULL)
754  return 0;
755  return t->tm_year + 1900;
756 }
757 
758 
759 unsigned int
761 {
762  struct tm *t;
763  time_t tp;
764 
765  tp = at.abs_value_us / 1000LL / 1000LL; /* microseconds to seconds */
766  t = gmtime (&tp);
767  if (t == NULL)
768  return 0;
769  return t->tm_year + 1900;
770 }
771 
772 
773 #ifndef HAVE_TIMEGM
777 static time_t
778 my_timegm (struct tm *tm)
779 {
780  time_t ret;
781  char *tz;
782 
783  tz = getenv ("TZ");
784  setenv ("TZ", "", 1);
785  tzset ();
786  ret = mktime (tm);
787  if (tz)
788  setenv ("TZ", tz, 1);
789  else
790  unsetenv ("TZ");
791  tzset ();
792  return ret;
793 }
794 
795 
796 #endif
797 
798 
800 GNUNET_TIME_year_to_time (unsigned int year)
801 {
802  struct GNUNET_TIME_Absolute ret;
803  time_t tp;
804  struct tm t;
805 
806  memset (&t, 0, sizeof(t));
807  if (year < 1900)
808  {
809  GNUNET_break (0);
810  return GNUNET_TIME_absolute_get (); /* now */
811  }
812  t.tm_year = year - 1900;
813  t.tm_mday = 1;
814  t.tm_mon = 0;
815  t.tm_wday = 1;
816  t.tm_yday = 1;
817 #ifndef HAVE_TIMEGM
818  tp = my_timegm (&t);
819 #else
820  tp = timegm (&t);
821 #endif
822  GNUNET_break (tp != (time_t) -1);
823  ret.abs_value_us = tp * 1000LL * 1000LL; /* seconds to microseconds */
824  return ret;
825 }
826 
827 
831 {
832  double r = (rand () % 500) / 1000.0;
833  struct GNUNET_TIME_Relative t;
834 
837  2 + r);
839 }
840 
841 
842 bool
844 {
845  return 0 == abs.abs_value_us;
846 }
847 
848 
851 {
852  double d = ((rand () % 1001) + 500) / 1000.0;
853 
854  return relative_multiply_double (r, d);
855 }
856 
857 
860  const struct GNUNET_CONFIGURATION_Handle *cfg)
861 {
862  static const struct GNUNET_CONFIGURATION_Handle *last_cfg;
863  static struct GNUNET_TIME_Absolute last_time;
864  static struct GNUNET_DISK_MapHandle *map_handle;
865  static ATOMIC volatile uint64_t *map;
866  struct GNUNET_TIME_Absolute now;
867 
868  now = GNUNET_TIME_absolute_get ();
869  if (last_cfg != cfg)
870  {
871  char *filename;
872 
873  if (NULL != map_handle)
874  {
875  GNUNET_DISK_file_unmap (map_handle);
876  map_handle = NULL;
877  }
878  map = NULL;
879 
880  last_cfg = cfg;
881  if ((NULL != cfg) &&
882  (GNUNET_OK ==
884  "util",
885  "MONOTONIC_TIME_FILENAME",
886  &filename)))
887  {
888  struct GNUNET_DISK_FileHandle *fh;
889 
897  if (NULL == fh)
898  {
900  _ ("Failed to map `%s', cannot assure monotonic time!\n"),
901  filename);
902  }
903  else
904  {
905  off_t size;
906 
907  size = 0;
909  if (size < (off_t) sizeof(*map))
910  {
911  struct GNUNET_TIME_AbsoluteNBO o;
912 
913  o = GNUNET_TIME_absolute_hton (now);
914  if (sizeof(o) != GNUNET_DISK_file_write (fh, &o, sizeof(o)))
915  size = 0;
916  else
917  size = sizeof(o);
918  }
919  if (size == sizeof(*map))
920  {
922  &map_handle,
924  sizeof(*map));
925  if (NULL == map)
927  _ (
928  "Failed to map `%s', cannot assure monotonic time!\n"),
929  filename);
930  }
931  else
932  {
933  GNUNET_log (
935  _ (
936  "Failed to setup monotonic time file `%s', cannot assure monotonic time!\n"),
937  filename);
938  }
939  }
942  }
943  }
944  if (NULL != map)
945  {
946  struct GNUNET_TIME_AbsoluteNBO mt;
947 
948 #if __STDC_NO_ATOMICS__
949 #if __GNUC__
950  mt.abs_value_us__ = __sync_fetch_and_or (map, 0);
951 #else
952  mt.abs_value_us__ = *map; /* godspeed, pray this is atomic */
953 #endif
954 #else
955  mt.abs_value_us__ = atomic_load (map);
956 #endif
957  last_time =
959  }
960  if (now.abs_value_us <= last_time.abs_value_us)
961  now.abs_value_us = last_time.abs_value_us + 1;
962  last_time = now;
963  if (NULL != map)
964  {
965  uint64_t val = GNUNET_TIME_absolute_hton (now).abs_value_us__;
966 #if __STDC_NO_ATOMICS__
967 #if __GNUC__
968  (void) __sync_lock_test_and_set (map, val);
969 #else
970  *map = val; /* godspeed, pray this is atomic */
971 #endif
972 #else
973  atomic_store (map, val);
974 #endif
975  }
976  return now;
977 }
978 
979 
983 void __attribute__ ((destructor))
984 GNUNET_util_time_fini ()
985 {
987 }
988 
989 
990 /* 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_SCHEDULER_Task * tt
Task scheduled to handle timeout.
Definition: gnunet-abd.c:76
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 void do_round(void *cls)
Send out PUSHes and PULLs, possibly update #view, samplers.
static char buf[2048]
static struct GNUNET_DISK_FileHandle * fh
File handle to STDIN, for reading restart/quit commands.
static struct GNUNET_SCHEDULER_Task * t
Main task.
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_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:99
@ GNUNET_YES
#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
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
#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:800
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:342
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_zero_()
Return relative time of 0ms.
Definition: time.c:132
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_hour_()
Return relative time of 1 hour.
Definition: time.c:186
#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:702
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition: time.c:627
bool GNUNET_TIME_absolute_is_future(struct GNUNET_TIME_Absolute abs)
Test if abs is truly in the future (excluding now).
Definition: time.c:678
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_millisecond_()
Return relative time of 1ms.
Definition: time.c:159
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:435
const char * GNUNET_TIME_absolute2s(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: time.c:238
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:530
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:350
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_minute_()
Return relative time of 1 minute.
Definition: time.c:177
struct GNUNET_TIME_Timestamp GNUNET_TIME_timestamp_min(struct GNUNET_TIME_Timestamp t1, struct GNUNET_TIME_Timestamp t2)
Return the minimum of two timestamps.
Definition: time.c:382
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_zero_()
Return absolute time of 0ms.
Definition: time.c:141
struct GNUNET_TIME_Timestamp GNUNET_TIME_relative_to_timestamp(struct GNUNET_TIME_Relative rel)
Convert relative time to a timestamp in the future.
Definition: time.c:334
#define GNUNET_TIME_relative_cmp(t1, op, t2)
Compare two relative times.
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_TIME_Timestamp GNUNET_TIME_timestamp_from_s(uint64_t s_after_epoch)
Convert seconds after the UNIX epoch to timestamp.
Definition: time.c:715
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:404
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:366
unsigned int GNUNET_TIME_get_current_year()
Return the current year (e.g.
Definition: time.c:746
bool GNUNET_TIME_absolute_is_zero(struct GNUNET_TIME_Absolute abs)
Test if abs is truly zero.
Definition: time.c:843
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:688
bool GNUNET_TIME_relative_is_zero(struct GNUNET_TIME_Relative rel)
Test if rel is zero.
Definition: time.c:661
bool GNUNET_TIME_absolute_is_never(struct GNUNET_TIME_Absolute abs)
Test if abs is never.
Definition: time.c:647
#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:829
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:602
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_forever_()
Return "forever".
Definition: time.c:204
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get()
Get the current time.
Definition: time.c:110
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_forever_()
Return "forever".
Definition: time.c:195
struct GNUNET_TIME_Timestamp GNUNET_TIME_timestamp_get()
Get timestamp representing the current time.
Definition: time.c:124
uint64_t GNUNET_TIME_timestamp_to_s(struct GNUNET_TIME_Timestamp ts)
Convert timestamp to number of seconds after the UNIX epoch.
Definition: time.c:729
bool GNUNET_TIME_relative_is_forever(struct GNUNET_TIME_Relative rel)
Test if rel is forever.
Definition: time.c:654
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:736
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_round_down(struct GNUNET_TIME_Absolute at, struct GNUNET_TIME_Relative rt)
Round down absolute time at to multiple of rt.
Definition: time.c:390
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:584
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:850
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:468
unsigned int GNUNET_TIME_time_to_year(struct GNUNET_TIME_Absolute at)
Convert an expiration time to the respective year (rounds)
Definition: time.c:760
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_second_()
Return relative time of 1s.
Definition: time.c:168
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_unit_()
Return relative time of 1 microsecond.
Definition: time.c:150
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:315
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:483
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:358
#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:617
#define GNUNET_TIME_UNIT_FOREVER_TS
Constant used to specify "forever".
bool GNUNET_TIME_absolute_approx_eq(struct GNUNET_TIME_Absolute a1, struct GNUNET_TIME_Absolute a2, struct GNUNET_TIME_Relative t)
Test if a1 and a2 are equal within a margin of error of t.
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:449
const char * GNUNET_TIME_timestamp2s(struct GNUNET_TIME_Timestamp ts)
Convert ts to human-readable timestamp.
Definition: time.c:213
struct GNUNET_TIME_Timestamp GNUNET_TIME_timestamp_max(struct GNUNET_TIME_Timestamp t1, struct GNUNET_TIME_Timestamp t2)
Return the maximum of two timestamps.
Definition: time.c:374
#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:859
struct GNUNET_TIME_TimestampNBO GNUNET_TIME_timestamp_hton(struct GNUNET_TIME_Timestamp t)
Convert timestamp to network byte order.
Definition: time.c:90
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:549
const char * GNUNET_TIME_relative2s(struct GNUNET_TIME_Relative delta, bool do_round)
Give relative time in human-readable fancy format.
Definition: time.c:263
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:420
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:637
bool GNUNET_TIME_absolute_is_past(struct GNUNET_TIME_Absolute abs)
Test if abs is truly in the past (excluding now).
Definition: time.c:668
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:563
struct GNUNET_TIME_Timestamp GNUNET_TIME_timestamp_ntoh(struct GNUNET_TIME_TimestampNBO tn)
Convert timestamp from network byte order.
Definition: time.c:100
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
struct GNUNET_TIME_Timestamp GNUNET_TIME_absolute_to_timestamp(struct GNUNET_TIME_Absolute at)
Round an absolute time to a timestamp.
Definition: time.c:78
static unsigned int size
Size of the "table".
Definition: peer.c:67
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
#define GNUNET_THREAD_LOCAL
Definition: platform.h:246
static struct GNUNET_TIME_Relative delta
Definition: speedup.c:35
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.
Time for timestamps used by GNUnet, in seconds and in network byte order.
struct GNUNET_TIME_AbsoluteNBO abs_time_nbo
The actual value.
Rounded time for timestamps used by GNUnet, in seconds.
struct GNUNET_TIME_Absolute abs_time
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:503
static time_t my_timegm(struct tm *tm)
As suggested in the timegm() man page.
Definition: time.c:778
void __attribute__((destructor))
Destructor.
Definition: time.c:983