GNUnet  0.10.x
Data Structures | Macros | Functions
Time library

Time and time calculations. More...

Data Structures

struct  GNUNET_TIME_Absolute
 Time for absolute times used by GNUnet, in microseconds. More...
 
struct  GNUNET_TIME_Relative
 Time for relative time used by GNUnet, in microseconds. More...
 
struct  GNUNET_TIME_RelativeNBO
 Time for relative time used by GNUnet, in microseconds and in network byte order. More...
 
struct  GNUNET_TIME_AbsoluteNBO
 Time for absolute time used by GNUnet, in microseconds and in network byte order. More...
 

Macros

#define GNUNET_TIME_UNIT_ZERO   GNUNET_TIME_relative_get_zero_()
 Relative time zero. More...
 
#define GNUNET_TIME_UNIT_ZERO_ABS   GNUNET_TIME_absolute_get_zero_()
 Absolute time zero. More...
 
#define GNUNET_TIME_UNIT_MICROSECONDS   GNUNET_TIME_relative_get_unit_()
 One microsecond, our basic time unit. More...
 
#define GNUNET_TIME_UNIT_MILLISECONDS   GNUNET_TIME_relative_get_millisecond_()
 One millisecond. More...
 
#define GNUNET_TIME_UNIT_SECONDS   GNUNET_TIME_relative_get_second_()
 One second. More...
 
#define GNUNET_TIME_UNIT_MINUTES   GNUNET_TIME_relative_get_minute_()
 One minute. More...
 
#define GNUNET_TIME_UNIT_HOURS   GNUNET_TIME_relative_get_hour_()
 One hour. More...
 
#define GNUNET_TIME_UNIT_DAYS   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 24)
 One day. More...
 
#define GNUNET_TIME_UNIT_WEEKS   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_DAYS, 7)
 One week. More...
 
#define GNUNET_TIME_UNIT_MONTHS   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_DAYS, 30)
 One month (30 days). More...
 
#define GNUNET_TIME_UNIT_YEARS   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_DAYS, 365)
 One year (365 days). More...
 
#define GNUNET_TIME_UNIT_FOREVER_REL   GNUNET_TIME_relative_get_forever_ ()
 Constant used to specify "forever". More...
 
#define GNUNET_TIME_UNIT_FOREVER_ABS   GNUNET_TIME_absolute_get_forever_ ()
 Constant used to specify "forever". More...
 
#define GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
 Threshold after which exponential backoff should not increase (15 m). More...
 
#define GNUNET_TIME_STD_BACKOFF(r)
 Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of 2 up unto a maximum of 15 m. More...
 

Functions

int GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time, struct GNUNET_TIME_Absolute *atime)
 Convert a given fancy human-readable time to our internal representation. More...
 
const char * GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t)
 Like asctime, except for GNUnet time. More...
 
const char * GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta, int do_round)
 Give relative time in human-readable fancy format. More...
 
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. More...
 
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. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_zero_ (void)
 Return relative time of 0ms. More...
 
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_zero_ (void)
 Return absolute time of 0ms. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_unit_ (void)
 Return relative time of 1 microsecond. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_millisecond_ (void)
 Return relative time of 1ms. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_second_ (void)
 Return relative time of 1s. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_minute_ (void)
 Return relative time of 1 minute. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_hour_ (void)
 Return relative time of 1 hour. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_forever_ (void)
 Return "forever". More...
 
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_forever_ (void)
 Return "forever". More...
 
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get (void)
 Get the current time. More...
 
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel)
 Convert relative time to an absolute time in the future. More...
 
int GNUNET_TIME_round_abs (struct GNUNET_TIME_Absolute *at)
 Round a time value so that it is suitable for transmission via JSON encodings. More...
 
int GNUNET_TIME_round_rel (struct GNUNET_TIME_Relative *rt)
 Round a time value so that it is suitable for transmission via JSON encodings. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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? More...
 
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. More...
 
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. More...
 
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 "hence". More...
 
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. More...
 
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. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel, unsigned long long factor)
 Multiply relative time by a given factor. More...
 
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. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel, unsigned long long factor)
 Divide relative time by a given factor. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_add (struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative a2)
 Add relative times together. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_subtract (struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative a2)
 Subtract relative timestamp from the other. More...
 
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton (struct GNUNET_TIME_Relative a)
 Convert relative time to network byte order. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh (struct GNUNET_TIME_RelativeNBO a)
 Convert relative time from network byte order. More...
 
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton (struct GNUNET_TIME_Absolute a)
 Convert absolute time to network byte order. More...
 
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh (struct GNUNET_TIME_AbsoluteNBO a)
 Convert absolute time from network byte order. More...
 
void GNUNET_TIME_set_offset (long long offset)
 Set the timestamp offset for this instance. More...
 
long long GNUNET_TIME_get_offset (void)
 Get the timestamp offset for this instance. More...
 
unsigned int GNUNET_TIME_get_current_year (void)
 Return the current year (i.e. More...
 
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. More...
 
unsigned int GNUNET_TIME_time_to_year (struct GNUNET_TIME_Absolute at)
 Convert an expiration time to the respective year (rounds) More...
 
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. More...
 

Detailed Description

Time and time calculations.

Macro Definition Documentation

◆ GNUNET_TIME_UNIT_ZERO

#define GNUNET_TIME_UNIT_ZERO   GNUNET_TIME_relative_get_zero_()

Relative time zero.

Definition at line 97 of file gnunet_time_lib.h.

Referenced by adapt_parallelism(), check_zone_namestore_next(), consider_sending_fc(), create_experiment(), GAS_mlp_solve_problem(), get_delay(), get_delay_randomization(), get_transmit_delay(), GNUNET_ATS_solver_logging_now(), GNUNET_BANDWIDTH_tracker_get_delay(), GNUNET_DEFRAGMENT_process_fragment(), GNUNET_FS_search_make_status_(), GNUNET_FS_unindex_stop(), GNUNET_HELLO_equals(), GNUNET_NSE_connect(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_with_priority(), GNUNET_TIME_absolute_get_difference(), GNUNET_TIME_absolute_get_duration(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_calculate_eta(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_relative_saturating_multiply(), GNUNET_TIME_relative_subtract(), GNUNET_TRANSPORT_core_connect(), GNUNET_TRANSPORT_core_get_mq(), GSF_peer_connect_handler(), GST_ats_block_reset(), GST_neighbours_calculate_receive_delay(), GST_receive_callback(), handle_acknowledged(), handle_ats_address_suggestion(), handle_ats_session_allocation(), handle_data(), handle_data_end(), handle_estimate(), handle_fragment_box(), handle_iterate_end(), handle_status(), handle_unindex_response(), handle_validation_response(), handle_watch_record(), main(), main_run(), maint_child_death(), process_result_with_request(), reconstruct_cb(), relative_multiply_double(), remove_timeout_messages_and_select(), reservations_reserve(), ril_step_schedule_next(), run(), signal_publish_completion(), simple_session_add(), start_dv_learn(), suggest_start_cb(), task_check(), transmit_next(), try_match_block(), udp_plugin_create_session(), update_excess(), and update_velocity().

◆ GNUNET_TIME_UNIT_ZERO_ABS

#define GNUNET_TIME_UNIT_ZERO_ABS   GNUNET_TIME_absolute_get_zero_()

◆ GNUNET_TIME_UNIT_MICROSECONDS

#define GNUNET_TIME_UNIT_MICROSECONDS   GNUNET_TIME_relative_get_unit_()

One microsecond, our basic time unit.

Definition at line 107 of file gnunet_time_lib.h.

Referenced by estimate_latency(), GNUNET_NETWORK_socket_select(), reannounce_regex(), revalidate_address(), and ril_step_schedule_next().

◆ GNUNET_TIME_UNIT_MILLISECONDS

#define GNUNET_TIME_UNIT_MILLISECONDS   GNUNET_TIME_relative_get_millisecond_()

◆ GNUNET_TIME_UNIT_SECONDS

#define GNUNET_TIME_UNIT_SECONDS   GNUNET_TIME_relative_get_second_()

◆ GNUNET_TIME_UNIT_MINUTES

#define GNUNET_TIME_UNIT_MINUTES   GNUNET_TIME_relative_get_minute_()

◆ GNUNET_TIME_UNIT_HOURS

#define GNUNET_TIME_UNIT_HOURS   GNUNET_TIME_relative_get_hour_()

◆ GNUNET_TIME_UNIT_DAYS

#define GNUNET_TIME_UNIT_DAYS   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 24)

One day.

Definition at line 132 of file gnunet_time_lib.h.

Referenced by make_file(), and process_result().

◆ GNUNET_TIME_UNIT_WEEKS

#define GNUNET_TIME_UNIT_WEEKS   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_DAYS, 7)

One week.

Definition at line 137 of file gnunet_time_lib.h.

◆ GNUNET_TIME_UNIT_MONTHS

#define GNUNET_TIME_UNIT_MONTHS   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_DAYS, 30)

One month (30 days).

Definition at line 142 of file gnunet_time_lib.h.

◆ GNUNET_TIME_UNIT_YEARS

#define GNUNET_TIME_UNIT_YEARS   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_DAYS, 365)

One year (365 days).

Definition at line 147 of file gnunet_time_lib.h.

Referenced by cadet_reply_proc(), handle_dht_reply(), and handle_p2p_put().

◆ GNUNET_TIME_UNIT_FOREVER_REL

#define GNUNET_TIME_UNIT_FOREVER_REL   GNUNET_TIME_relative_get_forever_ ()

Constant used to specify "forever".

This constant will be treated specially in all time operations.

Definition at line 153 of file gnunet_time_lib.h.

Referenced by accept_client(), ack_proc(), check_timeouts(), child_death_task(), compute_rand_delay(), connect_success_continuation(), connection_client_send_impl(), consider_sending_fc(), context_task(), create_listen_socket(), curl_download_prepare(), delayed_restart_task(), do_accept(), do_reconnect(), do_resume(), do_s5r_read(), do_send(), do_udp_read(), do_write(), ds_put_cont(), encapsulate_for_dv(), encode_cont(), enforce_start_send(), find_validation_entry(), free_queue(), get_transmit_delay(), GNUNET_ATS_solver_generate_preferences_start(), GNUNET_BANDWIDTH_tracker_get_delay(), GNUNET_BANDWIDTH_value_get_delay_for(), GNUNET_FS_publish_main_(), GNUNET_FS_unindex_start(), GNUNET_HELPER_send(), GNUNET_JSON_from_time_rel(), GNUNET_NAT_AUTO_test_start(), GNUNET_NAT_mini_get_external_ipv4_(), GNUNET_NAT_test_start(), GNUNET_NETWORK_socket_select(), GNUNET_OS_install_parent_control_handler(), GNUNET_SCHEDULER_driver_init(), GNUNET_SERVER_resume(), GNUNET_STRINGS_fancy_time_to_relative(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get_difference(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_calculate_eta(), GNUNET_TIME_relative_add(), GNUNET_TIME_relative_divide(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_relative_saturating_multiply(), GNUNET_TIME_relative_subtract(), GNUNET_TIME_round_rel(), gnunet_uri(), GST_neighbours_calculate_receive_delay(), GST_neighbours_keepalive(), handle_add_queue_message(), handle_command(), handle_dv_learn(), handle_test(), helper_read(), helper_write(), init_range(), internal_update(), LEGACY_SERVICE_run(), LEGACY_SERVICE_start(), listen_cb(), listen_stdio(), load_op_start_set_preference(), main(), maint_child_death(), mq_init(), mq_send(), nat_address_cb(), nat_server_read(), parent_control_handler(), parse_rel_time(), ping(), plugin_monitoring_cb(), pong(), prepare_daemon(), process_job_queue(), progress_cb(), proto_read_kx(), queue_destroy(), queue_write(), read_dns4(), read_dns6(), read_external_ipv4(), read_task(), receive_complete_cb(), receive_ready(), recursive_gns2dns_resolution(), relative_multiply_double(), rest_credential_process_request(), rest_identity_process_request(), rest_process_request(), restart_nat_server(), resume_client_receive(), route_control_message_without_fc(), route_via_neighbour(), run(), run_httpd(), schedule_httpd(), schedule_next_hello(), schedule_read(), schedule_select_v4(), schedule_select_v6(), select_read_cb(), select_write_cb(), send_disconnect(), send_keepalive(), send_session_ack_message(), send_syn_ack_message(), send_with_session(), service_client_recv(), service_mq_send(), set_incoming_quota(), setup_service(), shutdown_pipe_cb(), signal_publish_error(), signal_socks_failure(), signal_socks_success(), signal_unindex_error(), sock_read(), start_address_validation(), start_client(), start_helper(), stdin_cb(), stun_read_task(), suggest_start_cb(), testing_main(), tokenizer_cb(), topology_setup_done(), transmit_next(), transmit_ready(), try_connection_reversal(), udp_ipv4_broadcast_send(), udp_ipv6_broadcast_send(), unix_plugin_select_read(), unix_plugin_select_write(), unix_plugin_send(), unix_transport_server_start(), update_performance_data(), work(), write_task(), and zone_iteration_finished().

◆ GNUNET_TIME_UNIT_FOREVER_ABS

#define GNUNET_TIME_UNIT_FOREVER_ABS   GNUNET_TIME_absolute_get_forever_ ()

Constant used to specify "forever".

This constant will be treated specially in all time operations.

Definition at line 159 of file gnunet_time_lib.h.

Referenced by ack_proc(), add_address_to_hello(), add_host(), add_to_buf(), call_continuation(), consider_for_advertising(), create_session(), delayed_put(), disconnect_neighbour(), encrypt_existing_match(), extract_abs_time(), extract_abs_time_nbo(), flush_respect(), free_neighbour(), get_existing_record(), get_timeout(), GNUNET_ATS_TEST_generate_traffic_start(), GNUNET_GNSRECORD_record_get_expiration_time(), GNUNET_HELLO_equals(), GNUNET_JSON_from_time_abs(), GNUNET_NAMESTORE_set_nick(), GNUNET_PEERSTORE_iterate(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_STRINGS_absolute_time_to_string(), GNUNET_STRINGS_fancy_time_to_absolute(), GNUNET_TIME_absolute_add(), GNUNET_TIME_absolute_subtract(), GNUNET_TIME_relative_to_absolute(), GNUNET_TIME_round_abs(), GSC_KX_handle_client_monitor_peers(), GSF_pending_request_create_(), GSF_request_plan_reference_get_last_transmission_(), handle_data(), handle_dv_learn(), ns_lookup_result_cb(), parse_abs_time(), parse_abs_time_nbo(), parse_expiration(), parse_record(), process_reply(), process_result(), process_result_with_request(), quota_processor(), reconnect(), RPS_sampler_elem_reinit(), sampler_mod_get_rand_peer(), schedule_watch_request(), select_loop(), setup_neighbour(), setup_service(), sign_ephemeral_key(), suggest_start_cb(), try_transmission(), update_backtalker_monotime(), and update_hello().

◆ GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD

#define GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)

Threshold after which exponential backoff should not increase (15 m).

Definition at line 166 of file gnunet_time_lib.h.

Referenced by restart_nat_server().

◆ GNUNET_TIME_STD_BACKOFF

#define GNUNET_TIME_STD_BACKOFF (   r)
Value:
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:286
#define GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD
Threshold after which exponential backoff should not increase (15 m).
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:439
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
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:271

Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of 2 up unto a maximum of 15 m.

Parameters
rcurrent backoff time, initially zero

Definition at line 175 of file gnunet_time_lib.h.

Referenced by announce_id(), channel_open_sent_cb(), connect_fail_continuation(), data_sent_cb(), disconnect_and_schedule_reconnect(), do_reconnect(), force_reconnect(), GNUNET_TESTBED_is_host_habitable(), GST_ats_block_address(), habitability_check(), handle_client_listener_error(), maint_child_death(), mq_error_handler(), reconnect(), reconnect_arm_later(), reconnect_arm_monitor_later(), reconnect_cbk(), reconnect_later(), reconnect_peer_ctx(), reconnect_plugin_ctx(), reschedule_connect(), schedule_reconnect(), send_create(), send_create_ack(), send_kx(), send_kx_auth(), set_key_retry_task(), transmit_request(), transmit_typemap_task(), try_again(), and try_reconnect().

Function Documentation

◆ GNUNET_STRINGS_fancy_time_to_absolute()

int GNUNET_STRINGS_fancy_time_to_absolute ( const char *  fancy_time,
struct GNUNET_TIME_Absolute atime 
)

Convert a given fancy human-readable time to our internal representation.

The human-readable time is expected to be in local time, whereas the returned value will be in UTC.

Parameters
fancy_timehuman readable string (i.e. Y-m-d H:M:S)
atimeset to the absolute time
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 408 of file strings.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_ABS, and t.

Referenced by database_setup(), get_cred_issuer_cb(), identity_cb(), parse_expiration(), parse_record(), and set_absolute_time().

410 {
411  struct tm tv;
412  time_t t;
413  const char *eos;
414 
415  if (0 == strcasecmp ("end of time",
416  fancy_time))
417  {
419  return GNUNET_OK;
420  }
421  eos = &fancy_time[strlen (fancy_time)];
422  memset (&tv, 0, sizeof (tv));
423  if ( (eos != strptime (fancy_time, "%a %b %d %H:%M:%S %Y", &tv)) &&
424  (eos != strptime (fancy_time, "%c", &tv)) &&
425  (eos != strptime (fancy_time, "%Ec", &tv)) &&
426  (eos != strptime (fancy_time, "%Y-%m-%d %H:%M:%S", &tv)) &&
427  (eos != strptime (fancy_time, "%Y-%m-%d %H:%M", &tv)) &&
428  (eos != strptime (fancy_time, "%x", &tv)) &&
429  (eos != strptime (fancy_time, "%Ex", &tv)) &&
430  (eos != strptime (fancy_time, "%Y-%m-%d", &tv)) &&
431  (eos != strptime (fancy_time, "%Y-%m", &tv)) &&
432  (eos != strptime (fancy_time, "%Y", &tv)) )
433  return GNUNET_SYSERR;
434  t = mktime (&tv);
435  atime->abs_value_us = (uint64_t) ((uint64_t) t * 1000LL * 1000LL);
436  return GNUNET_OK;
437 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static struct GNUNET_SCHEDULER_Task * t
Main task.
uint64_t abs_value_us
The actual value.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
Here is the caller graph for this function:

◆ GNUNET_STRINGS_absolute_time_to_string()

const char* GNUNET_STRINGS_absolute_time_to_string ( struct GNUNET_TIME_Absolute  t)

Like asctime, except for GNUnet time.

Converts a GNUnet internal absolute time (which is in UTC) to a string in local time. Note that the returned value will be overwritten if this function is called again.

Parameters
tthe absolute time to convert
Returns
timestamp in human-readable form in local time

Like asctime, except for GNUnet time.

Converts a GNUnet internal absolute time (which is in UTC) to a string in local time. Note that the returned value will be overwritten if this function is called again.

Parameters
tthe absolute time to convert
Returns
timestamp in human-readable form in local time

Definition at line 792 of file strings.c.

References _, GNUNET_TIME_Absolute::abs_value_us, buf, GNUNET_strlcpy(), GNUNET_TIME_UNIT_FOREVER_ABS, and tt.

Referenced by display_record(), dump_pc(), execute_get(), execute_select(), fragmented_message_done(), get_resp_callback(), get_transmit_delay(), GNUNET_CONTAINER_meta_data_add_publication_date(), GNUNET_GNSRECORD_block_decrypt(), GNUNET_GNSRECORD_record_get_expiration_time(), GNUNET_JSON_from_gnsrecord(), got_hello(), handle_block_cache(), handle_dht_response(), handle_lookup_block_it(), handle_p2p_estimate(), handle_validation_response(), monitor_cb(), monitor_notify_connect(), monitor_notify_disconnect(), namecache_sqlite_cache_block(), neighbours_changed_notification(), ns_lookup_result_cb(), parse_expiration(), perform_dht_put(), print_info(), print_plugin_event_info(), printer(), printer_watch(), process_queue(), process_record(), put_callback(), refresh_block(), select_loop(), set_state_and_timeout(), sqlite_plugin_put(), store_and_free_entries(), store_pi(), timeout_cb(), transmit_item(), transmit_task_cb(), update_pm_next_attempt(), and warn_monitor_slow().

793 {
794  static char buf[255];
795  time_t tt;
796  struct tm *tp;
797 
798  if (t.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us)
799  return _("end of time");
800  tt = t.abs_value_us / 1000LL / 1000LL;
801  tp = localtime (&tt);
802  /* This is hacky, but i don't know a way to detect libc character encoding.
803  * Just expect utf8 from glibc these days.
804  * As for msvcrt, use the wide variant, which always returns utf16
805  * (otherwise we'd have to detect current codepage or use W32API character
806  * set conversion routines to convert to UTF8).
807  */
808 #ifndef WINDOWS
809  strftime (buf, sizeof (buf), "%a %b %d %H:%M:%S %Y", tp);
810 #else
811  {
812  static wchar_t wbuf[255];
813  uint8_t *conved;
814  size_t ssize;
815 
816  wcsftime (wbuf, sizeof (wbuf) / sizeof (wchar_t),
817  L"%a %b %d %H:%M:%S %Y", tp);
818 
819  ssize = sizeof (buf);
820  conved = u16_to_u8 (wbuf, sizeof (wbuf) / sizeof (wchar_t),
821  (uint8_t *) buf, &ssize);
822  if (conved != (uint8_t *) buf)
823  {
824  GNUNET_strlcpy (buf, (char *) conved, sizeof (buf));
825  free (conved);
826  }
827  }
828 #endif
829  return buf;
830 }
static struct GNUNET_SCHEDULER_Task * tt
Task scheduled to handle timeout.
uint64_t abs_value_us
The actual value.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static char buf[2048]
size_t GNUNET_strlcpy(char *dst, const char *src, size_t n)
Like strlcpy but portable.
Definition: strings.c:218
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_STRINGS_relative_time_to_string()

const char* GNUNET_STRINGS_relative_time_to_string ( struct GNUNET_TIME_Relative  delta,
int  do_round 
)

Give relative time in human-readable fancy format.

This is one of the very few calls in the entire API that is NOT reentrant!

Parameters
deltatime in milli seconds
do_roundare we allowed to round a bit?
Returns
string in human-readable form

This is one of the very few calls in the entire API that is NOT reentrant!

Parameters
deltatime in milli seconds
do_roundare we allowed to round a bit?
Returns
time as human-readable string

Definition at line 727 of file strings.c.

References _, buf, GNUNET_snprintf(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, and GNUNET_TIME_Relative::rel_value_us.

Referenced by ack_proc(), ats_reserve_callback(), channel_open_sent_cb(), client_receive(), client_receive_mst_cb(), client_session_timeout(), connect_fail_continuation(), consider_sending_fc(), data_sent_cb(), delay_warning(), delayed_restart_task(), disconnect_and_schedule_reconnect(), display_record(), do_directory_scan(), do_disconnect(), do_shutdown(), do_speedup(), experiment_done_cb(), expired_processor(), find_proof(), flush_bulk(), fragmented_message_done(), get_delay_randomization(), get_transmit_delay(), GNUNET_ATS_solver_logging_start(), GNUNET_ATS_solvers_experimentation_load(), GNUNET_ATS_solvers_experimentation_run(), GNUNET_ATS_TEST_experimentation_load(), GNUNET_ATS_TEST_experimentation_run(), GNUNET_BANDWIDTH_tracker_get_delay(), GNUNET_BANDWIDTH_value_get_available_until(), GNUNET_BANDWIDTH_value_get_delay_for(), GNUNET_DATASTORE_put(), GNUNET_HOSTLIST_client_start(), GNUNET_SCHEDULER_do_work(), GNUNET_SPEEDUP_start_(), GSC_CLIENTS_solicit_request(), GSF_block_peer_migration_(), GST_ats_block_address(), GST_ats_update_delay(), GST_manipulation_init(), GST_manipulation_recv(), GST_manipulation_send(), GST_neighbours_calculate_receive_delay(), GST_neighbours_keepalive_response(), GST_receive_callback(), GST_validation_start(), handle_announce(), handle_client_join(), handle_client_send(), handle_data(), handle_dv_learn(), handle_encrypted(), handle_monitor_event(), handle_p2p_migration_stop(), handle_p2p_put(), handle_send_transmit_continuation(), handle_tcp_data(), handler_advertisement(), http_client_plugin_update_inbound_delay(), http_server_plugin_update_inbound_delay(), load_episode(), load_episodes(), maint_child_death(), manage_first_hop_mq(), master_task(), monitor_cb(), odc_warn_delay_task(), parse_expiration(), plan(), pong_handler(), print_plugin_event_info(), process_job_queue(), process_mst(), process_stat(), process_stdin(), prof_time(), progress_cb(), put_gns_record(), put_migration_continuation(), qc_message_sent(), queue_read(), queue_timeout(), quota_processor(), read_process_ack(), receive_ready(), RECLAIM_TICKETS_init(), reconnect(), regex_found_handler(), remove_timeout_messages_and_select(), reschedule_connect(), reservations_reserve(), revalidate_address(), run(), schedule_peer_transmission(), schedule_select_v4(), schedule_select_v6(), search_timed_out(), server_access_cb(), server_receive_mst_cb(), server_session_timeout(), session_timeout(), shutdown_task(), sqlite_plugin_put(), start_dv_learn(), store_completed_cb(), task_check(), task_hostlist_saving(), tcp_plugin_update_inbound_delay(), test_master(), timeout_cb(), timeout_episode(), transmit_item(), transmit_next(), try_reconnect(), try_transmission(), udp_plugin_send(), update_excess(), update_ping_data(), update_tracker(), update_velocity(), validation_start_cb(), warn_delay(), warn_delay_task(), warn_no_client_continue(), warn_no_receive_done(), and zone_iteration_finished().

729 {
730  static char buf[128];
731  const char *unit = _( /* time unit */ "┬Ás");
732  uint64_t dval = delta.rel_value_us;
733 
734  if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == delta.rel_value_us)
735  return _("forever");
736  if (0 == delta.rel_value_us)
737  return _("0 ms");
738  if ( ( (GNUNET_YES == do_round) &&
739  (dval > 5 * 1000) ) ||
740  (0 == (dval % 1000) ))
741  {
742  dval = dval / 1000;
743  unit = _( /* time unit */ "ms");
744  if ( ( (GNUNET_YES == do_round) &&
745  (dval > 5 * 1000) ) ||
746  (0 == (dval % 1000) ))
747  {
748  dval = dval / 1000;
749  unit = _( /* time unit */ "s");
750  if ( ( (GNUNET_YES == do_round) &&
751  (dval > 5 * 60) ) ||
752  (0 == (dval % 60) ) )
753  {
754  dval = dval / 60;
755  unit = _( /* time unit */ "m");
756  if ( ( (GNUNET_YES == do_round) &&
757  (dval > 5 * 60) ) ||
758  (0 == (dval % 60) ))
759  {
760  dval = dval / 60;
761  unit = _( /* time unit */ "h");
762  if ( ( (GNUNET_YES == do_round) &&
763  (dval > 5 * 24) ) ||
764  (0 == (dval % 24)) )
765  {
766  dval = dval / 24;
767  if (1 == dval)
768  unit = _( /* time unit */ "day");
769  else
770  unit = _( /* time unit */ "days");
771  }
772  }
773  }
774  }
775  }
776  GNUNET_snprintf (buf, sizeof (buf),
777  "%llu %s", dval, unit);
778  return buf;
779 }
static void do_round(void *cls)
Send out PUSHes and PULLs, possibly update #view, samplers.
uint64_t rel_value_us
The actual value.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static char buf[2048]
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the call graph for this function:

◆ GNUNET_TIME_randomized_backoff()

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.

Parameters
rtcurrent backoff time, initially zero
thresholdmaximum value for backoff
Returns
the next backoff time
Parameters
rcurrent backoff time, initially zero
thresholdmaximum value for backoff
Returns
the next backoff time

Definition at line 759 of file time.c.

References GNUNET_TIME_relative_max(), GNUNET_TIME_relative_min(), GNUNET_TIME_UNIT_MILLISECONDS, relative_multiply_double(), and threshold.

Referenced by error_handler(), suggest_hello(), suggest_start_cb(), and validation_start_cb().

760 {
761  double r = (rand() % 500) / 1000.0;
762  struct GNUNET_TIME_Relative t;
763 
765  rt),
766  2 + r);
767  return GNUNET_TIME_relative_min (threshold,
768  t);
769 }
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:286
struct GNUNET_TIME_Relative relative_multiply_double(struct GNUNET_TIME_Relative rel, double factor)
Multiply relative time by a given floating-point factor.
Definition: time.c:465
static struct GNUNET_SCHEDULER_Task * t
Main task.
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
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:271
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TIME_randomize()

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.

Parameters
rinput time for scaling
Returns
randomized time

Definition at line 779 of file time.c.

References relative_multiply_double().

Referenced by start_dv_learn().

780 {
781  double d = ((rand() % 1001) - 500) / 1000.0;
782 
783  return relative_multiply_double (r,
784  d);
785 }
struct GNUNET_TIME_Relative relative_multiply_double(struct GNUNET_TIME_Relative rel, double factor)
Multiply relative time by a given floating-point factor.
Definition: time.c:465
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TIME_relative_get_zero_()

struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_zero_ ( void  )

Return relative time of 0ms.

Definition at line 135 of file time.c.

References zero.

136 {
137  static struct GNUNET_TIME_Relative zero;
138 
139  return zero;
140 }
static const struct GNUNET_CRYPTO_EcdsaPrivateKey zero
Public key of all zeros.
Time for relative time used by GNUnet, in microseconds.

◆ GNUNET_TIME_absolute_get_zero_()

struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_zero_ ( void  )

Return absolute time of 0ms.

Definition at line 147 of file time.c.

References zero.

148 {
149  static struct GNUNET_TIME_Absolute zero;
150 
151  return zero;
152 }
static const struct GNUNET_CRYPTO_EcdsaPrivateKey zero
Public key of all zeros.
Time for absolute times used by GNUnet, in microseconds.

◆ GNUNET_TIME_relative_get_unit_()

struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_unit_ ( void  )

Return relative time of 1 microsecond.

Return relative time of 1 microsecond.

Definition at line 159 of file time.c.

160 {
161  static struct GNUNET_TIME_Relative one = { 1 };
162 
163  return one;
164 }
Time for relative time used by GNUnet, in microseconds.

◆ GNUNET_TIME_relative_get_millisecond_()

struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_millisecond_ ( void  )

Return relative time of 1ms.

Definition at line 171 of file time.c.

172 {
173  static struct GNUNET_TIME_Relative one = { 1000 };
174 
175  return one;
176 }
Time for relative time used by GNUnet, in microseconds.

◆ GNUNET_TIME_relative_get_second_()

struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_second_ ( void  )

Return relative time of 1s.

Definition at line 183 of file time.c.

Referenced by login_cont().

184 {
185  static struct GNUNET_TIME_Relative one = { 1000 * 1000LL };
186 
187  return one;
188 }
Time for relative time used by GNUnet, in microseconds.
Here is the caller graph for this function:

◆ GNUNET_TIME_relative_get_minute_()

struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_minute_ ( void  )

Return relative time of 1 minute.

Definition at line 195 of file time.c.

Referenced by register_reciever().

196 {
197  static struct GNUNET_TIME_Relative one = { 60 * 1000 * 1000LL };
198 
199  return one;
200 }
Time for relative time used by GNUnet, in microseconds.
Here is the caller graph for this function:

◆ GNUNET_TIME_relative_get_hour_()

struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_hour_ ( void  )

Return relative time of 1 hour.

Definition at line 207 of file time.c.

208 {
209  static struct GNUNET_TIME_Relative one = { 60 * 60 * 1000 * 1000LL };
210 
211  return one;
212 }
Time for relative time used by GNUnet, in microseconds.

◆ GNUNET_TIME_relative_get_forever_()

struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_forever_ ( void  )

Return "forever".

Definition at line 219 of file time.c.

Referenced by main().

220 {
221  static struct GNUNET_TIME_Relative forever = { UINT64_MAX };
222 
223  return forever;
224 }
Time for relative time used by GNUnet, in microseconds.
Here is the caller graph for this function:

◆ GNUNET_TIME_absolute_get_forever_()

struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_forever_ ( void  )

Return "forever".

Definition at line 231 of file time.c.

232 {
233  static struct GNUNET_TIME_Absolute forever = { UINT64_MAX };
234  return forever;
235 }
Time for absolute times used by GNUnet, in microseconds.

◆ GNUNET_TIME_absolute_get()

struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get ( void  )

Get the current time.

Returns
the current time

Get the current time.

Returns
the current time

Definition at line 118 of file time.c.

References GNUNET_TIME_Absolute::abs_value_us, GETTIMEOFDAY, ret, and timestamp_offset.

Referenced by ack_proc(), add_valid_address(), add_without_sets(), announce_id(), block_create(), cache_nick(), check_vl_transmission(), cleanup_expired_records(), client_receive(), client_receive_mst_cb(), code_redirect(), comm_schedule_send(), consider_for_advertising(), consider_notify_transport(), consider_path_cb(), continue_store_activity(), convert_records_for_export(), cookie_identity_interpretation(), core_init(), create_download_context(), create_peers(), create_session(), cron_clean_data_hosts(), cummulative_ack(), data_sent_cb(), dht_connect_cb(), do_directory_scan(), do_transmit(), event_cb(), expire_blocks(), expired_processor(), find_proof(), flush_bulk(), GAS_addresses_add(), GAS_addresses_update(), GAS_mlp_solve_problem(), GCC_handle_connection_create_ack(), GCC_handle_encrypted(), GCC_transmit(), GCT_add_inbound_connection(), GDS_ROUTING_add(), get_age(), get_nick_record(), get_redirect_state(), get_timeout(), GNUNET_ATS_solver_generate_preferences_start(), GNUNET_ATS_solver_generate_property_start(), GNUNET_ATS_solver_logging_now(), GNUNET_ATS_solvers_experimentation_run(), GNUNET_ATS_TEST_experimentation_run(), GNUNET_ATS_TEST_generate_preferences_start(), GNUNET_ATS_TEST_generate_traffic_start(), GNUNET_ATS_TEST_logging_now(), GNUNET_ATS_TEST_logging_start(), GNUNET_ATS_TEST_logging_write_to_file(), GNUNET_ATS_TEST_traffic_handle_pong(), GNUNET_BANDWIDTH_tracker_init2(), GNUNET_CONTAINER_meta_data_add_publication_date(), GNUNET_DEFRAGMENT_process_fragment(), GNUNET_FS_publish_main_(), GNUNET_FS_queue_(), GNUNET_FS_search_probe_progress_(), GNUNET_FS_unindex_start(), GNUNET_GNSRECORD_block_decrypt(), GNUNET_LOAD_update(), GNUNET_LOAD_value_init(), GNUNET_SCHEDULER_add_at_with_priority(), GNUNET_SCHEDULER_add_select(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_add_with_reason_and_priority(), GNUNET_SCHEDULER_do_work(), GNUNET_SCHEDULER_run(), GNUNET_SERVER_connect_socket(), GNUNET_SERVER_inject(), GNUNET_TIME_absolute_get_duration(), GNUNET_TIME_absolute_get_monotonic(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_relative_to_absolute(), GNUNET_TIME_year_to_time(), GSC_KX_encrypt_and_transmit(), GSC_SESSIONS_set_typemap(), GSF_peer_transmit_(), GSF_pending_request_create_(), GSF_pending_request_get_message_(), GST_validation_start(), handle_client_send(), handle_client_send_request(), handle_connection_create(), handle_dht_local_get(), handle_dht_reply(), handle_dummy(), handle_dv_learn(), handle_ephemeral_key(), handle_fragment_box(), handle_icmp_back(), handle_monitor_event(), handle_monitor_next(), handle_p2p_estimate(), handle_p2p_put(), handle_stop(), handle_tcp_back(), handle_tcp_data(), handle_tcp_nat_probe(), handle_tcp_welcome(), handle_udp_back(), handler_advertisement(), insert_sorted(), iterate_zones(), iteration_start(), lookup_authz_cb(), manage_first_hop_mq(), merge_with_nick_records(), monitor_cb(), monitor_notify_connect(), monitor_notify_disconnect(), monitor_unblock(), mylog(), mysql_plugin_get_expiration(), namecache_postgres_expire_blocks(), namecache_sqlite_cache_block(), namecache_sqlite_expire_blocks(), notify_connect(), OIDC_id_token_new(), peer_transmit(), postgres_plugin_del(), postgres_plugin_get(), postgres_plugin_get_closest(), postgres_plugin_get_expiration(), postgres_plugin_get_random(), prepare_pending_acknowledgement(), printer(), printer_watch(), process_incoming(), process_local_reply(), process_queue(), process_result(), process_rq_task(), process_stdin(), progress_cb(), put_gns_record(), read_host_file(), read_process_fragment(), read_start_time(), read_stdio(), RECLAIM_TICKETS_consume(), remove_expired(), ril_calculate_discount(), ril_step(), route_message(), route_packet(), route_via_neighbour(), RPS_sampler_elem_reinit(), run(), run_zone_iteration_round(), sample_load_task(), sampler_mod_get_rand_peer(), scan(), schedule_peer_transmission(), search_start(), select_best_pending_from_link(), send_disconnect(), send_keepalive(), send_kx(), send_kx_auth(), send_syn(), send_utilization_data(), service_client_mst_cb(), session_disconnect_adapter(), set_feedback_task(), setup_estimate_message(), setup_neighbour(), setup_state_record(), shutdown_task(), sign_ephemeral_key(), solver_bandwidth_changed_cb(), sqlite_plugin_del(), sqlite_plugin_get(), sqlite_plugin_get_closest(), sqlite_plugin_get_expiration(), start_address_validation(), start_dht_request(), start_download(), start_dv_learn(), start_job(), start_local_query(), start_peers_task(), start_publish(), stat_iterator(), store_completed_cb(), store_skipped_key(), suggest_hello(), t_ax_encrypt(), test_exist_cb(), tmt_rdy_ping(), transmit_next(), transmit_ping_if_allowed(), transmit_ready_callback_wrapper(), try_transmission(), udp_plugin_create_session(), udp_plugin_send(), udp_select_send(), unix_plugin_send(), update_active_address(), update_ax_by_kx(), update_excess(), update_hello(), update_hostlist(), update_ping_data(), update_tracker(), update_velocity(), updateAgedLoad(), and wait_op_completion().

119 {
120  struct GNUNET_TIME_Absolute ret;
121  struct timeval tv;
122 
123  GETTIMEOFDAY (&tv, NULL);
124  ret.abs_value_us =
125  (uint64_t) (((uint64_t) tv.tv_sec * 1000LL * 1000LL) +
126  ((uint64_t) tv.tv_usec)) + timestamp_offset;
127  return ret;
128 }
static long long timestamp_offset
Variable used to simulate clock skew.
Definition: time.c:45
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GETTIMEOFDAY(t, n)
Definition: plibc.h:715
Time for absolute times used by GNUnet, in microseconds.

◆ GNUNET_TIME_relative_to_absolute()

struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute ( struct GNUNET_TIME_Relative  rel)

Convert relative time to an absolute time in the future.

Parameters
relrelative time to convert
Returns
timestamp that is "rel" in the future, or FOREVER if rel==FOREVER (or if we would overflow)
timestamp that is "rel" in the future, or FOREVER if rel==FOREVER (or if we would overflow)

Definition at line 245 of file time.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_break, GNUNET_TIME_absolute_get(), GNUNET_TIME_UNIT_FOREVER_ABS, and ret.

Referenced by add_setter_action(), add_without_sets(), boot_queue(), cadet_reply_proc(), check_for_glue(), client_receive_mst_cb(), client_reschedule_session_timeout(), create_macendpoint(), create_session(), data_sent_cb(), do_dht_put(), download_hostlist(), forward_dv_box(), get_cred_issuer_cb(), GNUNET_CONNECTION_notify_transmit_ready(), GNUNET_CONNECTION_receive(), GNUNET_DNSPARSER_parse_record(), GNUNET_GNSRECORD_record_get_expiration_time(), GNUNET_OS_command_run(), GNUNET_RESOLVER_hostname_get(), GNUNET_RESOLVER_ip_get(), GNUNET_SCHEDULER_add_delayed_with_priority(), GNUNET_SCHEDULER_add_select(), GSC_SESSIONS_transmit(), GSF_pending_request_create_(), GST_ats_block_address(), GST_manipulation_send(), GST_neighbours_handle_session_ack(), GST_neighbours_handle_session_syn(), GST_neighbours_handle_session_syn_ack(), GST_neighbours_keepalive_response(), GST_neighbours_send(), GST_neighbours_session_terminated(), GST_validation_handle_ping(), GST_validation_handle_pong(), handle_client_call_message(), handle_dht_reply(), handle_dv_box(), handle_dv_learn(), handle_find_peer(), handle_fragment_box(), handle_gns_resolution_result(), handle_p2p_migration_stop(), handle_p2p_put(), handle_reliability_box(), handle_validation_response(), http_client_plugin_get_session(), http_client_plugin_update_inbound_delay(), http_server_plugin_update_inbound_delay(), identity_cb(), learn_dv_path(), listen_cb(), login_cont(), maint_child_death(), make_file(), master_task(), modify_address(), mq_init(), ns_lookup_result_cb(), plan(), process_data(), process_record(), process_result(), publish_fs_connect_complete_cb(), put_migration_continuation(), refresh_hello_task(), regex_iterator(), reschedule_queue_timeout(), reschedule_receiver_timeout(), reschedule_sender_timeout(), reschedule_session_timeout(), revalidate_address(), run(), schedule_next_hello(), send_create(), send_create_ack(), send_keepalive(), send_kx(), send_kx_auth(), send_session_syn_ack_cont(), send_session_syn_cont(), send_syn(), send_syn_ack_message(), send_with_fragmentation(), server_lookup_connection(), server_receive_mst_cb(), server_reschedule_session_timeout(), setup_filter(), setup_out_cipher(), setup_queue(), setup_sender(), sign_ephemeral_key(), start_address_validation(), store_pi(), suggest_start_cb(), switch_address_bl_check_cont(), tcp_plugin_send(), tcp_plugin_update_inbound_delay(), transmit_next(), transmit_on_queue(), transmit_ping_if_allowed(), transmit_request(), udp_plugin_create_session(), udp_plugin_send(), unix_plugin_get_session(), update_timeout(), validation_start_cb(), vpn_allocation_cb(), and wlan_plugin_update_session_timeout().

246 {
247  struct GNUNET_TIME_Absolute ret;
248 
249  if (rel.rel_value_us == UINT64_MAX)
252 
253  if (rel.rel_value_us + now.abs_value_us < rel.rel_value_us)
254  {
255  GNUNET_break (0); /* overflow... */
257  }
258  ret.abs_value_us = rel.rel_value_us + now.abs_value_us;
259  return ret;
260 }
uint64_t rel_value_us
The actual value.
static int ret
Final status code.
Definition: gnunet-arm.c:89
uint64_t abs_value_us
The actual value.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get()
Get the current time (works just as "time", just that we use the unit of time that the cron-jobs use ...
Definition: time.c:118
Time for absolute times used by GNUnet, in microseconds.
Here is the call graph for this function:

◆ GNUNET_TIME_round_abs()

int GNUNET_TIME_round_abs ( struct GNUNET_TIME_Absolute at)

Round a time value so that it is suitable for transmission via JSON encodings.

Parameters
attime to round
Returns
GNUNET_OK if time was already rounded, GNUNET_NO if it was just now rounded

Definition at line 80 of file time.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_NO, GNUNET_OK, and GNUNET_TIME_UNIT_FOREVER_ABS.

Referenced by GNUNET_JSON_from_time_abs().

81 {
82  if (at->abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us)
83  return GNUNET_OK;
84  if (0 == at->abs_value_us % 1000000)
85  return GNUNET_OK;
86  at->abs_value_us -= at->abs_value_us % 1000000;
87  return GNUNET_NO;
88 }
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
uint64_t abs_value_us
The actual value.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
Here is the caller graph for this function:

◆ GNUNET_TIME_round_rel()

int GNUNET_TIME_round_rel ( struct GNUNET_TIME_Relative rt)

Round a time value so that it is suitable for transmission via JSON encodings.

Parameters
rttime to round
Returns
GNUNET_OK if time was already rounded, GNUNET_NO if it was just now rounded

Definition at line 100 of file time.c.

References GNUNET_NO, GNUNET_OK, GNUNET_TIME_UNIT_FOREVER_REL, and GNUNET_TIME_Relative::rel_value_us.

Referenced by GNUNET_JSON_from_time_rel().

101 {
102  if (rt->rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
103  return GNUNET_OK;
104  if (0 == rt->rel_value_us % 1000000)
105  return GNUNET_OK;
106  rt->rel_value_us -= rt->rel_value_us % 1000000;
107  return GNUNET_NO;
108 }
uint64_t rel_value_us
The actual value.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
Here is the caller graph for this function:

◆ GNUNET_TIME_relative_min()

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.

Parameters
t1first timestamp
t2other timestamp
Returns
timestamp that is smaller

Definition at line 271 of file time.c.

Referenced by announce_id(), calculate_put_interval(), check_timeouts(), check_zone_namestore_next(), delayed_restart_task(), download_prepare(), encapsulate_for_dv(), find_advertisable_hello(), find_min_max_it(), GNUNET_ATS_TEST_traffic_handle_pong(), GNUNET_FRAGMENT_process_ack(), GNUNET_TIME_randomized_backoff(), handle_validation_response(), master_task(), process_job_queue(), put_migration_continuation(), reconnect(), revalidate_address(), route_control_message_without_fc(), route_via_neighbour(), schedule_next_put(), schedule_next_task(), start_address_validation(), and try_connect_using_address().

273 {
274  return (t1.rel_value_us < t2.rel_value_us) ? t1 : t2;
275 }
uint64_t rel_value_us
The actual value.
Here is the caller graph for this function:

◆ GNUNET_TIME_relative_max()

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.

Parameters
t1first timestamp
t2other timestamp
Returns
timestamp that is larger

Definition at line 286 of file time.c.

Referenced by announce_id(), consider_gathering(), data_sent_cb(), find_min_max_it(), GNUNET_CURL_perform2(), GNUNET_TIME_randomized_backoff(), GST_manipulation_recv(), put_migration_continuation(), reconnect(), schedule_next_task(), send_keep_alive(), and transmit_next().

288 {
289  return (t1.rel_value_us > t2.rel_value_us) ? t1 : t2;
290 }
uint64_t rel_value_us
The actual value.
Here is the caller graph for this function:

◆ GNUNET_TIME_absolute_min()

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.

Parameters
t1first timestamp
t2other timestamp
Returns
timestamp that is smaller

Return the minimum of two absolute time values.

Parameters
t1first timestamp
t2other timestamp
Returns
timestamp that is smaller

Definition at line 302 of file time.c.

Referenced by cadet_reply_proc(), cummulative_ack(), find_other_matching(), GNUNET_GNSRECORD_record_get_expiration_time(), handle_dht_reply(), handle_p2p_put(), handle_validation_response(), ns_lookup_result_cb(), process_result(), and try_transmission().

304 {
305  return (t1.abs_value_us < t2.abs_value_us) ? t1 : t2;
306 }
uint64_t abs_value_us
The actual value.
Here is the caller graph for this function:

◆ GNUNET_TIME_absolute_max()

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.

Parameters
t1first timestamp
t2other timestamp
Returns
timestamp that is smaller

Return the maximum of two absolute time values.

Parameters
t1first timestamp
t2other timestamp
Returns
timestamp that is bigger

Definition at line 317 of file time.c.

Referenced by add_valid_address(), check_link_down(), find_max_expire(), GNUNET_GNSRECORD_record_get_expiration_time(), GNUNET_TIME_absolute_get_monotonic(), handle_dht_result(), learn_dv_path(), neighbour_dv_monotime_cb(), put_cb(), suggest_start_cb(), timeout_hello_validation(), transmit_ping_if_allowed(), udp_select_send(), and update_iterator().

319 {
320  return (t1.abs_value_us > t2.abs_value_us) ? t1 : t2;
321 }
uint64_t abs_value_us
The actual value.
Here is the caller graph for this function:

◆ GNUNET_TIME_absolute_get_remaining()

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?

Parameters
futuresome absolute time, typically in the future
Returns
future - now, or 0 if now >= future, or FOREVER if future==FOREVER.
future - now, or 0 if now >= future, or FOREVER if future==FOREVER.

Definition at line 331 of file time.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_TIME_absolute_get(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TIME_UNIT_ZERO, GNUNET_TIME_Relative::rel_value_us, and ret.

Referenced by add_record(), add_valid_address(), announce_id(), backtalker_timeout_cb(), block_plugin_dns_evaluate(), check_for_glue(), check_has_addr(), check_link_down(), check_timeouts(), client_session_timeout(), cmd_read(), connect_success_continuation(), connection_ready_cb(), consider_peer_destroy(), core_read_finished_cb(), count_address(), data_sent_cb(), datacache_get_iterator(), delayed_restart_task(), display_record(), do_dht_put(), download_prepare(), evaluate_block_regex_accept(), find_advertisable_hello(), get_cb(), get_transmit_delay(), GNUNET_ATS_TEST_traffic_handle_pong(), GNUNET_CONNECTION_notify_transmit_ready(), GNUNET_CONNECTION_receive(), GNUNET_DATASTORE_put(), GNUNET_GNSRECORD_is_expired(), GSF_block_peer_migration_(), GST_validation_handle_ping(), GST_validation_handle_pong(), handle_cadet_ring_message(), handle_dht_p2p_put(), handle_dht_p2p_result(), handle_dht_response(), handle_encrypted(), handle_namecache_block_response(), learn_dv_path(), macendpoint_timeout(), master_task(), monitor_cb(), path_cleanup_cb(), pick_random_dv_hops(), plan(), print_address(), print_plugin_event_info(), process_hello(), process_incoming(), process_job_queue(), process_migration_content(), process_pending_messages(), process_queue(), process_record(), proto_read_kx(), put_migration_continuation(), queue_read(), queue_read_kx(), queue_timeout(), queue_write(), quota_processor(), reassembly_cleanup_task(), remove_timeout_messages_and_select(), revalidate_address(), revive_migration(), schedule_next_hello(), schedule_peer_transmission(), schedule_select_v4(), schedule_select_v6(), select_loop(), send_keep_alive(), send_keepalive(), server_access_cb(), server_session_timeout(), session_timeout(), sqlite_plugin_put(), suggest_hello(), suggest_start_cb(), t_ax_encrypt(), task_download(), timeout_cb(), timeout_hello_validation(), transmit_item(), transmit_next_request_task(), transmit_ready(), try_connect_using_address(), try_transmission(), try_transmission_to_peer(), udp_plugin_send(), unix_plugin_do_write(), update_ephemeral(), update_flood_message(), validate_address_iterator(), validation_start_cb(), and watch_cb().

332 {
333  struct GNUNET_TIME_Relative ret;
334 
335  if (future.abs_value_us == UINT64_MAX)
338 
339  if (now.abs_value_us > future.abs_value_us)
340  return GNUNET_TIME_UNIT_ZERO;
341  ret.rel_value_us = future.abs_value_us - now.abs_value_us;
342  return ret;
343 }
static int ret
Final status code.
Definition: gnunet-arm.c:89
uint64_t abs_value_us
The actual value.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get()
Get the current time (works just as "time", just that we use the unit of time that the cron-jobs use ...
Definition: time.c:118
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:

◆ GNUNET_TIME_calculate_eta()

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.

Parameters
startwhen did the operation start?
finishedhow much has been done?
totalhow much must be done overall (same unit as for "finished")
Returns
remaining duration for the operation, assuming it continues at the same speed

Definition at line 549 of file time.c.

References GNUNET_break, GNUNET_TIME_absolute_get_duration(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TIME_UNIT_ZERO, GNUNET_TIME_Relative::rel_value_us, ret, and start.

Referenced by GNUNET_FS_download_make_status_(), GNUNET_FS_publish_make_status_(), GNUNET_FS_unindex_make_status_(), and progress_proc().

551 {
552  struct GNUNET_TIME_Relative dur;
553  double exp;
554  struct GNUNET_TIME_Relative ret;
555 
556  GNUNET_break (finished <= total);
557  if (finished >= total)
558  return GNUNET_TIME_UNIT_ZERO;
559  if (0 == finished)
561  dur = GNUNET_TIME_absolute_get_duration (start);
562  exp = ((double) dur.rel_value_us) * ((double) total) / ((double) finished);
563  ret.rel_value_us = ((uint64_t) exp) - dur.rel_value_us;
564  return ret;
565 }
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
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 "when...
Definition: time.c:373
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TIME_absolute_get_difference()

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.

Use this function instead of actual subtraction to ensure that "FOREVER" and overflows are handeled correctly.

Parameters
startsome absolute time
endsome absolute time (typically larger or equal to start)
Returns
0 if start >= end; FOREVER if end==FOREVER; otherwise end - start

Use this function instead of actual subtraction to ensure that "FOREVER" and overflows are handled correctly.

Returns
0 if start >= end; FOREVER if end==FOREVER; otherwise end - start

Definition at line 353 of file time.c.

References end, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TIME_UNIT_ZERO, GNUNET_TIME_Relative::rel_value_us, ret, and start.

Referenced by client_receive(), expire_blocks(), expired_processor(), GNUNET_ATS_solver_logging_write_to_disk(), GNUNET_ATS_TEST_logging_now(), GNUNET_ATS_TEST_logging_write_to_file(), GNUNET_ATS_TEST_traffic_handle_pong(), handle_client_join(), ril_calculate_discount(), sampler_mod_get_rand_peer(), send_utilization_data(), and update_timeout().

355 {
356  struct GNUNET_TIME_Relative ret;
357 
358  if (end.abs_value_us == UINT64_MAX)
360  if (end.abs_value_us < start.abs_value_us)
361  return GNUNET_TIME_UNIT_ZERO;
362  ret.rel_value_us = end.abs_value_us - start.abs_value_us;
363  return ret;
364 }
static int ret
Final status code.
Definition: gnunet-arm.c:89
uint64_t abs_value_us
The actual value.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
Time for relative time used by GNUnet, in microseconds.
Here is the caller graph for this function:

◆ GNUNET_TIME_absolute_get_duration()

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 "hence".

Parameters
whencesome absolute time, typically in the past
Returns
0 if hence > now, otherwise now-hence.

Get the duration of an operation as the difference of the current time and the given start time "hence".

Returns
0 if whence > now, otherwise now-whence.

Definition at line 373 of file time.c.

References GNUNET_TIME_absolute_get(), GNUNET_TIME_UNIT_ZERO, GNUNET_TIME_Relative::rel_value_us, and ret.

Referenced by consider_notify_transport(), consider_sending_fc(), do_directory_scan(), do_shutdown(), evaluate_connection(), find_best_address_it(), find_proof(), flush_bulk(), forward_dv_learn(), fragmented_message_done(), GAS_mlp_solve_problem(), get_delay(), get_preference(), get_property(), GNUNET_ATS_solver_logging_now(), GNUNET_BANDWIDTH_tracker_get_available(), GNUNET_FRAGMENT_process_ack(), GNUNET_FS_download_make_status_(), GNUNET_FS_publish_make_status_(), GNUNET_FS_search_make_status_(), GNUNET_FS_search_probe_progress_(), GNUNET_FS_unindex_make_status_(), GNUNET_SCHEDULER_do_work(), GNUNET_TIME_calculate_eta(), GSC_CLIENTS_solicit_request(), GSF_peer_update_performance_(), GSF_update_datastore_delay_(), GST_neighbours_keepalive_response(), GST_validation_handle_pong(), handle_acknowledged(), handle_client_send(), handle_data(), handle_encrypted(), handle_fragment_box(), handle_matching_ack(), handle_monitor_event(), handle_result(), handle_send_transmit_continuation(), handle_validation_response(), internal_update(), iteration_done(), lookup_authz_cb(), maint_child_death(), mylog(), namecache_sqlite_cache_block(), notify_client_chk_update(), odc_warn_delay_task(), peer_transmit(), pong_handler(), process_parallel_lookup_result(), process_queue(), process_reply(), process_result(), process_result_with_request(), process_stdin(), prof_time(), progress_cb(), put_gns_record(), put_migration_continuation(), qc_message_sent(), receive_ready(), regex_found_handler(), run(), run_zone_iteration_round(), schedule_next_task(), set_feedback_task(), shutdown_task(), signal_probe_result(), solver_bandwidth_changed_cb(), stop_job(), store_completed_cb(), test_master(), timeout_episode(), timeout_experiment(), transmit_cummulative_ack_cb(), update_tslots(), update_velocity(), updateAgedLoad(), warn_delay_task(), warn_no_client_continue(), warn_no_receive_done(), and write_start_time().

374 {
375  struct GNUNET_TIME_Absolute now;
376  struct GNUNET_TIME_Relative ret;
377 
378  now = GNUNET_TIME_absolute_get ();
379  if (whence.abs_value_us > now.abs_value_us)
380  return GNUNET_TIME_UNIT_ZERO;
381  ret.rel_value_us = now.abs_value_us - whence.abs_value_us;
382  return ret;
383 }
static int ret
Final status code.
Definition: gnunet-arm.c:89
uint64_t abs_value_us
The actual value.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get()
Get the current time (works just as "time", just that we use the unit of time that the cron-jobs use ...
Definition: time.c:118
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:

◆ GNUNET_TIME_absolute_add()

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.

Parameters
startsome absolute time
durationsome relative time to add
Returns
FOREVER if either argument is FOREVER or on overflow; start+duration otherwise
FOREVER if either argument is FOREVER or on overflow; start+duration otherwise

Definition at line 393 of file time.c.

References GNUNET_TIME_Absolute::abs_value_us, duration, GNUNET_break, GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_Relative::rel_value_us, ret, and start.

Referenced by announce_id(), block_create(), core_init(), enqueue_fragment(), get_transmit_delay(), handle_ephemeral_key(), OIDC_id_token_new(), process_incoming(), process_job_queue(), process_queue(), run(), session_disconnect_adapter(), suggest_start_cb(), t_ax_encrypt(), timeout_cb(), udp_plugin_send(), unix_plugin_send(), update_ax_by_kx(), update_ephemeral(), update_flood_message(), update_next_challenge_time(), and update_ping_data().

395 {
396  struct GNUNET_TIME_Absolute ret;
397 
398  if ((start.abs_value_us == UINT64_MAX) || (duration.rel_value_us == UINT64_MAX))
400  if (start.abs_value_us + duration.rel_value_us < start.abs_value_us)
401  {
402  GNUNET_break (0);
404  }
405  ret.abs_value_us = start.abs_value_us + duration.rel_value_us;
406  return ret;
407 }
uint64_t rel_value_us
The actual value.
static int ret
Final status code.
Definition: gnunet-arm.c:89
uint64_t abs_value_us
The actual value.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
Time for absolute times used by GNUnet, in microseconds.
Here is the caller graph for this function:

◆ GNUNET_TIME_absolute_subtract()

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.

Parameters
startsome absolute time
durationsome relative time to subtract
Returns
ZERO if start <= duration, or FOREVER if start time is FOREVER; start-duration otherwise

Definition at line 419 of file time.c.

References GNUNET_TIME_Absolute::abs_value_us, duration, GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TIME_Relative::rel_value_us, ret, and start.

Referenced by GSF_pending_request_create_(), handle_ephemeral_key(), handle_validation_response(), and read_start_time().

421 {
422  struct GNUNET_TIME_Absolute ret;
423 
424  if (start.abs_value_us <= duration.rel_value_us)
426  if (start.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us)
428  ret.abs_value_us = start.abs_value_us - duration.rel_value_us;
429  return ret;
430 }
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
uint64_t rel_value_us
The actual value.
static int ret
Final status code.
Definition: gnunet-arm.c:89
uint64_t abs_value_us
The actual value.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
Time for absolute times used by GNUnet, in microseconds.
Here is the caller graph for this function:

◆ GNUNET_TIME_relative_multiply()

struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply ( struct GNUNET_TIME_Relative  rel,
unsigned long long  factor 
)

Multiply relative time by a given factor.

Parameters
relsome duration
factorinteger to multiply with
Returns
FOREVER if rel=FOREVER or on overflow; otherwise rel*factor
FOREVER if rel=FOREVER or on overflow; otherwise rel*factor

Definition at line 439 of file time.c.

References GNUNET_break, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TIME_UNIT_ZERO, GNUNET_TIME_Relative::rel_value_us, and ret.

Referenced by announce_next_regex(), ats_perf_cb(), ats_perf_mon_cb(), attempt_connect_task(), check_zone_namestore_next(), churn(), churn_test_cb(), cleanup_expired_records(), client_schedule(), connection_create(), consider_gathering(), context_task(), create_macendpoint(), curl_download_prepare(), delay_ms_rnd(), download_prepare(), expire_records_continuation(), get_randomized_delay(), GNUNET_DNSPARSER_parse_record(), GNUNET_RPS_sub_start(), GNUNET_STATISTICS_destroy(), GNUNET_TESTBED_run(), GSF_pending_request_create_(), handle_connection_create(), handle_dv_learn(), handle_fragment_box(), handle_p2p_put(), handle_validation_response(), helper_read(), helper_write(), iter_finished(), libgnunet_plugin_transport_udp_init(), login_cont(), lookup_authz_cb(), main(), mal_cb(), peer_id_cb(), plan(), process_job_queue(), profiler_cb(), reannounce_regex(), reconnect(), register_sender(), rest_process_request(), revalidate_address(), run(), schedule_missing_requests(), schedule_next_put(), send_hello(), send_hello_beacon(), short_wait(), start_dv_learn(), start_helper(), start_test(), suggest_start_cb(), task_check(), test_master(), timeout_cb(), transmit_on_queue(), and udp_plugin_create_session().

441 {
442  struct GNUNET_TIME_Relative ret;
443 
444  if (0 == factor)
445  return GNUNET_TIME_UNIT_ZERO;
446  if (rel.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
448  ret.rel_value_us = rel.rel_value_us * factor;
449  if (ret.rel_value_us / factor != rel.rel_value_us)
450  {
451  GNUNET_break (0);
453  }
454  return ret;
455 }
uint64_t rel_value_us
The actual value.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
Time for relative time used by GNUnet, in microseconds.

◆ GNUNET_TIME_relative_saturating_multiply()

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.

Parameters
relsome duration
factorinteger to multiply with
Returns
FOREVER if rel=FOREVER or on overflow; otherwise rel*factor

Definition at line 499 of file time.c.

References GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TIME_UNIT_ZERO, GNUNET_TIME_Relative::rel_value_us, and ret.

Referenced by compute_rand_delay(), daemon_started(), GNUNET_DEFRAGMENT_process_fragment(), GNUNET_FRAGMENT_context_destroy(), GNUNET_FRAGMENT_process_ack(), GNUNET_FS_search_start_probe_(), process_job_queue(), put_migration_continuation(), reconnect(), ril_step_schedule_next(), schedule_next_task(), transmit_next(), and update_excess().

501 {
502  struct GNUNET_TIME_Relative ret;
503 
504  if (0 == factor)
505  return GNUNET_TIME_UNIT_ZERO;
506  if (rel.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
508  ret.rel_value_us = rel.rel_value_us * factor;
509  if (ret.rel_value_us / factor != rel.rel_value_us)
510  {
512  }
513  return ret;
514 }
uint64_t rel_value_us
The actual value.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
Time for relative time used by GNUnet, in microseconds.
Here is the caller graph for this function:

◆ GNUNET_TIME_relative_divide()

struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide ( struct GNUNET_TIME_Relative  rel,
unsigned long long  factor 
)

Divide relative time by a given factor.

Parameters
relsome duration
factorinteger to divide by
Returns
FOREVER if rel=FOREVER or factor==0; otherwise rel/factor

Definition at line 525 of file time.c.

References GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TIME_Relative::rel_value_us, and ret.

Referenced by adapt_parallelism(), add_valid_address(), calculate_put_interval(), compute_rand_delay(), consider_gathering(), do_shutdown(), find_proof(), GST_neighbours_keepalive_response(), GST_validation_handle_pong(), handle_dv_learn(), handle_reliability_box(), peerstore_store_own_cb(), run_zone_iteration_round(), schedule_next_put(), send_keep_alive(), send_with_session(), start_address_validation(), store_completed_cb(), udp_plugin_send(), and update_timeout().

527 {
528  struct GNUNET_TIME_Relative ret;
529 
530  if ((0 == factor) ||
531  (rel.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us))
533  ret.rel_value_us = rel.rel_value_us / factor;
534  return ret;
535 }
uint64_t rel_value_us
The actual value.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
Time for relative time used by GNUnet, in microseconds.
Here is the caller graph for this function:

◆ GNUNET_TIME_relative_add()

struct GNUNET_TIME_Relative GNUNET_TIME_relative_add ( struct GNUNET_TIME_Relative  a1,
struct GNUNET_TIME_Relative  a2 
)

Add relative times together.

Parameters
a1some relative time
a2some other relative time
Returns
FOREVER if either argument is FOREVER or on overflow; a1+a2 otherwise
Parameters
a1first timestamp
a2second timestamp
Returns
FOREVER if either argument is FOREVER or on overflow; a1+a2 otherwise

Definition at line 576 of file time.c.

References GNUNET_break, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TIME_Relative::rel_value_us, and ret.

Referenced by adapt_parallelism(), compute_rand_delay(), forward_dv_learn(), GNUNET_CURL_perform2(), load_episodes(), process_queue(), process_result(), revalidate_address(), run(), sign_ephemeral_key(), stop_job(), store_completed_cb(), topology_setup_done(), update_tslots(), and update_velocity().

578 {
579  struct GNUNET_TIME_Relative ret;
580 
581  if ((a1.rel_value_us == UINT64_MAX) || (a2.rel_value_us == UINT64_MAX))
583  if (a1.rel_value_us + a2.rel_value_us < a1.rel_value_us)
584  {
585  GNUNET_break (0);
587  }
588  ret.rel_value_us = a1.rel_value_us + a2.rel_value_us;
589  return ret;
590 }
uint64_t rel_value_us
The actual value.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
Time for relative time used by GNUnet, in microseconds.
Here is the caller graph for this function:

◆ GNUNET_TIME_relative_subtract()

struct GNUNET_TIME_Relative GNUNET_TIME_relative_subtract ( struct GNUNET_TIME_Relative  a1,
struct GNUNET_TIME_Relative  a2 
)

Subtract relative timestamp from the other.

Parameters
a1first timestamp
a2second timestamp
Returns
ZERO if a2>=a1 (including both FOREVER), FOREVER if a1 is FOREVER, a1-a2 otherwise

Definition at line 601 of file time.c.

References GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TIME_UNIT_ZERO, GNUNET_TIME_Relative::rel_value_us, and ret.

Referenced by check_zone_namestore_next(), GNUNET_FS_search_probe_progress_(), handle_acknowledged(), handle_dv_learn(), learn_dv_path(), ril_step_schedule_next(), store_completed_cb(), and update_velocity().

603 {
604  struct GNUNET_TIME_Relative ret;
605 
606  if (a2.rel_value_us >= a1.rel_value_us)
607  return GNUNET_TIME_UNIT_ZERO;
608  if (a1.rel_value_us == UINT64_MAX)
610  ret.rel_value_us = a1.rel_value_us - a2.rel_value_us;
611  return ret;
612 }
uint64_t rel_value_us
The actual value.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
Time for relative time used by GNUnet, in microseconds.
Here is the caller graph for this function:

◆ GNUNET_TIME_relative_hton()

struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton ( struct GNUNET_TIME_Relative  a)

Convert relative time to network byte order.

Parameters
atime to convert
Returns
converted time value
Parameters
atime to convert
Returns
time in network byte order

Definition at line 622 of file time.c.

References GNUNET_htonll(), GNUNET_TIME_RelativeNBO::rel_value_us__, and ret.

Referenced by announce_reconnect(), forward_dv_learn(), GAS_handle_reservation_request(), GNUNET_ATS_performance_give_feedback(), GNUNET_ATS_properties_hton(), GNUNET_RPS_sub_start(), GNUNET_TRANSPORT_address_to_string(), GNUNET_TRANSPORT_communicator_receive(), GNUNET_TRANSPORT_manipulation_set(), GSF_block_peer_migration_(), mq_send_impl(), notify_monitor(), properties_hton(), send_add_address(), start_dv_learn(), and transmit_cummulative_ack_cb().

623 {
625 
626  ret.rel_value_us__ = GNUNET_htonll (a.rel_value_us);
627  return ret;
628 }
uint64_t rel_value_us
The actual value.
Time for relative time used by GNUnet, in microseconds and in network byte order. ...
static int ret
Final status code.
Definition: gnunet-arm.c:89
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:35
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TIME_relative_ntoh()

struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh ( struct GNUNET_TIME_RelativeNBO  a)

Convert relative time from network byte order.

Parameters
atime to convert
Returns
converted time value
Parameters
atime to convert
Returns
time in host byte order

Definition at line 638 of file time.c.

References GNUNET_ntohll(), GNUNET_TIME_Relative::rel_value_us, and ret.

Referenced by forward_dv_learn(), GNUNET_ATS_properties_ntoh(), GST_manipulation_set_metric(), handle_add_address(), handle_announce(), handle_client_address_to_string(), handle_client_send(), handle_client_start_sub(), handle_dv_learn(), handle_feedback(), handle_monitor_data(), handle_p2p_migration_stop(), handle_reliability_ack(), handle_reservation_result(), handle_validation_response(), and prop_ntoh().

639 {
640  struct GNUNET_TIME_Relative ret;
641 
642  ret.rel_value_us = GNUNET_ntohll (a.rel_value_us__);
643  return ret;
644 }
uint64_t rel_value_us__
The actual value (in network byte order).
static int ret
Final status code.
Definition: gnunet-arm.c:89
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:48
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TIME_absolute_hton()

struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton ( struct GNUNET_TIME_Absolute  a)

Convert absolute time to network byte order.

Parameters
atime to convert
Returns
converted time value
Parameters
atime to convert
Returns
time in network byte order

Definition at line 654 of file time.c.

References GNUNET_TIME_AbsoluteNBO::abs_value_us__, GNUNET_htonll(), and ret.

Referenced by block_create(), client_response_handler(), consider_sending_fc(), create_loc_uri(), do_dht_put(), encapsulate_for_dv(), extract_abs_time_nbo(), forward_reply(), GDS_CLIENTS_process_get_resp(), GDS_CLIENTS_process_put(), GDS_NEIGHBOURS_handle_put(), GDS_NEIGHBOURS_handle_reply(), get_cb(), GNUNET_CONSENSUS_create(), GNUNET_DATASTORE_put(), GNUNET_DHT_put(), GNUNET_FS_uri_loc_create(), GNUNET_HELLO_add_address(), GNUNET_HELLO_extract_address(), GNUNET_HELLO_sign_address(), GNUNET_SECRETSHARING_create_session(), GNUNET_SECRETSHARING_decrypt(), GNUNET_TIME_absolute_get_monotonic(), GSC_KX_encrypt_and_transmit(), GSC_KX_handle_client_monitor_peers(), GST_clients_broadcast_peer_notification(), GST_validation_handle_ping(), handle_client_call_message(), handle_client_loc_sign(), handle_datastore_reply(), handle_p2p_reply(), inject_rekey(), monitor_notify_all(), mq_send(), notify_monitor(), parse_abs_time_nbo(), PEERSTORE_create_record_mq_envelope(), plugin_session_info_cb(), regex_iterator(), send_disconnect(), send_peer_information(), send_request(), send_syn(), send_syn_ack_message(), setup_estimate_message(), setup_flood_message(), sign_ephemeral_key(), start_dv_learn(), tmt_rdy_ping(), transmit_content(), transmit_item(), transmit_kx(), transmit_status(), update_backtalker_monotime(), uri_loc_parse(), and validation_transmit_on_queue().

655 {
657 
658  ret.abs_value_us__ = GNUNET_htonll (a.abs_value_us);
659  return ret;
660 }
static int ret
Final status code.
Definition: gnunet-arm.c:89
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
uint64_t abs_value_us
The actual value.
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:35
Here is the call graph for this function:

◆ GNUNET_TIME_absolute_ntoh()

struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh ( struct GNUNET_TIME_AbsoluteNBO  a)

Convert absolute time from network byte order.

Parameters
atime to convert
Returns
converted time value
Parameters
atime to convert
Returns
time in host byte order

Definition at line 670 of file time.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_ntohll(), and ret.

Referenced by backtalker_monotime_cb(), bind_nbotime(), block_plugin_dns_evaluate(), do_dht_put(), evaluate_block_regex_accept(), expire_blocks(), GNUNET_HELLO_iterate_addresses(), GNUNET_JSON_from_time_abs_nbo(), GNUNET_TIME_absolute_get_monotonic(), GST_neighbours_handle_disconnect_message(), GST_neighbours_handle_session_syn(), GST_neighbours_handle_session_syn_ack(), GST_validation_handle_pong(), handle_block_cache(), handle_cadet_ring_message(), handle_client_decrypt(), handle_client_join(), handle_client_keygen(), handle_client_loc_sign(), handle_client_redirect_to_ip(), handle_client_redirect_to_service(), handle_client_send_request(), handle_data(), handle_dht_local_put(), handle_dht_p2p_put(), handle_dht_p2p_result(), handle_dht_response(), handle_dht_result(), handle_dv_box(), handle_dv_learn(), handle_encrypted(), handle_ephemeral_key(), handle_estimate(), handle_event(), handle_flow_control(), handle_lookup_block_it(), handle_lookup_block_response(), handle_monitor_data(), handle_monitor_get_resp(), handle_monitor_put(), handle_namecache_block_response(), handle_p2p_estimate(), handle_p2p_put(), handle_put(), handle_receive_info(), handle_reply(), handle_response(), handle_result(), handle_signature_response(), handle_status(), handle_validation_response(), namecache_sqlite_cache_block(), neighbour_dv_monotime_cb(), PEERSTORE_parse_record_message(), pong_handler(), process_client_result(), put_cb(), transmit_task_cb(), and update_flood_message().

671 {
672  struct GNUNET_TIME_Absolute ret;
673 
674  ret.abs_value_us = GNUNET_ntohll (a.abs_value_us__);
675  return ret;
676 
677 }
static int ret
Final status code.
Definition: gnunet-arm.c:89
uint64_t abs_value_us__
The actual value (in network byte order).
Time for absolute times used by GNUnet, in microseconds.
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:48
Here is the call graph for this function:

◆ GNUNET_TIME_set_offset()

void GNUNET_TIME_set_offset ( long long  offset)

Set the timestamp offset for this instance.

Parameters
offsetthe offset to skew the locale time by

Definition at line 53 of file time.c.

References timestamp_offset.

Referenced by do_speedup(), GNUNET_PROGRAM_run2(), GNUNET_SERVICE_run_(), and LEGACY_SERVICE_run().

54 {
55  timestamp_offset = offset;
56 }
static long long timestamp_offset
Variable used to simulate clock skew.
Definition: time.c:45
Here is the caller graph for this function:

◆ GNUNET_TIME_get_offset()

long long GNUNET_TIME_get_offset ( void  )

Get the timestamp offset for this instance.

Returns
the offset we currently skew the locale time by

Definition at line 65 of file time.c.

References timestamp_offset.

Referenced by mylog().

66 {
67  return timestamp_offset;
68 }
static long long timestamp_offset
Variable used to simulate clock skew.
Definition: time.c:45
Here is the caller graph for this function:

◆ GNUNET_TIME_get_current_year()

unsigned int GNUNET_TIME_get_current_year ( void  )

Return the current year (i.e.

'2011').

Definition at line 684 of file time.c.

References t.

Referenced by main().

685 {
686  time_t tp;
687  struct tm *t;
688 
689  tp = time (NULL);
690  t = gmtime (&tp);
691  if (t == NULL)
692  return 0;
693  return t->tm_year + 1900;
694 }
static struct GNUNET_SCHEDULER_Task * t
Main task.
Here is the caller graph for this function:

◆ GNUNET_TIME_year_to_time()

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.

Parameters
yeara year (after 1970, please ;-)).
Returns
absolute time for January 1st of that year.

Definition at line 725 of file time.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_break, GNUNET_TIME_absolute_get(), and ret.

Referenced by main().

726 {
727  struct GNUNET_TIME_Absolute ret;
728  time_t tp;
729  struct tm t;
730 
731  memset (&t, 0, sizeof (t));
732  if (year < 1900)
733  {
734  GNUNET_break (0);
735  return GNUNET_TIME_absolute_get (); /* now */
736  }
737  t.tm_year = year - 1900;
738  t.tm_mday = 1;
739  t.tm_mon = 0;
740  t.tm_wday = 1;
741  t.tm_yday = 1;
742  tp = mktime (&t);
743  GNUNET_break (tp != (time_t) - 1);
744  ret.abs_value_us = tp * 1000LL * 1000LL; /* seconds to microseconds */
745  return ret;
746 }
static struct GNUNET_SCHEDULER_Task * t
Main task.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get()
Get the current time (works just as "time", just that we use the unit of time that the cron-jobs use ...
Definition: time.c:118
Time for absolute times used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TIME_time_to_year()

unsigned int GNUNET_TIME_time_to_year ( struct GNUNET_TIME_Absolute  at)

Convert an expiration time to the respective year (rounds)

Parameters
atabsolute time
Returns
year a year (after 1970), 0 on error

Definition at line 704 of file time.c.

References GNUNET_TIME_Absolute::abs_value_us, and t.

705 {
706  struct tm *t;
707  time_t tp;
708 
709  tp = at.abs_value_us / 1000LL / 1000LL; /* microseconds to seconds */
710  t = gmtime (&tp);
711  if (t == NULL)
712  return 0;
713  return t->tm_year + 1900;
714 
715 }
static struct GNUNET_SCHEDULER_Task * t
Main task.
uint64_t abs_value_us
The actual value.

◆ GNUNET_TIME_absolute_get_monotonic()

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.

Guards against systems without an RTC or clocks running backwards and other nasty surprises. Does not guarantee that the returned time is near the current time returned by GNUNET_TIME_absolute_get(). Two subsequent calls (within a short time period) may return the same value. Persists the last returned time on disk to ensure that time never goes backwards. As a result, the resulting value can be used to check if a message is the "most recent" value and replays of older messages (from the same origin) would be discarded.

Parameters
cfgconfiguration, used to determine where to store the time; user can also insist RTC is working nicely and disable the feature
Returns
monotonically increasing time

Definition at line 807 of file time.c.

References _, GNUNET_TIME_Absolute::abs_value_us, GNUNET_TIME_AbsoluteNBO::abs_value_us__, ATOMIC, cfg, fh, filename, GNUNET_break, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_DISK_file_close(), GNUNET_DISK_file_handle_size(), GNUNET_DISK_file_map(), GNUNET_DISK_file_open(), GNUNET_DISK_file_unmap(), GNUNET_DISK_file_write(), GNUNET_DISK_MAP_TYPE_READWRITE, GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_OPEN_READWRITE, GNUNET_DISK_PERM_GROUP_READ, GNUNET_DISK_PERM_GROUP_WRITE, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_OK, GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_hton(), GNUNET_TIME_absolute_max(), GNUNET_TIME_absolute_ntoh(), map, and size.

Referenced by __attribute__(), consider_sending_fc(), inject_rekey(), mq_send(), run(), start_dv_learn(), transmit_kx(), update_ephemeral(), and validation_transmit_on_queue().

808 {
809  static const struct GNUNET_CONFIGURATION_Handle *last_cfg;
810  static struct GNUNET_TIME_Absolute last_time;
811  static struct GNUNET_DISK_MapHandle *map_handle;
812  static ATOMIC volatile uint64_t *map;
813  struct GNUNET_TIME_Absolute now;
814 
815  now = GNUNET_TIME_absolute_get ();
816  if (last_cfg != cfg)
817  {
818  char *filename;
819 
820  if (NULL != map_handle)
821  {
822  GNUNET_DISK_file_unmap (map_handle);
823  map_handle = NULL;
824  }
825  map = NULL;
826 
827  last_cfg = cfg;
828  if ( (NULL != cfg) &&
829  (GNUNET_OK ==
831  "util",
832  "MONOTONIC_TIME_FILENAME",
833  &filename)) )
834  {
835  struct GNUNET_DISK_FileHandle *fh;
836 
837  fh = GNUNET_DISK_file_open (filename,
841  if (NULL == fh)
842  {
844  _("Failed to map `%s', cannot assure monotonic time!\n"),
845  filename);
846  }
847  else
848  {
849  off_t size;
850 
851  size = 0;
854  &size));
855  if (size < (off_t) sizeof (*map))
856  {
857  struct GNUNET_TIME_AbsoluteNBO o;
858 
859  o = GNUNET_TIME_absolute_hton (now);
860  if (sizeof (o) !=
862  &o,
863  sizeof (o)))
864  size = 0;
865  else
866  size = sizeof (o);
867  }
868  if (size == sizeof (*map))
869  {
870  map = GNUNET_DISK_file_map (fh,
871  &map_handle,
873  sizeof (*map));
874  if (NULL == map)
876  _("Failed to map `%s', cannot assure monotonic time!\n"),
877  filename);
878  }
879  else
880  {
882  _("Failed to setup monotonic time file `%s', cannot assure monotonic time!\n"),
883  filename);
884  }
885  }
887  GNUNET_free (filename);
888  }
889  }
890  if (NULL != map)
891  {
892  struct GNUNET_TIME_AbsoluteNBO mt;
893 
894 #if __STDC_NO_ATOMICS__
895 #if __GNUC__
896  mt.abs_value_us__ = __sync_fetch_and_or (map, 0);
897 #else
898  mt.abs_value_us__ = *map; /* godspeed, pray this is atomic */
899 #endif
900 #else
901  mt.abs_value_us__ = atomic_load (map);
902 #endif
904  last_time);
905  }
906  if (now.abs_value_us <= last_time.abs_value_us)
907  now.abs_value_us = last_time.abs_value_us+1;
908  last_time = now;
909  if (NULL != map)
910  {
911  uint64_t val = GNUNET_TIME_absolute_hton (now).abs_value_us__;
912 #if __STDC_NO_ATOMICS__
913 #if __GNUC__
914  (void) __sync_lock_test_and_set (map, val);
915 #else
916  *map = val; /* godspeed, pray this is atomic */
917 #endif
918 #else
919  atomic_store (map,
920  val);
921 #endif
922  }
923  return now;
924 }
Create file if it doesn&#39;t exist.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:670
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1817
Read-write memory map.
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.
Definition: disk.c:2020
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_CONTAINER_MultiPeerMap * map
Handle to the map used to store old latency values for peers.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:1049
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_max(struct GNUNET_TIME_Absolute t1, struct GNUNET_TIME_Absolute t2)
Return the maximum of two relative time values.
Definition: time.c:317
static char * filename
static int fh
Handle to the unique file.
#define ATOMIC
Definition: time.c:36
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get()
Get the current time (works just as "time", just that we use the unit of time that the cron-jobs use ...
Definition: time.c:118
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
static unsigned int size
Size of the "table".
Definition: peer.c:67
int GNUNET_DISK_file_unmap(struct GNUNET_DISK_MapHandle *h)
Unmap a file.
Definition: disk.c:2100
configuration data
Definition: configuration.c:85
uint64_t abs_value_us__
The actual value (in network byte order).
int GNUNET_DISK_file_handle_size(struct GNUNET_DISK_FileHandle *fh, off_t *size)
Get the size of an open file.
Definition: disk.c:208
#define GNUNET_log(kind,...)
Open the file for both reading and writing.
int 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.
Time for absolute times used by GNUnet, in microseconds.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1673
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:654
Handle used to access files (and pipes).
Handle for a memory-mapping operation.
Definition: disk.c:1985
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function: