GNUnet 0.21.0
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 "end of time";
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 "end of time";
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
323
324 if (rel.rel_value_us + now.abs_value_us < rel.rel_value_us)
325 {
326 GNUNET_break (0); /* overflow... */
328 }
329 ret.abs_value_us = rel.rel_value_us + now.abs_value_us;
330 return ret;
331}
332
333
336{
339}
340
341
344 struct GNUNET_TIME_Relative t2)
345{
346 return (t1.rel_value_us < t2.rel_value_us) ? t1 : t2;
347}
348
349
352 struct GNUNET_TIME_Relative t2)
353{
354 return (t1.rel_value_us > t2.rel_value_us) ? t1 : t2;
355}
356
357
360 struct GNUNET_TIME_Absolute t2)
361{
362 return (t1.abs_value_us < t2.abs_value_us) ? t1 : t2;
363}
364
365
368 struct GNUNET_TIME_Absolute t2)
369{
370 return (t1.abs_value_us > t2.abs_value_us) ? t1 : t2;
371}
372
373
376 struct GNUNET_TIME_Timestamp t2)
377{
378 return (t1.abs_time.abs_value_us > t2.abs_time.abs_value_us) ? t1 : t2;
379}
380
381
384 struct GNUNET_TIME_Timestamp t2)
385{
386 return (t1.abs_time.abs_value_us < t2.abs_time.abs_value_us) ? t1 : t2;
387}
388
389
392 struct GNUNET_TIME_Relative rt)
393{
395
397 ret.abs_value_us
398 = at.abs_value_us
399 - at.abs_value_us % rt.rel_value_us;
400 return ret;
401}
402
403
406{
408
412
413 if (now.abs_value_us > future.abs_value_us)
415 ret.rel_value_us = future.abs_value_us - now.abs_value_us;
416 return ret;
417}
418
419
423{
425
428 if (end.abs_value_us < start.abs_value_us)
430 ret.rel_value_us = end.abs_value_us - start.abs_value_us;
431 return ret;
432}
433
434
437{
438 struct GNUNET_TIME_Absolute now;
440
442 if (whence.abs_value_us > now.abs_value_us)
444 ret.rel_value_us = now.abs_value_us - whence.abs_value_us;
445 return ret;
446}
447
448
452{
454
458 if (start.abs_value_us + duration.rel_value_us < start.abs_value_us)
459 {
460 GNUNET_break (0);
462 }
463 ret.abs_value_us = start.abs_value_us + duration.rel_value_us;
464 return ret;
465}
466
467
471{
473
474 if (start.abs_value_us <= duration.rel_value_us)
478 ret.abs_value_us = start.abs_value_us - duration.rel_value_us;
479 return ret;
480}
481
482
485 unsigned long long factor)
486{
488
489 if (0 == factor)
493 ret.rel_value_us = rel.rel_value_us * factor;
494 if (ret.rel_value_us / factor != rel.rel_value_us)
495 {
496 GNUNET_break (0);
498 }
499 return ret;
500}
501
502
505 double factor)
506{
507 struct GNUNET_TIME_Relative out;
508 double m;
509
510 GNUNET_assert (0 <= factor);
511
512 if (0 == factor)
516
517 m = ((double) rel.rel_value_us) * factor;
518
520 {
521 GNUNET_break (0);
523 }
524
525 out.rel_value_us = (uint64_t) m;
526 return out;
527}
528
529
532 unsigned long long factor)
533{
535
536 if (0 == factor)
540 ret.rel_value_us = rel.rel_value_us * factor;
541 if (ret.rel_value_us / factor != rel.rel_value_us)
542 {
544 }
545 return ret;
546}
547
548
551 unsigned long long factor)
552{
554
555 if ((0 == factor) ||
558 ret.rel_value_us = rel.rel_value_us / factor;
559 return ret;
560}
561
562
565 uint64_t finished,
566 uint64_t total)
567{
568 struct GNUNET_TIME_Relative due;
569 double exp;
571
572 GNUNET_break (finished <= total);
573 if (finished >= total)
575 if (0 == finished)
578 exp = ((double) due.rel_value_us) * ((double) total) / ((double) finished);
579 ret.rel_value_us = ((uint64_t) exp) - due.rel_value_us;
580 return ret;
581}
582
583
586 struct GNUNET_TIME_Relative a2)
587{
589
590 if ((a1.rel_value_us == UINT64_MAX) || (a2.rel_value_us == UINT64_MAX))
592 if (a1.rel_value_us + a2.rel_value_us < a1.rel_value_us)
593 {
594 GNUNET_break (0);
596 }
597 ret.rel_value_us = a1.rel_value_us + a2.rel_value_us;
598 return ret;
599}
600
601
604 struct GNUNET_TIME_Relative a2)
605{
607
608 if (a2.rel_value_us >= a1.rel_value_us)
610 if (a1.rel_value_us == UINT64_MAX)
612 ret.rel_value_us = a1.rel_value_us - a2.rel_value_us;
613 return ret;
614}
615
616
619{
621
622 ret.rel_value_us__ = GNUNET_htonll (a.rel_value_us);
623 return ret;
624}
625
626
629{
631
632 ret.rel_value_us = GNUNET_ntohll (a.rel_value_us__);
633 return ret;
634}
635
636
639{
641
642 ret.abs_value_us__ = GNUNET_htonll (a.abs_value_us);
643 return ret;
644}
645
646
647bool
649{
650 return GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us == abs.abs_value_us;
651}
652
653
654bool
656{
657 return GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == rel.rel_value_us;
658}
659
660
661bool
663{
664 return 0 == rel.rel_value_us;
665}
666
667
668bool
670{
671 struct GNUNET_TIME_Absolute now;
672
674 return abs.abs_value_us < now.abs_value_us;
675}
676
677
678bool
680{
681 struct GNUNET_TIME_Absolute now;
682
684 return abs.abs_value_us > now.abs_value_us;
685}
686
687
689GNUNET_TIME_absolute_from_ms (uint64_t ms_after_epoch)
690{
692
693 ret.abs_value_us = GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us
694 * ms_after_epoch;
695 if (ret.abs_value_us / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us !=
696 ms_after_epoch)
698 return ret;
699}
700
701
703GNUNET_TIME_absolute_from_s (uint64_t s_after_epoch)
704{
706
707 ret.abs_value_us = GNUNET_TIME_UNIT_SECONDS.rel_value_us * s_after_epoch;
708 if (ret.abs_value_us / GNUNET_TIME_UNIT_SECONDS.rel_value_us !=
709 s_after_epoch)
711 return ret;
712}
713
714
716GNUNET_TIME_timestamp_from_s (uint64_t s_after_epoch)
717{
719
720 ret.abs_time.abs_value_us
721 = GNUNET_TIME_UNIT_SECONDS.rel_value_us * s_after_epoch;
722 if (ret.abs_time.abs_value_us / GNUNET_TIME_UNIT_SECONDS.rel_value_us
723 != s_after_epoch)
725 return ret;
726}
727
728
729uint64_t
731{
732 return ts.abs_time.abs_value_us / GNUNET_TIME_UNIT_SECONDS.rel_value_us;
733}
734
735
738{
740
741 ret.abs_value_us = GNUNET_ntohll (a.abs_value_us__);
742 return ret;
743}
744
745
746unsigned int
748{
749 time_t tp;
750 struct tm *t;
751
752 tp = time (NULL);
753 t = gmtime (&tp);
754 if (t == NULL)
755 return 0;
756 return t->tm_year + 1900;
757}
758
759
760unsigned int
762{
763 struct tm *t;
764 time_t tp;
765
766 tp = at.abs_value_us / 1000LL / 1000LL; /* microseconds to seconds */
767 t = gmtime (&tp);
768 if (t == NULL)
769 return 0;
770 return t->tm_year + 1900;
771}
772
773
774#ifndef HAVE_TIMEGM
778static time_t
779my_timegm (struct tm *tm)
780{
781 time_t ret;
782 char *tz;
783
784 tz = getenv ("TZ");
785 setenv ("TZ", "", 1);
786 tzset ();
787 ret = mktime (tm);
788 if (tz)
789 setenv ("TZ", tz, 1);
790 else
791 unsetenv ("TZ");
792 tzset ();
793 return ret;
794}
795
796
797#endif
798
799
802{
804 time_t tp;
805 struct tm t;
806
807 memset (&t, 0, sizeof(t));
808 if (year < 1900)
809 {
810 GNUNET_break (0);
811 return GNUNET_TIME_absolute_get (); /* now */
812 }
813 t.tm_year = year - 1900;
814 t.tm_mday = 1;
815 t.tm_mon = 0;
816 t.tm_wday = 1;
817 t.tm_yday = 1;
818#ifndef HAVE_TIMEGM
819 tp = my_timegm (&t);
820#else
821 tp = timegm (&t);
822#endif
823 GNUNET_break (tp != (time_t) -1);
824 ret.abs_value_us = tp * 1000LL * 1000LL; /* seconds to microseconds */
825 return ret;
826}
827
828
831 struct GNUNET_TIME_Relative threshold)
832{
833 double r = (rand () % 500) / 1000.0;
834 struct GNUNET_TIME_Relative t;
835
838 2 + r);
839 return GNUNET_TIME_relative_min (threshold, t);
840}
841
842
843bool
845{
846 return 0 == abs.abs_value_us;
847}
848
849
852{
853 double d = ((rand () % 1001) + 500) / 1000.0;
854
856}
857
858
861 const struct GNUNET_CONFIGURATION_Handle *cfg)
862{
863 static const struct GNUNET_CONFIGURATION_Handle *last_cfg;
864 static struct GNUNET_TIME_Absolute last_time;
865 static struct GNUNET_DISK_MapHandle *map_handle;
866 static ATOMIC volatile uint64_t *map;
867 struct GNUNET_TIME_Absolute now;
868
870 if (last_cfg != cfg)
871 {
872 char *filename;
873
874 if (NULL != map_handle)
875 {
876 GNUNET_DISK_file_unmap (map_handle);
877 map_handle = NULL;
878 }
879 map = NULL;
880
881 last_cfg = cfg;
882 if ((NULL != cfg) &&
883 (GNUNET_OK ==
885 "util",
886 "MONOTONIC_TIME_FILENAME",
887 &filename)))
888 {
890
898 if (NULL == fh)
899 {
901 _ ("Failed to map `%s', cannot assure monotonic time!\n"),
902 filename);
903 }
904 else
905 {
906 off_t size;
907
908 size = 0;
910 if (size < (off_t) sizeof(*map))
911 {
913
915 if (sizeof(o) != GNUNET_DISK_file_write (fh, &o, sizeof(o)))
916 size = 0;
917 else
918 size = sizeof(o);
919 }
920 if (size == sizeof(*map))
921 {
923 &map_handle,
925 sizeof(*map));
926 if (NULL == map)
928 _ (
929 "Failed to map `%s', cannot assure monotonic time!\n"),
930 filename);
931 }
932 else
933 {
934 GNUNET_log (
936 _ (
937 "Failed to setup monotonic time file `%s', cannot assure monotonic time!\n"),
938 filename);
939 }
940 }
943 }
944 }
945 if (NULL != map)
946 {
947 struct GNUNET_TIME_AbsoluteNBO mt;
948
949#if __STDC_NO_ATOMICS__
950#if __GNUC__
951 mt.abs_value_us__ = __sync_fetch_and_or (map, 0);
952#else
953 mt.abs_value_us__ = *map; /* godspeed, pray this is atomic */
954#endif
955#else
956 mt.abs_value_us__ = atomic_load (map);
957#endif
958 last_time =
960 }
961 if (now.abs_value_us <= last_time.abs_value_us)
962 now.abs_value_us = last_time.abs_value_us + 1;
963 last_time = now;
964 if (NULL != map)
965 {
966 uint64_t val = GNUNET_TIME_absolute_hton (now).abs_value_us__;
967#if __STDC_NO_ATOMICS__
968#if __GNUC__
969 (void) __sync_lock_test_and_set (map, val);
970#else
971 *map = val; /* godspeed, pray this is atomic */
972#endif
973#else
974 atomic_store (map, val);
975#endif
976 }
977 return now;
978}
979
980
984void __attribute__ ((destructor))
985GNUNET_util_time_fini ()
986{
988}
989
990
991/* 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:104
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
static int ret
Final status code.
Definition: gnunet-arm.c:94
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
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_DISK_FileHandle * fh
File handle to STDIN, for reading restart/quit commands.
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:1237
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
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1308
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:1380
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:192
enum GNUNET_GenericReturnValue GNUNET_DISK_file_unmap(struct GNUNET_DISK_MapHandle *h)
Unmap a file.
Definition: disk.c:1411
@ 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:801
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:343
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:703
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition: time.c:628
bool GNUNET_TIME_absolute_is_future(struct GNUNET_TIME_Absolute abs)
Test if abs is truly in the future (excluding now).
Definition: time.c:679
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:436
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:531
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:351
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:383
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:335
#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:716
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:405
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:367
unsigned int GNUNET_TIME_get_current_year()
Return the current year (e.g.
Definition: time.c:747
bool GNUNET_TIME_absolute_is_zero(struct GNUNET_TIME_Absolute abs)
Test if abs is truly zero.
Definition: time.c:844
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:689
bool GNUNET_TIME_relative_is_zero(struct GNUNET_TIME_Relative rel)
Test if rel is zero.
Definition: time.c:662
bool GNUNET_TIME_absolute_is_never(struct GNUNET_TIME_Absolute abs)
Test if abs is never.
Definition: time.c:648
#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:830
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:603
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:730
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:504
bool GNUNET_TIME_relative_is_forever(struct GNUNET_TIME_Relative rel)
Test if rel is forever.
Definition: time.c:655
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:737
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:391
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:585
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:851
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:469
unsigned int GNUNET_TIME_time_to_year(struct GNUNET_TIME_Absolute at)
Convert an expiration time to the respective year (rounds)
Definition: time.c:761
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:484
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:359
#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:618
#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:450
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:375
#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:860
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:550
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:421
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:638
bool GNUNET_TIME_absolute_is_past(struct GNUNET_TIME_Absolute abs)
Test if abs is truly in the past (excluding now).
Definition: time.c:669
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:564
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:1361
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:46
#define ATOMIC
Definition: time.c:37
static time_t my_timegm(struct tm *tm)
As suggested in the timegm() man page.
Definition: time.c:779
void __attribute__((destructor))
Destructor.
Definition: time.c:984