summaryrefslogtreecommitdiff
path: root/core/Lossless_UDP.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/Lossless_UDP.c')
-rw-r--r--core/Lossless_UDP.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/core/Lossless_UDP.c b/core/Lossless_UDP.c
index 4affc38f..33b8eb19 100644
--- a/core/Lossless_UDP.c
+++ b/core/Lossless_UDP.c
@@ -202,15 +202,16 @@ int new_connection(IP_Port ip_port)
202 for (i = 0; i < MAX_CONNECTIONS; ++i) { 202 for (i = 0; i < MAX_CONNECTIONS; ++i) {
203 if(connections[i].status == 0) { 203 if(connections[i].status == 0) {
204 memset(&connections[i], 0, sizeof(Connection)); 204 memset(&connections[i], 0, sizeof(Connection));
205 uint32_t handshake_id1 = handshake_id(ip_port);
205 206
206 connections[i] = (Connection) { 207 connections[i] = (Connection) {
207 .ip_port = ip_port, 208 .ip_port = ip_port,
208 .status = 1, 209 .status = 1,
209 .inbound = 0, 210 .inbound = 0,
210 .handshake_id1 = handshake_id(ip_port), 211 .handshake_id1 = handshake_id1,
211 .sent_packetnum = connections[i].handshake_id1, 212 .sent_packetnum = handshake_id1,
212 .sendbuff_packetnum = connections[i].handshake_id1, 213 .sendbuff_packetnum = handshake_id1,
213 .successful_sent = connections[i].handshake_id1, 214 .successful_sent = handshake_id1,
214 .SYNC_rate = SYNC_RATE, 215 .SYNC_rate = SYNC_RATE,
215 .data_rate = DATA_SYNC_RATE, 216 .data_rate = DATA_SYNC_RATE,
216 .last_recvSYNC = current_time(), 217 .last_recvSYNC = current_time(),
@@ -254,6 +255,7 @@ int new_inconnection(IP_Port ip_port)
254 for (i = 0; i < MAX_CONNECTIONS; ++i) { 255 for (i = 0; i < MAX_CONNECTIONS; ++i) {
255 if (connections[i].status == 0) { 256 if (connections[i].status == 0) {
256 memset(&connections[i], 0, sizeof(Connection)); 257 memset(&connections[i], 0, sizeof(Connection));
258 uint64_t timeout = CONNEXION_TIMEOUT + rand() % CONNEXION_TIMEOUT;
257 259
258 connections[i] = (Connection){ 260 connections[i] = (Connection){
259 .ip_port = ip_port, 261 .ip_port = ip_port,
@@ -266,10 +268,10 @@ int new_inconnection(IP_Port ip_port)
266 .send_counter = 127, 268 .send_counter = 127,
267 269
268 /* add randomness to timeout to prevent connections getting stuck in a loop. */ 270 /* add randomness to timeout to prevent connections getting stuck in a loop. */
269 .timeout = CONNEXION_TIMEOUT + rand() % CONNEXION_TIMEOUT, 271 .timeout = timeout,
270 272
271 /* if this connection isn't handled within the timeout kill it. */ 273 /* if this connection isn't handled within the timeout kill it. */
272 .killat = current_time() + 1000000UL*connections[i].timeout 274 .killat = current_time() + 1000000UL*timeout
273 }; 275 };
274 ++connections_number; 276 ++connections_number;
275 return i; 277 return i;