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 
540 
541 
547 void
548 GNUNET_TIME_set_offset (long long offset);
549 
550 
556 long long
558 
559 
563 unsigned int
565 
566 
574 GNUNET_TIME_year_to_time (unsigned int year);
575 
576 
583 unsigned int
585 
586 
591 
592 
614 
615 
616 #if 0 /* keep Emacsens' auto-indent happy */
617 {
618 #endif
619 #ifdef __cplusplus
620 }
621 #endif
622 
623 /* ifndef GNUNET_TIME_LIB_H */
624 #endif
625  /* end of group time */
627 
628 /* 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:726
static unsigned int threshold
What should the threshold for then key be?
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
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_(void)
Return relative time of 1 hour.
Definition: time.c:207
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
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: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
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_millisecond_(void)
Return relative time of 1ms.
Definition: time.c:171
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
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: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_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won&#39;t work on W32.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_forever_(void)
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_(void)
Return relative time of 0ms.
Definition: time.c:135
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_forever_(void)
Return "forever".
Definition: time.c:231
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_minute_(void)
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 absolute time values.
Definition: time.c:317
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_zero_(void)
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
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
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
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition: time.c:641
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
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
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_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(void)
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_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:579
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_second_(void)
Return relative time of 1s.
Definition: time.c:183
unsigned int GNUNET_TIME_get_current_year(void)
Return the current year (i.e.
Definition: time.c:686
#define GNUNET_PACKED
gcc-ism to get packed structs.
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 absolute 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 "henc...
Definition: time.c:375
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
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:706
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:657
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
Time for relative time used by GNUnet, in microseconds.