Attempted fix of disconnect when switching from TCP to UDP.

This commit is contained in:
irungentoo 2015-11-19 15:03:02 -05:00
parent 61c20d48aa
commit 0c29c00125
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
2 changed files with 48 additions and 30 deletions

View File

@ -501,6 +501,14 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, const uint8_t
int ret = send_packet_tcp_connection(c->tcp_c, conn->connection_number_tcp, data, length); int ret = send_packet_tcp_connection(c->tcp_c, conn->connection_number_tcp, data, length);
pthread_mutex_unlock(&c->tcp_mutex); pthread_mutex_unlock(&c->tcp_mutex);
pthread_mutex_lock(&conn->mutex);
if (ret == 0) {
conn->last_tcp_sent = current_time_monotonic();
}
pthread_mutex_unlock(&conn->mutex);
if (ret == 0 || direct_send_attempt) { if (ret == 0 || direct_send_attempt) {
return 0; return 0;
} }
@ -2190,6 +2198,13 @@ static void send_crypto_packets(Net_Crypto *c)
unsigned int n_p_pos = conn->last_sendqueue_counter % CONGESTION_LAST_SENT_ARRAY_SIZE; unsigned int n_p_pos = conn->last_sendqueue_counter % CONGESTION_LAST_SENT_ARRAY_SIZE;
conn->last_num_packets_sent[n_p_pos] = packets_sent; conn->last_num_packets_sent[n_p_pos] = packets_sent;
_Bool direct_connected = 0;
crypto_connection_status(c, i, &direct_connected, NULL);
if (direct_connected && conn->last_tcp_sent + CONGESTION_EVENT_TIMEOUT > temp_time) {
/* When switching from TCP to UDP, don't change the packet send rate for CONGESTION_EVENT_TIMEOUT ms. */
} else {
long signed int total_sent = 0; long signed int total_sent = 0;
//TODO use real delay //TODO use real delay
@ -2225,6 +2240,7 @@ static void send_crypto_packets(Net_Crypto *c)
if (conn->packet_send_rate < CRYPTO_PACKET_MIN_RATE) { if (conn->packet_send_rate < CRYPTO_PACKET_MIN_RATE) {
conn->packet_send_rate = CRYPTO_PACKET_MIN_RATE; conn->packet_send_rate = CRYPTO_PACKET_MIN_RATE;
} }
}
} }

View File

@ -124,6 +124,8 @@ typedef struct {
uint64_t direct_lastrecv_timev4; /* The Time at which we last received a direct packet in ms. */ uint64_t direct_lastrecv_timev4; /* The Time at which we last received a direct packet in ms. */
uint64_t direct_lastrecv_timev6; uint64_t direct_lastrecv_timev6;
uint64_t last_tcp_sent; /* Time the last TCP packet was sent. */
Packets_Array send_array; Packets_Array send_array;
Packets_Array recv_array; Packets_Array recv_array;