diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/net_crypto.c | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 62001a3e..4d76e659 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c | |||
@@ -2125,25 +2125,19 @@ static void send_crypto_packets(Net_Crypto *c) | |||
2125 | 2125 | ||
2126 | /* if queue is too big only allow resending packets. */ | 2126 | /* if queue is too big only allow resending packets. */ |
2127 | uint32_t npackets = num_packets_array(&conn->send_array); | 2127 | uint32_t npackets = num_packets_array(&conn->send_array); |
2128 | |||
2129 | if (conn->packet_send_rate * 4 < npackets && CRYPTO_MIN_QUEUE_LENGTH * 4 < npackets) { | ||
2130 | conn->last_congestion_event = temp_time; | ||
2131 | } | ||
2132 | |||
2133 | double min_speed = 1000.0 * (((double)(total_sent)) / ((double)(CONGESTION_QUEUE_ARRAY_SIZE) * | 2128 | double min_speed = 1000.0 * (((double)(total_sent)) / ((double)(CONGESTION_QUEUE_ARRAY_SIZE) * |
2134 | PACKET_COUNTER_AVERAGE_INTERVAL)); | 2129 | PACKET_COUNTER_AVERAGE_INTERVAL)); |
2130 | double send_array_ratio = (((double)npackets) / min_speed); | ||
2135 | 2131 | ||
2136 | if (conn->last_congestion_event + CONGESTION_EVENT_TIMEOUT < temp_time) { | 2132 | //TODO: Improve formula? |
2133 | if (send_array_ratio > 2.0 && CRYPTO_MIN_QUEUE_LENGTH * 3 < npackets) { | ||
2134 | conn->packet_send_rate = min_speed * (1.0 / (send_array_ratio / 2.0)); | ||
2135 | } else if (conn->last_congestion_event + CONGESTION_EVENT_TIMEOUT < temp_time) { | ||
2137 | conn->packet_send_rate = min_speed * 1.2; | 2136 | conn->packet_send_rate = min_speed * 1.2; |
2138 | } else { | 2137 | } else { |
2139 | conn->packet_send_rate = min_speed * 0.9; | 2138 | conn->packet_send_rate = min_speed * 0.9; |
2140 | } | 2139 | } |
2141 | 2140 | ||
2142 | //TODO: find real formula and remove all those magic numbers | ||
2143 | if (conn->packet_send_rate * 8 < npackets && CRYPTO_MIN_QUEUE_LENGTH * 8 < npackets) { | ||
2144 | conn->packet_send_rate = min_speed * 0.5; | ||
2145 | } | ||
2146 | |||
2147 | if (conn->packet_send_rate < CRYPTO_PACKET_MIN_RATE) { | 2141 | if (conn->packet_send_rate < CRYPTO_PACKET_MIN_RATE) { |
2148 | conn->packet_send_rate = CRYPTO_PACKET_MIN_RATE; | 2142 | conn->packet_send_rate = CRYPTO_PACKET_MIN_RATE; |
2149 | } | 2143 | } |