From d6d305feeb76735ee4b4e14c6bca737a5482bc19 Mon Sep 17 00:00:00 2001 From: iphydf Date: Wed, 1 Aug 2018 23:02:13 +0000 Subject: Use per-instance `Mono_Time` for Messenger and onion. --- other/DHT_bootstrap.c | 17 +++++++-------- other/astyle/format-source | 4 +++- other/bootstrap_daemon/src/tox-bootstrapd.c | 33 +++++++++++++++++++++-------- 3 files changed, 35 insertions(+), 19 deletions(-) (limited to 'other') diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index fc1bba47..6af042ac 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c @@ -115,12 +115,11 @@ int main(int argc, char *argv[]) IP ip; ip_init(&ip, ipv6enabled); - unix_time_update(); - Logger *logger = logger_new(); - DHT *dht = new_dht(logger, new_networking(logger, ip, PORT), true); - Onion *onion = new_onion(dht); - Onion_Announce *onion_a = new_onion_announce(dht); + Mono_Time *mono_time = mono_time_new(); + DHT *dht = new_dht(logger, mono_time, new_networking(logger, ip, PORT), true); + Onion *onion = new_onion(mono_time, dht); + Onion_Announce *onion_a = new_onion_announce(mono_time, dht); #ifdef DHT_NODE_EXTRA_PACKETS bootstrap_set_callbacks(dht_get_net(dht), DHT_VERSION_NUMBER, DHT_MOTD, sizeof(DHT_MOTD)); @@ -188,7 +187,7 @@ int main(int argc, char *argv[]) lan_discovery_init(dht); while (1) { - unix_time_update(); + mono_time_update(mono_time); if (is_waiting_for_dht_connection && dht_isconnected(dht)) { printf("Connected to other bootstrap node successfully.\n"); @@ -197,13 +196,13 @@ int main(int argc, char *argv[]) do_dht(dht); - if (is_timeout(last_LANdiscovery, is_waiting_for_dht_connection ? 5 : LAN_DISCOVERY_INTERVAL)) { + if (mono_time_is_timeout(mono_time, last_LANdiscovery, is_waiting_for_dht_connection ? 5 : LAN_DISCOVERY_INTERVAL)) { lan_discovery_send(net_htons(PORT), dht); - last_LANdiscovery = unix_time(); + last_LANdiscovery = mono_time_get(mono_time); } #ifdef TCP_RELAY_ENABLED - do_TCP_server(tcp_s); + do_TCP_server(tcp_s, mono_time); #endif networking_poll(dht_get_net(dht), nullptr); diff --git a/other/astyle/format-source b/other/astyle/format-source index 5b560622..5e139d89 100755 --- a/other/astyle/format-source +++ b/other/astyle/format-source @@ -36,11 +36,13 @@ apidsl_curl() { # Check if apidsl generated sources are up to date. $APIDSL toxcore/crypto_core.api.h > toxcore/crypto_core.h & +$APIDSL toxcore/ping.api.h > toxcore/ping.h & +$APIDSL toxcore/ping_array.api.h > toxcore/ping_array.h & $APIDSL toxcore/tox.api.h > toxcore/tox.h & $APIDSL toxav/toxav.api.h > toxav/toxav.h & $APIDSL toxencryptsave/toxencryptsave.api.h > toxencryptsave/toxencryptsave.h & -wait; wait; wait; wait +wait; wait; wait; wait; wait; wait if grep '' */*.h; then echo "error: some apidsl references were unresolved" diff --git a/other/bootstrap_daemon/src/tox-bootstrapd.c b/other/bootstrap_daemon/src/tox-bootstrapd.c index d75018d8..807e1100 100644 --- a/other/bootstrap_daemon/src/tox-bootstrapd.c +++ b/other/bootstrap_daemon/src/tox-bootstrapd.c @@ -230,8 +230,6 @@ int main(int argc, char *argv[]) IP ip; ip_init(&ip, enable_ipv6); - unix_time_update(); - Logger *logger = logger_new(); Networking_Core *net = new_networking(logger, ip, port); @@ -255,19 +253,31 @@ int main(int argc, char *argv[]) } } - DHT *dht = new_dht(logger, net, true); + Mono_Time *const mono_time = mono_time_new(); + + if (mono_time == nullptr) { + log_write(LOG_LEVEL_ERROR, "Couldn't initialize monotonic timer. Exiting.\n"); + logger_kill(logger); + return 1; + } + + mono_time_update(mono_time); + + DHT *const dht = new_dht(logger, mono_time, net, true); if (dht == nullptr) { log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox DHT instance. Exiting.\n"); + mono_time_free(mono_time); logger_kill(logger); return 1; } - Onion *onion = new_onion(dht); - Onion_Announce *onion_a = new_onion_announce(dht); + Onion *onion = new_onion(mono_time, dht); + Onion_Announce *onion_a = new_onion_announce(mono_time, dht); if (!(onion && onion_a)) { log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox Onion. Exiting.\n"); + mono_time_free(mono_time); logger_kill(logger); return 1; } @@ -277,6 +287,7 @@ int main(int argc, char *argv[]) log_write(LOG_LEVEL_INFO, "Set MOTD successfully.\n"); } else { log_write(LOG_LEVEL_ERROR, "Couldn't set MOTD: %s. Exiting.\n", motd); + mono_time_free(mono_time); logger_kill(logger); return 1; } @@ -288,6 +299,7 @@ int main(int argc, char *argv[]) log_write(LOG_LEVEL_INFO, "Keys are managed successfully.\n"); } else { log_write(LOG_LEVEL_ERROR, "Couldn't read/write: %s. Exiting.\n", keys_file_path); + mono_time_free(mono_time); logger_kill(logger); return 1; } @@ -299,6 +311,7 @@ int main(int argc, char *argv[]) if (enable_tcp_relay) { if (tcp_relay_port_count == 0) { log_write(LOG_LEVEL_ERROR, "No TCP relay ports read. Exiting.\n"); + mono_time_free(mono_time); logger_kill(logger); return 1; } @@ -312,6 +325,7 @@ int main(int argc, char *argv[]) log_write(LOG_LEVEL_INFO, "Initialized Tox TCP server successfully.\n"); } else { log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox TCP server. Exiting.\n"); + mono_time_free(mono_time); logger_kill(logger); return 1; } @@ -321,6 +335,7 @@ int main(int argc, char *argv[]) log_write(LOG_LEVEL_INFO, "List of bootstrap nodes read successfully.\n"); } else { log_write(LOG_LEVEL_ERROR, "Couldn't read list of bootstrap nodes in %s. Exiting.\n", cfg_file_path); + mono_time_free(mono_time); logger_kill(logger); return 1; } @@ -338,17 +353,17 @@ int main(int argc, char *argv[]) } while (1) { - unix_time_update(); + mono_time_update(mono_time); do_dht(dht); - if (enable_lan_discovery && is_timeout(last_LANdiscovery, LAN_DISCOVERY_INTERVAL)) { + if (enable_lan_discovery && mono_time_is_timeout(mono_time, last_LANdiscovery, LAN_DISCOVERY_INTERVAL)) { lan_discovery_send(net_htons_port, dht); - last_LANdiscovery = unix_time(); + last_LANdiscovery = mono_time_get(mono_time); } if (enable_tcp_relay) { - do_TCP_server(tcp_server); + do_TCP_server(tcp_server, mono_time); } networking_poll(dht_get_net(dht), nullptr); -- cgit v1.2.3