summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--auto_tests/TCP_test.c17
-rw-r--r--toxcore/TCP_connection.c36
-rw-r--r--toxcore/TCP_connection.h28
3 files changed, 47 insertions, 34 deletions
diff --git a/auto_tests/TCP_test.c b/auto_tests/TCP_test.c
index 7f96ef35..6a721b43 100644
--- a/auto_tests/TCP_test.c
+++ b/auto_tests/TCP_test.c
@@ -560,11 +560,11 @@ START_TEST(test_tcp_connection)
560 proxy_info.proxy_type = TCP_PROXY_NONE; 560 proxy_info.proxy_type = TCP_PROXY_NONE;
561 crypto_box_keypair(self_public_key, self_secret_key); 561 crypto_box_keypair(self_public_key, self_secret_key);
562 TCP_Connections *tc_1 = new_tcp_connections(self_secret_key, &proxy_info); 562 TCP_Connections *tc_1 = new_tcp_connections(self_secret_key, &proxy_info);
563 ck_assert_msg(public_key_cmp(tc_1->self_public_key, self_public_key) == 0, "Wrong public key"); 563 ck_assert_msg(public_key_cmp(tcp_connections_public_key(tc_1), self_public_key) == 0, "Wrong public key");
564 564
565 crypto_box_keypair(self_public_key, self_secret_key); 565 crypto_box_keypair(self_public_key, self_secret_key);
566 TCP_Connections *tc_2 = new_tcp_connections(self_secret_key, &proxy_info); 566 TCP_Connections *tc_2 = new_tcp_connections(self_secret_key, &proxy_info);
567 ck_assert_msg(public_key_cmp(tc_2->self_public_key, self_public_key) == 0, "Wrong public key"); 567 ck_assert_msg(public_key_cmp(tcp_connections_public_key(tc_2), self_public_key) == 0, "Wrong public key");
568 568
569 IP_Port ip_port_tcp_s; 569 IP_Port ip_port_tcp_s;
570 570
@@ -572,18 +572,19 @@ START_TEST(test_tcp_connection)
572 ip_port_tcp_s.ip.family = AF_INET6; 572 ip_port_tcp_s.ip.family = AF_INET6;
573 ip_port_tcp_s.ip.ip6.in6_addr = in6addr_loopback; 573 ip_port_tcp_s.ip.ip6.in6_addr = in6addr_loopback;
574 574
575 int connection = new_tcp_connection_to(tc_1, tc_2->self_public_key, 123); 575 int connection = new_tcp_connection_to(tc_1, tcp_connections_public_key(tc_2), 123);
576 ck_assert_msg(connection == 0, "Connection id wrong"); 576 ck_assert_msg(connection == 0, "Connection id wrong");
577 ck_assert_msg(add_tcp_relay_connection(tc_1, connection, ip_port_tcp_s, tcp_server_public_key(tcp_s)) == 0, 577 ck_assert_msg(add_tcp_relay_connection(tc_1, connection, ip_port_tcp_s, tcp_server_public_key(tcp_s)) == 0,
578 "Could not add tcp relay to connection\n"); 578 "Could not add tcp relay to connection\n");
579 579
580 ip_port_tcp_s.port = htons(ports[rand() % NUM_PORTS]); 580 ip_port_tcp_s.port = htons(ports[rand() % NUM_PORTS]);
581 connection = new_tcp_connection_to(tc_2, tc_1->self_public_key, 123); 581 connection = new_tcp_connection_to(tc_2, tcp_connections_public_key(tc_1), 123);
582 ck_assert_msg(connection == 0, "Connection id wrong"); 582 ck_assert_msg(connection == 0, "Connection id wrong");
583 ck_assert_msg(add_tcp_relay_connection(tc_2, connection, ip_port_tcp_s, tcp_server_public_key(tcp_s)) == 0, 583 ck_assert_msg(add_tcp_relay_connection(tc_2, connection, ip_port_tcp_s, tcp_server_public_key(tcp_s)) == 0,
584 "Could not add tcp relay to connection\n"); 584 "Could not add tcp relay to connection\n");
585 585
586 ck_assert_msg(new_tcp_connection_to(tc_2, tc_1->self_public_key, 123) == -1, "Managed to readd same connection\n"); 586 ck_assert_msg(new_tcp_connection_to(tc_2, tcp_connections_public_key(tc_1), 123) == -1,
587 "Managed to readd same connection\n");
587 588
588 c_sleep(50); 589 c_sleep(50);
589 do_TCP_server(tcp_s); 590 do_TCP_server(tcp_s);
@@ -666,11 +667,11 @@ START_TEST(test_tcp_connection2)
666 proxy_info.proxy_type = TCP_PROXY_NONE; 667 proxy_info.proxy_type = TCP_PROXY_NONE;
667 crypto_box_keypair(self_public_key, self_secret_key); 668 crypto_box_keypair(self_public_key, self_secret_key);
668 TCP_Connections *tc_1 = new_tcp_connections(self_secret_key, &proxy_info); 669 TCP_Connections *tc_1 = new_tcp_connections(self_secret_key, &proxy_info);
669 ck_assert_msg(public_key_cmp(tc_1->self_public_key, self_public_key) == 0, "Wrong public key"); 670 ck_assert_msg(public_key_cmp(tcp_connections_public_key(tc_1), self_public_key) == 0, "Wrong public key");
670 671
671 crypto_box_keypair(self_public_key, self_secret_key); 672 crypto_box_keypair(self_public_key, self_secret_key);
672 TCP_Connections *tc_2 = new_tcp_connections(self_secret_key, &proxy_info); 673 TCP_Connections *tc_2 = new_tcp_connections(self_secret_key, &proxy_info);
673 ck_assert_msg(public_key_cmp(tc_2->self_public_key, self_public_key) == 0, "Wrong public key"); 674 ck_assert_msg(public_key_cmp(tcp_connections_public_key(tc_2), self_public_key) == 0, "Wrong public key");
674 675
675 IP_Port ip_port_tcp_s; 676 IP_Port ip_port_tcp_s;
676 677
@@ -678,7 +679,7 @@ START_TEST(test_tcp_connection2)
678 ip_port_tcp_s.ip.family = AF_INET6; 679 ip_port_tcp_s.ip.family = AF_INET6;
679 ip_port_tcp_s.ip.ip6.in6_addr = in6addr_loopback; 680 ip_port_tcp_s.ip.ip6.in6_addr = in6addr_loopback;
680 681
681 int connection = new_tcp_connection_to(tc_1, tc_2->self_public_key, 123); 682 int connection = new_tcp_connection_to(tc_1, tcp_connections_public_key(tc_2), 123);
682 ck_assert_msg(connection == 0, "Connection id wrong"); 683 ck_assert_msg(connection == 0, "Connection id wrong");
683 ck_assert_msg(add_tcp_relay_connection(tc_1, connection, ip_port_tcp_s, tcp_server_public_key(tcp_s)) == 0, 684 ck_assert_msg(add_tcp_relay_connection(tc_1, connection, ip_port_tcp_s, tcp_server_public_key(tcp_s)) == 0,
684 "Could not add tcp relay to connection\n"); 685 "Could not add tcp relay to connection\n");
diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c
index 25dfa09c..e838c281 100644
--- a/toxcore/TCP_connection.c
+++ b/toxcore/TCP_connection.c
@@ -29,6 +29,42 @@
29 29
30#include "util.h" 30#include "util.h"
31 31
32
33struct TCP_Connections {
34 DHT *dht;
35
36 uint8_t self_public_key[crypto_box_PUBLICKEYBYTES];
37 uint8_t self_secret_key[crypto_box_SECRETKEYBYTES];
38
39 TCP_Connection_to *connections;
40 uint32_t connections_length; /* Length of connections array. */
41
42 TCP_con *tcp_connections;
43 uint32_t tcp_connections_length; /* Length of tcp_connections array. */
44
45 int (*tcp_data_callback)(void *object, int id, const uint8_t *data, uint16_t length, void *userdata);
46 void *tcp_data_callback_object;
47
48 int (*tcp_oob_callback)(void *object, const uint8_t *public_key, unsigned int tcp_connections_number,
49 const uint8_t *data, uint16_t length, void *userdata);
50 void *tcp_oob_callback_object;
51
52 int (*tcp_onion_callback)(void *object, const uint8_t *data, uint16_t length, void *userdata);
53 void *tcp_onion_callback_object;
54
55 TCP_Proxy_Info proxy_info;
56
57 bool onion_status;
58 uint16_t onion_num_conns;
59};
60
61
62const uint8_t *tcp_connections_public_key(const TCP_Connections *tcp_c)
63{
64 return tcp_c->self_public_key;
65}
66
67
32/* Set the size of the array to num. 68/* Set the size of the array to num.
33 * 69 *
34 * return -1 if realloc fails. 70 * return -1 if realloc fails.
diff --git a/toxcore/TCP_connection.h b/toxcore/TCP_connection.h
index edf9ec8f..e87196f0 100644
--- a/toxcore/TCP_connection.h
+++ b/toxcore/TCP_connection.h
@@ -78,33 +78,9 @@ typedef struct {
78 bool unsleep; /* set to 1 to unsleep connection. */ 78 bool unsleep; /* set to 1 to unsleep connection. */
79} TCP_con; 79} TCP_con;
80 80
81typedef struct { 81typedef struct TCP_Connections TCP_Connections;
82 DHT *dht;
83
84 uint8_t self_public_key[crypto_box_PUBLICKEYBYTES];
85 uint8_t self_secret_key[crypto_box_SECRETKEYBYTES];
86
87 TCP_Connection_to *connections;
88 uint32_t connections_length; /* Length of connections array. */
89
90 TCP_con *tcp_connections;
91 uint32_t tcp_connections_length; /* Length of tcp_connections array. */
92
93 int (*tcp_data_callback)(void *object, int id, const uint8_t *data, uint16_t length, void *userdata);
94 void *tcp_data_callback_object;
95
96 int (*tcp_oob_callback)(void *object, const uint8_t *public_key, unsigned int tcp_connections_number,
97 const uint8_t *data, uint16_t length, void *userdata);
98 void *tcp_oob_callback_object;
99
100 int (*tcp_onion_callback)(void *object, const uint8_t *data, uint16_t length, void *userdata);
101 void *tcp_onion_callback_object;
102
103 TCP_Proxy_Info proxy_info;
104 82
105 bool onion_status; 83const uint8_t *tcp_connections_public_key(const TCP_Connections *tcp_c);
106 uint16_t onion_num_conns;
107} TCP_Connections;
108 84
109/* Send a packet to the TCP connection. 85/* Send a packet to the TCP connection.
110 * 86 *