Make TCP_Connections module-private.

This commit is contained in:
iphydf 2016-09-21 20:23:46 +01:00
parent fd50660f40
commit 18b298a3d6
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
3 changed files with 47 additions and 34 deletions

View File

@ -560,11 +560,11 @@ START_TEST(test_tcp_connection)
proxy_info.proxy_type = TCP_PROXY_NONE;
crypto_box_keypair(self_public_key, self_secret_key);
TCP_Connections *tc_1 = new_tcp_connections(self_secret_key, &proxy_info);
ck_assert_msg(public_key_cmp(tc_1->self_public_key, self_public_key) == 0, "Wrong public key");
ck_assert_msg(public_key_cmp(tcp_connections_public_key(tc_1), self_public_key) == 0, "Wrong public key");
crypto_box_keypair(self_public_key, self_secret_key);
TCP_Connections *tc_2 = new_tcp_connections(self_secret_key, &proxy_info);
ck_assert_msg(public_key_cmp(tc_2->self_public_key, self_public_key) == 0, "Wrong public key");
ck_assert_msg(public_key_cmp(tcp_connections_public_key(tc_2), self_public_key) == 0, "Wrong public key");
IP_Port ip_port_tcp_s;
@ -572,18 +572,19 @@ START_TEST(test_tcp_connection)
ip_port_tcp_s.ip.family = AF_INET6;
ip_port_tcp_s.ip.ip6.in6_addr = in6addr_loopback;
int connection = new_tcp_connection_to(tc_1, tc_2->self_public_key, 123);
int connection = new_tcp_connection_to(tc_1, tcp_connections_public_key(tc_2), 123);
ck_assert_msg(connection == 0, "Connection id wrong");
ck_assert_msg(add_tcp_relay_connection(tc_1, connection, ip_port_tcp_s, tcp_server_public_key(tcp_s)) == 0,
"Could not add tcp relay to connection\n");
ip_port_tcp_s.port = htons(ports[rand() % NUM_PORTS]);
connection = new_tcp_connection_to(tc_2, tc_1->self_public_key, 123);
connection = new_tcp_connection_to(tc_2, tcp_connections_public_key(tc_1), 123);
ck_assert_msg(connection == 0, "Connection id wrong");
ck_assert_msg(add_tcp_relay_connection(tc_2, connection, ip_port_tcp_s, tcp_server_public_key(tcp_s)) == 0,
"Could not add tcp relay to connection\n");
ck_assert_msg(new_tcp_connection_to(tc_2, tc_1->self_public_key, 123) == -1, "Managed to readd same connection\n");
ck_assert_msg(new_tcp_connection_to(tc_2, tcp_connections_public_key(tc_1), 123) == -1,
"Managed to readd same connection\n");
c_sleep(50);
do_TCP_server(tcp_s);
@ -666,11 +667,11 @@ START_TEST(test_tcp_connection2)
proxy_info.proxy_type = TCP_PROXY_NONE;
crypto_box_keypair(self_public_key, self_secret_key);
TCP_Connections *tc_1 = new_tcp_connections(self_secret_key, &proxy_info);
ck_assert_msg(public_key_cmp(tc_1->self_public_key, self_public_key) == 0, "Wrong public key");
ck_assert_msg(public_key_cmp(tcp_connections_public_key(tc_1), self_public_key) == 0, "Wrong public key");
crypto_box_keypair(self_public_key, self_secret_key);
TCP_Connections *tc_2 = new_tcp_connections(self_secret_key, &proxy_info);
ck_assert_msg(public_key_cmp(tc_2->self_public_key, self_public_key) == 0, "Wrong public key");
ck_assert_msg(public_key_cmp(tcp_connections_public_key(tc_2), self_public_key) == 0, "Wrong public key");
IP_Port ip_port_tcp_s;
@ -678,7 +679,7 @@ START_TEST(test_tcp_connection2)
ip_port_tcp_s.ip.family = AF_INET6;
ip_port_tcp_s.ip.ip6.in6_addr = in6addr_loopback;
int connection = new_tcp_connection_to(tc_1, tc_2->self_public_key, 123);
int connection = new_tcp_connection_to(tc_1, tcp_connections_public_key(tc_2), 123);
ck_assert_msg(connection == 0, "Connection id wrong");
ck_assert_msg(add_tcp_relay_connection(tc_1, connection, ip_port_tcp_s, tcp_server_public_key(tcp_s)) == 0,
"Could not add tcp relay to connection\n");

View File

@ -29,6 +29,42 @@
#include "util.h"
struct TCP_Connections {
DHT *dht;
uint8_t self_public_key[crypto_box_PUBLICKEYBYTES];
uint8_t self_secret_key[crypto_box_SECRETKEYBYTES];
TCP_Connection_to *connections;
uint32_t connections_length; /* Length of connections array. */
TCP_con *tcp_connections;
uint32_t tcp_connections_length; /* Length of tcp_connections array. */
int (*tcp_data_callback)(void *object, int id, const uint8_t *data, uint16_t length, void *userdata);
void *tcp_data_callback_object;
int (*tcp_oob_callback)(void *object, const uint8_t *public_key, unsigned int tcp_connections_number,
const uint8_t *data, uint16_t length, void *userdata);
void *tcp_oob_callback_object;
int (*tcp_onion_callback)(void *object, const uint8_t *data, uint16_t length, void *userdata);
void *tcp_onion_callback_object;
TCP_Proxy_Info proxy_info;
bool onion_status;
uint16_t onion_num_conns;
};
const uint8_t *tcp_connections_public_key(const TCP_Connections *tcp_c)
{
return tcp_c->self_public_key;
}
/* Set the size of the array to num.
*
* return -1 if realloc fails.

View File

@ -78,33 +78,9 @@ typedef struct {
bool unsleep; /* set to 1 to unsleep connection. */
} TCP_con;
typedef struct {
DHT *dht;
typedef struct TCP_Connections TCP_Connections;
uint8_t self_public_key[crypto_box_PUBLICKEYBYTES];
uint8_t self_secret_key[crypto_box_SECRETKEYBYTES];
TCP_Connection_to *connections;
uint32_t connections_length; /* Length of connections array. */
TCP_con *tcp_connections;
uint32_t tcp_connections_length; /* Length of tcp_connections array. */
int (*tcp_data_callback)(void *object, int id, const uint8_t *data, uint16_t length, void *userdata);
void *tcp_data_callback_object;
int (*tcp_oob_callback)(void *object, const uint8_t *public_key, unsigned int tcp_connections_number,
const uint8_t *data, uint16_t length, void *userdata);
void *tcp_oob_callback_object;
int (*tcp_onion_callback)(void *object, const uint8_t *data, uint16_t length, void *userdata);
void *tcp_onion_callback_object;
TCP_Proxy_Info proxy_info;
bool onion_status;
uint16_t onion_num_conns;
} TCP_Connections;
const uint8_t *tcp_connections_public_key(const TCP_Connections *tcp_c);
/* Send a packet to the TCP connection.
*