GNUnet  0.11.x
gnunet_time_lib.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2001-2013 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 
32 #ifndef GNUNET_TIME_LIB_H
33 #define GNUNET_TIME_LIB_H
34 
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #if 0 /* keep Emacsens' auto-indent happy */
39 }
40 #endif
41 #endif
42 
43 #include "gnunet_common.h"
44 
49 {
53  uint64_t abs_value_us;
54 };
55 
61 {
65  uint64_t rel_value_us;
66 };
67 
69 
74 {
78  uint64_t rel_value_us__ GNUNET_PACKED;
79 };
80 
81 
86 {
90  uint64_t abs_value_us__ GNUNET_PACKED;
91 };
93 
97 #define GNUNET_TIME_UNIT_ZERO GNUNET_TIME_relative_get_zero_ ()
98 
102 #define GNUNET_TIME_UNIT_ZERO_ABS GNUNET_TIME_absolute_get_zero_ ()
103 
107 #define GNUNET_TIME_UNIT_MICROSECONDS GNUNET_TIME_relative_get_unit_ ()
108 
112 #define GNUNET_TIME_UNIT_MILLISECONDS GNUNET_TIME_relative_get_millisecond_ ()
113 
117 #define GNUNET_TIME_UNIT_SECONDS GNUNET_TIME_relative_get_second_ ()
118 
122 #define GNUNET_TIME_UNIT_MINUTES GNUNET_TIME_relative_get_minute_ ()
123 
127 #define GNUNET_TIME_UNIT_HOURS GNUNET_TIME_relative_get_hour_ ()
128 
132 #define GNUNET_TIME_UNIT_DAYS GNUNET_TIME_relative_multiply ( \
133  GNUNET_TIME_UNIT_HOURS, 24)
134 
138 #define GNUNET_TIME_UNIT_WEEKS GNUNET_TIME_relative_multiply ( \
139  GNUNET_TIME_UNIT_DAYS, 7)
140 
144 #define GNUNET_TIME_UNIT_MONTHS GNUNET_TIME_relative_multiply ( \
145  GNUNET_TIME_UNIT_DAYS, 30)
146 
150 #define GNUNET_TIME_UNIT_YEARS GNUNET_TIME_relative_multiply ( \
151  GNUNET_TIME_UNIT_DAYS, 365)
152 
157 #define GNUNET_TIME_UNIT_FOREVER_REL GNUNET_TIME_relative_get_forever_ ()
158 
163 #define GNUNET_TIME_UNIT_FOREVER_ABS GNUNET_TIME_absolute_get_forever_ ()
164 
165 
169 #define GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD \
170  GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
171 
172 
179 #define GNUNET_TIME_STD_BACKOFF(r) GNUNET_TIME_relative_min ( \
180  GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD, \
181  GNUNET_TIME_relative_multiply ( \
182  GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS, (r)), 2))
183 
184 
197 
198 
207 
208 
214 
215 
221 
222 
228 
229 
235 
236 
242 
243 
249 
250 
256 
257 
263 
264 
270 
271 
279 
280 
290 
291 
300 int
302 
303 
312 int
314 
315 
325  struct GNUNET_TIME_Relative t2);
326 
327 
337  struct GNUNET_TIME_Relative t2);
338 
339 
349  struct GNUNET_TIME_Absolute t2);
350 
351 
361  struct GNUNET_TIME_Absolute t2);
362 
363 
373 
374 
387  uint64_t finished,
388  uint64_t total);
389 
390 
402  struct GNUNET_TIME_Absolute end);
403 
404 
414 
415 
427 
428 
440 
441 
451  unsigned long long factor);
452 
453 
463  unsigned long long factor);
464 
465 
475  unsigned long long factor);
476 
477 
487  struct GNUNET_TIME_Relative a2);
488 
489 
499  struct GNUNET_TIME_Relative a2);
500 
501 
510 
511 
520 
521 
530 
531 
539 GNUNET_TIME_absolute_from_ms (uint64_t ms_after_epoch);
540 
541 
547 bool
549 
550 
556 bool
558 
559 
565 bool
567 
568 
574 bool
576 
577 
583 bool
585 
586 
594 GNUNET_TIME_absolute_from_s (uint64_t s_after_epoch);
595 
596 
605 
606 
612 void
613 GNUNET_TIME_set_offset (long long offset);
614 
615 
621 long long
623 
624 
628 unsigned int
630 
631 
639 GNUNET_TIME_year_to_time (unsigned int year);
640 
641 
648 unsigned int
650 
651 
656 
657 
678  const struct GNUNET_CONFIGURATION_Handle *cfg);
679 
680 
681 #if 0 /* keep Emacsens' auto-indent happy */
682 {
683 #endif
684 #ifdef __cplusplus
685 }
686 #endif
687 
688 /* ifndef GNUNET_TIME_LIB_H */
689 #endif
690  /* end of group time */
692 
693 /* end of gnunet_time_lib.h */
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:606
static unsigned int threshold
What should the threshold for then key be?
bool GNUNET_TIME_relative_is_zero(struct GNUNET_TIME_Relative rel)
Test if rel is zero.
Definition: time.c:488
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:296
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:542
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
bool GNUNET_TIME_relative_is_forever(struct GNUNET_TIME_Relative rel)
Test if rel is forever.
Definition: time.c:481
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_hour_(void)
Return relative time of 1 hour.
Definition: time.c:154
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:208
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_(void)
Return relative time of 1 microsecond.
Definition: time.c:118
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:181
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_millisecond_(void)
Return relative time of 1ms.
Definition: time.c:127
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:277
Time for relative time used by GNUnet, in microseconds and in network byte order. ...
void GNUNET_TIME_set_offset(long long offset)
Set the timestamp offset for this instance.
Definition: time.c:48
bool GNUNET_TIME_absolute_is_never(struct GNUNET_TIME_Absolute abs)
Test if abs is never.
Definition: time.c:474
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
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:515
uint64_t abs_value_us
The actual value.
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won&#39;t work on W32.
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:529
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_forever_(void)
Return "forever".
Definition: time.c:163
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:62
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_zero_(void)
Return relative time of 0ms.
Definition: time.c:100
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_forever_(void)
Return "forever".
Definition: time.c:172
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_minute_(void)
Return relative time of 1 minute.
Definition: time.c:145
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:224
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_zero_(void)
Return absolute time of 0ms.
Definition: time.c:109
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:311
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:649
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:429
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition: time.c:454
bool GNUNET_TIME_absolute_is_future(struct GNUNET_TIME_Absolute abs)
Test if abs is truly in the future (excluding now).
Definition: time.c:505
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:86
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:200
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
Definition: time.c:444
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:74
long long GNUNET_TIME_get_offset(void)
Get the timestamp offset for this instance.
Definition: time.c:55
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:658
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won&#39;t work on W32;.
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:411
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_second_(void)
Return relative time of 1s.
Definition: time.c:136
unsigned int GNUNET_TIME_get_current_year(void)
Return the current year (e.g.
Definition: time.c:552
#define GNUNET_PACKED
gcc-ism to get packed structs.
configuration data
Definition: configuration.c:84
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:216
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:263
bool GNUNET_TIME_absolute_is_past(struct GNUNET_TIME_Absolute abs)
Test if abs is truly in the past (excluding now).
Definition: time.c:495
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:232
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:390
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:376
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:248
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
unsigned int GNUNET_TIME_time_to_year(struct GNUNET_TIME_Absolute at)
Convert an expiration time to the respective year (rounds)
Definition: time.c:566
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:464
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:357
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:635
Time for relative time used by GNUnet, in microseconds.