diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/Lossless_UDP.c | 46 | ||||
-rw-r--r-- | core/network.c | 4 |
2 files changed, 35 insertions, 15 deletions
diff --git a/core/Lossless_UDP.c b/core/Lossless_UDP.c index 482d88b1..d40b2851 100644 --- a/core/Lossless_UDP.c +++ b/core/Lossless_UDP.c | |||
@@ -309,6 +309,7 @@ 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 | uint32_t temp; | ||
312 | 313 | ||
313 | if(recvqueue(connection_id) >= BUFFER_PACKET_NUM)//don't request packets if the buffer is full. | 314 | if(recvqueue(connection_id) >= BUFFER_PACKET_NUM)//don't request packets if the buffer is full. |
314 | { | 315 | { |
@@ -318,7 +319,8 @@ uint32_t missing_packets(int connection_id, uint32_t * requested) | |||
318 | { | 319 | { |
319 | if(connections[connection_id].recvbuffer[i % MAX_QUEUE_NUM].size == 0) | 320 | if(connections[connection_id].recvbuffer[i % MAX_QUEUE_NUM].size == 0) |
320 | { | 321 | { |
321 | memcpy(requested + number, &i, 4); | 322 | temp = htonl(i); |
323 | memcpy(requested + number, &temp, 4); | ||
322 | number++; | 324 | number++; |
323 | } | 325 | } |
324 | } | 326 | } |
@@ -338,9 +340,13 @@ uint32_t missing_packets(int connection_id, uint32_t * requested) | |||
338 | int send_handshake(IP_Port ip_port, uint32_t handshake_id1, uint32_t handshake_id2) | 340 | int send_handshake(IP_Port ip_port, uint32_t handshake_id1, uint32_t handshake_id2) |
339 | { | 341 | { |
340 | char packet[1 + 4 + 4]; | 342 | char packet[1 + 4 + 4]; |
343 | uint32_t temp; | ||
344 | |||
341 | packet[0] = 16; | 345 | packet[0] = 16; |
342 | memcpy(packet + 1, &handshake_id1, 4); | 346 | temp = htonl(handshake_id1); |
343 | memcpy(packet + 5, &handshake_id2, 4); | 347 | memcpy(packet + 1, &temp, 4); |
348 | temp = htonl(handshake_id2); | ||
349 | memcpy(packet + 5, &temp, 4); | ||
344 | return sendpacket(ip_port, packet, sizeof(packet)); | 350 | return sendpacket(ip_port, packet, sizeof(packet)); |
345 | 351 | ||
346 | } | 352 | } |
@@ -354,8 +360,8 @@ int send_SYNC(uint32_t connection_id) | |||
354 | 360 | ||
355 | IP_Port ip_port = connections[connection_id].ip_port; | 361 | IP_Port ip_port = connections[connection_id].ip_port; |
356 | uint8_t counter = connections[connection_id].send_counter; | 362 | uint8_t counter = connections[connection_id].send_counter; |
357 | uint32_t recv_packetnum = connections[connection_id].recv_packetnum; | 363 | uint32_t recv_packetnum = htonl(connections[connection_id].recv_packetnum); |
358 | uint32_t sent_packetnum = connections[connection_id].sent_packetnum; | 364 | uint32_t sent_packetnum = htonl(connections[connection_id].sent_packetnum); |
359 | uint32_t requested[BUFFER_PACKET_NUM]; | 365 | uint32_t requested[BUFFER_PACKET_NUM]; |
360 | uint32_t number = missing_packets(connection_id, requested); | 366 | uint32_t number = missing_packets(connection_id, requested); |
361 | 367 | ||
@@ -376,9 +382,11 @@ int send_SYNC(uint32_t connection_id) | |||
376 | int send_data_packet(uint32_t connection_id, uint32_t packet_num) | 382 | int send_data_packet(uint32_t connection_id, uint32_t packet_num) |
377 | { | 383 | { |
378 | uint32_t index = packet_num % MAX_QUEUE_NUM; | 384 | uint32_t index = packet_num % MAX_QUEUE_NUM; |
385 | uint32_t temp; | ||
379 | char packet[1 + 4 + MAX_DATA_SIZE]; | 386 | char packet[1 + 4 + MAX_DATA_SIZE]; |
380 | packet[0] = 18; | 387 | packet[0] = 18; |
381 | memcpy(packet + 1, &packet_num, 4); | 388 | temp = htonl(packet_num); |
389 | memcpy(packet + 1, &temp, 4); | ||
382 | memcpy(packet + 5, connections[connection_id].sendbuffer[index].data, | 390 | memcpy(packet + 5, connections[connection_id].sendbuffer[index].data, |
383 | connections[connection_id].sendbuffer[index].size); | 391 | connections[connection_id].sendbuffer[index].size); |
384 | return sendpacket(connections[connection_id].ip_port, packet, | 392 | return sendpacket(connections[connection_id].ip_port, packet, |
@@ -420,11 +428,13 @@ int handle_handshake(char * packet, uint32_t length, IP_Port source) | |||
420 | { | 428 | { |
421 | return 1; | 429 | return 1; |
422 | } | 430 | } |
431 | uint32_t temp; | ||
423 | uint32_t handshake_id1, handshake_id2; | 432 | uint32_t handshake_id1, handshake_id2; |
424 | int connection = getconnection_id(source); | 433 | int connection = getconnection_id(source); |
425 | memcpy(&handshake_id1, packet + 1, 4); | 434 | memcpy(&temp, packet + 1, 4); |
426 | memcpy(&handshake_id2, packet + 5, 4); | 435 | handshake_id1 = ntohl(temp); |
427 | 436 | memcpy(&temp, packet + 5, 4); | |
437 | handshake_id2 = ntohl(temp); | ||
428 | 438 | ||
429 | if(handshake_id2 == 0) | 439 | if(handshake_id2 == 0) |
430 | { | 440 | { |
@@ -505,6 +515,7 @@ int handle_SYNC3(int connection_id, uint8_t counter, uint32_t recv_packetnum, ui | |||
505 | uint16_t number) | 515 | uint16_t number) |
506 | { | 516 | { |
507 | uint8_t comp_counter = (counter - connections[connection_id].recv_counter ); | 517 | uint8_t comp_counter = (counter - connections[connection_id].recv_counter ); |
518 | uint32_t i, temp; | ||
508 | //uint32_t comp_1 = (recv_packetnum - connections[connection_id].successful_sent); | 519 | //uint32_t comp_1 = (recv_packetnum - connections[connection_id].successful_sent); |
509 | //uint32_t comp_2 = (sent_packetnum - connections[connection_id].successful_read); | 520 | //uint32_t comp_2 = (sent_packetnum - connections[connection_id].successful_read); |
510 | uint32_t comp_1 = (recv_packetnum - connections[connection_id].orecv_packetnum); | 521 | uint32_t comp_1 = (recv_packetnum - connections[connection_id].orecv_packetnum); |
@@ -517,7 +528,11 @@ int handle_SYNC3(int connection_id, uint8_t counter, uint32_t recv_packetnum, ui | |||
517 | connections[connection_id].last_recv = current_time(); | 528 | connections[connection_id].last_recv = current_time(); |
518 | connections[connection_id].recv_counter = counter; | 529 | connections[connection_id].recv_counter = counter; |
519 | connections[connection_id].send_counter++; | 530 | connections[connection_id].send_counter++; |
520 | memcpy(connections[connection_id].req_packets, req_packets, 4 * number); | 531 | for(i = 0; i < number; i++) |
532 | { | ||
533 | temp = ntohl(req_packets[i]); | ||
534 | memcpy(connections[connection_id].req_packets + i, &temp, 4 * number); | ||
535 | } | ||
521 | connections[connection_id].num_req_paquets = number; | 536 | connections[connection_id].num_req_paquets = number; |
522 | return 0; | 537 | return 0; |
523 | } | 538 | } |
@@ -533,13 +548,16 @@ int handle_SYNC(char * packet, uint32_t length, IP_Port source) | |||
533 | } | 548 | } |
534 | int connection = getconnection_id(source); | 549 | int connection = getconnection_id(source); |
535 | uint8_t counter; | 550 | uint8_t counter; |
551 | uint32_t temp; | ||
536 | uint32_t recv_packetnum, sent_packetnum; | 552 | uint32_t recv_packetnum, sent_packetnum; |
537 | uint32_t req_packets[BUFFER_PACKET_NUM]; | 553 | uint32_t req_packets[BUFFER_PACKET_NUM]; |
538 | uint16_t number = (length - 4 - 4 - 2)/ 4; | 554 | uint16_t number = (length - 4 - 4 - 2)/ 4; |
539 | 555 | ||
540 | memcpy(&counter, packet + 1, 1); | 556 | memcpy(&counter, packet + 1, 1); |
541 | memcpy(&recv_packetnum, packet + 2, 4); | 557 | memcpy(&temp, packet + 2, 4); |
542 | memcpy(&sent_packetnum,packet + 6, 4); | 558 | recv_packetnum = ntohl(temp); |
559 | memcpy(&temp,packet + 6, 4); | ||
560 | sent_packetnum = ntohl(temp); | ||
543 | if(number != 0) | 561 | if(number != 0) |
544 | { | 562 | { |
545 | memcpy(req_packets, packet + 10, 4 * number); | 563 | memcpy(req_packets, packet + 10, 4 * number); |
@@ -613,10 +631,12 @@ int handle_data(char * packet, uint32_t length, IP_Port source) | |||
613 | { | 631 | { |
614 | return 1; | 632 | return 1; |
615 | } | 633 | } |
634 | uint32_t temp; | ||
616 | uint32_t number; | 635 | uint32_t number; |
617 | uint16_t size = length - 1 - 4; | 636 | uint16_t size = length - 1 - 4; |
618 | 637 | ||
619 | memcpy(&number, packet + 1, 4); | 638 | memcpy(&temp, packet + 1, 4); |
639 | number = ntohl(temp); | ||
620 | return add_recv(connection, number, packet + 5, size); | 640 | return add_recv(connection, number, packet + 5, size); |
621 | 641 | ||
622 | } | 642 | } |
diff --git a/core/network.c b/core/network.c index bbc1f570..e7999416 100644 --- a/core/network.c +++ b/core/network.c | |||
@@ -70,8 +70,8 @@ int recievepacket(IP_Port * ip_port, char * data, uint32_t * length) | |||
70 | { | 70 | { |
71 | ADDR addr; | 71 | ADDR addr; |
72 | uint32_t addrlen = sizeof(addr); | 72 | uint32_t addrlen = sizeof(addr); |
73 | (*(int *)length) = recvfrom(sock, data, MAX_UDP_PACKET_SIZE, 0, (struct sockaddr *)&addr, &addrlen); | 73 | (*(int32_t *)length) = recvfrom(sock, data, MAX_UDP_PACKET_SIZE, 0, (struct sockaddr *)&addr, &addrlen); |
74 | if(*(int *)length <= 0) | 74 | if(*(int32_t *)length <= 0) |
75 | { | 75 | { |
76 | //nothing received | 76 | //nothing received |
77 | //or empty packet | 77 | //or empty packet |