summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Lossless_UDP.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/core/Lossless_UDP.c b/core/Lossless_UDP.c
index b92e6806..482d88b1 100644
--- a/core/Lossless_UDP.c
+++ b/core/Lossless_UDP.c
@@ -28,22 +28,22 @@
28 28
29 29
30 //maximum data packets in sent and recieve queues. 30 //maximum data packets in sent and recieve queues.
31#define MAX_QUEUE_NUM 32 31#define MAX_QUEUE_NUM 16
32 32
33//maximum length of the data in the data packets 33//maximum length of the data in the data packets
34#define MAX_DATA_SIZE 1024 34#define MAX_DATA_SIZE 1024
35 35
36//maximum number of data packets in the buffer 36//maximum number of data packets in the buffer
37#define BUFFER_PACKET_NUM MAX_QUEUE_NUM 37#define BUFFER_PACKET_NUM (16-1)
38 38
39//Lossless UDP connection timeout. 39//Lossless UDP connection timeout.
40#define CONNEXION_TIMEOUT 10 40#define CONNEXION_TIMEOUT 10
41 41
42//initial amount of sync/hanshake packets to send per second. 42//initial amount of sync/hanshake packets to send per second.
43#define SYNC_RATE 5 43#define SYNC_RATE 50
44 44
45//initial send rate of sync packets when data is being sent/recieved. 45//initial send rate of sync packets when data is being sent/recieved.
46#define DATA_SYNC_RATE 20 46#define DATA_SYNC_RATE 200
47 47
48typedef struct 48typedef struct
49{ 49{
@@ -242,7 +242,7 @@ int is_connected(int connection_id)
242//returns the ip_port of the corresponding connection. 242//returns the ip_port of the corresponding connection.
243IP_Port connection_ip(int connection_id) 243IP_Port connection_ip(int connection_id)
244{ 244{
245 if(connection_id > 0 && connection_id < MAX_CONNECTIONS) 245 if(connection_id >= 0 && connection_id < MAX_CONNECTIONS)
246 { 246 {
247 return connections[connection_id].ip_port; 247 return connections[connection_id].ip_port;
248 } 248 }
@@ -290,7 +290,7 @@ int write_packet(int connection_id, char * data, uint32_t length)
290 { 290 {
291 return 0; 291 return 0;
292 } 292 }
293 if(sendqueue(connection_id) < MAX_QUEUE_NUM) 293 if(sendqueue(connection_id) < BUFFER_PACKET_NUM)
294 { 294 {
295 uint32_t index = connections[connection_id].sendbuff_packetnum % MAX_QUEUE_NUM; 295 uint32_t index = connections[connection_id].sendbuff_packetnum % MAX_QUEUE_NUM;
296 memcpy(connections[connection_id].sendbuffer[index].data, data, length); 296 memcpy(connections[connection_id].sendbuffer[index].data, data, length);
@@ -309,6 +309,11 @@ uint32_t missing_packets(int connection_id, uint32_t * requested)
309{ 309{
310 uint32_t number = 0; 310 uint32_t number = 0;
311 uint32_t i; 311 uint32_t i;
312
313 if(recvqueue(connection_id) >= BUFFER_PACKET_NUM)//don't request packets if the buffer is full.
314 {
315 return 0;
316 }
312 for(i = connections[connection_id].recv_packetnum; i != connections[connection_id].osent_packetnum; i++ ) 317 for(i = connections[connection_id].recv_packetnum; i != connections[connection_id].osent_packetnum; i++ )
313 { 318 {
314 if(connections[connection_id].recvbuffer[i % MAX_QUEUE_NUM].size == 0) 319 if(connections[connection_id].recvbuffer[i % MAX_QUEUE_NUM].size == 0)
@@ -500,9 +505,11 @@ int handle_SYNC3(int connection_id, uint8_t counter, uint32_t recv_packetnum, ui
500 uint16_t number) 505 uint16_t number)
501{ 506{
502 uint8_t comp_counter = (counter - connections[connection_id].recv_counter ); 507 uint8_t comp_counter = (counter - connections[connection_id].recv_counter );
508 //uint32_t comp_1 = (recv_packetnum - connections[connection_id].successful_sent);
509 //uint32_t comp_2 = (sent_packetnum - connections[connection_id].successful_read);
503 uint32_t comp_1 = (recv_packetnum - connections[connection_id].orecv_packetnum); 510 uint32_t comp_1 = (recv_packetnum - connections[connection_id].orecv_packetnum);
504 uint32_t comp_2 = (sent_packetnum - connections[connection_id].osent_packetnum); 511 uint32_t comp_2 = (sent_packetnum - connections[connection_id].osent_packetnum);
505 if(comp_1 < BUFFER_PACKET_NUM && comp_2 < BUFFER_PACKET_NUM && comp_counter < 10) //packet valid 512 if(comp_1 <= BUFFER_PACKET_NUM && comp_2 <= BUFFER_PACKET_NUM && comp_counter < 10 && comp_counter != 0) //packet valid
506 { 513 {
507 connections[connection_id].orecv_packetnum = recv_packetnum; 514 connections[connection_id].orecv_packetnum = recv_packetnum;
508 connections[connection_id].osent_packetnum = sent_packetnum; 515 connections[connection_id].osent_packetnum = sent_packetnum;