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 
52 void
53 GNUNET_TIME_set_offset (long long offset)
54 {
55  timestamp_offset = offset;
56 }
57 
58 
64 long long
66 {
67  return timestamp_offset;
68 }
69 
70 
79 int
81 {
82  if (at->abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us)
83  return GNUNET_OK;
84  if (0 == at->abs_value_us % 1000000)
85  return GNUNET_OK;
86  at->abs_value_us -= at->abs_value_us % 1000000;
87  return GNUNET_NO;
88 }
89 
90 
99 int
101 {
102  if (rt->rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
103  return GNUNET_OK;
104  if (0 == rt->rel_value_us % 1000000)
105  return GNUNET_OK;
106  rt->rel_value_us -= rt->rel_value_us % 1000000;
107  return GNUNET_NO;
108 }
109 
110 
119 {
120  struct GNUNET_TIME_Absolute ret;
121  struct timeval tv;
122 
123  gettimeofday (&tv, NULL);
124  ret.abs_value_us = (uint64_t) (((uint64_t) tv.tv_sec * 1000LL * 1000LL)
125  + ((uint64_t) tv.tv_usec))
127  return ret;
128 }
129 
130 
136 {
137  static struct GNUNET_TIME_Relative zero;
138 
139  return zero;
140 }
141 
142 
148 {
149  static struct GNUNET_TIME_Absolute zero;
150 
151  return zero;
152 }
153 
154 
160 {
161  static struct GNUNET_TIME_Relative one = { 1 };
162 
163  return one;
164 }
165 
166 
172 {
173  static struct GNUNET_TIME_Relative one = { 1000 };
174 
175  return one;
176 }
177 
178 
184 {
185  static struct GNUNET_TIME_Relative one = { 1000 * 1000LL };
186 
187  return one;
188 }
189 
190 
196 {
197  static struct GNUNET_TIME_Relative one = { 60 * 1000 * 1000LL };
198 
199  return one;
200 }
201 
202 
208 {
209  static struct GNUNET_TIME_Relative one = { 60 * 60 * 1000 * 1000LL };
210 
211  return one;
212 }
213 
214 
220 {
221  static struct GNUNET_TIME_Relative forever = { UINT64_MAX };
222 
223  return forever;
224 }
225 
226 
232 {
233  static struct GNUNET_TIME_Absolute forever = { UINT64_MAX };
234 
235  return forever;
236 }
237 
238 
247 {
248  struct GNUNET_TIME_Absolute ret;
249 
250  if (rel.rel_value_us == UINT64_MAX)
253 
254  if (rel.rel_value_us + now.abs_value_us < rel.rel_value_us)
255  {
256  GNUNET_break (0); /* overflow... */
258  }
259  ret.abs_value_us = rel.rel_value_us + now.abs_value_us;
260  return ret;
261 }
262 
263 
273  struct GNUNET_TIME_Relative t2)
274 {
275  return (t1.rel_value_us < t2.rel_value_us) ? t1 : t2;
276 }
277 
278 
288  struct GNUNET_TIME_Relative t2)
289 {
290  return (t1.rel_value_us > t2.rel_value_us) ? t1 : t2;
291 }
292 
293 
303  struct GNUNET_TIME_Absolute t2)
304 {
305  return (t1.abs_value_us < t2.abs_value_us) ? t1 : t2;
306 }
307 
308 
318  struct GNUNET_TIME_Absolute t2)
319 {
320  return (t1.abs_value_us > t2.abs_value_us) ? t1 : t2;
321 }
322 
323 
332 {
333  struct GNUNET_TIME_Relative ret;
334 
335  if (future.abs_value_us == UINT64_MAX)
338 
339  if (now.abs_value_us > future.abs_value_us)
340  return GNUNET_TIME_UNIT_ZERO;
341  ret.rel_value_us = future.abs_value_us - now.abs_value_us;
342  return ret;
343 }
344 
345 
355  struct GNUNET_TIME_Absolute end)
356 {
357  struct GNUNET_TIME_Relative ret;
358 
359  if (end.abs_value_us == UINT64_MAX)
361  if (end.abs_value_us < start.abs_value_us)
362  return GNUNET_TIME_UNIT_ZERO;
363  ret.rel_value_us = end.abs_value_us - start.abs_value_us;
364  return ret;
365 }
366 
367 
376 {
377  struct GNUNET_TIME_Absolute now;
378  struct GNUNET_TIME_Relative ret;
379 
380  now = GNUNET_TIME_absolute_get ();
381  if (whence.abs_value_us > now.abs_value_us)
382  return GNUNET_TIME_UNIT_ZERO;
383  ret.rel_value_us = now.abs_value_us - whence.abs_value_us;
384  return ret;
385 }
386 
387 
397 {
398  struct GNUNET_TIME_Absolute ret;
399 
400  if ((start.abs_value_us == UINT64_MAX) ||
401  (duration.rel_value_us == UINT64_MAX))
403  if (start.abs_value_us + duration.rel_value_us < start.abs_value_us)
404  {
405  GNUNET_break (0);
407  }
408  ret.abs_value_us = start.abs_value_us + duration.rel_value_us;
409  return ret;
410 }
411 
412 
424 {
425  struct GNUNET_TIME_Absolute ret;
426 
427  if (start.abs_value_us <= duration.rel_value_us)
429  if (start.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us)
431  ret.abs_value_us = start.abs_value_us - duration.rel_value_us;
432  return ret;
433 }
434 
435 
443  unsigned long long factor)
444 {
445  struct GNUNET_TIME_Relative ret;
446 
447  if (0 == factor)
448  return GNUNET_TIME_UNIT_ZERO;
449  if (rel.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
451  ret.rel_value_us = rel.rel_value_us * factor;
452  if (ret.rel_value_us / factor != rel.rel_value_us)
453  {
454  GNUNET_break (0);
456  }
457  return ret;
458 }
459 
460 
469 {
470  struct GNUNET_TIME_Relative out;
471  double m;
472 
473  GNUNET_assert (0 <= factor);
474 
475  if (0 == factor)
476  return GNUNET_TIME_UNIT_ZERO;
477  if (rel.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
479 
480  m = ((double) rel.rel_value_us) * factor;
481 
482  if (m >= (double) (GNUNET_TIME_UNIT_FOREVER_REL).rel_value_us)
483  {
484  GNUNET_break (0);
486  }
487 
488  out.rel_value_us = (uint64_t) m;
489  return out;
490 }
491 
492 
502  unsigned long long factor)
503 {
504  struct GNUNET_TIME_Relative ret;
505 
506  if (0 == factor)
507  return GNUNET_TIME_UNIT_ZERO;
508  if (rel.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
510  ret.rel_value_us = rel.rel_value_us * factor;
511  if (ret.rel_value_us / factor != rel.rel_value_us)
512  {
514  }
515  return ret;
516 }
517 
518 
528  unsigned long long factor)
529 {
530  struct GNUNET_TIME_Relative ret;
531 
532  if ((0 == factor) ||
533  (rel.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us))
535  ret.rel_value_us = rel.rel_value_us / factor;
536  return ret;
537 }
538 
539 
552  uint64_t finished,
553  uint64_t total)
554 {
555  struct GNUNET_TIME_Relative dur;
556  double exp;
557  struct GNUNET_TIME_Relative ret;
558 
559  GNUNET_break (finished <= total);
560  if (finished >= total)
561  return GNUNET_TIME_UNIT_ZERO;
562  if (0 == finished)
565  exp = ((double) dur.rel_value_us) * ((double) total) / ((double) finished);
566  ret.rel_value_us = ((uint64_t) exp) - dur.rel_value_us;
567  return ret;
568 }
569 
570 
580  struct GNUNET_TIME_Relative a2)
581 {
582  struct GNUNET_TIME_Relative ret;
583 
584  if ((a1.rel_value_us == UINT64_MAX) || (a2.rel_value_us == UINT64_MAX))
586  if (a1.rel_value_us + a2.rel_value_us < a1.rel_value_us)
587  {
588  GNUNET_break (0);
590  }
591  ret.rel_value_us = a1.rel_value_us + a2.rel_value_us;
592  return ret;
593 }
594 
595 
605  struct GNUNET_TIME_Relative a2)
606 {
607  struct GNUNET_TIME_Relative ret;
608 
609  if (a2.rel_value_us >= a1.rel_value_us)
610  return GNUNET_TIME_UNIT_ZERO;
611  if (a1.rel_value_us == UINT64_MAX)
613  ret.rel_value_us = a1.rel_value_us - a2.rel_value_us;
614  return ret;
615 }
616 
617 
626 {
627  struct GNUNET_TIME_RelativeNBO ret;
628 
629  ret.rel_value_us__ = GNUNET_htonll (a.rel_value_us);
630  return ret;
631 }
632 
633 
642 {
643  struct GNUNET_TIME_Relative ret;
644 
645  ret.rel_value_us = GNUNET_ntohll (a.rel_value_us__);
646  return ret;
647 }
648 
649 
658 {
659  struct GNUNET_TIME_AbsoluteNBO ret;
660 
661  ret.abs_value_us__ = GNUNET_htonll (a.abs_value_us);
662  return ret;
663 }
664 
665 
674 {
675  struct GNUNET_TIME_Absolute ret;
676 
677  ret.abs_value_us = GNUNET_ntohll (a.abs_value_us__);
678  return ret;
679 }
680 
681 
685 unsigned int
687 {
688  time_t tp;
689  struct tm *t;
690 
691  tp = time (NULL);
692  t = gmtime (&tp);
693  if (t == NULL)
694  return 0;
695  return t->tm_year + 1900;
696 }
697 
698 
705 unsigned int
707 {
708  struct tm *t;
709  time_t tp;
710 
711  tp = at.abs_value_us / 1000LL / 1000LL; /* microseconds to seconds */
712  t = gmtime (&tp);
713  if (t == NULL)
714  return 0;
715  return t->tm_year + 1900;
716 }
717 
718 
726 GNUNET_TIME_year_to_time (unsigned int year)
727 {
728  struct GNUNET_TIME_Absolute ret;
729  time_t tp;
730  struct tm t;
731 
732  memset (&t, 0, sizeof(t));
733  if (year < 1900)
734  {
735  GNUNET_break (0);
736  return GNUNET_TIME_absolute_get (); /* now */
737  }
738  t.tm_year = year - 1900;
739  t.tm_mday = 1;
740  t.tm_mon = 0;
741  t.tm_wday = 1;
742  t.tm_yday = 1;
743  tp = mktime (&t);
744  GNUNET_break (tp != (time_t) -1);
745  ret.abs_value_us = tp * 1000LL * 1000LL; /* seconds to microseconds */
746  return ret;
747 }
748 
749 
762 {
763  double r = (rand () % 500) / 1000.0;
764  struct GNUNET_TIME_Relative t;
765 
768  2 + r);
770 }
771 
772 
781 {
782  double d = ((rand () % 1001) - 500) / 1000.0;
783 
784  return relative_multiply_double (r, d);
785 }
786 
787 
808  const struct GNUNET_CONFIGURATION_Handle *cfg)
809 {
810  static const struct GNUNET_CONFIGURATION_Handle *last_cfg;
811  static struct GNUNET_TIME_Absolute last_time;
812  static struct GNUNET_DISK_MapHandle *map_handle;
813  static ATOMIC volatile uint64_t *map;
814  struct GNUNET_TIME_Absolute now;
815 
816  now = GNUNET_TIME_absolute_get ();
817  if (last_cfg != cfg)
818  {
819  char *filename;
820 
821  if (NULL != map_handle)
822  {
823  GNUNET_DISK_file_unmap (map_handle);
824  map_handle = NULL;
825  }
826  map = NULL;
827 
828  last_cfg = cfg;
829  if ((NULL != cfg) &&
830  (GNUNET_OK ==
832  "util",
833  "MONOTONIC_TIME_FILENAME",
834  &filename)))
835  {
836  struct GNUNET_DISK_FileHandle *fh;
837 
838  fh = GNUNET_DISK_file_open (filename,
845  if (NULL == fh)
846  {
848  _ ("Failed to map `%s', cannot assure monotonic time!\n"),
849  filename);
850  }
851  else
852  {
853  off_t size;
854 
855  size = 0;
857  if (size < (off_t) sizeof(*map))
858  {
859  struct GNUNET_TIME_AbsoluteNBO o;
860 
861  o = GNUNET_TIME_absolute_hton (now);
862  if (sizeof(o) != GNUNET_DISK_file_write (fh, &o, sizeof(o)))
863  size = 0;
864  else
865  size = sizeof(o);
866  }
867  if (size == sizeof(*map))
868  {
869  map = GNUNET_DISK_file_map (fh,
870  &map_handle,
872  sizeof(*map));
873  if (NULL == map)
875  _ (
876  "Failed to map `%s', cannot assure monotonic time!\n"),
877  filename);
878  }
879  else
880  {
881  GNUNET_log (
883  _ (
884  "Failed to setup monotonic time file `%s', cannot assure monotonic time!\n"),
885  filename);
886  }
887  }
889  GNUNET_free (filename);
890  }
891  }
892  if (NULL != map)
893  {
894  struct GNUNET_TIME_AbsoluteNBO mt;
895 
896 #if __STDC_NO_ATOMICS__
897 #if __GNUC__
898  mt.abs_value_us__ = __sync_fetch_and_or (map, 0);
899 #else
900  mt.abs_value_us__ = *map; /* godspeed, pray this is atomic */
901 #endif
902 #else
903  mt.abs_value_us__ = atomic_load (map);
904 #endif
905  last_time =
907  }
908  if (now.abs_value_us <= last_time.abs_value_us)
909  now.abs_value_us = last_time.abs_value_us + 1;
910  last_time = now;
911  if (NULL != map)
912  {
913  uint64_t val = GNUNET_TIME_absolute_hton (now).abs_value_us__;
914 #if __STDC_NO_ATOMICS__
915 #if __GNUC__
916  (void) __sync_lock_test_and_set (map, val);
917 #else
918  *map = val; /* godspeed, pray this is atomic */
919 #endif
920 #else
921  atomic_store (map, val);
922 #endif
923  }
924  return now;
925 }
926 
927 
931 void __attribute__ ((destructor))
932 GNUNET_util_time_fini ()
933 {
935 }
936 
937 
938 /* end of time.c */
static const struct GNUNET_CRYPTO_EcdsaPrivateKey zero
Public key of all zeros.
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:726
static unsigned int threshold
What should the threshold for then key be?
Create file if it doesn&#39;t exist.
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:422
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:673
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1345
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
uint64_t rel_value_us
The actual value.
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_hour_()
Return relative time of 1 hour.
Definition: time.c:207
static long long timestamp_offset
Variable used to simulate clock skew.
Definition: time.c:45
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:287
Read-write memory map.
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_unit_()
Return relative time of 1us.
Definition: time.c:159
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:246
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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:1440
uint64_t rel_value_us__
The actual value (in network byte order).
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_millisecond_()
Return relative time of 1ms.
Definition: time.c:171
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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:395
struct GNUNET_TIME_Relative relative_multiply_double(struct GNUNET_TIME_Relative rel, double factor)
Multiply relative time by a given floating-point factor.
Definition: time.c:468
Time for relative time used by GNUnet, in microseconds and in network byte order. ...
static struct GNUNET_SCHEDULER_Task * t
Main task.
void GNUNET_TIME_set_offset(long long offset)
Set the timestamp offset for this instance.
Definition: time.c:53
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
uint64_t abs_value_us
The actual value.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_CONTAINER_MultiPeerMap * map
Handle to the map used to store old latency values for peers.
void __attribute__((destructor))
Destructor.
Definition: time.c:931
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_forever_()
Return "forever".
Definition: time.c:219
int GNUNET_TIME_round_abs(struct GNUNET_TIME_Absolute *at)
Round a time value so that it is suitable for transmission via JSON encodings.
Definition: time.c:80
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_zero_()
Return relative time of 0ms.
Definition: time.c:135
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_forever_()
Return "forever".
Definition: time.c:231
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:820
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_minute_()
Return relative time of 1 minute.
Definition: time.c:195
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_max(struct GNUNET_TIME_Absolute t1, struct GNUNET_TIME_Absolute t2)
Return the maximum of two relative time values.
Definition: time.c:317
static char * filename
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_zero_()
Return absolute time of 0ms.
Definition: time.c:147
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:442
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
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:780
static int fh
Handle to the unique file.
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:604
#define ATOMIC
Definition: time.c:36
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition: time.c:641
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get()
Get the current time (works just as "time", just that we use the unit of time that the cron-jobs use ...
Definition: time.c:118
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:35
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:272
static unsigned int size
Size of the "table".
Definition: peer.c:67
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
Definition: time.c:625
int GNUNET_DISK_file_unmap(struct GNUNET_DISK_MapHandle *h)
Unmap a file.
Definition: disk.c:1477
int GNUNET_TIME_round_rel(struct GNUNET_TIME_Relative *rt)
Round a time value so that it is suitable for transmission via JSON encodings.
Definition: time.c:100
long long GNUNET_TIME_get_offset()
Get the timestamp offset for this instance.
Definition: time.c:65
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:807
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
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:579
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_second_()
Return relative time of 1s.
Definition: time.c:183
unsigned int GNUNET_TIME_get_current_year()
Return the current year (i.e.
Definition: time.c:686
configuration data
Definition: configuration.c:85
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_min(struct GNUNET_TIME_Absolute t1, struct GNUNET_TIME_Absolute t2)
Return the minimum of two relative time values.
Definition: time.c:302
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 "when...
Definition: time.c:375
uint64_t abs_value_us__
The actual value (in network byte order).
int GNUNET_DISK_file_handle_size(struct GNUNET_DISK_FileHandle *fh, off_t *size)
Get the size of an open file.
Definition: disk.c:206
#define GNUNET_log(kind,...)
Open the file for both reading and writing.
int 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.
static struct GNUNET_TIME_Relative duration
How long do we run the test?
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:331
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:551
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:527
Time for absolute times used by GNUnet, in microseconds.
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:354
unsigned int GNUNET_TIME_time_to_year(struct GNUNET_TIME_Absolute at)
Convert an expiration time to the respective year (rounds)
Definition: time.c:706
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:1268
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:657
Handle used to access files (and pipes).
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:501
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, where 0 <= r <= 0.5, up to a maximum of the given threshold.
Definition: time.c:760
Handle for a memory-mapping operation.
Definition: disk.c:1412
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:48
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.