aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-12-14 15:59:07 +0100
committerChristian Grothoff <christian@grothoff.org>2021-12-14 15:59:12 +0100
commit99779b455ce3bf9c53dd411575766bf298a3a5f3 (patch)
tree12cd49f097fdd1947580b08ec10ca961f8c250b9 /src/include
parent8c702327dae9e504e0f6e1678884d9327321f44a (diff)
downloadgnunet-99779b455ce3bf9c53dd411575766bf298a3a5f3.tar.gz
gnunet-99779b455ce3bf9c53dd411575766bf298a3a5f3.zip
introducing GNUNET_TIME_Timestamp
Diffstat (limited to 'src/include')
-rw-r--r--src/include/gnunet_getopt_lib.h18
-rw-r--r--src/include/gnunet_json_lib.h38
-rw-r--r--src/include/gnunet_pq_lib.h53
-rw-r--r--src/include/gnunet_sq_lib.h10
-rw-r--r--src/include/gnunet_strings_lib.h19
-rw-r--r--src/include/gnunet_time_lib.h220
6 files changed, 312 insertions, 46 deletions
diff --git a/src/include/gnunet_getopt_lib.h b/src/include/gnunet_getopt_lib.h
index 731be4159..259d648dd 100644
--- a/src/include/gnunet_getopt_lib.h
+++ b/src/include/gnunet_getopt_lib.h
@@ -378,6 +378,24 @@ GNUNET_GETOPT_option_absolute_time (char shortName,
378 378
379 379
380/** 380/**
381 * Allow user to specify a `struct GNUNET_TIME_Timestamp`
382 * (using human-readable "fancy" time).
383 *
384 * @param shortName short name of the option
385 * @param name long name of the option
386 * @param argumentHelp help text for the option argument
387 * @param description long help text for the option
388 * @param[out] val set to the time specified at the command line
389 */
390struct GNUNET_GETOPT_CommandLineOption
391GNUNET_GETOPT_option_timestamp (char shortName,
392 const char *name,
393 const char *argumentHelp,
394 const char *description,
395 struct GNUNET_TIME_Timestamp *val);
396
397
398/**
381 * Increment @a val each time the option flag is given by one. 399 * Increment @a val each time the option flag is given by one.
382 * 400 *
383 * @param shortName short name of the option 401 * @param shortName short name of the option
diff --git a/src/include/gnunet_json_lib.h b/src/include/gnunet_json_lib.h
index 5ef4592e5..7d101196c 100644
--- a/src/include/gnunet_json_lib.h
+++ b/src/include/gnunet_json_lib.h
@@ -304,25 +304,25 @@ GNUNET_JSON_spec_boolean (const char *name,
304/* ************ GNUnet-specific parser specifications ******************* */ 304/* ************ GNUnet-specific parser specifications ******************* */
305 305
306/** 306/**
307 * Absolute time. 307 * Timestamp.
308 * 308 *
309 * @param name name of the JSON field 309 * @param name name of the JSON field
310 * @param[out] at where to store the absolute time found under @a name 310 * @param[out] at where to store the absolute time found under @a name
311 */ 311 */
312struct GNUNET_JSON_Specification 312struct GNUNET_JSON_Specification
313GNUNET_JSON_spec_absolute_time (const char *name, 313GNUNET_JSON_spec_timestamp (const char *name,
314 struct GNUNET_TIME_Absolute *at); 314 struct GNUNET_TIME_Timestamp *t);
315 315
316 316
317/** 317/**
318 * Absolute time in network byte order. 318 * Timestamp in network byte order.
319 * 319 *
320 * @param name name of the JSON field 320 * @param name name of the JSON field
321 * @param[out] at where to store the absolute time found under @a name 321 * @param[out] tn where to store the absolute time found under @a name
322 */ 322 */
323struct GNUNET_JSON_Specification 323struct GNUNET_JSON_Specification
324GNUNET_JSON_spec_absolute_time_nbo (const char *name, 324GNUNET_JSON_spec_timestamp_nbo (const char *name,
325 struct GNUNET_TIME_AbsoluteNBO *at); 325 struct GNUNET_TIME_TimestampNBO *tn);
326 326
327 327
328/** 328/**
@@ -385,23 +385,23 @@ GNUNET_JSON_from_data (const void *data, size_t size);
385 385
386 386
387/** 387/**
388 * Convert absolute timestamp to a json string. 388 * Convert timestamp to a json string.
389 * 389 *
390 * @param stamp the time stamp 390 * @param stamp the time stamp
391 * @return a json string with the timestamp in @a stamp 391 * @return a json string with the timestamp in @a stamp
392 */ 392 */
393json_t * 393json_t *
394GNUNET_JSON_from_time_abs (struct GNUNET_TIME_Absolute stamp); 394GNUNET_JSON_from_timestamp (struct GNUNET_TIME_Timestamp stamp);
395 395
396 396
397/** 397/**
398 * Convert absolute timestamp to a json string. 398 * Convert timestamp to a json string.
399 * 399 *
400 * @param stamp the time stamp 400 * @param stamp the time stamp
401 * @return a json string with the timestamp in @a stamp 401 * @return a json string with the timestamp in @a stamp
402 */ 402 */
403json_t * 403json_t *
404GNUNET_JSON_from_time_abs_nbo (struct GNUNET_TIME_AbsoluteNBO stamp); 404GNUNET_JSON_from_timestamp_nbo (struct GNUNET_TIME_TimestampNBO stamp);
405 405
406 406
407/** 407/**
@@ -747,30 +747,30 @@ GNUNET_JSON_pack_data_varsize (const char *name,
747 747
748/** 748/**
749 * Generate packer instruction for a JSON field of type 749 * Generate packer instruction for a JSON field of type
750 * absolute time. 750 * timestamp.
751 * 751 *
752 * @param name name of the field to add to the object 752 * @param name name of the field to add to the object
753 * @param at absolute time to pack, a value of 0 is only 753 * @param at timestamp pack, a value of 0 is only
754 * allowed with #GNUNET_JSON_pack_allow_null()! 754 * allowed with #GNUNET_JSON_pack_allow_null()!
755 * @return json pack specification 755 * @return json pack specification
756 */ 756 */
757struct GNUNET_JSON_PackSpec 757struct GNUNET_JSON_PackSpec
758GNUNET_JSON_pack_time_abs (const char *name, 758GNUNET_JSON_pack_timestamp (const char *name,
759 struct GNUNET_TIME_Absolute at); 759 struct GNUNET_TIME_Timestamp at);
760 760
761 761
762/** 762/**
763 * Generate packer instruction for a JSON field of type 763 * Generate packer instruction for a JSON field of type
764 * absolute time in network byte order. 764 * timestamp in network byte order.
765 * 765 *
766 * @param name name of the field to add to the object 766 * @param name name of the field to add to the object
767 * @param at absolute time to pack, a value of 0 is only 767 * @param at timestamp to pack, a value of 0 is only
768 * allowed with #GNUNET_JSON_pack_allow_null()! 768 * allowed with #GNUNET_JSON_pack_allow_null()!
769 * @return json pack specification 769 * @return json pack specification
770 */ 770 */
771struct GNUNET_JSON_PackSpec 771struct GNUNET_JSON_PackSpec
772GNUNET_JSON_pack_time_abs_nbo (const char *name, 772GNUNET_JSON_pack_timestamp_nbo (const char *name,
773 struct GNUNET_TIME_AbsoluteNBO at); 773 struct GNUNET_TIME_TimestampNBO at);
774 774
775 775
776/** 776/**
diff --git a/src/include/gnunet_pq_lib.h b/src/include/gnunet_pq_lib.h
index 05d373f88..f7bf59212 100644
--- a/src/include/gnunet_pq_lib.h
+++ b/src/include/gnunet_pq_lib.h
@@ -96,7 +96,11 @@ struct GNUNET_PQ_QueryParam
96 */ 96 */
97#define GNUNET_PQ_query_param_end \ 97#define GNUNET_PQ_query_param_end \
98 { \ 98 { \
99 NULL, NULL, NULL, 0, 0 \ 99 .conv = NULL, \
100 .conv_cls = NULL, \
101 .data = NULL, \
102 .size = 0, \
103 .num_params = 0 \
100 } 104 }
101 105
102 106
@@ -200,6 +204,17 @@ GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x);
200 204
201 205
202/** 206/**
207 * Generate query parameter for a timestamp.
208 * The database must store a 64-bit integer.
209 *
210 * @param x pointer to the query parameter to pass
211 * @return query parameter to use
212 */
213struct GNUNET_PQ_QueryParam
214GNUNET_PQ_query_param_timestamp (const struct GNUNET_TIME_Timestamp *x);
215
216
217/**
203 * Generate query parameter for an absolute time value. 218 * Generate query parameter for an absolute time value.
204 * The database must store a 64-bit integer. 219 * The database must store a 64-bit integer.
205 * 220 *
@@ -212,6 +227,18 @@ GNUNET_PQ_query_param_absolute_time_nbo (
212 227
213 228
214/** 229/**
230 * Generate query parameter for a timestamp in NBO.
231 * The database must store a 64-bit integer.
232 *
233 * @param x pointer to the query parameter to pass
234 * @return query parameter to use
235 */
236struct GNUNET_PQ_QueryParam
237GNUNET_PQ_query_param_timestamp_nbo (
238 const struct GNUNET_TIME_TimestampNBO *t);
239
240
241/**
215 * Generate query parameter for an uint16_t in host byte order. 242 * Generate query parameter for an uint16_t in host byte order.
216 * 243 *
217 * @param x pointer to the query parameter to pass 244 * @param x pointer to the query parameter to pass
@@ -472,6 +499,18 @@ GNUNET_PQ_result_spec_absolute_time (const char *name,
472 499
473 500
474/** 501/**
502 * Timestamp expected.
503 *
504 * @param name name of the field in the table
505 * @param[out] t where to store the result
506 * @return array entry for the result specification to use
507 */
508struct GNUNET_PQ_ResultSpec
509GNUNET_PQ_result_spec_timestamp (const char *name,
510 struct GNUNET_TIME_Timestamp *t);
511
512
513/**
475 * Relative time expected. 514 * Relative time expected.
476 * 515 *
477 * @param name name of the field in the table 516 * @param name name of the field in the table
@@ -496,6 +535,18 @@ GNUNET_PQ_result_spec_absolute_time_nbo (const char *name,
496 535
497 536
498/** 537/**
538 * Timestamp expected.
539 *
540 * @param name name of the field in the table
541 * @param[out] tn where to store the result
542 * @return array entry for the result specification to use
543 */
544struct GNUNET_PQ_ResultSpec
545GNUNET_PQ_result_spec_timestamp_nbo (const char *name,
546 struct GNUNET_TIME_TimestampNBO *tn);
547
548
549/**
499 * uint16_t expected. 550 * uint16_t expected.
500 * 551 *
501 * @param name name of the field in the table 552 * @param name name of the field in the table
diff --git a/src/include/gnunet_sq_lib.h b/src/include/gnunet_sq_lib.h
index 21ce5b393..e89ded07e 100644
--- a/src/include/gnunet_sq_lib.h
+++ b/src/include/gnunet_sq_lib.h
@@ -40,7 +40,7 @@
40 * so immediately suitable for passing to `sqlite3_bind`-functions. 40 * so immediately suitable for passing to `sqlite3_bind`-functions.
41 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 41 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
42 */ 42 */
43typedef int 43typedef enum GNUNET_GenericReturnValue
44(*GNUNET_SQ_QueryConverter)(void *cls, 44(*GNUNET_SQ_QueryConverter)(void *cls,
45 const void *data, 45 const void *data,
46 size_t data_len, 46 size_t data_len,
@@ -156,8 +156,8 @@ GNUNET_SQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x);
156 * @param x pointer to the query parameter to pass 156 * @param x pointer to the query parameter to pass
157 */ 157 */
158struct GNUNET_SQ_QueryParam 158struct GNUNET_SQ_QueryParam
159GNUNET_SQ_query_param_absolute_time_nbo (const struct 159GNUNET_SQ_query_param_absolute_time_nbo (
160 GNUNET_TIME_AbsoluteNBO *x); 160 const struct GNUNET_TIME_AbsoluteNBO *x);
161 161
162 162
163/** 163/**
@@ -222,7 +222,7 @@ GNUNET_SQ_reset (sqlite3 *dbh,
222 * #GNUNET_YES if all results could be extracted 222 * #GNUNET_YES if all results could be extracted
223 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 223 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
224 */ 224 */
225typedef int 225typedef enum GNUNET_GenericReturnValue
226(*GNUNET_SQ_ResultConverter)(void *cls, 226(*GNUNET_SQ_ResultConverter)(void *cls,
227 sqlite3_stmt *result, 227 sqlite3_stmt *result,
228 unsigned int column, 228 unsigned int column,
@@ -436,7 +436,7 @@ GNUNET_SQ_result_spec_uint64 (uint64_t *u64);
436 * #GNUNET_OK if all results could be extracted 436 * #GNUNET_OK if all results could be extracted
437 * #GNUNET_SYSERR if a result was invalid (non-existing field) 437 * #GNUNET_SYSERR if a result was invalid (non-existing field)
438 */ 438 */
439int 439enum GNUNET_GenericReturnValue
440GNUNET_SQ_extract_result (sqlite3_stmt *result, 440GNUNET_SQ_extract_result (sqlite3_stmt *result,
441 struct GNUNET_SQ_ResultSpec *rs); 441 struct GNUNET_SQ_ResultSpec *rs);
442 442
diff --git a/src/include/gnunet_strings_lib.h b/src/include/gnunet_strings_lib.h
index 977c2ead7..2e0c720ee 100644
--- a/src/include/gnunet_strings_lib.h
+++ b/src/include/gnunet_strings_lib.h
@@ -76,7 +76,7 @@ GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size,
76 * @param rtime set to the relative time 76 * @param rtime set to the relative time
77 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 77 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
78 */ 78 */
79int 79enum GNUNET_GenericReturnValue
80GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time, 80GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time,
81 struct GNUNET_TIME_Relative *rtime); 81 struct GNUNET_TIME_Relative *rtime);
82 82
@@ -91,12 +91,27 @@ GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time,
91 * @param atime set to the absolute time 91 * @param atime set to the absolute time
92 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 92 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
93 */ 93 */
94int 94enum GNUNET_GenericReturnValue
95GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time, 95GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time,
96 struct GNUNET_TIME_Absolute *atime); 96 struct GNUNET_TIME_Absolute *atime);
97 97
98 98
99/** 99/**
100 * @ingroup time
101 * Convert a given fancy human-readable time to our internal
102 * representation. The human-readable time is expected to be
103 * in local time, whereas the returned value will be in UTC.
104 *
105 * @param fancy_time human readable string (e.g. %Y-%m-%d %H:%M:%S)
106 * @param atime set to the absolute time
107 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
108 */
109enum GNUNET_GenericReturnValue
110GNUNET_STRINGS_fancy_time_to_timestamp (const char *fancy_time,
111 struct GNUNET_TIME_Timestamp *atime);
112
113
114/**
100 * Convert a given filesize into a fancy human-readable format. 115 * Convert a given filesize into a fancy human-readable format.
101 * 116 *
102 * @param size number of bytes 117 * @param size number of bytes
diff --git a/src/include/gnunet_time_lib.h b/src/include/gnunet_time_lib.h
index 26b442066..5e826ace0 100644
--- a/src/include/gnunet_time_lib.h
+++ b/src/include/gnunet_time_lib.h
@@ -54,6 +54,17 @@ struct GNUNET_TIME_Absolute
54}; 54};
55 55
56/** 56/**
57 * Rounded time for timestamps used by GNUnet, in seconds.
58 */
59struct GNUNET_TIME_Timestamp
60{
61 /**
62 * The actual value. Must be round number in seconds.
63 */
64 struct GNUNET_TIME_Absolute abs_time;
65};
66
67/**
57 * Time for relative time used by GNUnet, in microseconds. 68 * Time for relative time used by GNUnet, in microseconds.
58 * Always positive, so we can only refer to future time. 69 * Always positive, so we can only refer to future time.
59 */ 70 */
@@ -89,17 +100,34 @@ struct GNUNET_TIME_AbsoluteNBO
89 */ 100 */
90 uint64_t abs_value_us__ GNUNET_PACKED; 101 uint64_t abs_value_us__ GNUNET_PACKED;
91}; 102};
103
104/**
105 * Time for timestamps used by GNUnet, in seconds and in network byte order.
106 */
107struct GNUNET_TIME_TimestampNBO
108{
109 /**
110 * The actual value. Must be round number in seconds.
111 */
112 struct GNUNET_TIME_AbsoluteNBO abs_time_nbo;
113};
114
92GNUNET_NETWORK_STRUCT_END 115GNUNET_NETWORK_STRUCT_END
93 116
94/** 117/**
95 * Relative time zero. 118 * Relative time zero.
96 */ 119 */
97#define GNUNET_TIME_UNIT_ZERO GNUNET_TIME_relative_get_zero_ () 120#define GNUNET_TIME_UNIT_ZERO ((struct GNUNET_TIME_Relative){0})
98 121
99/** 122/**
100 * Absolute time zero. 123 * Absolute time zero.
101 */ 124 */
102#define GNUNET_TIME_UNIT_ZERO_ABS GNUNET_TIME_absolute_get_zero_ () 125#define GNUNET_TIME_UNIT_ZERO_ABS ((struct GNUNET_TIME_Absolute){0})
126
127/**
128 * Timestamp of zero.
129 */
130#define GNUNET_TIME_UNIT_ZERO_TS ((struct GNUNET_TIME_Timestamp){{0}})
103 131
104/** 132/**
105 * One microsecond, our basic time unit. 133 * One microsecond, our basic time unit.
@@ -154,13 +182,22 @@ GNUNET_NETWORK_STRUCT_END
154 * Constant used to specify "forever". This constant 182 * Constant used to specify "forever". This constant
155 * will be treated specially in all time operations. 183 * will be treated specially in all time operations.
156 */ 184 */
157#define GNUNET_TIME_UNIT_FOREVER_REL GNUNET_TIME_relative_get_forever_ () 185#define GNUNET_TIME_UNIT_FOREVER_REL \
186 ((struct GNUNET_TIME_Relative){UINT64_MAX})
158 187
159/** 188/**
160 * Constant used to specify "forever". This constant 189 * Constant used to specify "forever". This constant
161 * will be treated specially in all time operations. 190 * will be treated specially in all time operations.
162 */ 191 */
163#define GNUNET_TIME_UNIT_FOREVER_ABS GNUNET_TIME_absolute_get_forever_ () 192#define GNUNET_TIME_UNIT_FOREVER_ABS \
193 ((struct GNUNET_TIME_Absolute){UINT64_MAX})
194
195/**
196 * Constant used to specify "forever". This constant
197 * will be treated specially in all time operations.
198 */
199#define GNUNET_TIME_UNIT_FOREVER_TS \
200 ((struct GNUNET_TIME_Timestamp){{UINT64_MAX}})
164 201
165 202
166/** 203/**
@@ -183,6 +220,47 @@ GNUNET_NETWORK_STRUCT_END
183 220
184 221
185/** 222/**
223 * Convert @a ts to human-readable timestamp.
224 * Note that the returned value will be overwritten if this function
225 * is called again.
226 *
227 * @param ts the timestamp to convert
228 * @return statically allocated string, will change on the next call
229 */
230const char *
231GNUNET_TIME_timestamp2s (struct GNUNET_TIME_Timestamp ts);
232
233
234/**
235 * @ingroup time
236 * Like `asctime`, except for GNUnet time. Converts a GNUnet internal
237 * absolute time (which is in UTC) to a string in local time.
238 * Note that the returned value will be overwritten if this function
239 * is called again.
240 *
241 * @param t the absolute time to convert
242 * @return timestamp in human-readable form in local time
243 */
244const char *
245GNUNET_TIME_absolute2s (struct GNUNET_TIME_Absolute ts);
246
247
248/**
249 * @ingroup time
250 * Give relative time in human-readable fancy format.
251 * This is one of the very few calls in the entire API that is
252 * NOT reentrant!
253 *
254 * @param delta time in milli seconds
255 * @param do_round are we allowed to round a bit?
256 * @return string in human-readable form
257 */
258const char *
259GNUNET_TIME_relative2s (struct GNUNET_TIME_Relative delta,
260 bool do_round);
261
262
263/**
186 * Randomized exponential back-off, starting at 1 ms 264 * Randomized exponential back-off, starting at 1 ms
187 * and going up by a factor of 2+r, where 0 <= r <= 0.5, up 265 * and going up by a factor of 2+r, where 0 <= r <= 0.5, up
188 * to a maximum of the given threshold. 266 * to a maximum of the given threshold.
@@ -192,8 +270,8 @@ GNUNET_NETWORK_STRUCT_END
192 * @return the next backoff time 270 * @return the next backoff time
193 */ 271 */
194struct GNUNET_TIME_Relative 272struct GNUNET_TIME_Relative
195GNUNET_TIME_randomized_backoff (struct GNUNET_TIME_Relative rt, struct 273GNUNET_TIME_randomized_backoff (struct GNUNET_TIME_Relative rt,
196 GNUNET_TIME_Relative threshold); 274 struct GNUNET_TIME_Relative threshold);
197 275
198 276
199/** 277/**
@@ -290,27 +368,69 @@ GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel);
290 368
291 369
292/** 370/**
293 * Round a time value so that it is suitable for transmission 371 * Convert relative time to a timestamp in the
294 * via JSON encodings. 372 * future.
373 *
374 * @param rel relative time to convert
375 * @return timestamp that is "rel" in the future, or FOREVER if rel==FOREVER (or if we would overflow)
376 */
377struct GNUNET_TIME_Timestamp
378GNUNET_TIME_relative_to_timestamp (struct GNUNET_TIME_Relative rel);
379
380
381/**
382 * Round an absolute time to a timestamp.
295 * 383 *
296 * @param at time to round 384 * @param at time to round
297 * @return #GNUNET_OK if time was already rounded, #GNUNET_NO if 385 * @return the result
298 * it was just now rounded
299 */ 386 */
300int 387struct GNUNET_TIME_Timestamp
301GNUNET_TIME_round_abs (struct GNUNET_TIME_Absolute *at); 388GNUNET_TIME_absolute_to_timestamp (struct GNUNET_TIME_Absolute at);
302 389
303 390
304/** 391/**
305 * Round a time value so that it is suitable for transmission 392 * Get timestamp representing the current time.
306 * via JSON encodings.
307 * 393 *
308 * @param rt time to round 394 * @return current time, rounded down to seconds
309 * @return #GNUNET_OK if time was already rounded, #GNUNET_NO if
310 * it was just now rounded
311 */ 395 */
312int 396struct GNUNET_TIME_Timestamp
313GNUNET_TIME_round_rel (struct GNUNET_TIME_Relative *rt); 397GNUNET_TIME_timestamp_get (void);
398
399
400/**
401 * Compare two absolute times.
402 *
403 * @param t1 first time
404 * @param op compare operator
405 * @param t2 second time
406 * @return true if @a t1 @a op @a t2
407 */
408#define GNUNET_TIME_absolute_cmp(t1,op,t2) \
409 (((void) (1 op 2), (t1).abs_value_us op (t2).abs_value_us))
410
411
412/**
413 * Compare two timestamps
414 *
415 * @param t1 first timestamp
416 * @param op compare operator
417 * @param t2 second timestamp
418 * @return true if @a t1 @a op @a t2
419 */
420#define GNUNET_TIME_timestamp_cmp(t1,op,t2) \
421 GNUNET_TIME_absolute_cmp ((t1).abs_time,op,(t2).abs_time)
422
423
424/**
425 * Compare two relative times.
426 *
427 * @param t1 first time
428 * @param op compare operator
429 * @param t2 second time
430 * @return true if @a t1 @a op @a t2
431 */
432#define GNUNET_TIME_relative_cmp(t1,op,t2) \
433 ((void) (1 op 2), (t1).rel_value_us op (t2).rel_value_us)
314 434
315 435
316/** 436/**
@@ -362,6 +482,30 @@ GNUNET_TIME_absolute_max (struct GNUNET_TIME_Absolute t1,
362 482
363 483
364/** 484/**
485 * Return the maximum of two timestamps.
486 *
487 * @param t1 first timestamp
488 * @param t2 other timestamp
489 * @return timestamp that is smaller
490 */
491struct GNUNET_TIME_Timestamp
492GNUNET_TIME_timestamp_max (struct GNUNET_TIME_Timestamp t1,
493 struct GNUNET_TIME_Timestamp t2);
494
495
496/**
497 * Return the minimum of two timestamps.
498 *
499 * @param t1 first timestamp
500 * @param t2 other timestamp
501 * @return timestamp that is smaller
502 */
503struct GNUNET_TIME_Timestamp
504GNUNET_TIME_timestamp_min (struct GNUNET_TIME_Timestamp t1,
505 struct GNUNET_TIME_Timestamp t2);
506
507
508/**
365 * Given a timestamp in the future, how much time 509 * Given a timestamp in the future, how much time
366 * remains until then? 510 * remains until then?
367 * 511 *
@@ -530,6 +674,16 @@ GNUNET_TIME_absolute_hton (struct GNUNET_TIME_Absolute a);
530 674
531 675
532/** 676/**
677 * Convert timestamp to network byte order.
678 *
679 * @param t time to convert
680 * @return converted time value
681 */
682struct GNUNET_TIME_TimestampNBO
683GNUNET_TIME_timestamp_hton (struct GNUNET_TIME_Timestamp t);
684
685
686/**
533 * Convert milliseconds after the UNIX epoch to absolute time. 687 * Convert milliseconds after the UNIX epoch to absolute time.
534 * 688 *
535 * @param ms_after_epoch millisecond timestamp to convert 689 * @param ms_after_epoch millisecond timestamp to convert
@@ -558,6 +712,15 @@ GNUNET_TIME_absolute_is_past (struct GNUNET_TIME_Absolute abs);
558 712
559 713
560/** 714/**
715 * Test if @a abs is truly zero.
716 *
717 * @return true if it is.
718 */
719bool
720GNUNET_TIME_absolute_is_zero (struct GNUNET_TIME_Absolute abs);
721
722
723/**
561 * Test if @a abs is truly in the future (excluding now). 724 * Test if @a abs is truly in the future (excluding now).
562 * 725 *
563 * @return true if it is. 726 * @return true if it is.
@@ -595,6 +758,15 @@ GNUNET_TIME_absolute_from_s (uint64_t s_after_epoch);
595 758
596 759
597/** 760/**
761 * Convert seconds after the UNIX epoch to timestamp.
762 *
763 * @param s_after_epoch seconds after epoch to convert
764 * @return converted time value
765 */struct GNUNET_TIME_Timestamp
766GNUNET_TIME_timestamp_from_s (uint64_t s_after_epoch);
767
768
769/**
598 * Convert absolute time from network byte order. 770 * Convert absolute time from network byte order.
599 * 771 *
600 * @param a time to convert 772 * @param a time to convert
@@ -605,6 +777,16 @@ GNUNET_TIME_absolute_ntoh (struct GNUNET_TIME_AbsoluteNBO a);
605 777
606 778
607/** 779/**
780 * Convert timestamp from network byte order.
781 *
782 * @param tn time to convert
783 * @return converted time value
784 */
785struct GNUNET_TIME_Timestamp
786GNUNET_TIME_timestamp_ntoh (struct GNUNET_TIME_TimestampNBO tn);
787
788
789/**
608 * Set the timestamp offset for this instance. 790 * Set the timestamp offset for this instance.
609 * 791 *
610 * @param offset the offset to skew the locale time by 792 * @param offset the offset to skew the locale time by