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.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/core/Lossless_UDP.c b/core/Lossless_UDP.c
index a753e5ff..8538f76c 100644
--- a/core/Lossless_UDP.c
+++ b/core/Lossless_UDP.c
@@ -149,7 +149,7 @@ static uint32_t randtable[6][256];
149 * 149 *
150 * TODO: make this better 150 * TODO: make this better
151 */ 151 */
152uint32_t handshake_id(IP_Port source) 152static uint32_t handshake_id(IP_Port source)
153{ 153{
154 uint32_t id = 0, i; 154 uint32_t id = 0, i;
155 for (i = 0; i < 6; ++i) { 155 for (i = 0; i < 6; ++i) {
@@ -168,7 +168,7 @@ uint32_t handshake_id(IP_Port source)
168 * 168 *
169 * TODO: make this better 169 * TODO: make this better
170 */ 170 */
171void change_handshake(IP_Port source) 171static void change_handshake(IP_Port source)
172{ 172{
173 uint8_t rand = random_int() % 4; 173 uint8_t rand = random_int() % 4;
174 randtable[rand][((uint8_t *)&source)[rand]] = random_int(); 174 randtable[rand][((uint8_t *)&source)[rand]] = random_int();
@@ -234,7 +234,7 @@ int new_connection(IP_Port ip_port)
234 * Returns an integer corresponding to the connection id. 234 * Returns an integer corresponding to the connection id.
235 * Return -1 if it could not initialize the connection. 235 * Return -1 if it could not initialize the connection.
236 */ 236 */
237int new_inconnection(IP_Port ip_port) 237static int new_inconnection(IP_Port ip_port)
238{ 238{
239 if (getconnection_id(ip_port) != -1) 239 if (getconnection_id(ip_port) != -1)
240 return -1; 240 return -1;
@@ -470,7 +470,7 @@ uint32_t missing_packets(int connection_id, uint32_t * requested)
470 * see http://wiki.tox.im/index.php/Lossless_UDP for more information. 470 * see http://wiki.tox.im/index.php/Lossless_UDP for more information.
471 */ 471 */
472 472
473int send_handshake(IP_Port ip_port, uint32_t handshake_id1, uint32_t handshake_id2) 473static int send_handshake(IP_Port ip_port, uint32_t handshake_id1, uint32_t handshake_id2)
474{ 474{
475 uint8_t packet[1 + 4 + 4]; 475 uint8_t packet[1 + 4 + 4];
476 uint32_t temp; 476 uint32_t temp;
@@ -484,7 +484,7 @@ int send_handshake(IP_Port ip_port, uint32_t handshake_id1, uint32_t handshake_i
484 return sendpacket(ip_port, packet, sizeof(packet)); 484 return sendpacket(ip_port, packet, sizeof(packet));
485} 485}
486 486
487int send_SYNC(uint32_t connection_id) 487static int send_SYNC(uint32_t connection_id)
488{ 488{
489 uint8_t packet[(BUFFER_PACKET_NUM*4 + 4 + 4 + 2)]; 489 uint8_t packet[(BUFFER_PACKET_NUM*4 + 4 + 4 + 2)];
490 uint16_t index = 0; 490 uint16_t index = 0;
@@ -511,7 +511,7 @@ int send_SYNC(uint32_t connection_id)
511 511
512} 512}
513 513
514int send_data_packet(uint32_t connection_id, uint32_t packet_num) 514static int send_data_packet(uint32_t connection_id, uint32_t packet_num)
515{ 515{
516 uint32_t index = packet_num % MAX_QUEUE_NUM; 516 uint32_t index = packet_num % MAX_QUEUE_NUM;
517 uint32_t temp; 517 uint32_t temp;
@@ -526,7 +526,7 @@ int send_data_packet(uint32_t connection_id, uint32_t packet_num)
526} 526}
527 527
528/* sends 1 data packet */ 528/* sends 1 data packet */
529int send_DATA(uint32_t connection_id) 529static int send_DATA(uint32_t connection_id)
530{ 530{
531 int ret; 531 int ret;
532 uint32_t buffer[BUFFER_PACKET_NUM]; 532 uint32_t buffer[BUFFER_PACKET_NUM];
@@ -555,7 +555,7 @@ int send_DATA(uint32_t connection_id)
555 555
556 556
557/* Return 0 if handled correctly, 1 if packet is bad. */ 557/* Return 0 if handled correctly, 1 if packet is bad. */
558int handle_handshake(uint8_t * packet, uint32_t length, IP_Port source) 558static int handle_handshake(uint8_t * packet, uint32_t length, IP_Port source)
559{ 559{
560 if (length != (1 + 4 + 4)) 560 if (length != (1 + 4 + 4))
561 return 1; 561 return 1;
@@ -591,7 +591,7 @@ int handle_handshake(uint8_t * packet, uint32_t length, IP_Port source)
591} 591}
592 592
593/* returns 1 if sync packet is valid 0 if not. */ 593/* returns 1 if sync packet is valid 0 if not. */
594int SYNC_valid(uint32_t length) 594static int SYNC_valid(uint32_t length)
595{ 595{
596 if (length < 4 + 4 + 2) 596 if (length < 4 + 4 + 2)
597 return 0; 597 return 0;
@@ -602,7 +602,7 @@ int SYNC_valid(uint32_t length)
602} 602}
603 603
604/* case 1 in handle_SYNC: */ 604/* case 1 in handle_SYNC: */
605int handle_SYNC1(IP_Port source, uint32_t recv_packetnum, uint32_t sent_packetnum) 605static int handle_SYNC1(IP_Port source, uint32_t recv_packetnum, uint32_t sent_packetnum)
606{ 606{
607 if (handshake_id(source) == recv_packetnum) { 607 if (handshake_id(source) == recv_packetnum) {
608 int x = new_inconnection(source); 608 int x = new_inconnection(source);
@@ -622,7 +622,7 @@ int handle_SYNC1(IP_Port source, uint32_t recv_packetnum, uint32_t sent_packetnu
622} 622}
623 623
624/* case 2 in handle_SYNC: */ 624/* case 2 in handle_SYNC: */
625int handle_SYNC2(int connection_id, uint8_t counter, uint32_t recv_packetnum, uint32_t sent_packetnum) 625static int handle_SYNC2(int connection_id, uint8_t counter, uint32_t recv_packetnum, uint32_t sent_packetnum)
626{ 626{
627 if (recv_packetnum == connections[connection_id].orecv_packetnum) { 627 if (recv_packetnum == connections[connection_id].orecv_packetnum) {
628 /* && sent_packetnum == connections[connection_id].osent_packetnum) */ 628 /* && sent_packetnum == connections[connection_id].osent_packetnum) */
@@ -635,7 +635,7 @@ int handle_SYNC2(int connection_id, uint8_t counter, uint32_t recv_packetnum, ui
635 return 1; 635 return 1;
636} 636}
637/* case 3 in handle_SYNC: */ 637/* case 3 in handle_SYNC: */
638int handle_SYNC3(int connection_id, uint8_t counter, uint32_t recv_packetnum, uint32_t sent_packetnum, uint32_t * req_packets, 638static int handle_SYNC3(int connection_id, uint8_t counter, uint32_t recv_packetnum, uint32_t sent_packetnum, uint32_t * req_packets,
639 uint16_t number) 639 uint16_t number)
640{ 640{
641 uint8_t comp_counter = (counter - connections[connection_id].recv_counter ); 641 uint8_t comp_counter = (counter - connections[connection_id].recv_counter );
@@ -669,7 +669,7 @@ int handle_SYNC3(int connection_id, uint8_t counter, uint32_t recv_packetnum, ui
669 return 1; 669 return 1;
670} 670}
671 671
672int handle_SYNC(uint8_t *packet, uint32_t length, IP_Port source) 672static int handle_SYNC(uint8_t *packet, uint32_t length, IP_Port source)
673{ 673{
674 674
675 if (!SYNC_valid(length)) 675 if (!SYNC_valid(length))
@@ -708,7 +708,7 @@ int handle_SYNC(uint8_t *packet, uint32_t length, IP_Port source)
708 * Add a packet to the received buffer and set the recv_packetnum of the 708 * Add a packet to the received buffer and set the recv_packetnum of the
709 * connection to its proper value. Return 1 if data was too big, 0 if not. 709 * connection to its proper value. Return 1 if data was too big, 0 if not.
710 */ 710 */
711int add_recv(int connection_id, uint32_t data_num, uint8_t *data, uint16_t size) 711static int add_recv(int connection_id, uint32_t data_num, uint8_t *data, uint16_t size)
712{ 712{
713 if (size > MAX_DATA_SIZE) 713 if (size > MAX_DATA_SIZE)
714 return 1; 714 return 1;
@@ -742,7 +742,7 @@ int add_recv(int connection_id, uint32_t data_num, uint8_t *data, uint16_t size)
742 return 0; 742 return 0;
743} 743}
744 744
745int handle_data(uint8_t *packet, uint32_t length, IP_Port source) 745static int handle_data(uint8_t *packet, uint32_t length, IP_Port source)
746{ 746{
747 int connection = getconnection_id(source); 747 int connection = getconnection_id(source);
748 748
@@ -793,7 +793,7 @@ int LosslessUDP_handlepacket(uint8_t *packet, uint32_t length, IP_Port source)
793 * Send handshake requests 793 * Send handshake requests
794 * handshake packets are sent at the same rate as SYNC packets 794 * handshake packets are sent at the same rate as SYNC packets
795 */ 795 */
796void doNew() 796static void doNew()
797{ 797{
798 uint32_t i; 798 uint32_t i;
799 uint64_t temp_time = current_time(); 799 uint64_t temp_time = current_time();
@@ -817,7 +817,7 @@ void doNew()
817 } 817 }
818} 818}
819 819
820void doSYNC() 820static void doSYNC()
821{ 821{
822 uint32_t i; 822 uint32_t i;
823 uint64_t temp_time = current_time(); 823 uint64_t temp_time = current_time();
@@ -830,7 +830,7 @@ void doSYNC()
830 } 830 }
831} 831}
832 832
833void doData() 833static void doData()
834{ 834{
835 uint32_t i; 835 uint32_t i;
836 uint64_t j; 836 uint64_t j;
@@ -851,7 +851,7 @@ void doData()
851 * 851 *
852 * TODO: flow control. 852 * TODO: flow control.
853 */ 853 */
854void adjustRates() 854static void adjustRates()
855{ 855{
856 uint32_t i; 856 uint32_t i;
857 uint64_t temp_time = current_time(); 857 uint64_t temp_time = current_time();