mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Don't resend the same packet twice within a short timeframe.
This commit is contained in:
parent
b5d712502b
commit
e3ee9702fb
@ -676,6 +676,8 @@ static int handle_request_packet(Packets_Array *send_array, const uint8_t *data,
|
|||||||
uint32_t i, n = 1;
|
uint32_t i, n = 1;
|
||||||
uint32_t requested = 0;
|
uint32_t requested = 0;
|
||||||
|
|
||||||
|
uint64_t temp_time = current_time_monotonic();
|
||||||
|
|
||||||
for (i = send_array->buffer_start; i != send_array->buffer_end; ++i) {
|
for (i = send_array->buffer_start; i != send_array->buffer_end; ++i) {
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
break;
|
break;
|
||||||
@ -684,7 +686,11 @@ static int handle_request_packet(Packets_Array *send_array, const uint8_t *data,
|
|||||||
|
|
||||||
if (n == data[0]) {
|
if (n == data[0]) {
|
||||||
if (send_array->buffer[num]) {
|
if (send_array->buffer[num]) {
|
||||||
send_array->buffer[num]->sent = 0;
|
uint64_t sent_time = send_array->buffer[num]->sent_time;
|
||||||
|
|
||||||
|
if ((sent_time + DEFAULT_PING_CONNECTION) < temp_time) {
|
||||||
|
send_array->buffer[num]->sent_time = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
++data;
|
++data;
|
||||||
@ -788,12 +794,12 @@ static int reset_max_speed_reached(Net_Crypto *c, int crypt_connection_id)
|
|||||||
uint8_t send_failed = 0;
|
uint8_t send_failed = 0;
|
||||||
|
|
||||||
if (ret == 1) {
|
if (ret == 1) {
|
||||||
if (!dt->sent) {
|
if (!dt->sent_time) {
|
||||||
if (send_data_packet_helper(c, crypt_connection_id, conn->recv_array.buffer_start, packet_num, dt->data,
|
if (send_data_packet_helper(c, crypt_connection_id, conn->recv_array.buffer_start, packet_num, dt->data,
|
||||||
dt->length) != 0) {
|
dt->length) != 0) {
|
||||||
send_failed = 1;
|
send_failed = 1;
|
||||||
} else {
|
} else {
|
||||||
dt->sent = 1;
|
dt->sent_time = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -831,7 +837,7 @@ static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
Packet_Data dt;
|
Packet_Data dt;
|
||||||
dt.sent = 0;
|
dt.sent_time = 0;
|
||||||
dt.length = length;
|
dt.length = length;
|
||||||
memcpy(dt.data, data, length);
|
memcpy(dt.data, data, length);
|
||||||
pthread_mutex_lock(&conn->mutex);
|
pthread_mutex_lock(&conn->mutex);
|
||||||
@ -849,7 +855,7 @@ static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, cons
|
|||||||
Packet_Data *dt1 = NULL;
|
Packet_Data *dt1 = NULL;
|
||||||
|
|
||||||
if (get_data_pointer(&conn->send_array, &dt1, packet_num) == 1)
|
if (get_data_pointer(&conn->send_array, &dt1, packet_num) == 1)
|
||||||
dt1->sent = 1;
|
dt1->sent_time = 1;
|
||||||
} else {
|
} else {
|
||||||
conn->maximum_speed_reached = 1;
|
conn->maximum_speed_reached = 1;
|
||||||
LOGGER_ERROR("send_data_packet failed\n");
|
LOGGER_ERROR("send_data_packet failed\n");
|
||||||
@ -946,6 +952,7 @@ static int send_requested_packets(Net_Crypto *c, int crypt_connection_id, uint32
|
|||||||
if (conn == 0)
|
if (conn == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
uint64_t temp_time = current_time_monotonic();
|
||||||
uint32_t i, num_sent = 0, array_size = num_packets_array(&conn->send_array);
|
uint32_t i, num_sent = 0, array_size = num_packets_array(&conn->send_array);
|
||||||
|
|
||||||
for (i = 0; i < array_size; ++i) {
|
for (i = 0; i < array_size; ++i) {
|
||||||
@ -959,13 +966,13 @@ static int send_requested_packets(Net_Crypto *c, int crypt_connection_id, uint32
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dt->sent) {
|
if (dt->sent_time) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (send_data_packet_helper(c, crypt_connection_id, conn->recv_array.buffer_start, packet_num, dt->data,
|
if (send_data_packet_helper(c, crypt_connection_id, conn->recv_array.buffer_start, packet_num, dt->data,
|
||||||
dt->length) == 0) {
|
dt->length) == 0) {
|
||||||
dt->sent = 1;
|
dt->sent_time = temp_time;
|
||||||
++num_sent;
|
++num_sent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,8 +82,11 @@
|
|||||||
at the dT defined in net_crypto.c */
|
at the dT defined in net_crypto.c */
|
||||||
#define CONGESTION_QUEUE_ARRAY_SIZE 24
|
#define CONGESTION_QUEUE_ARRAY_SIZE 24
|
||||||
|
|
||||||
|
/* Connection ping in ms. TODO: calculate it per connection. */
|
||||||
|
#define DEFAULT_PING_CONNECTION 100
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
_Bool sent;
|
uint64_t sent_time;
|
||||||
uint16_t length;
|
uint16_t length;
|
||||||
uint8_t data[MAX_CRYPTO_DATA_SIZE];
|
uint8_t data[MAX_CRYPTO_DATA_SIZE];
|
||||||
} Packet_Data;
|
} Packet_Data;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user