summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-06-29 20:46:06 -0400
committerirungentoo <irungentoo@gmail.com>2014-06-29 20:46:06 -0400
commit8f7638da5ccaad58a957881bba56eb6491ea6066 (patch)
treefa9d6d04f85df3429e68b1f56ff916cb0690b00f
parentbd6f8a2186d73df531552457840d2260339f14b3 (diff)
Core should no longer attempt to send data faster than the links can
carry it.
-rw-r--r--toxcore/net_crypto.c32
-rw-r--r--toxcore/net_crypto.h2
2 files changed, 32 insertions, 2 deletions
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index 8d598469..15487f37 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -781,8 +781,29 @@ static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, uint
781 if (conn == 0) 781 if (conn == 0)
782 return -1; 782 return -1;
783 783
784 uint64_t temp_time = current_time_monotonic();
785
786 /* If last packet send failed, try to send packet again.
787 If sending it fails we won't be able to send the new packet. */
788 if (conn->maximum_speed_reached) {
789 Packet_Data *dt = NULL;
790 uint32_t packet_num = conn->send_array.buffer_end - 1;
791 int ret = get_data_pointer(&conn->send_array, &dt, packet_num);
792
793 if (ret == 1) {
794 if (!dt->time) {
795 if (send_data_packet_helper(c, crypt_connection_id, conn->recv_array.buffer_start, packet_num, dt->data,
796 dt->length) != 0) {
797 return -1;
798 }
799
800 dt->time = temp_time;
801 }
802 }
803 }
804
784 Packet_Data dt; 805 Packet_Data dt;
785 dt.time = current_time_monotonic(); 806 dt.time = temp_time;
786 dt.length = length; 807 dt.length = length;
787 memcpy(dt.data, data, length); 808 memcpy(dt.data, data, length);
788 int64_t packet_num = add_data_end_of_buffer(&conn->send_array, &dt); 809 int64_t packet_num = add_data_end_of_buffer(&conn->send_array, &dt);
@@ -790,8 +811,15 @@ static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, uint
790 if (packet_num == -1) 811 if (packet_num == -1)
791 return -1; 812 return -1;
792 813
793 if (send_data_packet_helper(c, crypt_connection_id, conn->recv_array.buffer_start, packet_num, data, length) != 0) 814 conn->maximum_speed_reached = 0;
815
816 if (send_data_packet_helper(c, crypt_connection_id, conn->recv_array.buffer_start, packet_num, data, length) != 0) {
817 Packet_Data *dt1 = NULL;
818 get_data_pointer(&conn->send_array, &dt1, packet_num);
819 dt1->time = 0;
820 conn->maximum_speed_reached = 1;
794 fprintf(stderr, "send_data_packet failed\n"); 821 fprintf(stderr, "send_data_packet failed\n");
822 }
795 823
796 return packet_num; 824 return packet_num;
797} 825}
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h
index d30d5a63..82d454d3 100644
--- a/toxcore/net_crypto.h
+++ b/toxcore/net_crypto.h
@@ -157,6 +157,8 @@ typedef struct {
157 Node_format tcp_relays[MAX_TCP_RELAYS_PEER]; 157 Node_format tcp_relays[MAX_TCP_RELAYS_PEER];
158 uint16_t num_tcp_relays; 158 uint16_t num_tcp_relays;
159 159
160 uint8_t maximum_speed_reached;
161
160 pthread_mutex_t mutex; 162 pthread_mutex_t mutex;
161} Crypto_Connection; 163} Crypto_Connection;
162 164