GNUnet  0.10.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 
52  uint64_t abs_value_us;
53 };
54 
63  uint64_t rel_value_us;
64 };
65 
67 
75  uint64_t rel_value_us__ GNUNET_PACKED;
76 };
77 
78 
86  uint64_t abs_value_us__ GNUNET_PACKED;
87 };
89 
93 #define GNUNET_TIME_UNIT_ZERO GNUNET_TIME_relative_get_zero_()
94 
98 #define GNUNET_TIME_UNIT_ZERO_ABS GNUNET_TIME_absolute_get_zero_()
99 
103 #define GNUNET_TIME_UNIT_MICROSECONDS GNUNET_TIME_relative_get_unit_()
104 
108 #define GNUNET_TIME_UNIT_MILLISECONDS GNUNET_TIME_relative_get_millisecond_()
109 
113 #define GNUNET_TIME_UNIT_SECONDS GNUNET_TIME_relative_get_second_()
114 
118 #define GNUNET_TIME_UNIT_MINUTES GNUNET_TIME_relative_get_minute_()
119 
123 #define GNUNET_TIME_UNIT_HOURS GNUNET_TIME_relative_get_hour_()
124 
128 #define GNUNET_TIME_UNIT_DAYS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 24)
129 
133 #define GNUNET_TIME_UNIT_WEEKS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_DAYS, 7)
134 
138 #define GNUNET_TIME_UNIT_MONTHS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_DAYS, 30)
139 
143 #define GNUNET_TIME_UNIT_YEARS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_DAYS, 365)
144 
149 #define GNUNET_TIME_UNIT_FOREVER_REL GNUNET_TIME_relative_get_forever_()
150 
155 #define GNUNET_TIME_UNIT_FOREVER_ABS GNUNET_TIME_absolute_get_forever_()
156 
157 
158 
162 #define GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15)
163 
164 
171 #define GNUNET_TIME_STD_BACKOFF(r) GNUNET_TIME_relative_min(GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD, \
172  GNUNET_TIME_relative_multiply(GNUNET_TIME_relative_max(GNUNET_TIME_UNIT_MILLISECONDS, (r)), 2));
173 
174 
186 
187 
196 
197 
203 
204 
210 
211 
217 
218 
224 
225 
231 
232 
238 
239 
245 
246 
252 
253 
259 
260 
268 
269 
279 
280 
289 int
291 
292 
301 int
303 
304 
314  struct GNUNET_TIME_Relative t2);
315 
316 
317 
327  struct GNUNET_TIME_Relative t2);
328 
329 
339  struct GNUNET_TIME_Absolute t2);
340 
341 
351  struct GNUNET_TIME_Absolute t2);
352 
353 
363 
364 
377  uint64_t finished,
378  uint64_t total);
379 
380 
392  struct GNUNET_TIME_Absolute end);
393 
394 
404 
405 
417 
418 
430 
431 
441  unsigned long long factor);
442 
443 
453  unsigned long long factor);
454 
455 
465  unsigned long long factor);
466 
467 
477  struct GNUNET_TIME_Relative a2);
478 
479 
489  struct GNUNET_TIME_Relative a2);
490 
491 
500 
501 
510 
511 
520 
521 
530 
531 
537 void
538 GNUNET_TIME_set_offset(long long offset);
539 
540 
546 long long
548 
549 
553 unsigned int
555 
556 
564 GNUNET_TIME_year_to_time(unsigned int year);
565 
566 
573 unsigned int
575 
576 
581 
582 
603 
604 
605 #if 0 /* keep Emacsens' auto-indent happy */
606 {
607 #endif
608 #ifdef __cplusplus
609 }
610 #endif
611 
612 /* ifndef GNUNET_TIME_LIB_H */
613 #endif
614  /* end of group time */
616 
617 /* 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:724
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:420
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:671
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:393
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:440
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:778
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:602
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition: time.c:639
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
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:623
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:805
#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:577
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:684
#define GNUNET_PACKED
gcc-ism to get packed structs.
configuration data
Definition: configuration.c:83
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:373
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:549
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:525
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:353
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:704
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:655
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:499
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:758
Time for relative time used by GNUnet, in microseconds.