summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Lossless_UDP.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/core/Lossless_UDP.c b/core/Lossless_UDP.c
index e61c04bc..55bc1cfb 100644
--- a/core/Lossless_UDP.c
+++ b/core/Lossless_UDP.c
@@ -37,6 +37,7 @@
37#define BUFFER_PACKET_NUM (16-1) 37#define BUFFER_PACKET_NUM (16-1)
38 38
39//Lossless UDP connection timeout. 39//Lossless UDP connection timeout.
40//timeout per connection is randomly set between CONNEXION_TIMEOUT and 2*CONNEXION_TIMEOUT
40#define CONNEXION_TIMEOUT 5 41#define CONNEXION_TIMEOUT 5
41 42
42//initial amount of sync/hanshake packets to send per second. 43//initial amount of sync/hanshake packets to send per second.
@@ -84,6 +85,7 @@ typedef struct
84 uint16_t num_req_paquets; //total number of currently requested packets(by the other person) 85 uint16_t num_req_paquets; //total number of currently requested packets(by the other person)
85 uint8_t recv_counter; 86 uint8_t recv_counter;
86 uint8_t send_counter; 87 uint8_t send_counter;
88 uint8_t timeout; //connection timeout in seconds.
87}Connection; 89}Connection;
88 90
89 91
@@ -175,6 +177,8 @@ int new_connection(IP_Port ip_port)
175 connections[i].last_sent = current_time(); 177 connections[i].last_sent = current_time();
176 connections[i].killat = ~0; 178 connections[i].killat = ~0;
177 connections[i].send_counter = 0; 179 connections[i].send_counter = 0;
180 //add randomness to timeout to prevent connections getting stuck in a loop.
181 connections[i].timeout = CONNEXION_TIMEOUT + rand() % CONNEXION_TIMEOUT;
178 return i; 182 return i;
179 } 183 }
180 } 184 }
@@ -203,8 +207,10 @@ int new_inconnection(IP_Port ip_port)
203 connections[i].data_rate = DATA_SYNC_RATE; 207 connections[i].data_rate = DATA_SYNC_RATE;
204 connections[i].last_recvSYNC = current_time(); 208 connections[i].last_recvSYNC = current_time();
205 connections[i].last_sent = current_time(); 209 connections[i].last_sent = current_time();
206 //if this connection isn't handled within 5 seconds, kill it 210 //add randomness to timeout to prevent connections getting stuck in a loop.
207 connections[i].killat = current_time() + 1000000UL*CONNEXION_TIMEOUT; 211 connections[i].timeout = CONNEXION_TIMEOUT + rand() % CONNEXION_TIMEOUT;
212 //if this connection isn't handled within the timeout kill it.
213 connections[i].killat = current_time() + 1000000UL*connections[i].timeout;
208 connections[i].send_counter = 127; 214 connections[i].send_counter = 127;
209 return i; 215 return i;
210 } 216 }
@@ -551,6 +557,7 @@ int handle_SYNC2(int connection_id, uint8_t counter, uint32_t recv_packetnum, ui
551 connections[connection_id].status = 3; 557 connections[connection_id].status = 3;
552 connections[connection_id].recv_counter = counter; 558 connections[connection_id].recv_counter = counter;
553 connections[connection_id].send_counter++; 559 connections[connection_id].send_counter++;
560 send_SYNC(connection_id);
554 return 0; 561 return 0;
555 } 562 }
556 return 1; 563 return 1;
@@ -671,6 +678,12 @@ int handle_data(uint8_t * packet, uint32_t length, IP_Port source)
671 { 678 {
672 return 1; 679 return 1;
673 } 680 }
681
682 if(connections[connection].status != 3)//Drop the data packet if connection is not connected.
683 {
684 return 1;
685 }
686
674 if(length > 1 + 4 + MAX_DATA_SIZE || length < 1 + 4 + 1) 687 if(length > 1 + 4 + MAX_DATA_SIZE || length < 1 + 4 + 1)
675 { 688 {
676 return 1; 689 return 1;
@@ -728,7 +741,7 @@ void doNew()
728 741
729 } 742 }
730 //kill all timed out connections 743 //kill all timed out connections
731 if( connections[i].status > 0 && (connections[i].last_recvSYNC + CONNEXION_TIMEOUT * 1000000UL) < temp_time && 744 if( connections[i].status > 0 && (connections[i].last_recvSYNC + connections[i].timeout * 1000000UL) < temp_time &&
732 connections[i].status != 4) 745 connections[i].status != 4)
733 { 746 {
734 //kill_connection(i); 747 //kill_connection(i);