diff options
Diffstat (limited to 'toxcore/net_crypto.c')
-rw-r--r-- | toxcore/net_crypto.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 707b675d..83561d1f 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c | |||
@@ -676,6 +676,8 @@ static int handle_request_packet(Packets_Array *send_array, const uint8_t *data, | |||
676 | uint32_t i, n = 1; | 676 | uint32_t i, n = 1; |
677 | uint32_t requested = 0; | 677 | uint32_t requested = 0; |
678 | 678 | ||
679 | uint64_t temp_time = current_time_monotonic(); | ||
680 | |||
679 | for (i = send_array->buffer_start; i != send_array->buffer_end; ++i) { | 681 | for (i = send_array->buffer_start; i != send_array->buffer_end; ++i) { |
680 | if (length == 0) | 682 | if (length == 0) |
681 | break; | 683 | break; |
@@ -684,7 +686,11 @@ static int handle_request_packet(Packets_Array *send_array, const uint8_t *data, | |||
684 | 686 | ||
685 | if (n == data[0]) { | 687 | if (n == data[0]) { |
686 | if (send_array->buffer[num]) { | 688 | if (send_array->buffer[num]) { |
687 | send_array->buffer[num]->sent = 0; | 689 | uint64_t sent_time = send_array->buffer[num]->sent_time; |
690 | |||
691 | if ((sent_time + DEFAULT_PING_CONNECTION) < temp_time) { | ||
692 | send_array->buffer[num]->sent_time = 0; | ||
693 | } | ||
688 | } | 694 | } |
689 | 695 | ||
690 | ++data; | 696 | ++data; |
@@ -788,12 +794,12 @@ static int reset_max_speed_reached(Net_Crypto *c, int crypt_connection_id) | |||
788 | uint8_t send_failed = 0; | 794 | uint8_t send_failed = 0; |
789 | 795 | ||
790 | if (ret == 1) { | 796 | if (ret == 1) { |
791 | if (!dt->sent) { | 797 | if (!dt->sent_time) { |
792 | if (send_data_packet_helper(c, crypt_connection_id, conn->recv_array.buffer_start, packet_num, dt->data, | 798 | if (send_data_packet_helper(c, crypt_connection_id, conn->recv_array.buffer_start, packet_num, dt->data, |
793 | dt->length) != 0) { | 799 | dt->length) != 0) { |
794 | send_failed = 1; | 800 | send_failed = 1; |
795 | } else { | 801 | } else { |
796 | dt->sent = 1; | 802 | dt->sent_time = 1; |
797 | } | 803 | } |
798 | } | 804 | } |
799 | } | 805 | } |
@@ -831,7 +837,7 @@ static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, cons | |||
831 | } | 837 | } |
832 | 838 | ||
833 | Packet_Data dt; | 839 | Packet_Data dt; |
834 | dt.sent = 0; | 840 | dt.sent_time = 0; |
835 | dt.length = length; | 841 | dt.length = length; |
836 | memcpy(dt.data, data, length); | 842 | memcpy(dt.data, data, length); |
837 | pthread_mutex_lock(&conn->mutex); | 843 | pthread_mutex_lock(&conn->mutex); |
@@ -849,7 +855,7 @@ static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, cons | |||
849 | Packet_Data *dt1 = NULL; | 855 | Packet_Data *dt1 = NULL; |
850 | 856 | ||
851 | if (get_data_pointer(&conn->send_array, &dt1, packet_num) == 1) | 857 | if (get_data_pointer(&conn->send_array, &dt1, packet_num) == 1) |
852 | dt1->sent = 1; | 858 | dt1->sent_time = 1; |
853 | } else { | 859 | } else { |
854 | conn->maximum_speed_reached = 1; | 860 | conn->maximum_speed_reached = 1; |
855 | LOGGER_ERROR("send_data_packet failed\n"); | 861 | LOGGER_ERROR("send_data_packet failed\n"); |
@@ -946,6 +952,7 @@ static int send_requested_packets(Net_Crypto *c, int crypt_connection_id, uint32 | |||
946 | if (conn == 0) | 952 | if (conn == 0) |
947 | return -1; | 953 | return -1; |
948 | 954 | ||
955 | uint64_t temp_time = current_time_monotonic(); | ||
949 | uint32_t i, num_sent = 0, array_size = num_packets_array(&conn->send_array); | 956 | uint32_t i, num_sent = 0, array_size = num_packets_array(&conn->send_array); |
950 | 957 | ||
951 | for (i = 0; i < array_size; ++i) { | 958 | for (i = 0; i < array_size; ++i) { |
@@ -959,13 +966,13 @@ static int send_requested_packets(Net_Crypto *c, int crypt_connection_id, uint32 | |||
959 | continue; | 966 | continue; |
960 | } | 967 | } |
961 | 968 | ||
962 | if (dt->sent) { | 969 | if (dt->sent_time) { |
963 | continue; | 970 | continue; |
964 | } | 971 | } |
965 | 972 | ||
966 | if (send_data_packet_helper(c, crypt_connection_id, conn->recv_array.buffer_start, packet_num, dt->data, | 973 | if (send_data_packet_helper(c, crypt_connection_id, conn->recv_array.buffer_start, packet_num, dt->data, |
967 | dt->length) == 0) { | 974 | dt->length) == 0) { |
968 | dt->sent = 1; | 975 | dt->sent_time = temp_time; |
969 | ++num_sent; | 976 | ++num_sent; |
970 | } | 977 | } |
971 | 978 | ||