diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-08-01 23:02:13 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-08-16 21:01:43 +0000 |
commit | d6d305feeb76735ee4b4e14c6bca737a5482bc19 (patch) | |
tree | 99005c635a452245006b3b5de44f1dd80da9f77f /toxcore/Messenger.c | |
parent | 54066f338f185f2fbd6694d9a4877f42cbfa21c8 (diff) |
Use per-instance `Mono_Time` for Messenger and onion.
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r-- | toxcore/Messenger.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index ab341e61..dacd662b 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -1949,7 +1949,7 @@ static int friend_already_added(const uint8_t *real_pk, void *data) | |||
1949 | } | 1949 | } |
1950 | 1950 | ||
1951 | /* Run this at startup. */ | 1951 | /* Run this at startup. */ |
1952 | Messenger *new_messenger(Messenger_Options *options, unsigned int *error) | 1952 | Messenger *new_messenger(Mono_Time *mono_time, Messenger_Options *options, unsigned int *error) |
1953 | { | 1953 | { |
1954 | if (!options) { | 1954 | if (!options) { |
1955 | return nullptr; | 1955 | return nullptr; |
@@ -1965,6 +1965,8 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error) | |||
1965 | return nullptr; | 1965 | return nullptr; |
1966 | } | 1966 | } |
1967 | 1967 | ||
1968 | m->mono_time = mono_time; | ||
1969 | |||
1968 | m->fr = friendreq_new(); | 1970 | m->fr = friendreq_new(); |
1969 | 1971 | ||
1970 | if (!m->fr) { | 1972 | if (!m->fr) { |
@@ -2010,7 +2012,7 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error) | |||
2010 | return nullptr; | 2012 | return nullptr; |
2011 | } | 2013 | } |
2012 | 2014 | ||
2013 | m->dht = new_dht(m->log, m->net, options->hole_punching_enabled); | 2015 | m->dht = new_dht(m->log, m->mono_time, m->net, options->hole_punching_enabled); |
2014 | 2016 | ||
2015 | if (m->dht == nullptr) { | 2017 | if (m->dht == nullptr) { |
2016 | kill_networking(m->net); | 2018 | kill_networking(m->net); |
@@ -2020,7 +2022,7 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error) | |||
2020 | return nullptr; | 2022 | return nullptr; |
2021 | } | 2023 | } |
2022 | 2024 | ||
2023 | m->net_crypto = new_net_crypto(m->log, m->dht, &options->proxy_info); | 2025 | m->net_crypto = new_net_crypto(m->log, m->mono_time, m->dht, &options->proxy_info); |
2024 | 2026 | ||
2025 | if (m->net_crypto == nullptr) { | 2027 | if (m->net_crypto == nullptr) { |
2026 | kill_networking(m->net); | 2028 | kill_networking(m->net); |
@@ -2031,10 +2033,10 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error) | |||
2031 | return nullptr; | 2033 | return nullptr; |
2032 | } | 2034 | } |
2033 | 2035 | ||
2034 | m->onion = new_onion(m->dht); | 2036 | m->onion = new_onion(m->mono_time, m->dht); |
2035 | m->onion_a = new_onion_announce(m->dht); | 2037 | m->onion_a = new_onion_announce(m->mono_time, m->dht); |
2036 | m->onion_c = new_onion_client(m->net_crypto); | 2038 | m->onion_c = new_onion_client(m->mono_time, m->net_crypto); |
2037 | m->fr_c = new_friend_connections(m->onion_c, options->local_discovery_enabled); | 2039 | m->fr_c = new_friend_connections(m->mono_time, m->onion_c, options->local_discovery_enabled); |
2038 | 2040 | ||
2039 | if (!(m->onion && m->onion_a && m->onion_c)) { | 2041 | if (!(m->onion && m->onion_a && m->onion_c)) { |
2040 | kill_friend_connections(m->fr_c); | 2042 | kill_friend_connections(m->fr_c); |
@@ -2468,7 +2470,7 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le | |||
2468 | static void do_friends(Messenger *m, void *userdata) | 2470 | static void do_friends(Messenger *m, void *userdata) |
2469 | { | 2471 | { |
2470 | uint32_t i; | 2472 | uint32_t i; |
2471 | uint64_t temp_time = unix_time(); | 2473 | uint64_t temp_time = mono_time_get(m->mono_time); |
2472 | 2474 | ||
2473 | for (i = 0; i < m->numfriends; ++i) { | 2475 | for (i = 0; i < m->numfriends; ++i) { |
2474 | if (m->friendlist[i].status == FRIEND_ADDED) { | 2476 | if (m->friendlist[i].status == FRIEND_ADDED) { |
@@ -2609,7 +2611,7 @@ void do_messenger(Messenger *m, void *userdata) | |||
2609 | } | 2611 | } |
2610 | 2612 | ||
2611 | if (m->tcp_server) { | 2613 | if (m->tcp_server) { |
2612 | do_TCP_server(m->tcp_server); | 2614 | do_TCP_server(m->tcp_server, m->mono_time); |
2613 | } | 2615 | } |
2614 | 2616 | ||
2615 | do_net_crypto(m->net_crypto, userdata); | 2617 | do_net_crypto(m->net_crypto, userdata); |
@@ -2618,8 +2620,8 @@ void do_messenger(Messenger *m, void *userdata) | |||
2618 | do_friends(m, userdata); | 2620 | do_friends(m, userdata); |
2619 | connection_status_callback(m, userdata); | 2621 | connection_status_callback(m, userdata); |
2620 | 2622 | ||
2621 | if (unix_time() > m->lastdump + DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS) { | 2623 | if (mono_time_get(m->mono_time) > m->lastdump + DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS) { |
2622 | m->lastdump = unix_time(); | 2624 | m->lastdump = mono_time_get(m->mono_time); |
2623 | uint32_t client, last_pinged; | 2625 | uint32_t client, last_pinged; |
2624 | 2626 | ||
2625 | for (client = 0; client < LCLIENT_LIST; ++client) { | 2627 | for (client = 0; client < LCLIENT_LIST; ++client) { |