diff options
author | irungentoo <irungentoo@gmail.com> | 2015-05-17 18:41:02 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2015-05-17 18:41:02 -0400 |
commit | 8760aba257b5f96d082a58abbc9fb4ca2dd73638 (patch) | |
tree | c05b001781c69cbedc9c005ffa859772dd18e3d3 /toxcore/net_crypto.c | |
parent | e3ee9702fb296b966acb55b802e9e799bce490bd (diff) |
Some protocol efficiency improvements.
Reduced the amount of waste from dropped packets.
Diffstat (limited to 'toxcore/net_crypto.c')
-rw-r--r-- | toxcore/net_crypto.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 83561d1f..762f5ebb 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c | |||
@@ -799,7 +799,7 @@ static int reset_max_speed_reached(Net_Crypto *c, int crypt_connection_id) | |||
799 | dt->length) != 0) { | 799 | dt->length) != 0) { |
800 | send_failed = 1; | 800 | send_failed = 1; |
801 | } else { | 801 | } else { |
802 | dt->sent_time = 1; | 802 | dt->sent_time = current_time_monotonic(); |
803 | } | 803 | } |
804 | } | 804 | } |
805 | } | 805 | } |
@@ -855,7 +855,7 @@ static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, cons | |||
855 | Packet_Data *dt1 = NULL; | 855 | Packet_Data *dt1 = NULL; |
856 | 856 | ||
857 | if (get_data_pointer(&conn->send_array, &dt1, packet_num) == 1) | 857 | if (get_data_pointer(&conn->send_array, &dt1, packet_num) == 1) |
858 | dt1->sent_time = 1; | 858 | dt1->sent_time = current_time_monotonic(); |
859 | } else { | 859 | } else { |
860 | conn->maximum_speed_reached = 1; | 860 | conn->maximum_speed_reached = 1; |
861 | LOGGER_ERROR("send_data_packet failed\n"); | 861 | LOGGER_ERROR("send_data_packet failed\n"); |
@@ -2000,7 +2000,14 @@ static int udp_handle_packet(void *object, IP_Port source, const uint8_t *packet | |||
2000 | /* Ratio of recv queue size / recv packet rate (in seconds) times | 2000 | /* Ratio of recv queue size / recv packet rate (in seconds) times |
2001 | * the number of ms between request packets to send at that ratio | 2001 | * the number of ms between request packets to send at that ratio |
2002 | */ | 2002 | */ |
2003 | #define REQUEST_PACKETS_COMPARE_CONSTANT (0.5 * 100.0) | 2003 | #define REQUEST_PACKETS_COMPARE_CONSTANT (0.125 * 100.0) |
2004 | |||
2005 | /* Multiplier for maximum allowed resends. */ | ||
2006 | #define PACKET_RESEND_MULTIPLIER 2 | ||
2007 | |||
2008 | /* Timeout for increasing speed after congestion event (in ms). */ | ||
2009 | #define CONGESTION_EVENT_TIMEOUT 4000 | ||
2010 | |||
2004 | static void send_crypto_packets(Net_Crypto *c) | 2011 | static void send_crypto_packets(Net_Crypto *c) |
2005 | { | 2012 | { |
2006 | uint32_t i; | 2013 | uint32_t i; |
@@ -2078,7 +2085,11 @@ static void send_crypto_packets(Net_Crypto *c) | |||
2078 | double min_speed = 1000.0 * (((double)(total_sent)) / ((double)(CONGESTION_QUEUE_ARRAY_SIZE) * | 2085 | double min_speed = 1000.0 * (((double)(total_sent)) / ((double)(CONGESTION_QUEUE_ARRAY_SIZE) * |
2079 | PACKET_COUNTER_AVERAGE_INTERVAL)); | 2086 | PACKET_COUNTER_AVERAGE_INTERVAL)); |
2080 | 2087 | ||
2081 | conn->packet_send_rate = min_speed * 1.2; | 2088 | if (conn->last_congestion_event + CONGESTION_EVENT_TIMEOUT < temp_time) { |
2089 | conn->packet_send_rate = min_speed * 1.2; | ||
2090 | } else { | ||
2091 | conn->packet_send_rate = min_speed; | ||
2092 | } | ||
2082 | 2093 | ||
2083 | if (conn->packet_send_rate < CRYPTO_PACKET_MIN_RATE) { | 2094 | if (conn->packet_send_rate < CRYPTO_PACKET_MIN_RATE) { |
2084 | conn->packet_send_rate = CRYPTO_PACKET_MIN_RATE; | 2095 | conn->packet_send_rate = CRYPTO_PACKET_MIN_RATE; |
@@ -2101,12 +2112,13 @@ static void send_crypto_packets(Net_Crypto *c) | |||
2101 | conn->last_packets_left_set = temp_time; | 2112 | conn->last_packets_left_set = temp_time; |
2102 | } | 2113 | } |
2103 | 2114 | ||
2104 | int ret = send_requested_packets(c, i, ~0); | 2115 | int ret = send_requested_packets(c, i, conn->packets_left * PACKET_RESEND_MULTIPLIER); |
2105 | 2116 | ||
2106 | if (ret != -1) { | 2117 | if (ret != -1) { |
2107 | if (ret < conn->packets_left) { | 2118 | if (ret < conn->packets_left) { |
2108 | conn->packets_left -= ret; | 2119 | conn->packets_left -= ret; |
2109 | } else { | 2120 | } else { |
2121 | conn->last_congestion_event = temp_time; | ||
2110 | conn->packets_left = 0; | 2122 | conn->packets_left = 0; |
2111 | } | 2123 | } |
2112 | } | 2124 | } |