GNUnet 0.22.2
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
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#if __STDC_NO_ATOMICS__
30#define ATOMIC
31#else
32#ifdef HAVE_STDATOMIC_H
33#include <stdatomic.h>
34#define ATOMIC _Atomic
35#else
36#define __STDC_NO_ATOMICS__ 1
37#define ATOMIC
38#endif
39#endif
40
41#define LOG(kind, ...) GNUNET_log_from (kind, "util-time", __VA_ARGS__)
42
46static long long timestamp_offset;
47
48void
49GNUNET_TIME_set_offset (long long offset)
50{
51 timestamp_offset = offset;
52}
53
54
55long long
57{
58 return timestamp_offset;
59}
60
61
62bool
64 struct GNUNET_TIME_Absolute a2,
66{
68
73 <=,
74 t);
75}
76
77
80{
81 struct GNUNET_TIME_Timestamp ts;
82
85 ts.abs_time.abs_value_us = at.abs_value_us - at.abs_value_us % 1000000;
86 return ts;
87}
88
89
92{
94
96 return tn;
97}
98
99
102{
104
105 t.abs_time = GNUNET_TIME_absolute_ntoh (tn.abs_time_nbo);
106 return t;
107}
108
109
112{
114 struct timeval tv;
115
116 gettimeofday (&tv, NULL);
117 ret.abs_value_us = (uint64_t) (((uint64_t) tv.tv_sec * 1000LL * 1000LL)
118 + ((uint64_t) tv.tv_usec))
120 return ret;
121}
122
123
126{
129}
130
131
134{
135 static struct GNUNET_TIME_Relative zero;
136
137 return zero;
138}
139
140
143{
144 static struct GNUNET_TIME_Absolute zero;
145
146 return zero;
147}
148
149
152{
153 static struct GNUNET_TIME_Relative one = { 1 };
154
155 return one;
156}
157
158
161{
162 static struct GNUNET_TIME_Relative one = { 1000 };
163
164 return one;
165}
166
167
170{
171 static struct GNUNET_TIME_Relative one = { 1000 * 1000LL };
172
173 return one;
174}
175
176
179{
180 static struct GNUNET_TIME_Relative one = { 60 * 1000 * 1000LL };
181
182 return one;
183}
184
185
188{
189 static struct GNUNET_TIME_Relative one = { 60 * 60 * 1000 * 1000LL };
190
191 return one;
192}
193
194
197{
198 static struct GNUNET_TIME_Relative forever = { UINT64_MAX };
199
200 return forever;
201}
202
203
206{
207 static struct GNUNET_TIME_Absolute forever = { UINT64_MAX };
208
209 return forever;
210}
211
212
213const char *
215{
216 static GNUNET_THREAD_LOCAL char buf[255];
217 time_t tt;
218 struct tm *tp;
219
221 return "never";
222 tt = ts.abs_time.abs_value_us / 1000LL / 1000LL;
223 tp = localtime (&tt);
224 /* This is hacky, but i don't know a way to detect libc character encoding.
225 * Just expect utf8 from glibc these days.
226 * As for msvcrt, use the wide variant, which always returns utf16
227 * (otherwise we'd have to detect current codepage or use W32API character
228 * set conversion routines to convert to UTF8).
229 */
230 strftime (buf,
231 sizeof(buf),
232 "%a %b %d %H:%M:%S %Y",
233 tp);
234 return buf;
235}
236
237
238const char *
240{
241 static GNUNET_THREAD_LOCAL char buf[255];
242 time_t tt;
243 struct tm *tp;
244
246 return "never";
247 tt = t.abs_value_us / 1000LL / 1000LL;
248 tp = localtime (&tt);
249 /* This is hacky, but i don't know a way to detect libc character encoding.
250 * Just expect utf8 from glibc these days.
251 * As for msvcrt, use the wide variant, which always returns utf16
252 * (otherwise we'd have to detect current codepage or use W32API character
253 * set conversion routines to convert to UTF8).
254 */
255 strftime (buf,
256 sizeof(buf),
257 "%a %b %d %H:%M:%S %Y",
258 tp);
259 return buf;
260}
261
262
263const char *
265 bool do_round)
266{
267 static GNUNET_THREAD_LOCAL char buf[128];
268 const char *unit = /* time unit */ "µs";
269 uint64_t dval = delta.rel_value_us;
270
272 return "forever";
273 if (0 == delta.rel_value_us)
274 return "0 ms";
275 if ( ((GNUNET_YES == do_round) &&
276 (dval > 5 * 1000)) ||
277 (0 == (dval % 1000)))
278 {
279 dval = dval / 1000;
280 unit = /* time unit */ "ms";
281 if (((GNUNET_YES == do_round) && (dval > 5 * 1000)) || (0 == (dval % 1000)))
282 {
283 dval = dval / 1000;
284 unit = /* time unit */ "s";
285 if (((GNUNET_YES == do_round) && (dval > 5 * 60)) || (0 == (dval % 60)))
286 {
287 dval = dval / 60;
288 unit = /* time unit */ "m";
289 if (((GNUNET_YES == do_round) && (dval > 5 * 60)) || (0 == (dval % 60)))
290 {
291 dval = dval / 60;
292 unit = /* time unit */ "h";
293 if (((GNUNET_YES == do_round) && (dval > 5 * 24)) ||
294 (0 == (dval % 24)))
295 {
296 dval = dval / 24;
297 if (1 == dval)
298 unit = /* time unit */ "day";
299 else
300 unit = /* time unit */ "days";
301 }
302 }
303 }
304 }
305 }
306 GNUNET_snprintf (buf,
307 sizeof(buf),
308 "%llu %s",
309 (unsigned long long) dval,
310 unit);
311 return buf;
312}
313
314
317{
319 struct GNUNET_TIME_Absolute now;
320
324
325 if (rel.rel_value_us + now.abs_value_us < rel.rel_value_us)
326 {
327 GNUNET_break (0); /* overflow... */
329 }
330 ret.abs_value_us = rel.rel_value_us + now.abs_value_us;
331 return ret;
332}
333
334
337{
340}
341
342
345 struct GNUNET_TIME_Relative t2)
346{
347 return (t1.rel_value_us < t2.rel_value_us) ? t1 : t2;
348}
349
350
353 struct GNUNET_TIME_Relative t2)
354{
355 return (t1.rel_value_us > t2.rel_value_us) ? t1 : t2;
356}
357
358
361 struct GNUNET_TIME_Absolute t2)
362{
363 return (t1.abs_value_us < t2.abs_value_us) ? t1 : t2;
364}
365
366
369 struct GNUNET_TIME_Absolute t2)
370{
371 return (t1.abs_value_us > t2.abs_value_us) ? t1 : t2;
372}
373
374
377 struct GNUNET_TIME_Timestamp t2)
378{
379 return (t1.abs_time.abs_value_us > t2.abs_time.abs_value_us) ? t1 : t2;
380}
381
382
385 struct GNUNET_TIME_Timestamp t2)
386{
387 return (t1.abs_time.abs_value_us < t2.abs_time.abs_value_us) ? t1 : t2;
388}
389
390
393 struct GNUNET_TIME_Relative rt)
394{
396
398 ret.abs_value_us
399 = at.abs_value_us
400 - at.abs_value_us % rt.rel_value_us;
401 return ret;
402}
403
404
407{
409 struct GNUNET_TIME_Absolute now;
410
414
415 if (now.abs_value_us > future.abs_value_us)
417 ret.rel_value_us = future.abs_value_us - now.abs_value_us;
418 return ret;
419}
420
421
425{
427
430 if (end.abs_value_us < start.abs_value_us)
432 ret.rel_value_us = end.abs_value_us - start.abs_value_us;
433 return ret;
434}
435
436
439{
440 struct GNUNET_TIME_Absolute now;
442
444 if (whence.abs_value_us > now.abs_value_us)
446 ret.rel_value_us = now.abs_value_us - whence.abs_value_us;
447 return ret;
448}
449
450
454{
456
460 if (start.abs_value_us + duration.rel_value_us < start.abs_value_us)
461 {
462 GNUNET_break (0);
464 }
465 ret.abs_value_us = start.abs_value_us + duration.rel_value_us;
466 return ret;
467}
468
469
473{
475
476 if (start.abs_value_us <= duration.rel_value_us)
480 ret.abs_value_us = start.abs_value_us - duration.rel_value_us;
481 return ret;
482}
483
484
487 unsigned long long factor)
488{
490
491 if (0 == factor)
495 ret.rel_value_us = rel.rel_value_us * factor;
496 if (ret.rel_value_us / factor != rel.rel_value_us)
497 {
498 GNUNET_break (0);
500 }
501 return ret;
502}
503
504
507 double factor)
508{
509 struct GNUNET_TIME_Relative out;
510 double m;
511
512 GNUNET_assert (0 <= factor);
513
514 if (0 == factor)
518
519 m = ((double) rel.rel_value_us) * factor;
520
522 {
523 GNUNET_break (0);
525 }
526
527 out.rel_value_us = (uint64_t) m;
528 return out;
529}
530
531
534 unsigned long long factor)
535{
537
538 if (0 == factor)
542 ret.rel_value_us = rel.rel_value_us * factor;
543 if (ret.rel_value_us / factor != rel.rel_value_us)
544 {
546 }
547 return ret;
548}
549
550
553 unsigned long long factor)
554{
556
557 if ((0 == factor) ||
560 ret.rel_value_us = rel.rel_value_us / factor;
561 return ret;
562}
563
564
567 uint64_t finished,
568 uint64_t total)
569{
570 struct GNUNET_TIME_Relative due;
571 double exp;
573
574 GNUNET_break (finished <= total);
575 if (finished >= total)
577 if (0 == finished)
580 exp = ((double) due.rel_value_us) * ((double) total) / ((double) finished);
581 ret.rel_value_us = ((uint64_t) exp) - due.rel_value_us;
582 return ret;
583}
584
585
588 struct GNUNET_TIME_Relative a2)
589{
591
592 if ((a1.rel_value_us == UINT64_MAX) || (a2.rel_value_us == UINT64_MAX))
594 if (a1.rel_value_us + a2.rel_value_us < a1.rel_value_us)
595 {
596 GNUNET_break (0);
598 }
599 ret.rel_value_us = a1.rel_value_us + a2.rel_value_us;
600 return ret;
601}
602
603
606 struct GNUNET_TIME_Relative a2)
607{
609
610 if (a2.rel_value_us >= a1.rel_value_us)
612 if (a1.rel_value_us == UINT64_MAX)
614 ret.rel_value_us = a1.rel_value_us - a2.rel_value_us;
615 return ret;
616}
617
618
621{
623
624 ret.rel_value_us__ = GNUNET_htonll (a.rel_value_us);
625 return ret;
626}
627
628
631{
633
634 ret.rel_value_us = GNUNET_ntohll (a.rel_value_us__);
635 return ret;
636}
637
638
641{
643
644 ret.abs_value_us__ = GNUNET_htonll (a.abs_value_us);
645 return ret;
646}
647
648
649bool
651{
652 return GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us == abs.abs_value_us;
653}
654
655
656bool
658{
659 return GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == rel.rel_value_us;
660}
661
662
663bool
665{
666 return 0 == rel.rel_value_us;
667}
668
669
670bool
672{
673 struct GNUNET_TIME_Absolute now;
674
676 return abs.abs_value_us < now.abs_value_us;
677}
678
679
680bool
682{
683 struct GNUNET_TIME_Absolute now;
684
686 return abs.abs_value_us > now.abs_value_us;
687}
688
689
691GNUNET_TIME_absolute_from_ms (uint64_t ms_after_epoch)
692{
694
695 ret.abs_value_us = GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us
696 * ms_after_epoch;
697 if (ret.abs_value_us / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us !=
698 ms_after_epoch)
700 return ret;
701}
702
703
705GNUNET_TIME_absolute_from_s (uint64_t s_after_epoch)
706{
708
709 ret.abs_value_us = GNUNET_TIME_UNIT_SECONDS.rel_value_us * s_after_epoch;
710 if (ret.abs_value_us / GNUNET_TIME_UNIT_SECONDS.rel_value_us !=
711 s_after_epoch)
713 return ret;
714}
715
716
718GNUNET_TIME_timestamp_from_s (uint64_t s_after_epoch)
719{
721
722 ret.abs_time.abs_value_us
723 = GNUNET_TIME_UNIT_SECONDS.rel_value_us * s_after_epoch;
724 if (ret.abs_time.abs_value_us / GNUNET_TIME_UNIT_SECONDS.rel_value_us
725 != s_after_epoch)
727 return ret;
728}
729
730
731uint64_t
733{
735 return UINT64_MAX;
736 return ts.abs_time.abs_value_us / GNUNET_TIME_UNIT_SECONDS.rel_value_us;
737}
738
739
742{
744
745 ret.abs_value_us = GNUNET_ntohll (a.abs_value_us__);
746 return ret;
747}
748
749
750unsigned int
752{
753 time_t tp;
754 struct tm *t;
755
756 tp = time (NULL);
757 t = gmtime (&tp);
758 if (t == NULL)
759 return 0;
760 return t->tm_year + 1900;
761}
762
763
764unsigned int
766{
767 struct tm *t;
768 time_t tp;
769
770 tp = at.abs_value_us / 1000LL / 1000LL; /* microseconds to seconds */
771 t = gmtime (&tp);
772 if (t == NULL)
773 return 0;
774 return t->tm_year + 1900;
775}
776
777
778#ifndef HAVE_TIMEGM
782static time_t
783my_timegm (struct tm *tm)
784{
785 time_t ret;
786 char *tz;
787
788 tz = getenv ("TZ");
789 setenv ("TZ", "", 1);
790 tzset ();
791 ret = mktime (tm);
792 if (tz)
793 setenv ("TZ", tz, 1);
794 else
795 unsetenv ("TZ");
796 tzset ();
797 return ret;
798}
799
800
801#endif
802
803
806{
808 time_t tp;
809 struct tm t;
810
811 memset (&t, 0, sizeof(t));
812 if (year < 1900)
813 {
814 GNUNET_break (0);
815 return GNUNET_TIME_absolute_get (); /* now */
816 }
817 t.tm_year = year - 1900;
818 t.tm_mday = 1;
819 t.tm_mon = 0;
820 t.tm_wday = 1;
821 t.tm_yday = 1;
822#ifndef HAVE_TIMEGM
823 tp = my_timegm (&t);
824#else
825 tp = timegm (&t);
826#endif
827 GNUNET_break (tp != (time_t) -1);
828 ret.abs_value_us = tp * 1000LL * 1000LL; /* seconds to microseconds */
829 return ret;
830}
831
832
835 struct GNUNET_TIME_Relative threshold)
836{
837 double r = (rand () % 500) / 1000.0;
838 struct GNUNET_TIME_Relative t;
839
842 2 + r);
843 return GNUNET_TIME_relative_min (threshold, t);
844}
845
846
847bool
849{
850 return 0 == abs.abs_value_us;
851}
852
853
856{
857 double d = ((rand () % 1001) + 500) / 1000.0;
858
860}
861
862
865 const struct GNUNET_CONFIGURATION_Handle *cfg)
866{
867 static const struct GNUNET_CONFIGURATION_Handle *last_cfg;
868 static struct GNUNET_TIME_Absolute last_time;
869 static struct GNUNET_DISK_MapHandle *map_handle;
870 static ATOMIC volatile uint64_t *map;
871 struct GNUNET_TIME_Absolute now;
872
874 if (last_cfg != cfg)
875 {
876 char *filename;
877
878 if (NULL != map_handle)
879 {
880 GNUNET_DISK_file_unmap (map_handle);
881 map_handle = NULL;
882 }
883 map = NULL;
884
885 last_cfg = cfg;
886 if ((NULL != cfg) &&
887 (GNUNET_OK ==
889 "util",
890 "MONOTONIC_TIME_FILENAME",
891 &filename)))
892 {
893 struct GNUNET_DISK_FileHandle *fh;
894
902 if (NULL == fh)
903 {
905 _ ("Failed to map `%s', cannot assure monotonic time!\n"),
906 filename);
907 }
908 else
909 {
910 off_t size;
911
912 size = 0;
914 if (size < (off_t) sizeof(*map))
915 {
917
919 if (sizeof(o) != GNUNET_DISK_file_write (fh, &o, sizeof(o)))
920 size = 0;
921 else
922 size = sizeof(o);
923 }
924 if (size == sizeof(*map))
925 {
927 &map_handle,
929 sizeof(*map));
930 if (NULL == map)
932 _ (
933 "Failed to map `%s', cannot assure monotonic time!\n")
934 ,
935 filename);
936 }
937 else
938 {
939 GNUNET_log (
941 _ (
942 "Failed to setup monotonic time file `%s', cannot assure monotonic time!\n"),
943 filename);
944 }
945 }
948 }
949 }
950 if (NULL != map)
951 {
952 struct GNUNET_TIME_AbsoluteNBO mt;
953
954#if __STDC_NO_ATOMICS__
955#if __GNUC__
956 mt.abs_value_us__ = __sync_fetch_and_or (map, 0);
957#else
958 mt.abs_value_us__ = *map; /* godspeed, pray this is atomic */
959#endif
960#else
961 mt.abs_value_us__ = atomic_load (map);
962#endif
963 last_time =
965 }
966 if (now.abs_value_us <= last_time.abs_value_us)
967 now.abs_value_us = last_time.abs_value_us + 1;
968 last_time = now;
969 if (NULL != map)
970 {
971 uint64_t val = GNUNET_TIME_absolute_hton (now).abs_value_us__;
972#if __STDC_NO_ATOMICS__
973#if __GNUC__
974 (void) __sync_lock_test_and_set (map, val);
975#else
976 *map = val; /* godspeed, pray this is atomic */
977#endif
978#else
979 atomic_store (map, val);
980#endif
981 }
982 return now;
983}
984
985
986void
988
992void __attribute__ ((destructor))
994{
996}
997
998
999/* end of time.c */
static mp_limb_t d[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
char * getenv()
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:103
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:38
static int ret
Final status code.
Definition: gnunet-arm.c:93
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:33
static bool finished
Set to true once we are finished and should exit after sending our final message to the parent.
static struct GNUNET_SCHEDULER_Task * tt
Task scheduled to handle timeout.
static char * filename
static const struct GNUNET_CRYPTO_PrivateKey zero
Public key of all zeros.
static void do_round(void *cls)
Send out PUSHes and PULLs, possibly update #view, samplers.
static struct GNUNET_TIME_Relative duration
Option '-d': duration of the mapping.
Definition: gnunet-vpn.c:90
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:1215
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:682
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1289
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:1361
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:1392
@ 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:54
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:37
@ GNUNET_OK
@ 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:805
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:344
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_zero_()
Return relative time of 0ms.
Definition: time.c:133
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_hour_()
Return relative time of 1 hour.
Definition: time.c:187
const char * GNUNET_TIME_relative2s(struct GNUNET_TIME_Relative delta, bool do_round)
Give relative time in human-readable fancy format.
Definition: time.c:264
#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:705
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition: time.c:630
bool GNUNET_TIME_absolute_is_future(struct GNUNET_TIME_Absolute abs)
Test if abs is truly in the future (excluding now).
Definition: time.c:681
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_millisecond_()
Return relative time of 1ms.
Definition: time.c:160
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:438
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:533
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:352
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_minute_()
Return relative time of 1 minute.
Definition: time.c:178
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:384
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_zero_()
Return absolute time of 0ms.
Definition: time.c:142
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:336
#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:718
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:406
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:368
unsigned int GNUNET_TIME_get_current_year()
Return the current year (e.g.
Definition: time.c:751
bool GNUNET_TIME_absolute_is_zero(struct GNUNET_TIME_Absolute abs)
Test if abs is truly zero.
Definition: time.c:848
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:691
bool GNUNET_TIME_relative_is_zero(struct GNUNET_TIME_Relative rel)
Test if rel is zero.
Definition: time.c:664
bool GNUNET_TIME_absolute_is_never(struct GNUNET_TIME_Absolute abs)
Test if abs is never.
Definition: time.c:650
#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:834
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:605
const char * GNUNET_TIME_absolute2s(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: time.c:239
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_forever_()
Return "forever".
Definition: time.c:205
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get()
Get the current time.
Definition: time.c:111
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_forever_()
Return "forever".
Definition: time.c:196
struct GNUNET_TIME_Timestamp GNUNET_TIME_timestamp_get()
Get timestamp representing the current time.
Definition: time.c:125
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:732
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply_double(struct GNUNET_TIME_Relative rel, double factor)
Multiply relative time by a given factor.
Definition: time.c:506
bool GNUNET_TIME_relative_is_forever(struct GNUNET_TIME_Relative rel)
Test if rel is forever.
Definition: time.c:657
long long GNUNET_TIME_get_offset()
Get the timestamp offset for this instance.
Definition: time.c:56
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:741
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:392
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:587
void GNUNET_TIME_set_offset(long long offset)
Set the timestamp offset for this instance.
Definition: time.c:49
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:855
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:471
unsigned int GNUNET_TIME_time_to_year(struct GNUNET_TIME_Absolute at)
Convert an expiration time to the respective year (rounds)
Definition: time.c:765
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_second_()
Return relative time of 1s.
Definition: time.c:169
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_unit_()
Return relative time of 1 microsecond.
Definition: time.c:151
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:316
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:486
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:360
#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:620
#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:63
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:452
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:376
#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:864
struct GNUNET_TIME_TimestampNBO GNUNET_TIME_timestamp_hton(struct GNUNET_TIME_Timestamp t)
Convert timestamp to network byte order.
Definition: time.c:91
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:552
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:423
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:640
bool GNUNET_TIME_absolute_is_past(struct GNUNET_TIME_Absolute abs)
Test if abs is truly in the past (excluding now).
Definition: time.c:671
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:566
struct GNUNET_TIME_Timestamp GNUNET_TIME_timestamp_ntoh(struct GNUNET_TIME_TimestampNBO tn)
Convert timestamp from network byte order.
Definition: time.c:101
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
const char * GNUNET_TIME_timestamp2s(struct GNUNET_TIME_Timestamp ts)
Convert ts to human-readable timestamp.
Definition: time.c:214
struct GNUNET_TIME_Timestamp GNUNET_TIME_absolute_to_timestamp(struct GNUNET_TIME_Absolute at)
Round an absolute time to a timestamp.
Definition: time.c:79
static struct GNUNET_CONTAINER_MultiPeerMap * map
Peermap of PeerIdentities to "struct PeerEntry" (for fast lookup).
Definition: peer.c:63
static unsigned int size
Size of the "table".
Definition: peer.c:68
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
#define GNUNET_THREAD_LOCAL
Definition: platform.h:247
static struct GNUNET_TIME_Relative delta
Definition: speedup.c:36
Handle used to access files (and pipes).
Handle for a memory-mapping operation.
Definition: disk.c:1342
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.
Time for timestamps used by GNUnet, in microseconds rounded to seconds.
struct GNUNET_TIME_Absolute abs_time
The actual value.
static long long timestamp_offset
Variable used to simulate clock skew.
Definition: time.c:46
#define ATOMIC
Definition: time.c:37
void GNUNET_util_time_fini(void)
static time_t my_timegm(struct tm *tm)
As suggested in the timegm() man page.
Definition: time.c:783
void __attribute__((destructor))
Destructor.
Definition: time.c:992