29#if __STDC_NO_ATOMICS__
32#ifdef HAVE_STDATOMIC_H
36#define __STDC_NO_ATOMICS__ 1
41#define LOG(kind, ...) GNUNET_log_from (kind, "util-time", __VA_ARGS__)
116 gettimeofday (&tv, NULL);
117 ret.abs_value_us = (uint64_t) (((uint64_t) tv.tv_sec * 1000LL * 1000LL)
118 + ((uint64_t) tv.tv_usec))
223 tp = localtime (&
tt);
232 "%a %b %d %H:%M:%S %Y",
247 tt =
t.abs_value_us / 1000LL / 1000LL;
248 tp = localtime (&
tt);
257 "%a %b %d %H:%M:%S %Y",
268 const char *unit =
"µs";
276 (dval > 5 * 1000)) ||
277 (0 == (dval % 1000)))
309 (
unsigned long long) dval,
325 if (rel.rel_value_us + now.
abs_value_us < rel.rel_value_us)
347 return (t1.rel_value_us < t2.rel_value_us) ? t1 : t2;
355 return (t1.rel_value_us > t2.rel_value_us) ? t1 : t2;
363 return (t1.abs_value_us < t2.abs_value_us) ? t1 : t2;
371 return (t1.abs_value_us > t2.abs_value_us) ? t1 : t2;
379 return (t1.abs_time.abs_value_us > t2.abs_time.abs_value_us) ? t1 : t2;
387 return (t1.abs_time.abs_value_us < t2.abs_time.abs_value_us) ? t1 : t2;
400 - at.abs_value_us % rt.rel_value_us;
430 if (
end.abs_value_us <
start.abs_value_us)
432 ret.rel_value_us =
end.abs_value_us -
start.abs_value_us;
487 unsigned long long factor)
495 ret.rel_value_us = rel.rel_value_us * factor;
496 if (
ret.rel_value_us / factor != rel.rel_value_us)
519 m = ((double) rel.rel_value_us) * factor;
534 unsigned long long factor)
542 ret.rel_value_us = rel.rel_value_us * factor;
543 if (
ret.rel_value_us / factor != rel.rel_value_us)
553 unsigned long long factor)
560 ret.rel_value_us = rel.rel_value_us / factor;
592 if ((a1.rel_value_us == UINT64_MAX) || (a2.rel_value_us == UINT64_MAX))
594 if (a1.rel_value_us + a2.rel_value_us < a1.rel_value_us)
599 ret.rel_value_us = a1.rel_value_us + a2.rel_value_us;
610 if (a2.rel_value_us >= a1.rel_value_us)
612 if (a1.rel_value_us == UINT64_MAX)
614 ret.rel_value_us = a1.rel_value_us - a2.rel_value_us;
722 ret.abs_time.abs_value_us
760 return t->tm_year + 1900;
774 return t->tm_year + 1900;
789 setenv (
"TZ",
"", 1);
793 setenv (
"TZ", tz, 1);
811 memset (&
t, 0,
sizeof(
t));
817 t.tm_year = year - 1900;
828 ret.abs_value_us = tp * 1000LL * 1000LL;
837 double r = (rand () % 500) / 1000.0;
857 double d = ((rand () % 1001) + 500) / 1000.0;
878 if (NULL != map_handle)
890 "MONOTONIC_TIME_FILENAME",
905 _ (
"Failed to map `%s', cannot assure monotonic time!\n"),
914 if (
size < (off_t)
sizeof(*
map))
933 "Failed to map `%s', cannot assure monotonic time!\n")
942 "Failed to setup monotonic time file `%s', cannot assure monotonic time!\n"),
954#if __STDC_NO_ATOMICS__
972#if __STDC_NO_ATOMICS__
974 (void) __sync_lock_test_and_set (
map, val);
979 atomic_store (
map, val);
static mp_limb_t d[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
static int start
Set if we are to start default services (including ARM).
static int ret
Final status code.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static int end
Set if we are to shutdown all services (including ARM).
static bool finished
Set to true once we are finished and should exit after sending our final message to the parent.
static struct GNUNET_SCHEDULER_Task * tt
Task scheduled to handle timeout.
static const struct GNUNET_CRYPTO_PrivateKey zero
Public key of all zeros.
static void do_round(void *cls)
Send out PUSHes and PULLs, possibly update #view, samplers.
static struct GNUNET_TIME_Relative duration
Option '-d': duration of the mapping.
static struct GNUNET_SCHEDULER_Task * t
Main task.
enum GNUNET_GenericReturnValue 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.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
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.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_handle_size(struct GNUNET_DISK_FileHandle *fh, off_t *size)
Get the size of an open file.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_unmap(struct GNUNET_DISK_MapHandle *h)
Unmap a file.
@ GNUNET_DISK_OPEN_CREATE
Create file if it doesn't exist.
@ GNUNET_DISK_OPEN_READWRITE
Open the file for both reading and writing.
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_GROUP_READ
Group can read.
@ GNUNET_DISK_PERM_GROUP_WRITE
Group can write.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
@ GNUNET_DISK_MAP_TYPE_READWRITE
Read-write memory map.
#define GNUNET_log(kind,...)
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
#define GNUNET_free(ptr)
Wrapper around free.
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.
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.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_zero_()
Return relative time of 0ms.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_hour_()
Return relative time of 1 hour.
const char * GNUNET_TIME_relative2s(struct GNUNET_TIME_Relative delta, bool do_round)
Give relative time in human-readable fancy format.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_from_s(uint64_t s_after_epoch)
Convert seconds after the UNIX epoch to absolute time.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
bool GNUNET_TIME_absolute_is_future(struct GNUNET_TIME_Absolute abs)
Test if abs is truly in the future (excluding now).
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_millisecond_()
Return relative time of 1ms.
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...
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.
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.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_minute_()
Return relative time of 1 minute.
struct GNUNET_TIME_Timestamp GNUNET_TIME_timestamp_min(struct GNUNET_TIME_Timestamp t1, struct GNUNET_TIME_Timestamp t2)
Return the minimum of two timestamps.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_zero_()
Return absolute time of 0ms.
struct GNUNET_TIME_Timestamp GNUNET_TIME_relative_to_timestamp(struct GNUNET_TIME_Relative rel)
Convert relative time to a timestamp in the future.
#define GNUNET_TIME_relative_cmp(t1, op, t2)
Compare two relative times.
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_TIME_Timestamp GNUNET_TIME_timestamp_from_s(uint64_t s_after_epoch)
Convert seconds after the UNIX epoch to timestamp.
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?
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.
unsigned int GNUNET_TIME_get_current_year()
Return the current year (e.g.
bool GNUNET_TIME_absolute_is_zero(struct GNUNET_TIME_Absolute abs)
Test if abs is truly zero.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_from_ms(uint64_t ms_after_epoch)
Convert milliseconds after the UNIX epoch to absolute time.
bool GNUNET_TIME_relative_is_zero(struct GNUNET_TIME_Relative rel)
Test if rel is zero.
bool GNUNET_TIME_absolute_is_never(struct GNUNET_TIME_Absolute abs)
Test if abs is never.
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
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,...
struct GNUNET_TIME_Relative GNUNET_TIME_relative_subtract(struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative a2)
Subtract relative timestamp from the other.
const char * GNUNET_TIME_absolute2s(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_forever_()
Return "forever".
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get()
Get the current time.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_forever_()
Return "forever".
struct GNUNET_TIME_Timestamp GNUNET_TIME_timestamp_get()
Get timestamp representing the current time.
uint64_t GNUNET_TIME_timestamp_to_s(struct GNUNET_TIME_Timestamp ts)
Convert timestamp to number of seconds after the UNIX epoch.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply_double(struct GNUNET_TIME_Relative rel, double factor)
Multiply relative time by a given factor.
bool GNUNET_TIME_relative_is_forever(struct GNUNET_TIME_Relative rel)
Test if rel is forever.
long long GNUNET_TIME_get_offset()
Get the timestamp offset for this instance.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_round_down(struct GNUNET_TIME_Absolute at, struct GNUNET_TIME_Relative rt)
Round down absolute time at to multiple of rt.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_add(struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative a2)
Add relative times together.
void GNUNET_TIME_set_offset(long long offset)
Set the timestamp offset for this instance.
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.
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.
unsigned int GNUNET_TIME_time_to_year(struct GNUNET_TIME_Absolute at)
Convert an expiration time to the respective year (rounds)
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_second_()
Return relative time of 1s.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_unit_()
Return relative time of 1 microsecond.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
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.
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
#define GNUNET_TIME_UNIT_FOREVER_TS
Constant used to specify "forever".
bool GNUNET_TIME_absolute_approx_eq(struct GNUNET_TIME_Absolute a1, struct GNUNET_TIME_Absolute a2, struct GNUNET_TIME_Relative t)
Test if a1 and a2 are equal within a margin of error of t.
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.
struct GNUNET_TIME_Timestamp GNUNET_TIME_timestamp_max(struct GNUNET_TIME_Timestamp t1, struct GNUNET_TIME_Timestamp t2)
Return the maximum of two timestamps.
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
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.
struct GNUNET_TIME_TimestampNBO GNUNET_TIME_timestamp_hton(struct GNUNET_TIME_Timestamp t)
Convert timestamp to network byte order.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Divide relative time by a given factor.
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.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
bool GNUNET_TIME_absolute_is_past(struct GNUNET_TIME_Absolute abs)
Test if abs is truly in the past (excluding now).
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.
struct GNUNET_TIME_Timestamp GNUNET_TIME_timestamp_ntoh(struct GNUNET_TIME_TimestampNBO tn)
Convert timestamp from network byte order.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
const char * GNUNET_TIME_timestamp2s(struct GNUNET_TIME_Timestamp ts)
Convert ts to human-readable timestamp.
struct GNUNET_TIME_Timestamp GNUNET_TIME_absolute_to_timestamp(struct GNUNET_TIME_Absolute at)
Round an absolute time to a timestamp.
static struct GNUNET_CONTAINER_MultiPeerMap * map
Peermap of PeerIdentities to "struct PeerEntry" (for fast lookup).
static unsigned int size
Size of the "table".
static struct GNUNET_TIME_Relative delta
Handle used to access files (and pipes).
Handle for a memory-mapping operation.
Time for absolute time used by GNUnet, in microseconds and in network byte order.
uint64_t abs_value_us__
The actual value (in network byte order).
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
Time for relative time used by GNUnet, in microseconds and in network byte order.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
Time for timestamps used by GNUnet, in seconds and in network byte order.
struct GNUNET_TIME_AbsoluteNBO abs_time_nbo
The actual value.
Time for timestamps used by GNUnet, in microseconds rounded to seconds.
struct GNUNET_TIME_Absolute abs_time
The actual value.
static long long timestamp_offset
Variable used to simulate clock skew.
void GNUNET_util_time_fini(void)
static time_t my_timegm(struct tm *tm)
As suggested in the timegm() man page.
void __attribute__((destructor))
Destructor.