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 
63 {
64  struct GNUNET_TIME_Timestamp ts;
65 
68  ts.abs_time.abs_value_us = at.abs_value_us - at.abs_value_us % 1000000;
69  return ts;
70 }
71 
72 
75 {
76  struct GNUNET_TIME_TimestampNBO tn;
77 
79  return tn;
80 }
81 
82 
85 {
86  struct GNUNET_TIME_Timestamp t;
87 
88  t.abs_time = GNUNET_TIME_absolute_ntoh (tn.abs_time_nbo);
89  return t;
90 }
91 
92 
95 {
97  struct timeval tv;
98 
99  gettimeofday (&tv, NULL);
100  ret.abs_value_us = (uint64_t) (((uint64_t) tv.tv_sec * 1000LL * 1000LL)
101  + ((uint64_t) tv.tv_usec))
103  return ret;
104 }
105 
106 
109 {
112 }
113 
114 
117 {
118  static struct GNUNET_TIME_Relative zero;
119 
120  return zero;
121 }
122 
123 
126 {
127  static struct GNUNET_TIME_Absolute zero;
128 
129  return zero;
130 }
131 
132 
135 {
136  static struct GNUNET_TIME_Relative one = { 1 };
137 
138  return one;
139 }
140 
141 
144 {
145  static struct GNUNET_TIME_Relative one = { 1000 };
146 
147  return one;
148 }
149 
150 
153 {
154  static struct GNUNET_TIME_Relative one = { 1000 * 1000LL };
155 
156  return one;
157 }
158 
159 
162 {
163  static struct GNUNET_TIME_Relative one = { 60 * 1000 * 1000LL };
164 
165  return one;
166 }
167 
168 
171 {
172  static struct GNUNET_TIME_Relative one = { 60 * 60 * 1000 * 1000LL };
173 
174  return one;
175 }
176 
177 
180 {
181  static struct GNUNET_TIME_Relative forever = { UINT64_MAX };
182 
183  return forever;
184 }
185 
186 
189 {
190  static struct GNUNET_TIME_Absolute forever = { UINT64_MAX };
191 
192  return forever;
193 }
194 
195 
196 const char *
198 {
199  static GNUNET_THREAD_LOCAL char buf[255];
200  time_t tt;
201  struct tm *tp;
202 
204  return "end of time";
205  tt = ts.abs_time.abs_value_us / 1000LL / 1000LL;
206  tp = localtime (&tt);
207  /* This is hacky, but i don't know a way to detect libc character encoding.
208  * Just expect utf8 from glibc these days.
209  * As for msvcrt, use the wide variant, which always returns utf16
210  * (otherwise we'd have to detect current codepage or use W32API character
211  * set conversion routines to convert to UTF8).
212  */
213  strftime (buf,
214  sizeof(buf),
215  "%a %b %d %H:%M:%S %Y",
216  tp);
217  return buf;
218 }
219 
220 
221 const char *
223 {
224  static GNUNET_THREAD_LOCAL char buf[255];
225  time_t tt;
226  struct tm *tp;
227 
229  return "end of time";
230  tt = t.abs_value_us / 1000LL / 1000LL;
231  tp = localtime (&tt);
232  /* This is hacky, but i don't know a way to detect libc character encoding.
233  * Just expect utf8 from glibc these days.
234  * As for msvcrt, use the wide variant, which always returns utf16
235  * (otherwise we'd have to detect current codepage or use W32API character
236  * set conversion routines to convert to UTF8).
237  */
238  strftime (buf,
239  sizeof(buf),
240  "%a %b %d %H:%M:%S %Y",
241  tp);
242  return buf;
243 }
244 
245 
246 const char *
248  bool do_round)
249 {
250  static GNUNET_THREAD_LOCAL char buf[128];
251  const char *unit = /* time unit */ "┬Ás";
252  uint64_t dval = delta.rel_value_us;
253 
255  return "forever";
256  if (0 == delta.rel_value_us)
257  return "0 ms";
258  if ( ((GNUNET_YES == do_round) &&
259  (dval > 5 * 1000)) ||
260  (0 == (dval % 1000)))
261  {
262  dval = dval / 1000;
263  unit = /* time unit */ "ms";
264  if (((GNUNET_YES == do_round) && (dval > 5 * 1000)) || (0 == (dval % 1000)))
265  {
266  dval = dval / 1000;
267  unit = /* time unit */ "s";
268  if (((GNUNET_YES == do_round) && (dval > 5 * 60)) || (0 == (dval % 60)))
269  {
270  dval = dval / 60;
271  unit = /* time unit */ "m";
272  if (((GNUNET_YES == do_round) && (dval > 5 * 60)) || (0 == (dval % 60)))
273  {
274  dval = dval / 60;
275  unit = /* time unit */ "h";
276  if (((GNUNET_YES == do_round) && (dval > 5 * 24)) ||
277  (0 == (dval % 24)))
278  {
279  dval = dval / 24;
280  if (1 == dval)
281  unit = /* time unit */ "day";
282  else
283  unit = /* time unit */ "days";
284  }
285  }
286  }
287  }
288  }
290  sizeof(buf),
291  "%llu %s",
292  (unsigned long long) dval,
293  unit);
294  return buf;
295 }
296 
297 
300 {
301  struct GNUNET_TIME_Absolute ret;
302 
306 
307  if (rel.rel_value_us + now.abs_value_us < rel.rel_value_us)
308  {
309  GNUNET_break (0); /* overflow... */
311  }
312  ret.abs_value_us = rel.rel_value_us + now.abs_value_us;
313  return ret;
314 }
315 
316 
319 {
322 }
323 
324 
327  struct GNUNET_TIME_Relative t2)
328 {
329  return (t1.rel_value_us < t2.rel_value_us) ? t1 : t2;
330 }
331 
332 
335  struct GNUNET_TIME_Relative t2)
336 {
337  return (t1.rel_value_us > t2.rel_value_us) ? t1 : t2;
338 }
339 
340 
343  struct GNUNET_TIME_Absolute t2)
344 {
345  return (t1.abs_value_us < t2.abs_value_us) ? t1 : t2;
346 }
347 
348 
351  struct GNUNET_TIME_Absolute t2)
352 {
353  return (t1.abs_value_us > t2.abs_value_us) ? t1 : t2;
354 }
355 
356 
359  struct GNUNET_TIME_Timestamp t2)
360 {
361  return (t1.abs_time.abs_value_us > t2.abs_time.abs_value_us) ? t1 : t2;
362 }
363 
364 
367  struct GNUNET_TIME_Timestamp t2)
368 {
369  return (t1.abs_time.abs_value_us < t2.abs_time.abs_value_us) ? t1 : t2;
370 }
371 
372 
375 {
376  struct GNUNET_TIME_Relative ret;
377 
378  if (GNUNET_TIME_absolute_is_never (future))
381 
382  if (now.abs_value_us > future.abs_value_us)
383  return GNUNET_TIME_UNIT_ZERO;
384  ret.rel_value_us = future.abs_value_us - now.abs_value_us;
385  return ret;
386 }
387 
388 
391  struct GNUNET_TIME_Absolute end)
392 {
393  struct GNUNET_TIME_Relative ret;
394 
397  if (end.abs_value_us < start.abs_value_us)
398  return GNUNET_TIME_UNIT_ZERO;
399  ret.rel_value_us = end.abs_value_us - start.abs_value_us;
400  return ret;
401 }
402 
403 
406 {
407  struct GNUNET_TIME_Absolute now;
408  struct GNUNET_TIME_Relative ret;
409 
410  now = GNUNET_TIME_absolute_get ();
411  if (whence.abs_value_us > now.abs_value_us)
412  return GNUNET_TIME_UNIT_ZERO;
413  ret.rel_value_us = now.abs_value_us - whence.abs_value_us;
414  return ret;
415 }
416 
417 
421 {
422  struct GNUNET_TIME_Absolute ret;
423 
427  if (start.abs_value_us + duration.rel_value_us < start.abs_value_us)
428  {
429  GNUNET_break (0);
431  }
432  ret.abs_value_us = start.abs_value_us + duration.rel_value_us;
433  return ret;
434 }
435 
436 
440 {
441  struct GNUNET_TIME_Absolute ret;
442 
443  if (start.abs_value_us <= duration.rel_value_us)
447  ret.abs_value_us = start.abs_value_us - duration.rel_value_us;
448  return ret;
449 }
450 
451 
454  unsigned long long factor)
455 {
456  struct GNUNET_TIME_Relative ret;
457 
458  if (0 == factor)
459  return GNUNET_TIME_UNIT_ZERO;
462  ret.rel_value_us = rel.rel_value_us * factor;
463  if (ret.rel_value_us / factor != rel.rel_value_us)
464  {
465  GNUNET_break (0);
467  }
468  return ret;
469 }
470 
471 
474  double factor)
475 {
476  struct GNUNET_TIME_Relative out;
477  double m;
478 
479  GNUNET_assert (0 <= factor);
480 
481  if (0 == factor)
482  return GNUNET_TIME_UNIT_ZERO;
485 
486  m = ((double) rel.rel_value_us) * factor;
487 
488  if (m >= (double) (GNUNET_TIME_UNIT_FOREVER_REL).rel_value_us)
489  {
490  GNUNET_break (0);
492  }
493 
494  out.rel_value_us = (uint64_t) m;
495  return out;
496 }
497 
498 
501  unsigned long long factor)
502 {
503  struct GNUNET_TIME_Relative ret;
504 
505  if (0 == factor)
506  return GNUNET_TIME_UNIT_ZERO;
509  ret.rel_value_us = rel.rel_value_us * factor;
510  if (ret.rel_value_us / factor != rel.rel_value_us)
511  {
513  }
514  return ret;
515 }
516 
517 
520  unsigned long long factor)
521 {
522  struct GNUNET_TIME_Relative ret;
523 
524  if ((0 == factor) ||
527  ret.rel_value_us = rel.rel_value_us / factor;
528  return ret;
529 }
530 
531 
534  uint64_t finished,
535  uint64_t total)
536 {
537  struct GNUNET_TIME_Relative due;
538  double exp;
539  struct GNUNET_TIME_Relative ret;
540 
541  GNUNET_break (finished <= total);
542  if (finished >= total)
543  return GNUNET_TIME_UNIT_ZERO;
544  if (0 == finished)
547  exp = ((double) due.rel_value_us) * ((double) total) / ((double) finished);
548  ret.rel_value_us = ((uint64_t) exp) - due.rel_value_us;
549  return ret;
550 }
551 
552 
555  struct GNUNET_TIME_Relative a2)
556 {
557  struct GNUNET_TIME_Relative ret;
558 
559  if ((a1.rel_value_us == UINT64_MAX) || (a2.rel_value_us == UINT64_MAX))
561  if (a1.rel_value_us + a2.rel_value_us < a1.rel_value_us)
562  {
563  GNUNET_break (0);
565  }
566  ret.rel_value_us = a1.rel_value_us + a2.rel_value_us;
567  return ret;
568 }
569 
570 
573  struct GNUNET_TIME_Relative a2)
574 {
575  struct GNUNET_TIME_Relative ret;
576 
577  if (a2.rel_value_us >= a1.rel_value_us)
578  return GNUNET_TIME_UNIT_ZERO;
579  if (a1.rel_value_us == UINT64_MAX)
581  ret.rel_value_us = a1.rel_value_us - a2.rel_value_us;
582  return ret;
583 }
584 
585 
588 {
590 
591  ret.rel_value_us__ = GNUNET_htonll (a.rel_value_us);
592  return ret;
593 }
594 
595 
598 {
599  struct GNUNET_TIME_Relative ret;
600 
601  ret.rel_value_us = GNUNET_ntohll (a.rel_value_us__);
602  return ret;
603 }
604 
605 
608 {
610 
611  ret.abs_value_us__ = GNUNET_htonll (a.abs_value_us);
612  return ret;
613 }
614 
615 
616 bool
618 {
619  return GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us == abs.abs_value_us;
620 }
621 
622 
623 bool
625 {
626  return GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == rel.rel_value_us;
627 }
628 
629 
630 bool
632 {
633  return 0 == rel.rel_value_us;
634 }
635 
636 
637 bool
639 {
640  struct GNUNET_TIME_Absolute now;
641 
642  now = GNUNET_TIME_absolute_get ();
643  return abs.abs_value_us < now.abs_value_us;
644 }
645 
646 
647 bool
649 {
650  struct GNUNET_TIME_Absolute now;
651 
652  now = GNUNET_TIME_absolute_get ();
653  return abs.abs_value_us > now.abs_value_us;
654 }
655 
656 
658 GNUNET_TIME_absolute_from_ms (uint64_t ms_after_epoch)
659 {
660  struct GNUNET_TIME_Absolute ret;
661 
662  ret.abs_value_us = GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us
663  * ms_after_epoch;
664  if (ret.abs_value_us / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us !=
665  ms_after_epoch)
667  return ret;
668 }
669 
670 
672 GNUNET_TIME_absolute_from_s (uint64_t s_after_epoch)
673 {
674  struct GNUNET_TIME_Absolute ret;
675 
676  ret.abs_value_us = GNUNET_TIME_UNIT_SECONDS.rel_value_us * s_after_epoch;
677  if (ret.abs_value_us / GNUNET_TIME_UNIT_SECONDS.rel_value_us !=
678  s_after_epoch)
680  return ret;
681 }
682 
683 
685 GNUNET_TIME_timestamp_from_s (uint64_t s_after_epoch)
686 {
687  struct GNUNET_TIME_Timestamp ret;
688 
689  ret.abs_time.abs_value_us
690  = GNUNET_TIME_UNIT_SECONDS.rel_value_us * s_after_epoch;
691  if (ret.abs_time.abs_value_us / GNUNET_TIME_UNIT_SECONDS.rel_value_us
692  != s_after_epoch)
694  return ret;
695 }
696 
697 
700 {
701  struct GNUNET_TIME_Absolute ret;
702 
703  ret.abs_value_us = GNUNET_ntohll (a.abs_value_us__);
704  return ret;
705 }
706 
707 
708 unsigned int
710 {
711  time_t tp;
712  struct tm *t;
713 
714  tp = time (NULL);
715  t = gmtime (&tp);
716  if (t == NULL)
717  return 0;
718  return t->tm_year + 1900;
719 }
720 
721 
722 unsigned int
724 {
725  struct tm *t;
726  time_t tp;
727 
728  tp = at.abs_value_us / 1000LL / 1000LL; /* microseconds to seconds */
729  t = gmtime (&tp);
730  if (t == NULL)
731  return 0;
732  return t->tm_year + 1900;
733 }
734 
735 
736 #ifndef HAVE_TIMEGM
740 static time_t
741 my_timegm (struct tm *tm)
742 {
743  time_t ret;
744  char *tz;
745 
746  tz = getenv ("TZ");
747  setenv ("TZ", "", 1);
748  tzset ();
749  ret = mktime (tm);
750  if (tz)
751  setenv ("TZ", tz, 1);
752  else
753  unsetenv ("TZ");
754  tzset ();
755  return ret;
756 }
757 
758 
759 #endif
760 
761 
763 GNUNET_TIME_year_to_time (unsigned int year)
764 {
765  struct GNUNET_TIME_Absolute ret;
766  time_t tp;
767  struct tm t;
768 
769  memset (&t, 0, sizeof(t));
770  if (year < 1900)
771  {
772  GNUNET_break (0);
773  return GNUNET_TIME_absolute_get (); /* now */
774  }
775  t.tm_year = year - 1900;
776  t.tm_mday = 1;
777  t.tm_mon = 0;
778  t.tm_wday = 1;
779  t.tm_yday = 1;
780 #ifndef HAVE_TIMEGM
781  tp = my_timegm (&t);
782 #else
783  tp = timegm (&t);
784 #endif
785  GNUNET_break (tp != (time_t) -1);
786  ret.abs_value_us = tp * 1000LL * 1000LL; /* seconds to microseconds */
787  return ret;
788 }
789 
790 
794 {
795  double r = (rand () % 500) / 1000.0;
796  struct GNUNET_TIME_Relative t;
797 
800  2 + r);
802 }
803 
804 
805 bool
807 {
808  return 0 == abs.abs_value_us;
809 }
810 
811 
814 {
815  double d = ((rand () % 1001) + 500) / 1000.0;
816 
817  return relative_multiply_double (r, d);
818 }
819 
820 
823  const struct GNUNET_CONFIGURATION_Handle *cfg)
824 {
825  static const struct GNUNET_CONFIGURATION_Handle *last_cfg;
826  static struct GNUNET_TIME_Absolute last_time;
827  static struct GNUNET_DISK_MapHandle *map_handle;
828  static ATOMIC volatile uint64_t *map;
829  struct GNUNET_TIME_Absolute now;
830 
831  now = GNUNET_TIME_absolute_get ();
832  if (last_cfg != cfg)
833  {
834  char *filename;
835 
836  if (NULL != map_handle)
837  {
838  GNUNET_DISK_file_unmap (map_handle);
839  map_handle = NULL;
840  }
841  map = NULL;
842 
843  last_cfg = cfg;
844  if ((NULL != cfg) &&
845  (GNUNET_OK ==
847  "util",
848  "MONOTONIC_TIME_FILENAME",
849  &filename)))
850  {
851  struct GNUNET_DISK_FileHandle *fh;
852 
860  if (NULL == fh)
861  {
863  _ ("Failed to map `%s', cannot assure monotonic time!\n"),
864  filename);
865  }
866  else
867  {
868  off_t size;
869 
870  size = 0;
872  if (size < (off_t) sizeof(*map))
873  {
874  struct GNUNET_TIME_AbsoluteNBO o;
875 
876  o = GNUNET_TIME_absolute_hton (now);
877  if (sizeof(o) != GNUNET_DISK_file_write (fh, &o, sizeof(o)))
878  size = 0;
879  else
880  size = sizeof(o);
881  }
882  if (size == sizeof(*map))
883  {
885  &map_handle,
887  sizeof(*map));
888  if (NULL == map)
890  _ (
891  "Failed to map `%s', cannot assure monotonic time!\n"),
892  filename);
893  }
894  else
895  {
896  GNUNET_log (
898  _ (
899  "Failed to setup monotonic time file `%s', cannot assure monotonic time!\n"),
900  filename);
901  }
902  }
905  }
906  }
907  if (NULL != map)
908  {
909  struct GNUNET_TIME_AbsoluteNBO mt;
910 
911 #if __STDC_NO_ATOMICS__
912 #if __GNUC__
913  mt.abs_value_us__ = __sync_fetch_and_or (map, 0);
914 #else
915  mt.abs_value_us__ = *map; /* godspeed, pray this is atomic */
916 #endif
917 #else
918  mt.abs_value_us__ = atomic_load (map);
919 #endif
920  last_time =
922  }
923  if (now.abs_value_us <= last_time.abs_value_us)
924  now.abs_value_us = last_time.abs_value_us + 1;
925  last_time = now;
926  if (NULL != map)
927  {
928  uint64_t val = GNUNET_TIME_absolute_hton (now).abs_value_us__;
929 #if __STDC_NO_ATOMICS__
930 #if __GNUC__
931  (void) __sync_lock_test_and_set (map, val);
932 #else
933  *map = val; /* godspeed, pray this is atomic */
934 #endif
935 #else
936  atomic_store (map, val);
937 #endif
938  }
939  return now;
940 }
941 
942 
946 void __attribute__ ((destructor))
947 GNUNET_util_time_fini ()
948 {
950 }
951 
952 
953 /* 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.
#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_YES
Definition: gnunet_common.h:97
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
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:763
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:326
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_zero_()
Return relative time of 0ms.
Definition: time.c:116
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_hour_()
Return relative time of 1 hour.
Definition: time.c:170
#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:672
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition: time.c:597
bool GNUNET_TIME_absolute_is_future(struct GNUNET_TIME_Absolute abs)
Test if abs is truly in the future (excluding now).
Definition: time.c:648
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_millisecond_()
Return relative time of 1ms.
Definition: time.c:143
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:405
const char * GNUNET_TIME_absolute2s(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: time.c:222
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:500
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:334
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_minute_()
Return relative time of 1 minute.
Definition: time.c:161
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:366
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_zero_()
Return absolute time of 0ms.
Definition: time.c:125
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:318
#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:685
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:374
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:350
unsigned int GNUNET_TIME_get_current_year()
Return the current year (e.g.
Definition: time.c:709
bool GNUNET_TIME_absolute_is_zero(struct GNUNET_TIME_Absolute abs)
Test if abs is truly zero.
Definition: time.c:806
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:658
bool GNUNET_TIME_relative_is_zero(struct GNUNET_TIME_Relative rel)
Test if rel is zero.
Definition: time.c:631
bool GNUNET_TIME_absolute_is_never(struct GNUNET_TIME_Absolute abs)
Test if abs is never.
Definition: time.c:617
#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:792
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:572
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_forever_()
Return "forever".
Definition: time.c:188
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get()
Get the current time.
Definition: time.c:94
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_forever_()
Return "forever".
Definition: time.c:179
struct GNUNET_TIME_Timestamp GNUNET_TIME_timestamp_get()
Get timestamp representing the current time.
Definition: time.c:108
bool GNUNET_TIME_relative_is_forever(struct GNUNET_TIME_Relative rel)
Test if rel is forever.
Definition: time.c:624
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:699
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:554
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:813
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:438
unsigned int GNUNET_TIME_time_to_year(struct GNUNET_TIME_Absolute at)
Convert an expiration time to the respective year (rounds)
Definition: time.c:723
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_second_()
Return relative time of 1s.
Definition: time.c:152
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_unit_()
Return relative time of 1 microsecond.
Definition: time.c:134
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:299
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:453
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:342
#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:587
#define GNUNET_TIME_UNIT_FOREVER_TS
Constant used to specify "forever".
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:419
const char * GNUNET_TIME_timestamp2s(struct GNUNET_TIME_Timestamp ts)
Convert ts to human-readable timestamp.
Definition: time.c:197
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:358
#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:822
struct GNUNET_TIME_TimestampNBO GNUNET_TIME_timestamp_hton(struct GNUNET_TIME_Timestamp t)
Convert timestamp to network byte order.
Definition: time.c:74
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:519
const char * GNUNET_TIME_relative2s(struct GNUNET_TIME_Relative delta, bool do_round)
Give relative time in human-readable fancy format.
Definition: time.c:247
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:390
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:607
bool GNUNET_TIME_absolute_is_past(struct GNUNET_TIME_Absolute abs)
Test if abs is truly in the past (excluding now).
Definition: time.c:638
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:533
struct GNUNET_TIME_Timestamp GNUNET_TIME_timestamp_ntoh(struct GNUNET_TIME_TimestampNBO tn)
Convert timestamp from network byte order.
Definition: time.c:84
#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:62
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:473
static time_t my_timegm(struct tm *tm)
As suggested in the timegm() man page.
Definition: time.c:741
void __attribute__((destructor))
Destructor.
Definition: time.c:946