summaryrefslogtreecommitdiff
path: root/toxcore/TCP_server.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/TCP_server.c')
-rw-r--r--toxcore/TCP_server.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c
index 620ff51b..70e6ede6 100644
--- a/toxcore/TCP_server.c
+++ b/toxcore/TCP_server.c
@@ -612,11 +612,28 @@ static int handle_TCP_packet(TCP_Server *TCP_server, uint32_t con_id, uint8_t *d
612 return disconnect_conection_index(TCP_server, con, data[1] - NUM_RESERVED_PORTS); 612 return disconnect_conection_index(TCP_server, con, data[1] - NUM_RESERVED_PORTS);
613 } 613 }
614 614
615 case TCP_PACKET_ONION_REQUEST: { 615 case TCP_PACKET_PING: {
616 if (length != 1 + sizeof(uint64_t))
617 return -1;
618
619 break;
620 }
621
622 case TCP_PACKET_PONG: {
623 if (length != 1 + sizeof(uint64_t))
624 return -1;
616 625
617 break; 626 break;
618 } 627 }
619 628
629 case TCP_PACKET_ONION_REQUEST: {
630 //if (length <= 1 + crypto_box_NONCEBYTES + ONION_SEND_BASE*2)
631 // return -1;
632
633 //TODO onion_send_1(Onion *onion, data + 1 + crypto_box_NONCEBYTES, length - (1 + crypto_box_NONCEBYTES), IP_Port source, data + 1);
634 return 0;
635 }
636
620 case TCP_PACKET_ONION_RESPONSE: { 637 case TCP_PACKET_ONION_RESPONSE: {
621 638
622 break; 639 break;
@@ -638,7 +655,7 @@ static int handle_TCP_packet(TCP_Server *TCP_server, uint32_t con_id, uint8_t *d
638 return 0; 655 return 0;
639 656
640 uint32_t index = con->connections[con_id].index; 657 uint32_t index = con->connections[con_id].index;
641 uint8_t other_con_id = con->connections[con_id].other_id; 658 uint8_t other_con_id = con->connections[con_id].other_id + NUM_RESERVED_PORTS;
642 uint8_t new_data[length]; 659 uint8_t new_data[length];
643 memcpy(new_data, data, length); 660 memcpy(new_data, data, length);
644 new_data[0] = other_con_id; 661 new_data[0] = other_con_id;
@@ -847,18 +864,19 @@ static void do_TCP_confirmed(TCP_Server *TCP_server)
847 864
848 send_pending_data(conn); 865 send_pending_data(conn);
849 uint8_t packet[MAX_PACKET_SIZE]; 866 uint8_t packet[MAX_PACKET_SIZE];
850 int len = read_packet_TCP_secure_connection(conn, packet, sizeof(packet)); 867 int len;
868
869 while ((len = read_packet_TCP_secure_connection(conn, packet, sizeof(packet)))) {
870 if (len == -1) {
871 kill_TCP_connection(conn);
872 del_accepted(TCP_server, i);
873 break;
874 }
851 875
852 if (len == 0) {
853 continue;
854 } else if (len == -1) {
855 kill_TCP_connection(conn);
856 del_accepted(TCP_server, i);
857 continue;
858 } else {
859 if (handle_TCP_packet(TCP_server, i, packet, len) == -1) { 876 if (handle_TCP_packet(TCP_server, i, packet, len) == -1) {
860 kill_TCP_connection(conn); 877 kill_TCP_connection(conn);
861 del_accepted(TCP_server, i); 878 del_accepted(TCP_server, i);
879 break;
862 } 880 }
863 } 881 }
864 } 882 }