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/TCP_client.c | |
parent | 54066f338f185f2fbd6694d9a4877f42cbfa21c8 (diff) |
Use per-instance `Mono_Time` for Messenger and onion.
Diffstat (limited to 'toxcore/TCP_client.c')
-rw-r--r-- | toxcore/TCP_client.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c index d6a27c95..a6beac4d 100644 --- a/toxcore/TCP_client.c +++ b/toxcore/TCP_client.c | |||
@@ -688,8 +688,8 @@ void onion_response_handler(TCP_Client_Connection *con, tcp_onion_response_cb *o | |||
688 | 688 | ||
689 | /* Create new TCP connection to ip_port/public_key | 689 | /* Create new TCP connection to ip_port/public_key |
690 | */ | 690 | */ |
691 | TCP_Client_Connection *new_TCP_connection(IP_Port ip_port, const uint8_t *public_key, const uint8_t *self_public_key, | 691 | TCP_Client_Connection *new_TCP_connection(const Mono_Time *mono_time, IP_Port ip_port, const uint8_t *public_key, |
692 | const uint8_t *self_secret_key, TCP_Proxy_Info *proxy_info) | 692 | const uint8_t *self_public_key, const uint8_t *self_secret_key, TCP_Proxy_Info *proxy_info) |
693 | { | 693 | { |
694 | if (networking_at_startup() != 0) { | 694 | if (networking_at_startup() != 0) { |
695 | return nullptr; | 695 | return nullptr; |
@@ -765,7 +765,7 @@ TCP_Client_Connection *new_TCP_connection(IP_Port ip_port, const uint8_t *public | |||
765 | break; | 765 | break; |
766 | } | 766 | } |
767 | 767 | ||
768 | temp->kill_at = unix_time() + TCP_CONNECTION_TIMEOUT; | 768 | temp->kill_at = mono_time_get(mono_time) + TCP_CONNECTION_TIMEOUT; |
769 | 769 | ||
770 | return temp; | 770 | return temp; |
771 | } | 771 | } |
@@ -949,13 +949,13 @@ static bool tcp_process_packet(TCP_Client_Connection *conn, void *userdata) | |||
949 | return true; | 949 | return true; |
950 | } | 950 | } |
951 | 951 | ||
952 | static int do_confirmed_TCP(TCP_Client_Connection *conn, void *userdata) | 952 | static int do_confirmed_TCP(TCP_Client_Connection *conn, const Mono_Time *mono_time, void *userdata) |
953 | { | 953 | { |
954 | client_send_pending_data(conn); | 954 | client_send_pending_data(conn); |
955 | tcp_send_ping_response(conn); | 955 | tcp_send_ping_response(conn); |
956 | tcp_send_ping_request(conn); | 956 | tcp_send_ping_request(conn); |
957 | 957 | ||
958 | if (is_timeout(conn->last_pinged, TCP_PING_FREQUENCY)) { | 958 | if (mono_time_is_timeout(mono_time, conn->last_pinged, TCP_PING_FREQUENCY)) { |
959 | uint64_t ping_id = random_u64(); | 959 | uint64_t ping_id = random_u64(); |
960 | 960 | ||
961 | if (!ping_id) { | 961 | if (!ping_id) { |
@@ -965,10 +965,10 @@ static int do_confirmed_TCP(TCP_Client_Connection *conn, void *userdata) | |||
965 | conn->ping_request_id = ping_id; | 965 | conn->ping_request_id = ping_id; |
966 | conn->ping_id = ping_id; | 966 | conn->ping_id = ping_id; |
967 | tcp_send_ping_request(conn); | 967 | tcp_send_ping_request(conn); |
968 | conn->last_pinged = unix_time(); | 968 | conn->last_pinged = mono_time_get(mono_time); |
969 | } | 969 | } |
970 | 970 | ||
971 | if (conn->ping_id && is_timeout(conn->last_pinged, TCP_PING_TIMEOUT)) { | 971 | if (conn->ping_id && mono_time_is_timeout(mono_time, conn->last_pinged, TCP_PING_TIMEOUT)) { |
972 | conn->status = TCP_CLIENT_DISCONNECTED; | 972 | conn->status = TCP_CLIENT_DISCONNECTED; |
973 | return 0; | 973 | return 0; |
974 | } | 974 | } |
@@ -983,7 +983,7 @@ static int do_confirmed_TCP(TCP_Client_Connection *conn, void *userdata) | |||
983 | 983 | ||
984 | /* Run the TCP connection | 984 | /* Run the TCP connection |
985 | */ | 985 | */ |
986 | void do_TCP_connection(TCP_Client_Connection *tcp_connection, void *userdata) | 986 | void do_TCP_connection(Mono_Time *mono_time, TCP_Client_Connection *tcp_connection, void *userdata) |
987 | { | 987 | { |
988 | if (tcp_connection->status == TCP_CLIENT_DISCONNECTED) { | 988 | if (tcp_connection->status == TCP_CLIENT_DISCONNECTED) { |
989 | return; | 989 | return; |
@@ -1059,10 +1059,10 @@ void do_TCP_connection(TCP_Client_Connection *tcp_connection, void *userdata) | |||
1059 | } | 1059 | } |
1060 | 1060 | ||
1061 | if (tcp_connection->status == TCP_CLIENT_CONFIRMED) { | 1061 | if (tcp_connection->status == TCP_CLIENT_CONFIRMED) { |
1062 | do_confirmed_TCP(tcp_connection, userdata); | 1062 | do_confirmed_TCP(tcp_connection, mono_time, userdata); |
1063 | } | 1063 | } |
1064 | 1064 | ||
1065 | if (tcp_connection->kill_at <= unix_time()) { | 1065 | if (tcp_connection->kill_at <= mono_time_get(mono_time)) { |
1066 | tcp_connection->status = TCP_CLIENT_DISCONNECTED; | 1066 | tcp_connection->status = TCP_CLIENT_DISCONNECTED; |
1067 | } | 1067 | } |
1068 | } | 1068 | } |