Fix the often call of event tox_friend_connection_status

Fixes #868

Is made by:
1. Fix enumeration mechanism of Crypto_Connection instances in function send_crypto_packets()
   (this item solves the main problem);
2. Disruption of correlation between parameters of different dimensions
   (the parameters MAX_NUM_SENDPACKET_TRIES and UDP_DIRECT_TIMEOUT have different dimensions).
This commit is contained in:
Pavel Karelin 2018-05-15 09:57:07 +03:00
parent 2d0a21adb3
commit 461c8f51f5
No known key found for this signature in database
GPG Key ID: 8528667A0E44A7C8
2 changed files with 4 additions and 4 deletions

View File

@ -2450,15 +2450,15 @@ static void send_crypto_packets(Net_Crypto *c)
Crypto_Connection *conn = get_crypto_connection(c, i);
if (conn == nullptr) {
return;
continue;
}
if (CRYPTO_SEND_PACKET_INTERVAL + conn->temp_packet_sent_time < temp_time) {
if ((CRYPTO_SEND_PACKET_INTERVAL + conn->temp_packet_sent_time) < temp_time) {
send_temp_packet(c, i);
}
if ((conn->status == CRYPTO_CONN_NOT_CONFIRMED || conn->status == CRYPTO_CONN_ESTABLISHED)
&& ((CRYPTO_SEND_PACKET_INTERVAL) + conn->last_request_packet_sent) < temp_time) {
&& (CRYPTO_SEND_PACKET_INTERVAL + conn->last_request_packet_sent) < temp_time) {
if (send_request_packet(c, i) == 0) {
conn->last_request_packet_sent = temp_time;
}

View File

@ -62,7 +62,7 @@
#define MAX_NUM_SENDPACKET_TRIES 8
/* The timeout of no received UDP packets before the direct UDP connection is considered dead. */
#define UDP_DIRECT_TIMEOUT ((MAX_NUM_SENDPACKET_TRIES * CRYPTO_SEND_PACKET_INTERVAL) / 1000)
#define UDP_DIRECT_TIMEOUT 8
#define PACKET_ID_PADDING 0 /* Denotes padding */
#define PACKET_ID_REQUEST 1 /* Used to request unreceived packets */