cleanup: Enforce stricter identifier naming using clang-tidy.

This commit is contained in:
iphydf 2023-08-31 10:45:00 +00:00
parent a549807df7
commit 4d3c97f49d
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
31 changed files with 645 additions and 591 deletions

View File

@ -144,10 +144,9 @@ jobs:
- run:
apt-get install -y --no-install-recommends
ca-certificates
clang-tidy-12
clang-tidy-14
- checkout
- run: git submodule update --init --recursive
- run: cmake . -B_build -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
- run:
other/analysis/run-clang-tidy ||
other/analysis/run-clang-tidy ||

35
.clang-tidy Normal file
View File

@ -0,0 +1,35 @@
# vim:ft=yaml
CheckOptions:
- key: readability-identifier-naming.ClassCase
value: Camel_Snake_Case
- key: readability-identifier-naming.ConstantCase
value: lower_case
# bootstrap-daemon has these.
- key: readability-identifier-naming.ConstantIgnoredRegexp
value: "^NAME_.*"
- key: readability-identifier-naming.EnumCase
value: Camel_Snake_Case
- key: readability-identifier-naming.EnumConstantCase
value: UPPER_CASE
- key: readability-identifier-naming.FunctionCase
value: lower_case
- key: readability-identifier-naming.GlobalConstantCase
value: lower_case
- key: readability-identifier-naming.MemberCase
value: lower_case
- key: readability-identifier-naming.MacroDefinitionCase
value: UPPER_CASE
- key: readability-identifier-naming.MacroDefinitionIgnoredRegexp
value: "^_.*|nullable|non_null|nullptr|static_assert|ck_.*"
- key: readability-identifier-naming.ParameterCase
value: lower_case
- key: readability-identifier-naming.StructCase
value: Camel_Snake_Case
- key: readability-identifier-naming.TypedefCase
value: Camel_Snake_Case
- key: readability-identifier-naming.TypedefIgnoredRegexp
value: ".*_cb"
- key: readability-identifier-naming.UnionCase
value: Camel_Snake_Case
- key: readability-identifier-naming.VariableCase
value: lower_case

View File

@ -34,11 +34,11 @@ static IP get_loopback(void)
return ip;
}
static void do_TCP_server_delay(TCP_Server *tcp_s, Mono_Time *mono_time, int delay)
static void do_tcp_server_delay(TCP_Server *tcp_s, Mono_Time *mono_time, int delay)
{
c_sleep(delay);
mono_time_update(mono_time);
do_TCP_server(tcp_s, mono_time);
do_tcp_server(tcp_s, mono_time);
c_sleep(delay);
}
static uint16_t ports[NUM_PORTS] = {13215, 33445, 25643};
@ -60,7 +60,7 @@ static void test_basic(void)
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
crypto_new_keypair(rng, self_public_key, self_secret_key);
TCP_Server *tcp_s = new_TCP_server(logger, mem, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
TCP_Server *tcp_s = new_tcp_server(logger, mem, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
ck_assert_msg(tcp_s != nullptr, "Failed to create a TCP relay server.");
ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS,
"Failed to bind a TCP relay server to all %d attempted ports.", NUM_PORTS);
@ -114,14 +114,14 @@ static void test_basic(void)
&localhost) == TCP_CLIENT_HANDSHAKE_SIZE - 1,
"An attempt to send the initial handshake minus last byte failed.");
do_TCP_server_delay(tcp_s, mono_time, 50);
do_tcp_server_delay(tcp_s, mono_time, 50);
ck_assert_msg(net_send(ns, logger, sock, handshake + (TCP_CLIENT_HANDSHAKE_SIZE - 1), 1, &localhost) == 1,
"The attempt to send the last byte of handshake failed.");
free(handshake);
do_TCP_server_delay(tcp_s, mono_time, 50);
do_tcp_server_delay(tcp_s, mono_time, 50);
// Receiving server response and decrypting it
uint8_t response[TCP_SERVER_HANDSHAKE_SIZE];
@ -161,7 +161,7 @@ static void test_basic(void)
c_sleep(50);
mono_time_update(mono_time);
do_TCP_server(tcp_s, mono_time);
do_tcp_server(tcp_s, mono_time);
}
// Receiving the second response and verifying its validity
@ -185,7 +185,7 @@ static void test_basic(void)
// Closing connections.
kill_sock(ns, sock);
kill_TCP_server(tcp_s);
kill_tcp_server(tcp_s);
logger_kill(logger);
mono_time_free(mem, mono_time);
@ -201,7 +201,7 @@ struct sec_TCP_con {
uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE];
};
static struct sec_TCP_con *new_TCP_con(const Logger *logger, const Memory *mem, const Random *rng, const Network *ns, TCP_Server *tcp_s, Mono_Time *mono_time)
static struct sec_TCP_con *new_tcp_con(const Logger *logger, const Memory *mem, const Random *rng, const Network *ns, TCP_Server *tcp_s, Mono_Time *mono_time)
{
struct sec_TCP_con *sec_c = (struct sec_TCP_con *)malloc(sizeof(struct sec_TCP_con));
ck_assert(sec_c != nullptr);
@ -237,12 +237,12 @@ static struct sec_TCP_con *new_TCP_con(const Logger *logger, const Memory *mem,
&localhost) == TCP_CLIENT_HANDSHAKE_SIZE - 1,
"Failed to send the first portion of the handshake to the TCP relay server.");
do_TCP_server_delay(tcp_s, mono_time, 50);
do_tcp_server_delay(tcp_s, mono_time, 50);
ck_assert_msg(net_send(ns, logger, sock, handshake + (TCP_CLIENT_HANDSHAKE_SIZE - 1), 1, &localhost) == 1,
"Failed to send last byte of handshake.");
do_TCP_server_delay(tcp_s, mono_time, 50);
do_tcp_server_delay(tcp_s, mono_time, 50);
uint8_t response[TCP_SERVER_HANDSHAKE_SIZE];
uint8_t response_plain[TCP_HANDSHAKE_PLAIN_SIZE];
@ -257,13 +257,13 @@ static struct sec_TCP_con *new_TCP_con(const Logger *logger, const Memory *mem,
return sec_c;
}
static void kill_TCP_con(struct sec_TCP_con *con)
static void kill_tcp_con(struct sec_TCP_con *con)
{
kill_sock(con->ns, con->sock);
free(con);
}
static int write_packet_TCP_test_connection(const Logger *logger, struct sec_TCP_con *con, const uint8_t *data,
static int write_packet_tcp_test_connection(const Logger *logger, struct sec_TCP_con *con, const uint8_t *data,
uint16_t length)
{
VLA(uint8_t, packet, sizeof(uint16_t) + length + CRYPTO_MAC_SIZE);
@ -287,7 +287,7 @@ static int write_packet_TCP_test_connection(const Logger *logger, struct sec_TCP
return 0;
}
static int read_packet_sec_TCP(const Logger *logger, struct sec_TCP_con *con, uint8_t *data, uint16_t length)
static int read_packet_sec_tcp(const Logger *logger, struct sec_TCP_con *con, uint8_t *data, uint16_t length)
{
IP_Port localhost;
localhost.ip = get_loopback();
@ -316,35 +316,35 @@ static void test_some(void)
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
crypto_new_keypair(rng, self_public_key, self_secret_key);
TCP_Server *tcp_s = new_TCP_server(logger, mem, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
TCP_Server *tcp_s = new_tcp_server(logger, mem, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
ck_assert_msg(tcp_s != nullptr, "Failed to create TCP relay server");
ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, "Failed to bind to all ports.");
struct sec_TCP_con *con1 = new_TCP_con(logger, mem, rng, ns, tcp_s, mono_time);
struct sec_TCP_con *con2 = new_TCP_con(logger, mem, rng, ns, tcp_s, mono_time);
struct sec_TCP_con *con3 = new_TCP_con(logger, mem, rng, ns, tcp_s, mono_time);
struct sec_TCP_con *con1 = new_tcp_con(logger, mem, rng, ns, tcp_s, mono_time);
struct sec_TCP_con *con2 = new_tcp_con(logger, mem, rng, ns, tcp_s, mono_time);
struct sec_TCP_con *con3 = new_tcp_con(logger, mem, rng, ns, tcp_s, mono_time);
uint8_t requ_p[1 + CRYPTO_PUBLIC_KEY_SIZE];
requ_p[0] = TCP_PACKET_ROUTING_REQUEST;
// Sending wrong public keys to test server response.
memcpy(requ_p + 1, con3->public_key, CRYPTO_PUBLIC_KEY_SIZE);
write_packet_TCP_test_connection(logger, con1, requ_p, sizeof(requ_p));
write_packet_tcp_test_connection(logger, con1, requ_p, sizeof(requ_p));
memcpy(requ_p + 1, con1->public_key, CRYPTO_PUBLIC_KEY_SIZE);
write_packet_TCP_test_connection(logger, con3, requ_p, sizeof(requ_p));
write_packet_tcp_test_connection(logger, con3, requ_p, sizeof(requ_p));
do_TCP_server_delay(tcp_s, mono_time, 50);
do_tcp_server_delay(tcp_s, mono_time, 50);
// Testing response from connection 1
uint8_t data[2048];
int len = read_packet_sec_TCP(logger, con1, data, 2 + 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE);
int len = read_packet_sec_tcp(logger, con1, data, 2 + 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE);
ck_assert_msg(len == 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE, "Wrong response packet length of %d.", len);
ck_assert_msg(data[0] == TCP_PACKET_ROUTING_RESPONSE, "Wrong response packet id of %d.", data[0]);
ck_assert_msg(data[1] == 16, "Server didn't refuse connection using wrong public key.");
ck_assert_msg(pk_equal(data + 2, con3->public_key), "Key in response packet wrong.");
// Connection 3
len = read_packet_sec_TCP(logger, con3, data, 2 + 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE);
len = read_packet_sec_tcp(logger, con3, data, 2 + 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE);
ck_assert_msg(len == 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE, "Wrong response packet length of %d.", len);
ck_assert_msg(data[0] == TCP_PACKET_ROUTING_RESPONSE, "Wrong response packet id of %d.", data[0]);
ck_assert_msg(data[1] == 16, "Server didn't refuse connection using wrong public key.");
@ -352,64 +352,64 @@ static void test_some(void)
uint8_t test_packet[512] = {16, 17, 16, 86, 99, 127, 255, 189, 78}; // What is this packet????
write_packet_TCP_test_connection(logger, con3, test_packet, sizeof(test_packet));
write_packet_TCP_test_connection(logger, con3, test_packet, sizeof(test_packet));
write_packet_TCP_test_connection(logger, con3, test_packet, sizeof(test_packet));
write_packet_tcp_test_connection(logger, con3, test_packet, sizeof(test_packet));
write_packet_tcp_test_connection(logger, con3, test_packet, sizeof(test_packet));
write_packet_tcp_test_connection(logger, con3, test_packet, sizeof(test_packet));
do_TCP_server_delay(tcp_s, mono_time, 50);
do_tcp_server_delay(tcp_s, mono_time, 50);
len = read_packet_sec_TCP(logger, con1, data, 2 + 2 + CRYPTO_MAC_SIZE);
len = read_packet_sec_tcp(logger, con1, data, 2 + 2 + CRYPTO_MAC_SIZE);
ck_assert_msg(len == 2, "wrong len %d", len);
ck_assert_msg(data[0] == TCP_PACKET_CONNECTION_NOTIFICATION, "wrong packet id %u", data[0]);
ck_assert_msg(data[1] == 16, "wrong peer id %u", data[1]);
len = read_packet_sec_TCP(logger, con3, data, 2 + 2 + CRYPTO_MAC_SIZE);
len = read_packet_sec_tcp(logger, con3, data, 2 + 2 + CRYPTO_MAC_SIZE);
ck_assert_msg(len == 2, "wrong len %d", len);
ck_assert_msg(data[0] == TCP_PACKET_CONNECTION_NOTIFICATION, "wrong packet id %u", data[0]);
ck_assert_msg(data[1] == 16, "wrong peer id %u", data[1]);
len = read_packet_sec_TCP(logger, con1, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE);
len = read_packet_sec_tcp(logger, con1, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE);
ck_assert_msg(len == sizeof(test_packet), "wrong len %d", len);
ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);
len = read_packet_sec_TCP(logger, con1, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE);
len = read_packet_sec_tcp(logger, con1, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE);
ck_assert_msg(len == sizeof(test_packet), "wrong len %d", len);
ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);
len = read_packet_sec_TCP(logger, con1, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE);
len = read_packet_sec_tcp(logger, con1, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE);
ck_assert_msg(len == sizeof(test_packet), "wrong len %d", len);
ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);
write_packet_TCP_test_connection(logger, con1, test_packet, sizeof(test_packet));
write_packet_TCP_test_connection(logger, con1, test_packet, sizeof(test_packet));
write_packet_TCP_test_connection(logger, con1, test_packet, sizeof(test_packet));
do_TCP_server_delay(tcp_s, mono_time, 50);
len = read_packet_sec_TCP(logger, con3, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE);
write_packet_tcp_test_connection(logger, con1, test_packet, sizeof(test_packet));
write_packet_tcp_test_connection(logger, con1, test_packet, sizeof(test_packet));
write_packet_tcp_test_connection(logger, con1, test_packet, sizeof(test_packet));
do_tcp_server_delay(tcp_s, mono_time, 50);
len = read_packet_sec_tcp(logger, con3, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE);
ck_assert_msg(len == sizeof(test_packet), "wrong len %d", len);
ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);
len = read_packet_sec_TCP(logger, con3, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE);
len = read_packet_sec_tcp(logger, con3, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE);
ck_assert_msg(len == sizeof(test_packet), "wrong len %d", len);
ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);
len = read_packet_sec_TCP(logger, con3, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE);
len = read_packet_sec_tcp(logger, con3, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE);
ck_assert_msg(len == sizeof(test_packet), "wrong len %d", len);
ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);
uint8_t ping_packet[1 + sizeof(uint64_t)] = {TCP_PACKET_PING, 8, 6, 9, 67};
write_packet_TCP_test_connection(logger, con1, ping_packet, sizeof(ping_packet));
write_packet_tcp_test_connection(logger, con1, ping_packet, sizeof(ping_packet));
do_TCP_server_delay(tcp_s, mono_time, 50);
do_tcp_server_delay(tcp_s, mono_time, 50);
len = read_packet_sec_TCP(logger, con1, data, 2 + sizeof(ping_packet) + CRYPTO_MAC_SIZE);
len = read_packet_sec_tcp(logger, con1, data, 2 + sizeof(ping_packet) + CRYPTO_MAC_SIZE);
ck_assert_msg(len == sizeof(ping_packet), "wrong len %d", len);
ck_assert_msg(data[0] == TCP_PACKET_PONG, "wrong packet id %u", data[0]);
ck_assert_msg(memcmp(ping_packet + 1, data + 1, sizeof(uint64_t)) == 0, "wrong packet data");
// Kill off the connections
kill_TCP_server(tcp_s);
kill_TCP_con(con1);
kill_TCP_con(con2);
kill_TCP_con(con3);
kill_tcp_server(tcp_s);
kill_tcp_con(con1);
kill_tcp_con(con2);
kill_tcp_con(con3);
logger_kill(logger);
mono_time_free(mem, mono_time);
@ -511,7 +511,7 @@ static void test_client(void)
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
crypto_new_keypair(rng, self_public_key, self_secret_key);
TCP_Server *tcp_s = new_TCP_server(logger, mem, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
TCP_Server *tcp_s = new_tcp_server(logger, mem, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
ck_assert_msg(tcp_s != nullptr, "Failed to create a TCP relay server.");
ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, "Failed to bind the relay server to all ports.");
@ -523,8 +523,8 @@ static void test_client(void)
ip_port_tcp_s.port = net_htons(ports[random_u32(rng) % NUM_PORTS]);
ip_port_tcp_s.ip = get_loopback();
TCP_Client_Connection *conn = new_TCP_connection(logger, mem, mono_time, rng, ns, &ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, nullptr);
do_TCP_connection(logger, mono_time, conn, nullptr);
TCP_Client_Connection *conn = new_tcp_connection(logger, mem, mono_time, rng, ns, &ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, nullptr);
do_tcp_connection(logger, mono_time, conn, nullptr);
c_sleep(50);
// The connection status should be unconfirmed here because we have finished
@ -532,22 +532,22 @@ static void test_client(void)
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_UNCONFIRMED, "Wrong connection status. Expected: %d, is: %d.",
TCP_CLIENT_UNCONFIRMED, tcp_con_status(conn));
do_TCP_server_delay(tcp_s, mono_time, 50); // Now let the server handle requests...
do_tcp_server_delay(tcp_s, mono_time, 50); // Now let the server handle requests...
const uint8_t LOOP_SIZE = 3;
const uint8_t loop_size = 3;
for (uint8_t i = 0; i < LOOP_SIZE; i++) {
for (uint8_t i = 0; i < loop_size; i++) {
mono_time_update(mono_time);
do_TCP_connection(logger, mono_time, conn, nullptr); // Run the connection loop.
do_tcp_connection(logger, mono_time, conn, nullptr); // Run the connection loop.
// The status of the connection should continue to be TCP_CLIENT_CONFIRMED after multiple subsequent do_TCP_connection() calls.
// The status of the connection should continue to be TCP_CLIENT_CONFIRMED after multiple subsequent do_tcp_connection() calls.
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONFIRMED, "Wrong connection status. Expected: %d, is: %d",
TCP_CLIENT_CONFIRMED, tcp_con_status(conn));
c_sleep(i == LOOP_SIZE - 1 ? 0 : 500); // Sleep for 500ms on all except third loop.
c_sleep(i == loop_size - 1 ? 0 : 500); // Sleep for 500ms on all except third loop.
}
do_TCP_server_delay(tcp_s, mono_time, 50);
do_tcp_server_delay(tcp_s, mono_time, 50);
// And still after the server runs again.
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONFIRMED, "Wrong status. Expected: %d, is: %d", TCP_CLIENT_CONFIRMED,
@ -557,7 +557,7 @@ static void test_client(void)
uint8_t f2_secret_key[CRYPTO_SECRET_KEY_SIZE];
crypto_new_keypair(rng, f2_public_key, f2_secret_key);
ip_port_tcp_s.port = net_htons(ports[random_u32(rng) % NUM_PORTS]);
TCP_Client_Connection *conn2 = new_TCP_connection(logger, mem, mono_time, rng, ns, &ip_port_tcp_s, self_public_key, f2_public_key,
TCP_Client_Connection *conn2 = new_tcp_connection(logger, mem, mono_time, rng, ns, &ip_port_tcp_s, self_public_key, f2_public_key,
f2_secret_key, nullptr);
// The client should call this function (defined earlier) during the routing process.
@ -572,13 +572,13 @@ static void test_client(void)
// These integers will increment per successful callback.
oob_data_callback_good = response_callback_good = status_callback_good = data_callback_good = 0;
do_TCP_connection(logger, mono_time, conn, nullptr);
do_TCP_connection(logger, mono_time, conn2, nullptr);
do_tcp_connection(logger, mono_time, conn, nullptr);
do_tcp_connection(logger, mono_time, conn2, nullptr);
do_TCP_server_delay(tcp_s, mono_time, 50);
do_tcp_server_delay(tcp_s, mono_time, 50);
do_TCP_connection(logger, mono_time, conn, nullptr);
do_TCP_connection(logger, mono_time, conn2, nullptr);
do_tcp_connection(logger, mono_time, conn, nullptr);
do_tcp_connection(logger, mono_time, conn2, nullptr);
c_sleep(50);
uint8_t data[5] = {1, 2, 3, 4, 5};
@ -587,10 +587,10 @@ static void test_client(void)
send_routing_request(logger, conn, f2_public_key);
send_routing_request(logger, conn2, f_public_key);
do_TCP_server_delay(tcp_s, mono_time, 50);
do_tcp_server_delay(tcp_s, mono_time, 50);
do_TCP_connection(logger, mono_time, conn, nullptr);
do_TCP_connection(logger, mono_time, conn2, nullptr);
do_tcp_connection(logger, mono_time, conn, nullptr);
do_tcp_connection(logger, mono_time, conn2, nullptr);
// All callback methods save data should have run during the above network prodding.
ck_assert_msg(oob_data_callback_good == 1, "OOB callback not called");
@ -601,29 +601,29 @@ static void test_client(void)
ck_assert_msg(status_callback_connection_id == response_callback_connection_id,
"Status and response callback connection IDs are not equal.");
do_TCP_server_delay(tcp_s, mono_time, 50);
do_tcp_server_delay(tcp_s, mono_time, 50);
ck_assert_msg(send_data(logger, conn2, 0, data, 5) == 1, "Failed a send_data() call.");
do_TCP_server_delay(tcp_s, mono_time, 50);
do_tcp_server_delay(tcp_s, mono_time, 50);
do_TCP_connection(logger, mono_time, conn, nullptr);
do_TCP_connection(logger, mono_time, conn2, nullptr);
do_tcp_connection(logger, mono_time, conn, nullptr);
do_tcp_connection(logger, mono_time, conn2, nullptr);
ck_assert_msg(data_callback_good == 1, "Data callback was not called.");
status_callback_good = 0;
send_disconnect_request(logger, conn2, 0);
do_TCP_server_delay(tcp_s, mono_time, 50);
do_tcp_server_delay(tcp_s, mono_time, 50);
do_TCP_connection(logger, mono_time, conn, nullptr);
do_TCP_connection(logger, mono_time, conn2, nullptr);
do_tcp_connection(logger, mono_time, conn, nullptr);
do_tcp_connection(logger, mono_time, conn2, nullptr);
ck_assert_msg(status_callback_good == 1, "Status callback not called");
ck_assert_msg(status_callback_status == 1, "Wrong status callback status.");
// Kill off all connections and servers.
kill_TCP_server(tcp_s);
kill_TCP_connection(conn);
kill_TCP_connection(conn2);
kill_tcp_server(tcp_s);
kill_tcp_connection(conn);
kill_tcp_connection(conn2);
logger_kill(logger);
mono_time_free(mem, mono_time);
@ -653,12 +653,12 @@ static void test_client_invalid(void)
ip_port_tcp_s.port = net_htons(ports[random_u32(rng) % NUM_PORTS]);
ip_port_tcp_s.ip = get_loopback();
TCP_Client_Connection *conn = new_TCP_connection(logger, mem, mono_time, rng, ns, &ip_port_tcp_s,
TCP_Client_Connection *conn = new_tcp_connection(logger, mem, mono_time, rng, ns, &ip_port_tcp_s,
self_public_key, f_public_key, f_secret_key, nullptr);
// Run the client's main loop but not the server.
mono_time_update(mono_time);
do_TCP_connection(logger, mono_time, conn, nullptr);
do_tcp_connection(logger, mono_time, conn, nullptr);
c_sleep(50);
// After 50ms of no response...
@ -667,17 +667,17 @@ static void test_client_invalid(void)
// After 5s...
c_sleep(5000);
mono_time_update(mono_time);
do_TCP_connection(logger, mono_time, conn, nullptr);
do_tcp_connection(logger, mono_time, conn, nullptr);
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONNECTING, "Wrong status. Expected: %d, is: %d.",
TCP_CLIENT_CONNECTING, tcp_con_status(conn));
// 11s... (Should wait for 10 before giving up.)
c_sleep(6000);
mono_time_update(mono_time);
do_TCP_connection(logger, mono_time, conn, nullptr);
do_tcp_connection(logger, mono_time, conn, nullptr);
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_DISCONNECTED, "Wrong status. Expected: %d, is: %d.",
TCP_CLIENT_DISCONNECTED, tcp_con_status(conn));
kill_TCP_connection(conn);
kill_tcp_connection(conn);
logger_kill(logger);
mono_time_free(mem, mono_time);
@ -725,7 +725,7 @@ static void test_tcp_connection(void)
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
crypto_new_keypair(rng, self_public_key, self_secret_key);
TCP_Server *tcp_s = new_TCP_server(logger, mem, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
TCP_Server *tcp_s = new_tcp_server(logger, mem, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
ck_assert_msg(pk_equal(tcp_server_public_key(tcp_s), self_public_key), "Wrong public key");
TCP_Proxy_Info proxy_info;
@ -757,17 +757,17 @@ static void test_tcp_connection(void)
ck_assert_msg(new_tcp_connection_to(tc_2, tcp_connections_public_key(tc_1), 123) == -1,
"Managed to read same connection\n");
do_TCP_server_delay(tcp_s, mono_time, 50);
do_tcp_server_delay(tcp_s, mono_time, 50);
do_tcp_connections(logger, tc_1, nullptr);
do_tcp_connections(logger, tc_2, nullptr);
do_TCP_server_delay(tcp_s, mono_time, 50);
do_tcp_server_delay(tcp_s, mono_time, 50);
do_tcp_connections(logger, tc_1, nullptr);
do_tcp_connections(logger, tc_2, nullptr);
do_TCP_server_delay(tcp_s, mono_time, 50);
do_tcp_server_delay(tcp_s, mono_time, 50);
do_tcp_connections(logger, tc_1, nullptr);
do_tcp_connections(logger, tc_2, nullptr);
@ -776,7 +776,7 @@ static void test_tcp_connection(void)
ck_assert_msg(ret == 0, "could not send packet.");
set_packet_tcp_connection_callback(tc_2, &tcp_data_callback, (void *) 120397);
do_TCP_server_delay(tcp_s, mono_time, 50);
do_tcp_server_delay(tcp_s, mono_time, 50);
do_tcp_connections(logger, tc_1, nullptr);
do_tcp_connections(logger, tc_2, nullptr);
@ -785,7 +785,7 @@ static void test_tcp_connection(void)
ck_assert_msg(tcp_connection_to_online_tcp_relays(tc_1, 0) == 1, "Wrong number of connected relays");
ck_assert_msg(kill_tcp_connection_to(tc_1, 0) == 0, "could not kill connection to\n");
do_TCP_server_delay(tcp_s, mono_time, 50);
do_tcp_server_delay(tcp_s, mono_time, 50);
do_tcp_connections(logger, tc_1, nullptr);
do_tcp_connections(logger, tc_2, nullptr);
@ -793,7 +793,7 @@ static void test_tcp_connection(void)
ck_assert_msg(send_packet_tcp_connection(tc_1, 0, (const uint8_t *)"Gentoo", 6) == -1, "could send packet.");
ck_assert_msg(kill_tcp_connection_to(tc_2, 0) == 0, "could not kill connection to\n");
kill_TCP_server(tcp_s);
kill_tcp_server(tcp_s);
kill_tcp_connections(tc_1);
kill_tcp_connections(tc_2);
@ -840,7 +840,7 @@ static void test_tcp_connection2(void)
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
crypto_new_keypair(rng, self_public_key, self_secret_key);
TCP_Server *tcp_s = new_TCP_server(logger, mem, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
TCP_Server *tcp_s = new_tcp_server(logger, mem, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
ck_assert_msg(pk_equal(tcp_server_public_key(tcp_s), self_public_key), "Wrong public key");
TCP_Proxy_Info proxy_info;
@ -866,17 +866,17 @@ static void test_tcp_connection2(void)
ck_assert_msg(add_tcp_relay_global(tc_2, &ip_port_tcp_s, tcp_server_public_key(tcp_s)) == 0,
"Could not add global relay");
do_TCP_server_delay(tcp_s, mono_time, 50);
do_tcp_server_delay(tcp_s, mono_time, 50);
do_tcp_connections(logger, tc_1, nullptr);
do_tcp_connections(logger, tc_2, nullptr);
do_TCP_server_delay(tcp_s, mono_time, 50);
do_tcp_server_delay(tcp_s, mono_time, 50);
do_tcp_connections(logger, tc_1, nullptr);
do_tcp_connections(logger, tc_2, nullptr);
do_TCP_server_delay(tcp_s, mono_time, 50);
do_tcp_server_delay(tcp_s, mono_time, 50);
do_tcp_connections(logger, tc_1, nullptr);
do_tcp_connections(logger, tc_2, nullptr);
@ -886,14 +886,14 @@ static void test_tcp_connection2(void)
set_oob_packet_tcp_connection_callback(tc_2, &tcp_oobdata_callback, tc_2);
set_packet_tcp_connection_callback(tc_1, &tcp_data_callback, (void *) 120397);
do_TCP_server_delay(tcp_s, mono_time, 50);
do_tcp_server_delay(tcp_s, mono_time, 50);
do_tcp_connections(logger, tc_1, nullptr);
do_tcp_connections(logger, tc_2, nullptr);
ck_assert_msg(tcp_oobdata_callback_called, "could not recv packet.");
do_TCP_server_delay(tcp_s, mono_time, 50);
do_tcp_server_delay(tcp_s, mono_time, 50);
do_tcp_connections(logger, tc_1, nullptr);
do_tcp_connections(logger, tc_2, nullptr);
@ -901,7 +901,7 @@ static void test_tcp_connection2(void)
ck_assert_msg(tcp_data_callback_called, "could not recv packet.");
ck_assert_msg(kill_tcp_connection_to(tc_1, 0) == 0, "could not kill connection to\n");
kill_TCP_server(tcp_s);
kill_tcp_server(tcp_s);
kill_tcp_connections(tc_1);
kill_tcp_connections(tc_2);
@ -909,7 +909,7 @@ static void test_tcp_connection2(void)
mono_time_free(mem, mono_time);
}
static void TCP_suite(void)
static void tcp_suite(void)
{
test_basic();
test_some();
@ -922,6 +922,6 @@ static void TCP_suite(void)
int main(void)
{
setvbuf(stdout, nullptr, _IONBF, 0);
TCP_suite();
tcp_suite();
return 0;
}

View File

@ -13,7 +13,7 @@
#define ABORT_ON_LOG_ERROR true
#endif
Run_Auto_Options default_run_auto_options()
Run_Auto_Options default_run_auto_options(void)
{
return (Run_Auto_Options) {
.graph = GRAPH_COMPLETE,
@ -27,7 +27,7 @@ static const struct BootstrapNodes {
const char *ip;
uint16_t port;
const uint8_t key[32];
} BootstrapNodes[] = {
} bootstrap_nodes[] = {
#ifndef USE_TEST_NETWORK
{
"tox.abilinski.com", 33445,
@ -80,10 +80,10 @@ void bootstrap_tox_live_network(Tox *tox, bool enable_tcp)
{
ck_assert(tox != nullptr);
for (size_t j = 0; BootstrapNodes[j].ip != nullptr; ++j) {
const char *ip = BootstrapNodes[j].ip;
uint16_t port = BootstrapNodes[j].port;
const uint8_t *key = BootstrapNodes[j].key;
for (size_t j = 0; bootstrap_nodes[j].ip != nullptr; ++j) {
const char *ip = bootstrap_nodes[j].ip;
uint16_t port = bootstrap_nodes[j].port;
const uint8_t *key = bootstrap_nodes[j].key;
Tox_Err_Bootstrap err;
tox_bootstrap(tox, ip, port, key, &err);

View File

@ -217,7 +217,7 @@ static bool test_audio(AutoTox *autotoxes, const bool *disabled, bool quiet)
printf("testing sending and receiving audio\n");
}
const int16_t PCM[GROUP_AV_TEST_SAMPLES] = {0};
const int16_t pcm[GROUP_AV_TEST_SAMPLES] = {0};
reset_received_audio(autotoxes);
@ -227,7 +227,7 @@ static bool test_audio(AutoTox *autotoxes, const bool *disabled, bool quiet)
continue;
}
if (toxav_group_send_audio(autotoxes[i].tox, 0, PCM, GROUP_AV_TEST_SAMPLES, 1, 48000) != 0) {
if (toxav_group_send_audio(autotoxes[i].tox, 0, pcm, GROUP_AV_TEST_SAMPLES, 1, 48000) != 0) {
if (!quiet) {
ck_abort_msg("#%u failed to send audio", autotoxes[i].index);
}
@ -268,12 +268,12 @@ static void test_eventual_audio(AutoTox *autotoxes, const bool *disabled, uint64
static void do_audio(AutoTox *autotoxes, uint32_t iterations)
{
const int16_t PCM[GROUP_AV_TEST_SAMPLES] = {0};
const int16_t pcm[GROUP_AV_TEST_SAMPLES] = {0};
printf("running audio for %u iterations\n", iterations);
for (uint32_t f = 0; f < iterations; ++f) {
for (uint32_t i = 0; i < NUM_AV_GROUP_TOX; ++i) {
ck_assert_msg(toxav_group_send_audio(autotoxes[i].tox, 0, PCM, GROUP_AV_TEST_SAMPLES, 1, 48000) == 0,
ck_assert_msg(toxav_group_send_audio(autotoxes[i].tox, 0, pcm, GROUP_AV_TEST_SAMPLES, 1, 48000) == 0,
"#%u failed to send audio", autotoxes[i].index);
iterate_all_wait(autotoxes, NUM_AV_GROUP_TOX, ITERATION_INTERVAL);
}

View File

@ -172,12 +172,12 @@ static void file_transfer_test(void)
uint32_t test = tox_friend_add(tox3, address, (const uint8_t *)"Gentoo", 7, nullptr);
ck_assert_msg(test == 0, "Failed to add friend error code: %u", test);
uint8_t dhtKey[TOX_PUBLIC_KEY_SIZE];
tox_self_get_dht_id(tox1, dhtKey);
uint16_t dhtPort = tox_self_get_udp_port(tox1, nullptr);
uint8_t dht_key[TOX_PUBLIC_KEY_SIZE];
tox_self_get_dht_id(tox1, dht_key);
uint16_t dht_port = tox_self_get_udp_port(tox1, nullptr);
tox_bootstrap(tox2, TOX_LOCALHOST, dhtPort, dhtKey, nullptr);
tox_bootstrap(tox3, TOX_LOCALHOST, dhtPort, dhtKey, nullptr);
tox_bootstrap(tox2, TOX_LOCALHOST, dht_port, dht_key, nullptr);
tox_bootstrap(tox3, TOX_LOCALHOST, dht_port, dht_key, nullptr);
printf("Waiting for toxes to come online\n");

View File

@ -10,7 +10,7 @@ typedef enum {
POSITIVE
} Comparison;
static const char *Comparison_Str[] = { "NEGATIVE", "ZERO", "POSITIVE" };
static const char *comparison_str[] = { "NEGATIVE", "ZERO", "POSITIVE" };
static void verify(const char *s1, const char *s2, size_t n, Comparison expected)
{
@ -19,7 +19,7 @@ static void verify(const char *s1, const char *s2, size_t n, Comparison expected
ck_assert_msg(actual == expected,
"tox_strncasecmp(\"%s\", \"%s\", %u) == %s, but expected %s.",
s1, s2, (unsigned)n, Comparison_Str[actual], Comparison_Str[expected]);
s1, s2, (unsigned)n, comparison_str[actual], comparison_str[expected]);
}
static void test_general(void)

View File

@ -93,67 +93,67 @@ static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const
/**
* Iterate helper
*/
static void iterate_tox(Tox *bootstrap, Tox *Alice, Tox *Bob)
static void iterate_tox(Tox *bootstrap, Tox *alice, Tox *bob)
{
c_sleep(100);
tox_iterate(bootstrap, nullptr);
tox_iterate(Alice, nullptr);
tox_iterate(Bob, nullptr);
tox_iterate(alice, nullptr);
tox_iterate(bob, nullptr);
}
static bool toxav_audio_send_frame_helper(ToxAV *av, uint32_t friend_number, Toxav_Err_Send_Frame *error)
{
static const int16_t PCM[960] = {0};
return toxav_audio_send_frame(av, 0, PCM, 960, 1, 48000, nullptr);
static const int16_t pcm[960] = {0};
return toxav_audio_send_frame(av, 0, pcm, 960, 1, 48000, nullptr);
}
static void regular_call_flow(
Tox *Alice, Tox *Bob, Tox *bootstrap,
ToxAV *AliceAV, ToxAV *BobAV,
CallControl *AliceCC, CallControl *BobCC,
Tox *alice, Tox *bob, Tox *bootstrap,
ToxAV *alice_av, ToxAV *bob_av,
CallControl *alice_cc, CallControl *bob_cc,
int a_br, int v_br)
{
clear_call_control(AliceCC);
clear_call_control(BobCC);
clear_call_control(alice_cc);
clear_call_control(bob_cc);
Toxav_Err_Call call_err;
toxav_call(AliceAV, 0, a_br, v_br, &call_err);
toxav_call(alice_av, 0, a_br, v_br, &call_err);
ck_assert_msg(call_err == TOXAV_ERR_CALL_OK, "toxav_call failed: %d\n", call_err);
const time_t start_time = time(nullptr);
do {
if (BobCC->incoming) {
if (bob_cc->incoming) {
Toxav_Err_Answer answer_err;
toxav_answer(BobAV, 0, a_br, v_br, &answer_err);
toxav_answer(bob_av, 0, a_br, v_br, &answer_err);
ck_assert_msg(answer_err == TOXAV_ERR_ANSWER_OK, "toxav_answer failed: %d\n", answer_err);
BobCC->incoming = false;
bob_cc->incoming = false;
} else { /* TODO(mannol): rtp */
if (time(nullptr) - start_time >= 1) {
Toxav_Err_Call_Control cc_err;
toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_CANCEL, &cc_err);
toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_CANCEL, &cc_err);
ck_assert_msg(cc_err == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %d\n", cc_err);
}
}
iterate_tox(bootstrap, Alice, Bob);
} while (BobCC->state != TOXAV_FRIEND_CALL_STATE_FINISHED);
iterate_tox(bootstrap, alice, bob);
} while (bob_cc->state != TOXAV_FRIEND_CALL_STATE_FINISHED);
printf("Success!\n");
}
static void test_av_flows(void)
{
Tox *Alice, *Bob, *bootstrap;
ToxAV *AliceAV, *BobAV;
Tox *alice, *bob, *bootstrap;
ToxAV *alice_av, *bob_av;
uint32_t index[] = { 1, 2, 3 };
CallControl AliceCC, BobCC;
CallControl alice_cc, bob_cc;
{
Tox_Err_New error;
@ -161,10 +161,10 @@ static void test_av_flows(void)
bootstrap = tox_new_log(nullptr, &error, &index[0]);
ck_assert(error == TOX_ERR_NEW_OK);
Alice = tox_new_log(nullptr, &error, &index[1]);
alice = tox_new_log(nullptr, &error, &index[1]);
ck_assert(error == TOX_ERR_NEW_OK);
Bob = tox_new_log(nullptr, &error, &index[2]);
bob = tox_new_log(nullptr, &error, &index[2]);
ck_assert(error == TOX_ERR_NEW_OK);
}
@ -174,33 +174,33 @@ static void test_av_flows(void)
uint8_t address[TOX_ADDRESS_SIZE];
tox_callback_friend_request(Alice, t_accept_friend_request_cb);
tox_self_get_address(Alice, address);
tox_callback_friend_request(alice, t_accept_friend_request_cb);
tox_self_get_address(alice, address);
printf("bootstrapping Alice and Bob off a third bootstrap node\n");
uint8_t dht_key[TOX_PUBLIC_KEY_SIZE];
tox_self_get_dht_id(bootstrap, dht_key);
const uint16_t dht_port = tox_self_get_udp_port(bootstrap, nullptr);
tox_bootstrap(Alice, "localhost", dht_port, dht_key, nullptr);
tox_bootstrap(Bob, "localhost", dht_port, dht_key, nullptr);
tox_bootstrap(alice, "localhost", dht_port, dht_key, nullptr);
tox_bootstrap(bob, "localhost", dht_port, dht_key, nullptr);
ck_assert(tox_friend_add(Bob, address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) -1);
ck_assert(tox_friend_add(bob, address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) -1);
uint8_t off = 1;
while (true) {
iterate_tox(bootstrap, Alice, Bob);
iterate_tox(bootstrap, alice, bob);
if (tox_self_get_connection_status(bootstrap) &&
tox_self_get_connection_status(Alice) &&
tox_self_get_connection_status(Bob) && off) {
tox_self_get_connection_status(alice) &&
tox_self_get_connection_status(bob) && off) {
printf("Toxes are online, took %llu seconds\n", time(nullptr) - cur_time);
off = 0;
}
if (tox_friend_get_connection_status(Alice, 0, nullptr) == TOX_CONNECTION_UDP &&
tox_friend_get_connection_status(Bob, 0, nullptr) == TOX_CONNECTION_UDP) {
if (tox_friend_get_connection_status(alice, 0, nullptr) == TOX_CONNECTION_UDP &&
tox_friend_get_connection_status(bob, 0, nullptr) == TOX_CONNECTION_UDP) {
break;
}
@ -210,72 +210,72 @@ static void test_av_flows(void)
{
Toxav_Err_New error;
AliceAV = toxav_new(Alice, &error);
alice_av = toxav_new(alice, &error);
ck_assert(error == TOXAV_ERR_NEW_OK);
BobAV = toxav_new(Bob, &error);
bob_av = toxav_new(bob, &error);
ck_assert(error == TOXAV_ERR_NEW_OK);
}
toxav_callback_call(AliceAV, t_toxav_call_cb, &AliceCC);
toxav_callback_call_state(AliceAV, t_toxav_call_state_cb, &AliceCC);
toxav_callback_video_receive_frame(AliceAV, t_toxav_receive_video_frame_cb, &AliceCC);
toxav_callback_audio_receive_frame(AliceAV, t_toxav_receive_audio_frame_cb, &AliceCC);
toxav_callback_call(alice_av, t_toxav_call_cb, &alice_cc);
toxav_callback_call_state(alice_av, t_toxav_call_state_cb, &alice_cc);
toxav_callback_video_receive_frame(alice_av, t_toxav_receive_video_frame_cb, &alice_cc);
toxav_callback_audio_receive_frame(alice_av, t_toxav_receive_audio_frame_cb, &alice_cc);
toxav_callback_call(BobAV, t_toxav_call_cb, &BobCC);
toxav_callback_call_state(BobAV, t_toxav_call_state_cb, &BobCC);
toxav_callback_video_receive_frame(BobAV, t_toxav_receive_video_frame_cb, &BobCC);
toxav_callback_audio_receive_frame(BobAV, t_toxav_receive_audio_frame_cb, &BobCC);
toxav_callback_call(bob_av, t_toxav_call_cb, &bob_cc);
toxav_callback_call_state(bob_av, t_toxav_call_state_cb, &bob_cc);
toxav_callback_video_receive_frame(bob_av, t_toxav_receive_video_frame_cb, &bob_cc);
toxav_callback_audio_receive_frame(bob_av, t_toxav_receive_audio_frame_cb, &bob_cc);
printf("Created 2 instances of ToxAV\n");
printf("All set after %llu seconds!\n", time(nullptr) - cur_time);
if (TEST_REGULAR_AV) {
printf("\nTrying regular call (Audio and Video)...\n");
regular_call_flow(Alice, Bob, bootstrap, AliceAV, BobAV, &AliceCC, &BobCC,
regular_call_flow(alice, bob, bootstrap, alice_av, bob_av, &alice_cc, &bob_cc,
48, 4000);
}
if (TEST_REGULAR_A) {
printf("\nTrying regular call (Audio only)...\n");
regular_call_flow(Alice, Bob, bootstrap, AliceAV, BobAV, &AliceCC, &BobCC,
regular_call_flow(alice, bob, bootstrap, alice_av, bob_av, &alice_cc, &bob_cc,
48, 0);
}
if (TEST_REGULAR_V) {
printf("\nTrying regular call (Video only)...\n");
regular_call_flow(Alice, Bob, bootstrap, AliceAV, BobAV, &AliceCC, &BobCC,
regular_call_flow(alice, bob, bootstrap, alice_av, bob_av, &alice_cc, &bob_cc,
0, 4000);
}
if (TEST_REJECT) { /* Alice calls; Bob rejects */
printf("\nTrying reject flow...\n");
clear_call_control(&AliceCC);
clear_call_control(&BobCC);
clear_call_control(&alice_cc);
clear_call_control(&bob_cc);
{
Toxav_Err_Call rc;
toxav_call(AliceAV, 0, 48, 0, &rc);
toxav_call(alice_av, 0, 48, 0, &rc);
ck_assert_msg(rc == TOXAV_ERR_CALL_OK, "toxav_call failed: %d\n", rc);
}
do {
iterate_tox(bootstrap, Alice, Bob);
} while (!BobCC.incoming);
iterate_tox(bootstrap, alice, bob);
} while (!bob_cc.incoming);
/* Reject */
{
Toxav_Err_Call_Control rc;
toxav_call_control(BobAV, 0, TOXAV_CALL_CONTROL_CANCEL, &rc);
toxav_call_control(bob_av, 0, TOXAV_CALL_CONTROL_CANCEL, &rc);
ck_assert_msg(rc == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %d\n", rc);
}
do {
iterate_tox(bootstrap, Alice, Bob);
} while (AliceCC.state != TOXAV_FRIEND_CALL_STATE_FINISHED);
iterate_tox(bootstrap, alice, bob);
} while (alice_cc.state != TOXAV_FRIEND_CALL_STATE_FINISHED);
printf("Success!\n");
}
@ -283,32 +283,32 @@ static void test_av_flows(void)
if (TEST_CANCEL) { /* Alice calls; Alice cancels while ringing */
printf("\nTrying cancel (while ringing) flow...\n");
clear_call_control(&AliceCC);
clear_call_control(&BobCC);
clear_call_control(&alice_cc);
clear_call_control(&bob_cc);
{
Toxav_Err_Call rc;
toxav_call(AliceAV, 0, 48, 0, &rc);
toxav_call(alice_av, 0, 48, 0, &rc);
ck_assert_msg(rc == TOXAV_ERR_CALL_OK, "toxav_call failed: %d\n", rc);
}
do {
iterate_tox(bootstrap, Alice, Bob);
} while (!BobCC.incoming);
iterate_tox(bootstrap, alice, bob);
} while (!bob_cc.incoming);
/* Cancel */
{
Toxav_Err_Call_Control rc;
toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_CANCEL, &rc);
toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_CANCEL, &rc);
ck_assert_msg(rc == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %d\n", rc);
}
/* Alice will not receive end state */
do {
iterate_tox(bootstrap, Alice, Bob);
} while (BobCC.state != TOXAV_FRIEND_CALL_STATE_FINISHED);
iterate_tox(bootstrap, alice, bob);
} while (bob_cc.state != TOXAV_FRIEND_CALL_STATE_FINISHED);
printf("Success!\n");
}
@ -316,80 +316,80 @@ static void test_av_flows(void)
if (TEST_MUTE_UNMUTE) { /* Check Mute-Unmute etc */
printf("\nTrying mute functionality...\n");
clear_call_control(&AliceCC);
clear_call_control(&BobCC);
clear_call_control(&alice_cc);
clear_call_control(&bob_cc);
/* Assume sending audio and video */
{
Toxav_Err_Call rc;
toxav_call(AliceAV, 0, 48, 1000, &rc);
toxav_call(alice_av, 0, 48, 1000, &rc);
ck_assert_msg(rc == TOXAV_ERR_CALL_OK, "toxav_call failed: %d\n", rc);
}
do {
iterate_tox(bootstrap, Alice, Bob);
} while (!BobCC.incoming);
iterate_tox(bootstrap, alice, bob);
} while (!bob_cc.incoming);
/* At first try all stuff while in invalid state */
ck_assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_PAUSE, nullptr));
ck_assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_RESUME, nullptr));
ck_assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_MUTE_AUDIO, nullptr));
ck_assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_UNMUTE_AUDIO, nullptr));
ck_assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_HIDE_VIDEO, nullptr));
ck_assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_SHOW_VIDEO, nullptr));
ck_assert(!toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_PAUSE, nullptr));
ck_assert(!toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_RESUME, nullptr));
ck_assert(!toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_MUTE_AUDIO, nullptr));
ck_assert(!toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_UNMUTE_AUDIO, nullptr));
ck_assert(!toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_HIDE_VIDEO, nullptr));
ck_assert(!toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_SHOW_VIDEO, nullptr));
{
Toxav_Err_Answer rc;
toxav_answer(BobAV, 0, 48, 4000, &rc);
toxav_answer(bob_av, 0, 48, 4000, &rc);
ck_assert_msg(rc == TOXAV_ERR_ANSWER_OK, "toxav_answer failed: %d\n", rc);
}
iterate_tox(bootstrap, Alice, Bob);
iterate_tox(bootstrap, alice, bob);
/* Pause and Resume */
printf("Pause and Resume\n");
ck_assert_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_PAUSE);
iterate_tox(bootstrap, Alice, Bob);
ck_assert(BobCC.state == 0);
ck_assert_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_RESUME);
iterate_tox(bootstrap, Alice, Bob);
ck_assert(BobCC.state & (TOXAV_FRIEND_CALL_STATE_SENDING_A | TOXAV_FRIEND_CALL_STATE_SENDING_V));
ck_assert_call_control(alice_av, 0, TOXAV_CALL_CONTROL_PAUSE);
iterate_tox(bootstrap, alice, bob);
ck_assert(bob_cc.state == 0);
ck_assert_call_control(alice_av, 0, TOXAV_CALL_CONTROL_RESUME);
iterate_tox(bootstrap, alice, bob);
ck_assert(bob_cc.state & (TOXAV_FRIEND_CALL_STATE_SENDING_A | TOXAV_FRIEND_CALL_STATE_SENDING_V));
/* Mute/Unmute single */
printf("Mute/Unmute single\n");
ck_assert_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_MUTE_AUDIO);
iterate_tox(bootstrap, Alice, Bob);
ck_assert(BobCC.state ^ TOXAV_FRIEND_CALL_STATE_ACCEPTING_A);
ck_assert_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_UNMUTE_AUDIO);
iterate_tox(bootstrap, Alice, Bob);
ck_assert(BobCC.state & TOXAV_FRIEND_CALL_STATE_ACCEPTING_A);
ck_assert_call_control(alice_av, 0, TOXAV_CALL_CONTROL_MUTE_AUDIO);
iterate_tox(bootstrap, alice, bob);
ck_assert(bob_cc.state ^ TOXAV_FRIEND_CALL_STATE_ACCEPTING_A);
ck_assert_call_control(alice_av, 0, TOXAV_CALL_CONTROL_UNMUTE_AUDIO);
iterate_tox(bootstrap, alice, bob);
ck_assert(bob_cc.state & TOXAV_FRIEND_CALL_STATE_ACCEPTING_A);
/* Mute/Unmute both */
printf("Mute/Unmute both\n");
ck_assert_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_MUTE_AUDIO);
iterate_tox(bootstrap, Alice, Bob);
ck_assert(BobCC.state ^ TOXAV_FRIEND_CALL_STATE_ACCEPTING_A);
ck_assert_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_HIDE_VIDEO);
iterate_tox(bootstrap, Alice, Bob);
ck_assert(BobCC.state ^ TOXAV_FRIEND_CALL_STATE_ACCEPTING_V);
ck_assert_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_UNMUTE_AUDIO);
iterate_tox(bootstrap, Alice, Bob);
ck_assert(BobCC.state & TOXAV_FRIEND_CALL_STATE_ACCEPTING_A);
ck_assert_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_SHOW_VIDEO);
iterate_tox(bootstrap, Alice, Bob);
ck_assert(BobCC.state & TOXAV_FRIEND_CALL_STATE_ACCEPTING_V);
ck_assert_call_control(alice_av, 0, TOXAV_CALL_CONTROL_MUTE_AUDIO);
iterate_tox(bootstrap, alice, bob);
ck_assert(bob_cc.state ^ TOXAV_FRIEND_CALL_STATE_ACCEPTING_A);
ck_assert_call_control(alice_av, 0, TOXAV_CALL_CONTROL_HIDE_VIDEO);
iterate_tox(bootstrap, alice, bob);
ck_assert(bob_cc.state ^ TOXAV_FRIEND_CALL_STATE_ACCEPTING_V);
ck_assert_call_control(alice_av, 0, TOXAV_CALL_CONTROL_UNMUTE_AUDIO);
iterate_tox(bootstrap, alice, bob);
ck_assert(bob_cc.state & TOXAV_FRIEND_CALL_STATE_ACCEPTING_A);
ck_assert_call_control(alice_av, 0, TOXAV_CALL_CONTROL_SHOW_VIDEO);
iterate_tox(bootstrap, alice, bob);
ck_assert(bob_cc.state & TOXAV_FRIEND_CALL_STATE_ACCEPTING_V);
{
Toxav_Err_Call_Control rc;
toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_CANCEL, &rc);
toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_CANCEL, &rc);
ck_assert_msg(rc == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %d\n", rc);
}
iterate_tox(bootstrap, Alice, Bob);
ck_assert(BobCC.state == TOXAV_FRIEND_CALL_STATE_FINISHED);
iterate_tox(bootstrap, alice, bob);
ck_assert(bob_cc.state == TOXAV_FRIEND_CALL_STATE_FINISHED);
printf("Success!\n");
}
@ -397,58 +397,58 @@ static void test_av_flows(void)
if (TEST_STOP_RESUME_PAYLOAD) { /* Stop and resume audio/video payload */
printf("\nTrying stop/resume functionality...\n");
clear_call_control(&AliceCC);
clear_call_control(&BobCC);
clear_call_control(&alice_cc);
clear_call_control(&bob_cc);
/* Assume sending audio and video */
{
Toxav_Err_Call rc;
toxav_call(AliceAV, 0, 48, 0, &rc);
toxav_call(alice_av, 0, 48, 0, &rc);
ck_assert_msg(rc == TOXAV_ERR_CALL_OK, "toxav_call failed: %d\n", rc);
}
do {
iterate_tox(bootstrap, Alice, Bob);
} while (!BobCC.incoming);
iterate_tox(bootstrap, alice, bob);
} while (!bob_cc.incoming);
{
Toxav_Err_Answer rc;
toxav_answer(BobAV, 0, 48, 0, &rc);
toxav_answer(bob_av, 0, 48, 0, &rc);
ck_assert_msg(rc == TOXAV_ERR_ANSWER_OK, "toxav_answer failed: %d\n", rc);
}
iterate_tox(bootstrap, Alice, Bob);
iterate_tox(bootstrap, alice, bob);
printf("Call started as audio only\n");
printf("Turning on video for Alice...\n");
ck_assert(toxav_video_set_bit_rate(AliceAV, 0, 1000, nullptr));
ck_assert(toxav_video_set_bit_rate(alice_av, 0, 1000, nullptr));
iterate_tox(bootstrap, Alice, Bob);
ck_assert(BobCC.state & TOXAV_FRIEND_CALL_STATE_SENDING_V);
iterate_tox(bootstrap, alice, bob);
ck_assert(bob_cc.state & TOXAV_FRIEND_CALL_STATE_SENDING_V);
printf("Turning off video for Alice...\n");
ck_assert(toxav_video_set_bit_rate(AliceAV, 0, 0, nullptr));
ck_assert(toxav_video_set_bit_rate(alice_av, 0, 0, nullptr));
iterate_tox(bootstrap, Alice, Bob);
ck_assert(!(BobCC.state & TOXAV_FRIEND_CALL_STATE_SENDING_V));
iterate_tox(bootstrap, alice, bob);
ck_assert(!(bob_cc.state & TOXAV_FRIEND_CALL_STATE_SENDING_V));
printf("Turning off audio for Alice...\n");
ck_assert(toxav_audio_set_bit_rate(AliceAV, 0, 0, nullptr));
ck_assert(toxav_audio_set_bit_rate(alice_av, 0, 0, nullptr));
iterate_tox(bootstrap, Alice, Bob);
ck_assert(!(BobCC.state & TOXAV_FRIEND_CALL_STATE_SENDING_A));
iterate_tox(bootstrap, alice, bob);
ck_assert(!(bob_cc.state & TOXAV_FRIEND_CALL_STATE_SENDING_A));
{
Toxav_Err_Call_Control rc;
toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_CANCEL, &rc);
toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_CANCEL, &rc);
ck_assert_msg(rc == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %d\n", rc);
}
iterate_tox(bootstrap, Alice, Bob);
ck_assert(BobCC.state == TOXAV_FRIEND_CALL_STATE_FINISHED);
iterate_tox(bootstrap, alice, bob);
ck_assert(bob_cc.state == TOXAV_FRIEND_CALL_STATE_FINISHED);
printf("Success!\n");
}
@ -456,56 +456,56 @@ static void test_av_flows(void)
if (TEST_PAUSE_RESUME_SEND) { /* Stop and resume audio/video payload and test send options */
printf("\nTrying stop/resume functionality...\n");
clear_call_control(&AliceCC);
clear_call_control(&BobCC);
clear_call_control(&alice_cc);
clear_call_control(&bob_cc);
/* Assume sending audio and video */
{
Toxav_Err_Call rc;
toxav_call(AliceAV, 0, 48, 0, &rc);
toxav_call(alice_av, 0, 48, 0, &rc);
ck_assert_msg(rc == TOXAV_ERR_CALL_OK, "toxav_call failed: %d\n", rc);
}
do {
iterate_tox(bootstrap, Alice, Bob);
} while (!BobCC.incoming);
iterate_tox(bootstrap, alice, bob);
} while (!bob_cc.incoming);
{
Toxav_Err_Answer rc;
toxav_answer(BobAV, 0, 48, 0, &rc);
toxav_answer(bob_av, 0, 48, 0, &rc);
ck_assert_msg(rc == TOXAV_ERR_ANSWER_OK, "toxav_answer failed: %d\n", rc);
}
iterate_tox(bootstrap, Alice, Bob);
ck_assert_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_PAUSE);
iterate_tox(bootstrap, Alice, Bob);
ck_assert(!toxav_audio_send_frame_helper(AliceAV, 0, nullptr));
ck_assert(!toxav_audio_send_frame_helper(BobAV, 0, nullptr));
ck_assert_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_RESUME);
iterate_tox(bootstrap, Alice, Bob);
ck_assert(toxav_audio_send_frame_helper(AliceAV, 0, nullptr));
ck_assert(toxav_audio_send_frame_helper(BobAV, 0, nullptr));
iterate_tox(bootstrap, Alice, Bob);
iterate_tox(bootstrap, alice, bob);
ck_assert_call_control(alice_av, 0, TOXAV_CALL_CONTROL_PAUSE);
iterate_tox(bootstrap, alice, bob);
ck_assert(!toxav_audio_send_frame_helper(alice_av, 0, nullptr));
ck_assert(!toxav_audio_send_frame_helper(bob_av, 0, nullptr));
ck_assert_call_control(alice_av, 0, TOXAV_CALL_CONTROL_RESUME);
iterate_tox(bootstrap, alice, bob);
ck_assert(toxav_audio_send_frame_helper(alice_av, 0, nullptr));
ck_assert(toxav_audio_send_frame_helper(bob_av, 0, nullptr));
iterate_tox(bootstrap, alice, bob);
{
Toxav_Err_Call_Control rc;
toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_CANCEL, &rc);
toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_CANCEL, &rc);
ck_assert_msg(rc == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %d\n", rc);
}
iterate_tox(bootstrap, Alice, Bob);
ck_assert(BobCC.state == TOXAV_FRIEND_CALL_STATE_FINISHED);
iterate_tox(bootstrap, alice, bob);
ck_assert(bob_cc.state == TOXAV_FRIEND_CALL_STATE_FINISHED);
printf("Success!\n");
}
toxav_kill(BobAV);
toxav_kill(AliceAV);
tox_kill(Bob);
tox_kill(Alice);
toxav_kill(bob_av);
toxav_kill(alice_av);
tox_kill(bob);
tox_kill(alice);
tox_kill(bootstrap);
printf("\nTest successful!\n");

View File

@ -21,18 +21,18 @@
#include "auto_test_support.h"
#include "check_compat.h"
typedef struct {
typedef struct CallControl {
bool incoming;
uint32_t state;
} CallControl;
typedef struct {
ToxAV *AliceAV;
ToxAV *BobAV;
CallControl *AliceCC;
CallControl *BobCC;
typedef struct Thread_Data {
ToxAV *alice_av;
ToxAV *bob_av;
CallControl *alice_cc;
CallControl *bob_cc;
uint32_t friend_number;
} thread_data;
} Thread_Data;
/**
* Callbacks
@ -78,28 +78,28 @@ static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const
/**
* Iterate helper
*/
static ToxAV *setup_av_instance(Tox *tox, CallControl *CC)
static ToxAV *setup_av_instance(Tox *tox, CallControl *cc)
{
Toxav_Err_New error;
ToxAV *av = toxav_new(tox, &error);
ck_assert(error == TOXAV_ERR_NEW_OK);
toxav_callback_call(av, t_toxav_call_cb, CC);
toxav_callback_call_state(av, t_toxav_call_state_cb, CC);
toxav_callback_video_receive_frame(av, t_toxav_receive_video_frame_cb, CC);
toxav_callback_audio_receive_frame(av, t_toxav_receive_audio_frame_cb, CC);
toxav_callback_call(av, t_toxav_call_cb, cc);
toxav_callback_call_state(av, t_toxav_call_state_cb, cc);
toxav_callback_video_receive_frame(av, t_toxav_receive_video_frame_cb, cc);
toxav_callback_audio_receive_frame(av, t_toxav_receive_audio_frame_cb, cc);
return av;
}
static void *call_thread(void *pd)
{
ToxAV *AliceAV = ((thread_data *) pd)->AliceAV;
ToxAV *BobAV = ((thread_data *) pd)->BobAV;
uint32_t friend_number = ((thread_data *) pd)->friend_number;
ToxAV *alice_av = ((Thread_Data *) pd)->alice_av;
ToxAV *bob_av = ((Thread_Data *) pd)->bob_av;
uint32_t friend_number = ((Thread_Data *) pd)->friend_number;
int16_t *PCM = (int16_t *)calloc(960, sizeof(int16_t));
int16_t *pcm = (int16_t *)calloc(960, sizeof(int16_t));
uint8_t *video_y = (uint8_t *)calloc(800 * 600, sizeof(uint8_t));
uint8_t *video_u = (uint8_t *)calloc(800 * 600 / 4, sizeof(uint8_t));
uint8_t *video_v = (uint8_t *)calloc(800 * 600 / 4, sizeof(uint8_t));
@ -107,19 +107,19 @@ static void *call_thread(void *pd)
time_t start_time = time(nullptr);
do {
toxav_iterate(AliceAV);
toxav_iterate(BobAV);
toxav_iterate(alice_av);
toxav_iterate(bob_av);
toxav_audio_send_frame(AliceAV, friend_number, PCM, 960, 1, 48000, nullptr);
toxav_audio_send_frame(BobAV, 0, PCM, 960, 1, 48000, nullptr);
toxav_audio_send_frame(alice_av, friend_number, pcm, 960, 1, 48000, nullptr);
toxav_audio_send_frame(bob_av, 0, pcm, 960, 1, 48000, nullptr);
toxav_video_send_frame(AliceAV, friend_number, 800, 600, video_y, video_u, video_v, nullptr);
toxav_video_send_frame(BobAV, 0, 800, 600, video_y, video_u, video_v, nullptr);
toxav_video_send_frame(alice_av, friend_number, 800, 600, video_y, video_u, video_v, nullptr);
toxav_video_send_frame(bob_av, 0, 800, 600, video_y, video_u, video_v, nullptr);
c_sleep(10);
} while (time(nullptr) - start_time < 4);
free(PCM);
free(pcm);
free(video_y);
free(video_u);
free(video_v);
@ -160,11 +160,11 @@ static void set_current_time_callback(Tox *tox, Time_Data *time_data)
static void test_av_three_calls(void)
{
uint32_t index[] = { 1, 2, 3, 4, 5 };
Tox *Alice, *bootstrap, *Bobs[3];
ToxAV *AliceAV, *BobsAV[3];
Tox *alice, *bootstrap, *bobs[3];
ToxAV *alice_av, *bobs_av[3];
void *retval;
CallControl AliceCC[3], BobsCC[3];
CallControl alice_cc[3], bobs_cc[3];
Time_Data time_data;
pthread_mutex_init(&time_data.lock, nullptr);
@ -177,21 +177,21 @@ static void test_av_three_calls(void)
time_data.clock = current_time_monotonic(bootstrap->mono_time);
set_current_time_callback(bootstrap, &time_data);
Alice = tox_new_log(nullptr, &error, &index[1]);
alice = tox_new_log(nullptr, &error, &index[1]);
ck_assert(error == TOX_ERR_NEW_OK);
set_current_time_callback(Alice, &time_data);
set_current_time_callback(alice, &time_data);
Bobs[0] = tox_new_log(nullptr, &error, &index[2]);
bobs[0] = tox_new_log(nullptr, &error, &index[2]);
ck_assert(error == TOX_ERR_NEW_OK);
set_current_time_callback(Bobs[0], &time_data);
set_current_time_callback(bobs[0], &time_data);
Bobs[1] = tox_new_log(nullptr, &error, &index[3]);
bobs[1] = tox_new_log(nullptr, &error, &index[3]);
ck_assert(error == TOX_ERR_NEW_OK);
set_current_time_callback(Bobs[1], &time_data);
set_current_time_callback(bobs[1], &time_data);
Bobs[2] = tox_new_log(nullptr, &error, &index[4]);
bobs[2] = tox_new_log(nullptr, &error, &index[4]);
ck_assert(error == TOX_ERR_NEW_OK);
set_current_time_callback(Bobs[2], &time_data);
set_current_time_callback(bobs[2], &time_data);
}
printf("Created 5 instances of Tox\n");
@ -200,48 +200,48 @@ static void test_av_three_calls(void)
uint8_t address[TOX_ADDRESS_SIZE];
tox_callback_friend_request(Alice, t_accept_friend_request_cb);
tox_self_get_address(Alice, address);
tox_callback_friend_request(alice, t_accept_friend_request_cb);
tox_self_get_address(alice, address);
printf("bootstrapping Alice and the %u Bobs off a third bootstrap node\n",
(unsigned)(sizeof(Bobs) / sizeof(Bobs[0])));
(unsigned)(sizeof(bobs) / sizeof(bobs[0])));
uint8_t dht_key[TOX_PUBLIC_KEY_SIZE];
tox_self_get_dht_id(bootstrap, dht_key);
const uint16_t dht_port = tox_self_get_udp_port(bootstrap, nullptr);
tox_bootstrap(Alice, "localhost", dht_port, dht_key, nullptr);
tox_bootstrap(Bobs[0], "localhost", dht_port, dht_key, nullptr);
tox_bootstrap(Bobs[1], "localhost", dht_port, dht_key, nullptr);
tox_bootstrap(Bobs[2], "localhost", dht_port, dht_key, nullptr);
tox_bootstrap(alice, "localhost", dht_port, dht_key, nullptr);
tox_bootstrap(bobs[0], "localhost", dht_port, dht_key, nullptr);
tox_bootstrap(bobs[1], "localhost", dht_port, dht_key, nullptr);
tox_bootstrap(bobs[2], "localhost", dht_port, dht_key, nullptr);
ck_assert(tox_friend_add(Bobs[0], address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) -1);
ck_assert(tox_friend_add(Bobs[1], address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) -1);
ck_assert(tox_friend_add(Bobs[2], address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) -1);
ck_assert(tox_friend_add(bobs[0], address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) -1);
ck_assert(tox_friend_add(bobs[1], address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) -1);
ck_assert(tox_friend_add(bobs[2], address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) -1);
uint8_t off = 1;
while (true) {
tox_iterate(bootstrap, nullptr);
tox_iterate(Alice, nullptr);
tox_iterate(Bobs[0], nullptr);
tox_iterate(Bobs[1], nullptr);
tox_iterate(Bobs[2], nullptr);
tox_iterate(alice, nullptr);
tox_iterate(bobs[0], nullptr);
tox_iterate(bobs[1], nullptr);
tox_iterate(bobs[2], nullptr);
if (tox_self_get_connection_status(bootstrap) &&
tox_self_get_connection_status(Alice) &&
tox_self_get_connection_status(Bobs[0]) &&
tox_self_get_connection_status(Bobs[1]) &&
tox_self_get_connection_status(Bobs[2]) && off) {
tox_self_get_connection_status(alice) &&
tox_self_get_connection_status(bobs[0]) &&
tox_self_get_connection_status(bobs[1]) &&
tox_self_get_connection_status(bobs[2]) && off) {
printf("Toxes are online, took %lu seconds\n", (unsigned long)(time(nullptr) - cur_time));
off = 0;
}
if (tox_friend_get_connection_status(Alice, 0, nullptr) == TOX_CONNECTION_UDP &&
tox_friend_get_connection_status(Alice, 1, nullptr) == TOX_CONNECTION_UDP &&
tox_friend_get_connection_status(Alice, 2, nullptr) == TOX_CONNECTION_UDP &&
tox_friend_get_connection_status(Bobs[0], 0, nullptr) == TOX_CONNECTION_UDP &&
tox_friend_get_connection_status(Bobs[1], 0, nullptr) == TOX_CONNECTION_UDP &&
tox_friend_get_connection_status(Bobs[2], 0, nullptr) == TOX_CONNECTION_UDP) {
if (tox_friend_get_connection_status(alice, 0, nullptr) == TOX_CONNECTION_UDP &&
tox_friend_get_connection_status(alice, 1, nullptr) == TOX_CONNECTION_UDP &&
tox_friend_get_connection_status(alice, 2, nullptr) == TOX_CONNECTION_UDP &&
tox_friend_get_connection_status(bobs[0], 0, nullptr) == TOX_CONNECTION_UDP &&
tox_friend_get_connection_status(bobs[1], 0, nullptr) == TOX_CONNECTION_UDP &&
tox_friend_get_connection_status(bobs[2], 0, nullptr) == TOX_CONNECTION_UDP) {
break;
}
@ -249,24 +249,24 @@ static void test_av_three_calls(void)
c_sleep(5);
}
AliceAV = setup_av_instance(Alice, AliceCC);
BobsAV[0] = setup_av_instance(Bobs[0], &BobsCC[0]);
BobsAV[1] = setup_av_instance(Bobs[1], &BobsCC[1]);
BobsAV[2] = setup_av_instance(Bobs[2], &BobsCC[2]);
alice_av = setup_av_instance(alice, alice_cc);
bobs_av[0] = setup_av_instance(bobs[0], &bobs_cc[0]);
bobs_av[1] = setup_av_instance(bobs[1], &bobs_cc[1]);
bobs_av[2] = setup_av_instance(bobs[2], &bobs_cc[2]);
printf("Created 4 instances of ToxAV\n");
printf("All set after %lu seconds!\n", (unsigned long)(time(nullptr) - cur_time));
thread_data tds[3];
Thread_Data tds[3];
for (size_t i = 0; i < 3; i++) {
tds[i].AliceAV = AliceAV;
tds[i].BobAV = BobsAV[i];
tds[i].AliceCC = &AliceCC[i];
tds[i].BobCC = &BobsCC[i];
tds[i].alice_av = alice_av;
tds[i].bob_av = bobs_av[i];
tds[i].alice_cc = &alice_cc[i];
tds[i].bob_cc = &bobs_cc[i];
tds[i].friend_number = i;
memset(tds[i].AliceCC, 0, sizeof(CallControl));
memset(tds[i].BobCC, 0, sizeof(CallControl));
memset(tds[i].alice_cc, 0, sizeof(CallControl));
memset(tds[i].bob_cc, 0, sizeof(CallControl));
}
pthread_t tids[3];
@ -279,10 +279,10 @@ static void test_av_three_calls(void)
do {
tox_iterate(bootstrap, nullptr);
tox_iterate(Alice, nullptr);
tox_iterate(Bobs[0], nullptr);
tox_iterate(Bobs[1], nullptr);
tox_iterate(Bobs[2], nullptr);
tox_iterate(alice, nullptr);
tox_iterate(bobs[0], nullptr);
tox_iterate(bobs[1], nullptr);
tox_iterate(bobs[2], nullptr);
increment_clock(&time_data, 100);
c_sleep(5);
@ -291,7 +291,7 @@ static void test_av_three_calls(void)
/* Call */
for (size_t i = 0; i < 3; i++) {
Toxav_Err_Call rc;
toxav_call(AliceAV, tds[i].friend_number, 48, 3000, &rc);
toxav_call(alice_av, tds[i].friend_number, 48, 3000, &rc);
if (rc != TOXAV_ERR_CALL_OK) {
printf("toxav_call failed: %d\n", rc);
@ -302,23 +302,23 @@ static void test_av_three_calls(void)
do {
tox_iterate(bootstrap, nullptr);
tox_iterate(Alice, nullptr);
tox_iterate(Bobs[0], nullptr);
tox_iterate(Bobs[1], nullptr);
tox_iterate(Bobs[2], nullptr);
tox_iterate(alice, nullptr);
tox_iterate(bobs[0], nullptr);
tox_iterate(bobs[1], nullptr);
tox_iterate(bobs[2], nullptr);
for (size_t i = 0; i < 3; i++) {
if (BobsCC[i].incoming) {
if (bobs_cc[i].incoming) {
/* Answer */
Toxav_Err_Answer rc;
toxav_answer(BobsAV[i], 0, 8, 500, &rc);
toxav_answer(bobs_av[i], 0, 8, 500, &rc);
if (rc != TOXAV_ERR_ANSWER_OK) {
printf("toxav_answer failed: %d\n", rc);
ck_assert(0);
}
BobsCC[i].incoming = false;
bobs_cc[i].incoming = false;
}
}
@ -329,19 +329,19 @@ static void test_av_three_calls(void)
/* Hangup */
for (size_t i = 0; i < 3; i++) {
Toxav_Err_Call_Control rc;
toxav_call_control(AliceAV, i, TOXAV_CALL_CONTROL_CANCEL, &rc);
toxav_call_control(alice_av, i, TOXAV_CALL_CONTROL_CANCEL, &rc);
if (rc != TOXAV_ERR_CALL_CONTROL_OK) {
printf("toxav_call_control failed: %d %p %p\n", rc, (void *)AliceAV, (void *)&BobsAV[i]);
printf("toxav_call_control failed: %d %p %p\n", rc, (void *)alice_av, (void *)&bobs_av[i]);
}
}
do {
tox_iterate(bootstrap, nullptr);
tox_iterate(Alice, nullptr);
tox_iterate(Bobs[0], nullptr);
tox_iterate(Bobs[1], nullptr);
tox_iterate(Bobs[2], nullptr);
tox_iterate(alice, nullptr);
tox_iterate(bobs[0], nullptr);
tox_iterate(bobs[1], nullptr);
tox_iterate(bobs[2], nullptr);
increment_clock(&time_data, 100);
c_sleep(5);
@ -357,14 +357,14 @@ static void test_av_three_calls(void)
ck_assert(retval == nullptr);
printf("Killing all instances\n");
toxav_kill(BobsAV[2]);
toxav_kill(BobsAV[1]);
toxav_kill(BobsAV[0]);
toxav_kill(AliceAV);
tox_kill(Bobs[2]);
tox_kill(Bobs[1]);
tox_kill(Bobs[0]);
tox_kill(Alice);
toxav_kill(bobs_av[2]);
toxav_kill(bobs_av[1]);
toxav_kill(bobs_av[0]);
toxav_kill(alice_av);
tox_kill(bobs[2]);
tox_kill(bobs[1]);
tox_kill(bobs[0]);
tox_kill(alice);
tox_kill(bootstrap);
pthread_mutex_destroy(&time_data.lock);

View File

@ -1,7 +1,7 @@
#include "../toxcore/tox.h"
#include "check_compat.h"
#define check(major, minor, patch, expected) \
#define CHECK(major, minor, patch, expected) \
do_check(TOX_VERSION_MAJOR, TOX_VERSION_MINOR, TOX_VERSION_PATCH, \
major, minor, patch, \
TOX_VERSION_IS_API_COMPATIBLE(major, minor, patch), expected)
@ -26,11 +26,11 @@ int main(void)
#define TOX_VERSION_MINOR 0
#define TOX_VERSION_PATCH 4
// Tox versions from 0.0.* are only compatible with themselves.
check(0, 0, 0, false);
check(0, 0, 3, false);
check(0, 0, 4, true);
check(0, 0, 5, false);
check(1, 0, 4, false);
CHECK(0, 0, 0, false);
CHECK(0, 0, 3, false);
CHECK(0, 0, 4, true);
CHECK(0, 0, 5, false);
CHECK(1, 0, 4, false);
#undef TOX_VERSION_MAJOR
#undef TOX_VERSION_MINOR
#undef TOX_VERSION_PATCH
@ -39,19 +39,19 @@ int main(void)
#define TOX_VERSION_MINOR 1
#define TOX_VERSION_PATCH 4
// Tox versions from 0.1.* are only compatible with themselves or 0.1.<*
check(0, 0, 0, false);
check(0, 0, 4, false);
check(0, 0, 5, false);
check(0, 1, 0, true);
check(0, 1, 4, true);
check(0, 1, 5, false);
check(0, 2, 0, false);
check(0, 2, 4, false);
check(0, 2, 5, false);
check(1, 0, 0, false);
check(1, 0, 4, false);
check(1, 0, 5, false);
check(1, 1, 4, false);
CHECK(0, 0, 0, false);
CHECK(0, 0, 4, false);
CHECK(0, 0, 5, false);
CHECK(0, 1, 0, true);
CHECK(0, 1, 4, true);
CHECK(0, 1, 5, false);
CHECK(0, 2, 0, false);
CHECK(0, 2, 4, false);
CHECK(0, 2, 5, false);
CHECK(1, 0, 0, false);
CHECK(1, 0, 4, false);
CHECK(1, 0, 5, false);
CHECK(1, 1, 4, false);
#undef TOX_VERSION_MAJOR
#undef TOX_VERSION_MINOR
#undef TOX_VERSION_PATCH
@ -60,14 +60,14 @@ int main(void)
#define TOX_VERSION_MINOR 0
#define TOX_VERSION_PATCH 4
// Beyond 0.*.* Tox is comfortable with any lower version within their major
check(0, 0, 4, false);
check(1, 0, 0, true);
check(1, 0, 1, true);
check(1, 0, 4, true);
check(1, 0, 5, false);
check(1, 1, 0, false);
check(2, 0, 0, false);
check(2, 0, 4, false);
CHECK(0, 0, 4, false);
CHECK(1, 0, 0, true);
CHECK(1, 0, 1, true);
CHECK(1, 0, 4, true);
CHECK(1, 0, 5, false);
CHECK(1, 1, 0, false);
CHECK(2, 0, 0, false);
CHECK(2, 0, 4, false);
#undef TOX_VERSION_MAJOR
#undef TOX_VERSION_MINOR
#undef TOX_VERSION_PATCH
@ -75,19 +75,19 @@ int main(void)
#define TOX_VERSION_MAJOR 1
#define TOX_VERSION_MINOR 1
#define TOX_VERSION_PATCH 4
check(0, 0, 4, false);
check(1, 0, 0, true);
check(1, 0, 4, true);
check(1, 0, 5, true);
check(1, 1, 0, true);
check(1, 1, 1, true);
check(1, 1, 4, true);
check(1, 1, 5, false);
check(1, 2, 0, false);
check(1, 2, 4, false);
check(1, 2, 5, false);
check(2, 0, 0, false);
check(2, 1, 4, false);
CHECK(0, 0, 4, false);
CHECK(1, 0, 0, true);
CHECK(1, 0, 4, true);
CHECK(1, 0, 5, true);
CHECK(1, 1, 0, true);
CHECK(1, 1, 1, true);
CHECK(1, 1, 4, true);
CHECK(1, 1, 5, false);
CHECK(1, 2, 0, false);
CHECK(1, 2, 4, false);
CHECK(1, 2, 5, false);
CHECK(2, 0, 0, false);
CHECK(2, 1, 4, false);
#undef TOX_VERSION_MAJOR
#undef TOX_VERSION_MINOR
#undef TOX_VERSION_PATCH

View File

@ -175,7 +175,7 @@ int main(int argc, char *argv[])
#ifdef TCP_RELAY_ENABLED
#define NUM_PORTS 3
uint16_t ports[NUM_PORTS] = {443, 3389, PORT};
TCP_Server *tcp_s = new_TCP_server(logger, mem, rng, ns, ipv6enabled, NUM_PORTS, ports, dht_get_self_secret_key(dht), onion, forwarding);
TCP_Server *tcp_s = new_tcp_server(logger, mem, rng, ns, ipv6enabled, NUM_PORTS, ports, dht_get_self_secret_key(dht), onion, forwarding);
if (tcp_s == nullptr) {
printf("TCP server failed to initialize.\n");
@ -228,7 +228,7 @@ int main(int argc, char *argv[])
int is_waiting_for_dht_connection = 1;
uint64_t last_LANdiscovery = 0;
uint64_t last_lan_discovery = 0;
const Broadcast_Info *broadcast = lan_discovery_init(ns);
while (1) {
@ -241,13 +241,13 @@ int main(int argc, char *argv[])
do_dht(dht);
if (mono_time_is_timeout(mono_time, last_LANdiscovery, is_waiting_for_dht_connection ? 5 : LAN_DISCOVERY_INTERVAL)) {
if (mono_time_is_timeout(mono_time, last_lan_discovery, is_waiting_for_dht_connection ? 5 : LAN_DISCOVERY_INTERVAL)) {
lan_discovery_send(dht_get_net(dht), broadcast, dht_get_self_public_key(dht), net_htons(PORT));
last_LANdiscovery = mono_time_get(mono_time);
last_lan_discovery = mono_time_get(mono_time);
}
#ifdef TCP_RELAY_ENABLED
do_TCP_server(tcp_s, mono_time);
do_tcp_server(tcp_s, mono_time);
#endif
networking_poll(dht_get_net(dht), nullptr);

View File

@ -6,18 +6,32 @@ CHECKS="*"
CHECKS="$CHECKS,-clang-diagnostic-pointer-bool-conversion"
CHECKS="$CHECKS,-clang-diagnostic-tautological-pointer-compare"
# TODO(iphydf): We might want some of these. For the ones we don't want, add a
# comment explaining why not.
CHECKS="$CHECKS,-clang-diagnostic-unknown-warning-option"
# Short variable names are used quite a lot, and we don't consider them a
# readability issue.
CHECKS="$CHECKS,-readability-identifier-length"
# This finds all the do {} while (0) loops and tells us to unroll them.
CHECKS="$CHECKS,-altera-unroll-loops"
# We target systems other than Android, so we don't want to use non-standard
# functions from the Android libc.
CHECKS="$CHECKS,-android-cloexec-accept"
CHECKS="$CHECKS,-android-cloexec-fopen"
CHECKS="$CHECKS,-bugprone-not-null-terminated-result"
# This catches all the feature test macros (_POSIX_SOURCE etc.).
CHECKS="$CHECKS,-bugprone-reserved-identifier"
CHECKS="$CHECKS,-bugprone-sizeof-expression"
CHECKS="$CHECKS,-cert-dcl37-c"
CHECKS="$CHECKS,-cert-dcl51-cpp"
# We intentionally send some not null-terminated strings in tests and use it for
# the toxencryptsave magic number.
CHECKS="$CHECKS,-bugprone-not-null-terminated-result"
# TODO(iphydf): We might want some of these. For the ones we don't want, add a
# comment explaining why not.
CHECKS="$CHECKS,-clang-analyzer-optin.performance.Padding"
CHECKS="$CHECKS,-cppcoreguidelines-avoid-magic-numbers"
CHECKS="$CHECKS,-cppcoreguidelines-init-variables"
CHECKS="$CHECKS,-hicpp-multiway-paths-covered"
CHECKS="$CHECKS,-hicpp-signed-bitwise"
@ -50,6 +64,11 @@ CHECKS="$CHECKS,-cppcoreguidelines-narrowing-conversions"
CHECKS="$CHECKS,-google-readability-casting"
CHECKS="$CHECKS,-misc-no-recursion"
# TODO(iphydf): Probably fix these.
CHECKS="$CHECKS,-cert-err33-c"
CHECKS="$CHECKS,-cppcoreguidelines-avoid-magic-numbers"
CHECKS="$CHECKS,-modernize-macro-to-enum"
ERRORS="*"
# TODO(iphydf): Fix these.
@ -60,7 +79,6 @@ ERRORS="$ERRORS,-cert-err34-c"
ERRORS="$ERRORS,-cert-str34-c"
ERRORS="$ERRORS,-hicpp-uppercase-literal-suffix"
ERRORS="$ERRORS,-readability-suspicious-call-argument"
ERRORS="$ERRORS,-readability-uppercase-literal-suffix"
set -eux
@ -70,7 +88,7 @@ run() {
for i in "${!EXTRA_ARGS[@]}"; do
EXTRA_ARGS[$i]="--extra-arg=${EXTRA_ARGS[$i]}"
done
clang-tidy-12 \
clang-tidy-14 \
-p=_build \
--extra-arg=-DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE \
"${EXTRA_ARGS[@]}" \
@ -84,4 +102,6 @@ run() {
toxencryptsave/*.c
}
cmake . -B_build -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
. other/analysis/variants.sh

View File

@ -1 +1 @@
6f4ec4239de5ea05ae341271bbda4cb78535f943a693321648ee1ab043a203d2 /usr/local/bin/tox-bootstrapd
a8917dcace422e2a6644f140463da7b9e70e67a7e15f5209c572b72650d87368 /usr/local/bin/tox-bootstrapd

View File

@ -29,7 +29,7 @@
*/
static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int *tcp_relay_port_count)
{
const char *NAME_TCP_RELAY_PORTS = "tcp_relay_ports";
const char *const NAME_TCP_RELAY_PORTS = "tcp_relay_ports";
*tcp_relay_port_count = 0;
@ -129,15 +129,15 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
{
config_t cfg;
const char *NAME_PORT = "port";
const char *NAME_PID_FILE_PATH = "pid_file_path";
const char *NAME_KEYS_FILE_PATH = "keys_file_path";
const char *NAME_ENABLE_IPV6 = "enable_ipv6";
const char *NAME_ENABLE_IPV4_FALLBACK = "enable_ipv4_fallback";
const char *NAME_ENABLE_LAN_DISCOVERY = "enable_lan_discovery";
const char *NAME_ENABLE_TCP_RELAY = "enable_tcp_relay";
const char *NAME_ENABLE_MOTD = "enable_motd";
const char *NAME_MOTD = "motd";
const char *const NAME_PORT = "port";
const char *const NAME_PID_FILE_PATH = "pid_file_path";
const char *const NAME_KEYS_FILE_PATH = "keys_file_path";
const char *const NAME_ENABLE_IPV6 = "enable_ipv6";
const char *const NAME_ENABLE_IPV4_FALLBACK = "enable_ipv4_fallback";
const char *const NAME_ENABLE_LAN_DISCOVERY = "enable_lan_discovery";
const char *const NAME_ENABLE_TCP_RELAY = "enable_tcp_relay";
const char *const NAME_ENABLE_MOTD = "enable_motd";
const char *const NAME_MOTD = "motd";
config_init(&cfg);
@ -307,11 +307,11 @@ static uint8_t *bootstrap_hex_string_to_bin(const char *hex_string)
int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
{
const char *NAME_BOOTSTRAP_NODES = "bootstrap_nodes";
const char *const NAME_BOOTSTRAP_NODES = "bootstrap_nodes";
const char *NAME_PUBLIC_KEY = "public_key";
const char *NAME_PORT = "port";
const char *NAME_ADDRESS = "address";
const char *const NAME_PUBLIC_KEY = "public_key";
const char *const NAME_PORT = "port";
const char *const NAME_ADDRESS = "address";
config_t cfg;

View File

@ -477,7 +477,7 @@ int main(int argc, char *argv[])
return 1;
}
tcp_server = new_TCP_server(logger, mem, rng, ns, enable_ipv6,
tcp_server = new_tcp_server(logger, mem, rng, ns, enable_ipv6,
tcp_relay_port_count, tcp_relay_ports,
dht_get_self_secret_key(dht), onion, forwarding);
@ -528,7 +528,7 @@ int main(int argc, char *argv[])
log_write(LOG_LEVEL_INFO, "List of bootstrap nodes read successfully.\n");
} else {
log_write(LOG_LEVEL_ERROR, "Couldn't read list of bootstrap nodes in %s. Exiting.\n", cfg_file_path);
kill_TCP_server(tcp_server);
kill_tcp_server(tcp_server);
kill_onion_announce(onion_a);
kill_gca(group_announce);
kill_onion(onion);
@ -543,7 +543,7 @@ int main(int argc, char *argv[])
print_public_key(dht_get_self_public_key(dht));
uint64_t last_LANdiscovery = 0;
uint64_t last_lan_discovery = 0;
const uint16_t net_htons_port = net_htons(start_port);
int waiting_for_dht_connection = 1;
@ -578,13 +578,13 @@ int main(int argc, char *argv[])
do_dht(dht);
if (enable_lan_discovery && mono_time_is_timeout(mono_time, last_LANdiscovery, LAN_DISCOVERY_INTERVAL)) {
if (enable_lan_discovery && mono_time_is_timeout(mono_time, last_lan_discovery, LAN_DISCOVERY_INTERVAL)) {
lan_discovery_send(dht_get_net(dht), broadcast, dht_get_self_public_key(dht), net_htons_port);
last_LANdiscovery = mono_time_get(mono_time);
last_lan_discovery = mono_time_get(mono_time);
}
if (enable_tcp_relay) {
do_TCP_server(tcp_server, mono_time);
do_tcp_server(tcp_server, mono_time);
}
networking_poll(dht_get_net(dht), nullptr);
@ -611,7 +611,7 @@ int main(int argc, char *argv[])
}
lan_discovery_kill(broadcast);
kill_TCP_server(tcp_server);
kill_tcp_server(tcp_server);
kill_onion_announce(onion_a);
kill_gca(group_announce);
kill_onion(onion);

View File

@ -759,7 +759,7 @@ bool add_to_list(Node_format *nodes_list, uint32_t length, const uint8_t *pk, co
non_null()
static void get_close_nodes_inner(uint64_t cur_time, const uint8_t *public_key, Node_format *nodes_list,
Family sa_family, const Client_data *client_list, uint32_t client_list_length,
uint32_t *num_nodes_ptr, bool is_LAN,
uint32_t *num_nodes_ptr, bool is_lan,
bool want_announce)
{
if (!net_family_is_ipv4(sa_family) && !net_family_is_ipv6(sa_family) && !net_family_is_unspec(sa_family)) {
@ -794,7 +794,7 @@ static void get_close_nodes_inner(uint64_t cur_time, const uint8_t *public_key,
}
/* don't send LAN ips to non LAN peers */
if (ip_is_lan(&ipptp->ip_port.ip) && !is_LAN) {
if (ip_is_lan(&ipptp->ip_port.ip) && !is_lan) {
continue;
}
@ -828,27 +828,27 @@ static void get_close_nodes_inner(uint64_t cur_time, const uint8_t *public_key,
*/
non_null()
static int get_somewhat_close_nodes(const DHT *dht, const uint8_t *public_key, Node_format *nodes_list,
Family sa_family, bool is_LAN, bool want_announce)
Family sa_family, bool is_lan, bool want_announce)
{
uint32_t num_nodes = 0;
get_close_nodes_inner(dht->cur_time, public_key, nodes_list, sa_family,
dht->close_clientlist, LCLIENT_LIST, &num_nodes, is_LAN, want_announce);
dht->close_clientlist, LCLIENT_LIST, &num_nodes, is_lan, want_announce);
for (uint32_t i = 0; i < dht->num_friends; ++i) {
get_close_nodes_inner(dht->cur_time, public_key, nodes_list, sa_family,
dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS,
&num_nodes, is_LAN, want_announce);
&num_nodes, is_lan, want_announce);
}
return num_nodes;
}
int get_close_nodes(const DHT *dht, const uint8_t *public_key, Node_format *nodes_list, Family sa_family,
bool is_LAN, bool want_announce)
bool is_lan, bool want_announce)
{
memset(nodes_list, 0, MAX_SENT_NODES * sizeof(Node_format));
return get_somewhat_close_nodes(dht, public_key, nodes_list, sa_family,
is_LAN, want_announce);
is_lan, want_announce);
}
typedef struct DHT_Cmp_Data {
@ -1884,7 +1884,7 @@ static void do_dht_friends(DHT *dht)
* Send a get nodes request every GET_NODE_INTERVAL seconds to a random good node in the list.
*/
non_null()
static void do_Close(DHT *dht)
static void do_close(DHT *dht)
{
for (size_t i = 0; i < dht->num_to_bootstrap; ++i) {
dht_getnodes(dht, &dht->to_bootstrap[i].ip_port, dht->to_bootstrap[i].public_key, dht->self_public_key);
@ -2209,7 +2209,7 @@ static uint32_t routeone_to_friend(const DHT *dht, const uint8_t *friend_id, con
/*---------------------BEGINNING OF NAT PUNCHING FUNCTIONS--------------------------*/
non_null()
static int send_NATping(const DHT *dht, const uint8_t *public_key, uint64_t ping_id, uint8_t type)
static int send_nat_ping(const DHT *dht, const uint8_t *public_key, uint64_t ping_id, uint8_t type)
{
uint8_t data[sizeof(uint64_t) + 1];
uint8_t packet_data[MAX_CRYPTO_REQUEST_SIZE];
@ -2244,8 +2244,8 @@ static int send_NATping(const DHT *dht, const uint8_t *public_key, uint64_t ping
/** Handle a received ping request for. */
non_null()
static int handle_NATping(void *object, const IP_Port *source, const uint8_t *source_pubkey, const uint8_t *packet,
uint16_t length, void *userdata)
static int handle_nat_ping(void *object, const IP_Port *source, const uint8_t *source_pubkey, const uint8_t *packet,
uint16_t length, void *userdata)
{
if (length != sizeof(uint64_t) + 1) {
return 1;
@ -2265,7 +2265,7 @@ static int handle_NATping(void *object, const IP_Port *source, const uint8_t *so
if (packet[0] == NAT_PING_REQUEST) {
/* 1 is reply */
send_NATping(dht, source_pubkey, ping_id, NAT_PING_RESPONSE);
send_nat_ping(dht, source_pubkey, ping_id, NAT_PING_RESPONSE);
dht_friend->nat.recv_nat_ping_timestamp = mono_time_get(dht->mono_time);
return 0;
}
@ -2397,7 +2397,7 @@ static void punch_holes(DHT *dht, const IP *ip, const uint16_t *port_list, uint1
}
non_null()
static void do_NAT(DHT *dht)
static void do_nat(DHT *dht)
{
const uint64_t temp_time = mono_time_get(dht->mono_time);
@ -2411,7 +2411,7 @@ static void do_NAT(DHT *dht)
}
if (dht->friends_list[i].nat.nat_ping_timestamp + PUNCH_INTERVAL < temp_time) {
send_NATping(dht, dht->friends_list[i].public_key, dht->friends_list[i].nat.nat_ping_id, NAT_PING_REQUEST);
send_nat_ping(dht, dht->friends_list[i].public_key, dht->friends_list[i].nat.nat_ping_id, NAT_PING_REQUEST);
dht->friends_list[i].nat.nat_ping_timestamp = temp_time;
}
@ -2586,8 +2586,8 @@ void dht_callback_get_nodes_response(DHT *dht, dht_get_nodes_response_cb *functi
}
non_null(1, 2, 3) nullable(5)
static int handle_LANdiscovery(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
void *userdata)
static int handle_lan_discovery(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
void *userdata)
{
DHT *dht = (DHT *)object;
@ -2644,8 +2644,8 @@ DHT *new_dht(const Logger *log, const Memory *mem, const Random *rng, const Netw
networking_registerhandler(dht->net, NET_PACKET_GET_NODES, &handle_getnodes, dht);
networking_registerhandler(dht->net, NET_PACKET_SEND_NODES_IPV6, &handle_sendnodes_ipv6, dht);
networking_registerhandler(dht->net, NET_PACKET_CRYPTO, &cryptopacket_handle, dht);
networking_registerhandler(dht->net, NET_PACKET_LAN_DISCOVERY, &handle_LANdiscovery, dht);
cryptopacket_registerhandler(dht, CRYPTO_PACKET_NAT_PING, &handle_NATping, dht);
networking_registerhandler(dht->net, NET_PACKET_LAN_DISCOVERY, &handle_lan_discovery, dht);
cryptopacket_registerhandler(dht, CRYPTO_PACKET_NAT_PING, &handle_nat_ping, dht);
#ifdef CHECK_ANNOUNCE_NODE
networking_registerhandler(dht->net, NET_PACKET_DATA_SEARCH_RESPONSE, &handle_data_search_response, dht);
@ -2706,9 +2706,9 @@ void do_dht(DHT *dht)
dht_connect_after_load(dht);
}
do_Close(dht);
do_close(dht);
do_dht_friends(dht);
do_NAT(dht);
do_nat(dht);
ping_iterate(dht->ping);
}

View File

@ -394,7 +394,7 @@ void set_announce_node(DHT *dht, const uint8_t *public_key);
*/
non_null()
int get_close_nodes(const DHT *dht, const uint8_t *public_key, Node_format *nodes_list, Family sa_family,
bool is_LAN, bool want_announce);
bool is_lan, bool want_announce);
/** @brief Put up to max_num nodes in nodes from the random friends.

View File

@ -2640,7 +2640,7 @@ void do_messenger(Messenger *m, void *userdata)
}
if (m->tcp_server != nullptr) {
do_TCP_server(m->tcp_server, m->mono_time);
do_tcp_server(m->tcp_server, m->mono_time);
}
do_net_crypto(m->net_crypto, userdata);
@ -3664,7 +3664,7 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
#endif /* VANILLA_NACL */
if (options->tcp_server_port != 0) {
m->tcp_server = new_TCP_server(m->log, m->mem, m->rng, m->ns, options->ipv6enabled, 1,
m->tcp_server = new_tcp_server(m->log, m->mem, m->rng, m->ns, options->ipv6enabled, 1,
&options->tcp_server_port, dht_get_self_secret_key(m->dht),
m->onion, m->forwarding);
@ -3725,7 +3725,7 @@ void kill_messenger(Messenger *m)
}
if (m->tcp_server != nullptr) {
kill_TCP_server(m->tcp_server);
kill_tcp_server(m->tcp_server);
}
kill_onion(m->onion);

View File

@ -153,7 +153,7 @@ static int proxy_http_read_connection_response(const Logger *logger, const TCP_C
uint8_t data[16]; // draining works the best if the length is a power of 2
const TCP_Connection *con0 = &tcp_conn->con;
const int ret = read_TCP_packet(logger, con0->mem, con0->ns, con0->sock, data, sizeof(data) - 1, &con0->ip_port);
const int ret = read_tcp_packet(logger, con0->mem, con0->ns, con0->sock, data, sizeof(data) - 1, &con0->ip_port);
if (ret == -1) {
return 0;
@ -170,7 +170,7 @@ static int proxy_http_read_connection_response(const Logger *logger, const TCP_C
const uint16_t temp_data_size = min_u16(data_left, sizeof(temp_data));
const TCP_Connection *con = &tcp_conn->con;
if (read_TCP_packet(logger, con->mem, con->ns, con->sock, temp_data, temp_data_size,
if (read_tcp_packet(logger, con->mem, con->ns, con->sock, temp_data, temp_data_size,
&con->ip_port) == -1) {
LOGGER_ERROR(logger, "failed to drain TCP data (but ignoring failure)");
return 1;
@ -215,7 +215,7 @@ static int socks5_read_handshake_response(const Logger *logger, const TCP_Client
{
uint8_t data[2];
const TCP_Connection *con = &tcp_conn->con;
const int ret = read_TCP_packet(logger, con->mem, con->ns, con->sock, data, sizeof(data), &con->ip_port);
const int ret = read_tcp_packet(logger, con->mem, con->ns, con->sock, data, sizeof(data), &con->ip_port);
if (ret == -1) {
return 0;
@ -266,7 +266,7 @@ static int proxy_socks5_read_connection_response(const Logger *logger, const TCP
if (net_family_is_ipv4(tcp_conn->ip_port.ip.family)) {
uint8_t data[4 + sizeof(IP4) + sizeof(uint16_t)];
const TCP_Connection *con = &tcp_conn->con;
const int ret = read_TCP_packet(logger, con->mem, con->ns, con->sock, data, sizeof(data), &con->ip_port);
const int ret = read_tcp_packet(logger, con->mem, con->ns, con->sock, data, sizeof(data), &con->ip_port);
if (ret == -1) {
return 0;
@ -278,7 +278,7 @@ static int proxy_socks5_read_connection_response(const Logger *logger, const TCP
} else {
uint8_t data[4 + sizeof(IP6) + sizeof(uint16_t)];
const TCP_Connection *con = &tcp_conn->con;
int ret = read_TCP_packet(logger, con->mem, con->ns, con->sock, data, sizeof(data), &con->ip_port);
int ret = read_tcp_packet(logger, con->mem, con->ns, con->sock, data, sizeof(data), &con->ip_port);
if (ret == -1) {
return 0;
@ -350,7 +350,7 @@ int send_routing_request(const Logger *logger, TCP_Client_Connection *con, const
uint8_t packet[1 + CRYPTO_PUBLIC_KEY_SIZE];
packet[0] = TCP_PACKET_ROUTING_REQUEST;
memcpy(packet + 1, public_key, CRYPTO_PUBLIC_KEY_SIZE);
return write_packet_TCP_secure_connection(logger, &con->con, packet, sizeof(packet), true);
return write_packet_tcp_secure_connection(logger, &con->con, packet, sizeof(packet), true);
}
void routing_response_handler(TCP_Client_Connection *con, tcp_routing_response_cb *response_callback, void *object)
@ -390,7 +390,7 @@ int send_data(const Logger *logger, TCP_Client_Connection *con, uint8_t con_id,
VLA(uint8_t, packet, 1 + length);
packet[0] = con_id + NUM_RESERVED_PORTS;
memcpy(packet + 1, data, length);
return write_packet_TCP_secure_connection(logger, &con->con, packet, SIZEOF_VLA(packet), false);
return write_packet_tcp_secure_connection(logger, &con->con, packet, SIZEOF_VLA(packet), false);
}
/**
@ -409,7 +409,7 @@ int send_oob_packet(const Logger *logger, TCP_Client_Connection *con, const uint
packet[0] = TCP_PACKET_OOB_SEND;
memcpy(packet + 1, public_key, CRYPTO_PUBLIC_KEY_SIZE);
memcpy(packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, data, length);
return write_packet_TCP_secure_connection(logger, &con->con, packet, SIZEOF_VLA(packet), false);
return write_packet_tcp_secure_connection(logger, &con->con, packet, SIZEOF_VLA(packet), false);
}
@ -457,7 +457,7 @@ static int client_send_disconnect_notification(const Logger *logger, TCP_Client_
uint8_t packet[1 + 1];
packet[0] = TCP_PACKET_DISCONNECT_NOTIFICATION;
packet[1] = id;
return write_packet_TCP_secure_connection(logger, &con->con, packet, sizeof(packet), true);
return write_packet_tcp_secure_connection(logger, &con->con, packet, sizeof(packet), true);
}
/**
@ -474,7 +474,7 @@ static int tcp_send_ping_request(const Logger *logger, TCP_Client_Connection *co
uint8_t packet[1 + sizeof(uint64_t)];
packet[0] = TCP_PACKET_PING;
memcpy(packet + 1, &con->ping_request_id, sizeof(uint64_t));
const int ret = write_packet_TCP_secure_connection(logger, &con->con, packet, sizeof(packet), true);
const int ret = write_packet_tcp_secure_connection(logger, &con->con, packet, sizeof(packet), true);
if (ret == 1) {
con->ping_request_id = 0;
@ -497,7 +497,7 @@ static int tcp_send_ping_response(const Logger *logger, TCP_Client_Connection *c
uint8_t packet[1 + sizeof(uint64_t)];
packet[0] = TCP_PACKET_PONG;
memcpy(packet + 1, &con->ping_response_id, sizeof(uint64_t));
const int ret = write_packet_TCP_secure_connection(logger, &con->con, packet, sizeof(packet), true);
const int ret = write_packet_tcp_secure_connection(logger, &con->con, packet, sizeof(packet), true);
if (ret == 1) {
con->ping_response_id = 0;
@ -532,7 +532,7 @@ int send_onion_request(const Logger *logger, TCP_Client_Connection *con, const u
VLA(uint8_t, packet, 1 + length);
packet[0] = TCP_PACKET_ONION_REQUEST;
memcpy(packet + 1, data, length);
return write_packet_TCP_secure_connection(logger, &con->con, packet, SIZEOF_VLA(packet), false);
return write_packet_tcp_secure_connection(logger, &con->con, packet, SIZEOF_VLA(packet), false);
}
void onion_response_handler(TCP_Client_Connection *con, tcp_onion_response_cb *onion_callback, void *object)
@ -560,7 +560,7 @@ int send_forward_request_tcp(const Logger *logger, TCP_Client_Connection *con, c
}
memcpy(packet + 1 + ipport_length, data, length);
return write_packet_TCP_secure_connection(logger, &con->con, packet, 1 + ipport_length + length, false);
return write_packet_tcp_secure_connection(logger, &con->con, packet, 1 + ipport_length + length, false);
}
void forwarding_handler(TCP_Client_Connection *con, forwarded_response_cb *forwarded_response_callback, void *object)
@ -570,7 +570,7 @@ void forwarding_handler(TCP_Client_Connection *con, forwarded_response_cb *forwa
}
/** Create new TCP connection to ip_port/public_key */
TCP_Client_Connection *new_TCP_connection(
TCP_Client_Connection *new_tcp_connection(
const Logger *logger, const Memory *mem, const Mono_Time *mono_time, const Random *rng, const Network *ns,
const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *self_public_key, const uint8_t *self_secret_key,
const TCP_Proxy_Info *proxy_info)
@ -663,7 +663,7 @@ TCP_Client_Connection *new_TCP_connection(
}
non_null()
static int handle_TCP_client_routing_response(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length)
static int handle_tcp_client_routing_response(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length)
{
if (length != 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE) {
return -1;
@ -691,7 +691,7 @@ static int handle_TCP_client_routing_response(TCP_Client_Connection *conn, const
}
non_null()
static int handle_TCP_client_connection_notification(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length)
static int handle_tcp_client_connection_notification(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length)
{
if (length != 1 + 1) {
return -1;
@ -718,7 +718,7 @@ static int handle_TCP_client_connection_notification(TCP_Client_Connection *conn
}
non_null()
static int handle_TCP_client_disconnect_notification(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length)
static int handle_tcp_client_disconnect_notification(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length)
{
if (length != 1 + 1) {
return -1;
@ -749,7 +749,7 @@ static int handle_TCP_client_disconnect_notification(TCP_Client_Connection *conn
}
non_null()
static int handle_TCP_client_ping(const Logger *logger, TCP_Client_Connection *conn, const uint8_t *data, uint16_t length)
static int handle_tcp_client_ping(const Logger *logger, TCP_Client_Connection *conn, const uint8_t *data, uint16_t length)
{
if (length != 1 + sizeof(uint64_t)) {
return -1;
@ -763,7 +763,7 @@ static int handle_TCP_client_ping(const Logger *logger, TCP_Client_Connection *c
}
non_null()
static int handle_TCP_client_pong(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length)
static int handle_tcp_client_pong(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length)
{
if (length != 1 + sizeof(uint64_t)) {
return -1;
@ -784,7 +784,7 @@ static int handle_TCP_client_pong(TCP_Client_Connection *conn, const uint8_t *da
}
non_null(1, 2) nullable(4)
static int handle_TCP_client_oob_recv(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length, void *userdata)
static int handle_tcp_client_oob_recv(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length, void *userdata)
{
if (length <= 1 + CRYPTO_PUBLIC_KEY_SIZE) {
return -1;
@ -803,7 +803,7 @@ static int handle_TCP_client_oob_recv(TCP_Client_Connection *conn, const uint8_t
* @retval -1 on failure
*/
non_null(1, 2, 3) nullable(5)
static int handle_TCP_client_packet(const Logger *logger, TCP_Client_Connection *conn, const uint8_t *data,
static int handle_tcp_client_packet(const Logger *logger, TCP_Client_Connection *conn, const uint8_t *data,
uint16_t length, void *userdata)
{
if (length <= 1) {
@ -812,22 +812,22 @@ static int handle_TCP_client_packet(const Logger *logger, TCP_Client_Connection
switch (data[0]) {
case TCP_PACKET_ROUTING_RESPONSE:
return handle_TCP_client_routing_response(conn, data, length);
return handle_tcp_client_routing_response(conn, data, length);
case TCP_PACKET_CONNECTION_NOTIFICATION:
return handle_TCP_client_connection_notification(conn, data, length);
return handle_tcp_client_connection_notification(conn, data, length);
case TCP_PACKET_DISCONNECT_NOTIFICATION:
return handle_TCP_client_disconnect_notification(conn, data, length);
return handle_tcp_client_disconnect_notification(conn, data, length);
case TCP_PACKET_PING:
return handle_TCP_client_ping(logger, conn, data, length);
return handle_tcp_client_ping(logger, conn, data, length);
case TCP_PACKET_PONG:
return handle_TCP_client_pong(conn, data, length);
return handle_tcp_client_pong(conn, data, length);
case TCP_PACKET_OOB_RECV:
return handle_TCP_client_oob_recv(conn, data, length, userdata);
return handle_tcp_client_oob_recv(conn, data, length, userdata);
case TCP_PACKET_ONION_RESPONSE: {
if (conn->onion_callback != nullptr) {
@ -864,7 +864,7 @@ non_null(1, 2) nullable(3)
static bool tcp_process_packet(const Logger *logger, TCP_Client_Connection *conn, void *userdata)
{
uint8_t packet[MAX_PACKET_SIZE];
const int len = read_packet_TCP_secure_connection(logger, conn->con.mem, conn->con.ns, conn->con.sock, &conn->next_packet_length, conn->con.shared_key, conn->recv_nonce, packet, sizeof(packet), &conn->ip_port);
const int len = read_packet_tcp_secure_connection(logger, conn->con.mem, conn->con.ns, conn->con.sock, &conn->next_packet_length, conn->con.shared_key, conn->recv_nonce, packet, sizeof(packet), &conn->ip_port);
if (len == 0) {
return false;
@ -875,7 +875,7 @@ static bool tcp_process_packet(const Logger *logger, TCP_Client_Connection *conn
return false;
}
if (handle_TCP_client_packet(logger, conn, packet, len, userdata) == -1) {
if (handle_tcp_client_packet(logger, conn, packet, len, userdata) == -1) {
conn->status = TCP_CLIENT_DISCONNECTED;
return false;
}
@ -884,7 +884,7 @@ static bool tcp_process_packet(const Logger *logger, TCP_Client_Connection *conn
}
non_null(1, 2, 3) nullable(4)
static int do_confirmed_TCP(const Logger *logger, TCP_Client_Connection *conn, const Mono_Time *mono_time,
static int do_confirmed_tcp(const Logger *logger, TCP_Client_Connection *conn, const Mono_Time *mono_time,
void *userdata)
{
send_pending_data(logger, &conn->con);
@ -918,7 +918,7 @@ static int do_confirmed_TCP(const Logger *logger, TCP_Client_Connection *conn, c
}
/** Run the TCP connection */
void do_TCP_connection(const Logger *logger, const Mono_Time *mono_time,
void do_tcp_connection(const Logger *logger, const Mono_Time *mono_time,
TCP_Client_Connection *tcp_connection, void *userdata)
{
if (tcp_connection->status == TCP_CLIENT_DISCONNECTED) {
@ -982,7 +982,7 @@ void do_TCP_connection(const Logger *logger, const Mono_Time *mono_time,
if (tcp_connection->status == TCP_CLIENT_UNCONFIRMED) {
uint8_t data[TCP_SERVER_HANDSHAKE_SIZE];
const TCP_Connection *con = &tcp_connection->con;
const int len = read_TCP_packet(logger, con->mem, con->ns, con->sock, data, sizeof(data), &con->ip_port);
const int len = read_tcp_packet(logger, con->mem, con->ns, con->sock, data, sizeof(data), &con->ip_port);
if (sizeof(data) == len) {
if (handle_handshake(tcp_connection, data) == 0) {
@ -996,7 +996,7 @@ void do_TCP_connection(const Logger *logger, const Mono_Time *mono_time,
}
if (tcp_connection->status == TCP_CLIENT_CONFIRMED) {
do_confirmed_TCP(logger, tcp_connection, mono_time, userdata);
do_confirmed_tcp(logger, tcp_connection, mono_time, userdata);
}
if (tcp_connection->kill_at <= mono_time_get(mono_time)) {
@ -1005,7 +1005,7 @@ void do_TCP_connection(const Logger *logger, const Mono_Time *mono_time,
}
/** Kill the TCP connection */
void kill_TCP_connection(TCP_Client_Connection *tcp_connection)
void kill_tcp_connection(TCP_Client_Connection *tcp_connection)
{
if (tcp_connection == nullptr) {
return;

View File

@ -58,19 +58,19 @@ void tcp_con_set_custom_uint(TCP_Client_Connection *con, uint32_t value);
/** Create new TCP connection to ip_port/public_key */
non_null(1, 2, 3, 4, 5, 6, 7, 8, 9) nullable(10)
TCP_Client_Connection *new_TCP_connection(
TCP_Client_Connection *new_tcp_connection(
const Logger *logger, const Memory *mem, const Mono_Time *mono_time, const Random *rng, const Network *ns,
const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *self_public_key, const uint8_t *self_secret_key,
const TCP_Proxy_Info *proxy_info);
/** Run the TCP connection */
non_null(1, 2, 3) nullable(4)
void do_TCP_connection(const Logger *logger, const Mono_Time *mono_time,
void do_tcp_connection(const Logger *logger, const Mono_Time *mono_time,
TCP_Client_Connection *tcp_connection, void *userdata);
/** Kill the TCP connection */
nullable(1)
void kill_TCP_connection(TCP_Client_Connection *tcp_connection);
void kill_tcp_connection(TCP_Client_Connection *tcp_connection);
typedef int tcp_onion_response_cb(void *object, const uint8_t *data, uint16_t length, void *userdata);

View File

@ -129,7 +129,7 @@ static bool add_priority(TCP_Connection *con, const uint8_t *packet, uint16_t si
* @retval 0 if could not send packet.
* @retval -1 on failure (connection must be killed).
*/
int write_packet_TCP_secure_connection(const Logger *logger, TCP_Connection *con, const uint8_t *data, uint16_t length,
int write_packet_tcp_secure_connection(const Logger *logger, TCP_Connection *con, const uint8_t *data, uint16_t length,
bool priority)
{
if (length + CRYPTO_MAC_SIZE > MAX_PACKET_SIZE) {
@ -195,7 +195,7 @@ int write_packet_TCP_secure_connection(const Logger *logger, TCP_Connection *con
* return length on success
* return -1 on failure/no data in buffer.
*/
int read_TCP_packet(
int read_tcp_packet(
const Logger *logger, const Memory *mem, const Network *ns, Socket sock, uint8_t *data, uint16_t length, const IP_Port *ip_port)
{
const uint16_t count = net_socket_data_recv_buffer(ns, sock);
@ -223,7 +223,7 @@ int read_TCP_packet(
* return -1 on failure.
*/
non_null()
static uint16_t read_TCP_length(const Logger *logger, const Memory *mem, const Network *ns, Socket sock, const IP_Port *ip_port)
static uint16_t read_tcp_length(const Logger *logger, const Memory *mem, const Network *ns, Socket sock, const IP_Port *ip_port)
{
const uint16_t count = net_socket_data_recv_buffer(ns, sock);
@ -255,14 +255,14 @@ static uint16_t read_TCP_length(const Logger *logger, const Memory *mem, const N
* @retval 0 if could not read any packet.
* @retval -1 on failure (connection must be killed).
*/
int read_packet_TCP_secure_connection(
int read_packet_tcp_secure_connection(
const Logger *logger, const Memory *mem, const Network *ns,
Socket sock, uint16_t *next_packet_length,
const uint8_t *shared_key, uint8_t *recv_nonce, uint8_t *data,
uint16_t max_len, const IP_Port *ip_port)
{
if (*next_packet_length == 0) {
const uint16_t len = read_TCP_length(logger, mem, ns, sock, ip_port);
const uint16_t len = read_tcp_length(logger, mem, ns, sock, ip_port);
if (len == (uint16_t) -1) {
return -1;
@ -281,7 +281,7 @@ int read_packet_TCP_secure_connection(
}
VLA(uint8_t, data_encrypted, (int) *next_packet_length);
const int len_packet = read_TCP_packet(logger, mem, ns, sock, data_encrypted, *next_packet_length, ip_port);
const int len_packet = read_tcp_packet(logger, mem, ns, sock, data_encrypted, *next_packet_length, ip_port);
if (len_packet == -1) {
return 0;

View File

@ -99,7 +99,7 @@ int send_pending_data(const Logger *logger, TCP_Connection *con);
* @retval -1 on failure (connection must be killed).
*/
non_null()
int write_packet_TCP_secure_connection(
int write_packet_tcp_secure_connection(
const Logger *logger, TCP_Connection *con, const uint8_t *data, uint16_t length,
bool priority);
@ -109,7 +109,7 @@ int write_packet_TCP_secure_connection(
* return -1 on failure/no data in buffer.
*/
non_null()
int read_TCP_packet(
int read_tcp_packet(
const Logger *logger, const Memory *mem, const Network *ns, Socket sock, uint8_t *data, uint16_t length, const IP_Port *ip_port);
/**
@ -118,7 +118,7 @@ int read_TCP_packet(
* @retval -1 on failure (connection must be killed).
*/
non_null()
int read_packet_TCP_secure_connection(
int read_packet_tcp_secure_connection(
const Logger *logger, const Memory *mem, const Network *ns,
Socket sock, uint16_t *next_packet_length,
const uint8_t *shared_key, uint8_t *recv_nonce, uint8_t *data,

View File

@ -74,7 +74,7 @@ uint32_t tcp_connections_count(const TCP_Connections *tcp_c)
* @retval 0 if it succeeds.
*/
non_null()
static int realloc_TCP_Connection_to(const Memory *mem, TCP_Connection_to **array, size_t num)
static int realloc_tcp_connection_to(const Memory *mem, TCP_Connection_to **array, size_t num)
{
if (num == 0) {
mem_delete(mem, *array);
@ -95,7 +95,7 @@ static int realloc_TCP_Connection_to(const Memory *mem, TCP_Connection_to **arra
}
non_null()
static int realloc_TCP_con(const Memory *mem, TCP_con **array, size_t num)
static int realloc_tcp_con(const Memory *mem, TCP_con **array, size_t num)
{
if (num == 0) {
mem_delete(mem, *array);
@ -165,7 +165,7 @@ static int create_connection(TCP_Connections *tcp_c)
int id = -1;
if (realloc_TCP_Connection_to(tcp_c->mem, &tcp_c->connections, tcp_c->connections_length + 1) == 0) {
if (realloc_tcp_connection_to(tcp_c->mem, &tcp_c->connections, tcp_c->connections_length + 1) == 0) {
id = tcp_c->connections_length;
++tcp_c->connections_length;
tcp_c->connections[id] = empty_tcp_connection_to;
@ -190,7 +190,7 @@ static int create_tcp_connection(TCP_Connections *tcp_c)
int id = -1;
if (realloc_TCP_con(tcp_c->mem, &tcp_c->tcp_connections, tcp_c->tcp_connections_length + 1) == 0) {
if (realloc_tcp_con(tcp_c->mem, &tcp_c->tcp_connections, tcp_c->tcp_connections_length + 1) == 0) {
id = tcp_c->tcp_connections_length;
++tcp_c->tcp_connections_length;
tcp_c->tcp_connections[id] = empty_tcp_con;
@ -222,7 +222,7 @@ static int wipe_connection(TCP_Connections *tcp_c, int connections_number)
if (tcp_c->connections_length != i) {
tcp_c->connections_length = i;
if (realloc_TCP_Connection_to(tcp_c->mem, &tcp_c->connections, tcp_c->connections_length) != 0) {
if (realloc_tcp_connection_to(tcp_c->mem, &tcp_c->connections, tcp_c->connections_length) != 0) {
return -1;
}
}
@ -254,7 +254,7 @@ static int wipe_tcp_connection(TCP_Connections *tcp_c, int tcp_connections_numbe
if (tcp_c->tcp_connections_length != i) {
tcp_c->tcp_connections_length = i;
if (realloc_TCP_con(tcp_c->mem, &tcp_c->tcp_connections, tcp_c->tcp_connections_length) != 0) {
if (realloc_tcp_con(tcp_c->mem, &tcp_c->tcp_connections, tcp_c->tcp_connections_length) != 0) {
return -1;
}
}
@ -903,7 +903,7 @@ int kill_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connections_number
--tcp_c->onion_num_conns;
}
kill_TCP_connection(tcp_con->connection);
kill_tcp_connection(tcp_con->connection);
return wipe_tcp_connection(tcp_c, tcp_connections_number);
}
@ -924,8 +924,8 @@ static int reconnect_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connec
IP_Port ip_port = tcp_con_ip_port(tcp_con->connection);
uint8_t relay_pk[CRYPTO_PUBLIC_KEY_SIZE];
memcpy(relay_pk, tcp_con_public_key(tcp_con->connection), CRYPTO_PUBLIC_KEY_SIZE);
kill_TCP_connection(tcp_con->connection);
tcp_con->connection = new_TCP_connection(tcp_c->logger, tcp_c->mem, tcp_c->mono_time, tcp_c->rng, tcp_c->ns, &ip_port, relay_pk, tcp_c->self_public_key, tcp_c->self_secret_key, &tcp_c->proxy_info);
kill_tcp_connection(tcp_con->connection);
tcp_con->connection = new_tcp_connection(tcp_c->logger, tcp_c->mem, tcp_c->mono_time, tcp_c->rng, tcp_c->ns, &ip_port, relay_pk, tcp_c->self_public_key, tcp_c->self_secret_key, &tcp_c->proxy_info);
if (tcp_con->connection == nullptr) {
kill_tcp_relay_connection(tcp_c, tcp_connections_number);
@ -974,7 +974,7 @@ static int sleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connection
tcp_con->ip_port = tcp_con_ip_port(tcp_con->connection);
memcpy(tcp_con->relay_pk, tcp_con_public_key(tcp_con->connection), CRYPTO_PUBLIC_KEY_SIZE);
kill_TCP_connection(tcp_con->connection);
kill_tcp_connection(tcp_con->connection);
tcp_con->connection = nullptr;
for (uint32_t i = 0; i < tcp_c->connections_length; ++i) {
@ -1012,7 +1012,7 @@ static int unsleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connecti
return -1;
}
tcp_con->connection = new_TCP_connection(
tcp_con->connection = new_tcp_connection(
tcp_c->logger, tcp_c->mem, tcp_c->mono_time, tcp_c->rng, tcp_c->ns, &tcp_con->ip_port,
tcp_con->relay_pk, tcp_c->self_public_key, tcp_c->self_secret_key, &tcp_c->proxy_info);
@ -1308,7 +1308,7 @@ static int add_tcp_relay_instance(TCP_Connections *tcp_c, const IP_Port *ip_port
TCP_con *tcp_con = &tcp_c->tcp_connections[tcp_connections_number];
tcp_con->connection = new_TCP_connection(
tcp_con->connection = new_tcp_connection(
tcp_c->logger, tcp_c->mem, tcp_c->mono_time, tcp_c->rng, tcp_c->ns, &ipp_copy,
relay_pk, tcp_c->self_public_key, tcp_c->self_secret_key, &tcp_c->proxy_info);
@ -1628,7 +1628,7 @@ static void do_tcp_conns(const Logger *logger, TCP_Connections *tcp_c, void *use
}
if (tcp_con->status != TCP_CONN_SLEEPING) {
do_TCP_connection(logger, tcp_c->mono_time, tcp_con->connection, userdata);
do_tcp_connection(logger, tcp_c->mono_time, tcp_con->connection, userdata);
/* callbacks can change TCP connection address. */
tcp_con = get_tcp_connection(tcp_c, i);
@ -1713,7 +1713,7 @@ void kill_tcp_connections(TCP_Connections *tcp_c)
}
for (uint32_t i = 0; i < tcp_c->tcp_connections_length; ++i) {
kill_TCP_connection(tcp_c->tcp_connections[i].connection);
kill_tcp_connection(tcp_c->tcp_connections[i].connection);
}
crypto_memzero(tcp_c->self_secret_key, sizeof(tcp_c->self_secret_key));

View File

@ -172,7 +172,7 @@ static void free_accepted_connection_array(TCP_Server *tcp_server)
* @retval -1 on failure.
*/
non_null()
static int get_TCP_connection_index(const TCP_Server *tcp_server, const uint8_t *public_key)
static int get_tcp_connection_index(const TCP_Server *tcp_server, const uint8_t *public_key)
{
return bs_list_find(&tcp_server->accepted_key_list, public_key);
}
@ -189,7 +189,7 @@ static int kill_accepted(TCP_Server *tcp_server, int index);
non_null()
static int add_accepted(TCP_Server *tcp_server, const Mono_Time *mono_time, TCP_Secure_Connection *con)
{
int index = get_TCP_connection_index(tcp_server, con->public_key);
int index = get_tcp_connection_index(tcp_server, con->public_key);
if (index != -1) { /* If an old connection to the same public key exists, kill it. */
kill_accepted(tcp_server, index);
@ -263,7 +263,7 @@ static int del_accepted(TCP_Server *tcp_server, int index)
/** Kill a TCP_Secure_Connection */
non_null()
static void kill_TCP_secure_connection(TCP_Secure_Connection *con)
static void kill_tcp_secure_connection(TCP_Secure_Connection *con)
{
kill_sock(con->con.ns, con->con.sock);
wipe_secure_connection(con);
@ -302,7 +302,7 @@ static int kill_accepted(TCP_Server *tcp_server, int index)
* @retval -1 if the connection must be killed.
*/
non_null()
static int handle_TCP_handshake(const Logger *logger, TCP_Secure_Connection *con, const uint8_t *data, uint16_t length,
static int handle_tcp_handshake(const Logger *logger, TCP_Secure_Connection *con, const uint8_t *data, uint16_t length,
const uint8_t *self_secret_key)
{
if (length != TCP_CLIENT_HANDSHAKE_SIZE) {
@ -370,14 +370,14 @@ non_null()
static int read_connection_handshake(const Logger *logger, TCP_Secure_Connection *con, const uint8_t *self_secret_key)
{
uint8_t data[TCP_CLIENT_HANDSHAKE_SIZE];
const int len = read_TCP_packet(logger, con->con.mem, con->con.ns, con->con.sock, data, TCP_CLIENT_HANDSHAKE_SIZE, &con->con.ip_port);
const int len = read_tcp_packet(logger, con->con.mem, con->con.ns, con->con.sock, data, TCP_CLIENT_HANDSHAKE_SIZE, &con->con.ip_port);
if (len == -1) {
LOGGER_TRACE(logger, "connection handshake is not ready yet");
return 0;
}
return handle_TCP_handshake(logger, con, data, len, self_secret_key);
return handle_tcp_handshake(logger, con, data, len, self_secret_key);
}
/**
@ -394,7 +394,7 @@ static int send_routing_response(const Logger *logger, TCP_Secure_Connection *co
data[1] = rpid;
memcpy(data + 2, public_key, CRYPTO_PUBLIC_KEY_SIZE);
return write_packet_TCP_secure_connection(logger, &con->con, data, sizeof(data), true);
return write_packet_tcp_secure_connection(logger, &con->con, data, sizeof(data), true);
}
/**
@ -406,7 +406,7 @@ non_null()
static int send_connect_notification(const Logger *logger, TCP_Secure_Connection *con, uint8_t id)
{
uint8_t data[2] = {TCP_PACKET_CONNECTION_NOTIFICATION, (uint8_t)(id + NUM_RESERVED_PORTS)};
return write_packet_TCP_secure_connection(logger, &con->con, data, sizeof(data), true);
return write_packet_tcp_secure_connection(logger, &con->con, data, sizeof(data), true);
}
/**
@ -418,7 +418,7 @@ non_null()
static int send_disconnect_notification(const Logger *logger, TCP_Secure_Connection *con, uint8_t id)
{
uint8_t data[2] = {TCP_PACKET_DISCONNECT_NOTIFICATION, (uint8_t)(id + NUM_RESERVED_PORTS)};
return write_packet_TCP_secure_connection(logger, &con->con, data, sizeof(data), true);
return write_packet_tcp_secure_connection(logger, &con->con, data, sizeof(data), true);
}
/**
@ -426,7 +426,7 @@ static int send_disconnect_notification(const Logger *logger, TCP_Secure_Connect
* @retval -1 on failure (connection must be killed).
*/
non_null()
static int handle_TCP_routing_req(TCP_Server *tcp_server, uint32_t con_id, const uint8_t *public_key)
static int handle_tcp_routing_req(TCP_Server *tcp_server, uint32_t con_id, const uint8_t *public_key)
{
uint32_t index = -1;
TCP_Secure_Connection *con = &tcp_server->accepted_connection_array[con_id];
@ -474,7 +474,7 @@ static int handle_TCP_routing_req(TCP_Server *tcp_server, uint32_t con_id, const
con->connections[index].status = 1;
memcpy(con->connections[index].public_key, public_key, CRYPTO_PUBLIC_KEY_SIZE);
const int other_index = get_TCP_connection_index(tcp_server, public_key);
const int other_index = get_tcp_connection_index(tcp_server, public_key);
if (other_index != -1) {
uint32_t other_id = -1;
@ -509,7 +509,7 @@ static int handle_TCP_routing_req(TCP_Server *tcp_server, uint32_t con_id, const
* @retval -1 on failure (connection must be killed).
*/
non_null()
static int handle_TCP_oob_send(TCP_Server *tcp_server, uint32_t con_id, const uint8_t *public_key, const uint8_t *data,
static int handle_tcp_oob_send(TCP_Server *tcp_server, uint32_t con_id, const uint8_t *public_key, const uint8_t *data,
uint16_t length)
{
if (length == 0 || length > TCP_MAX_OOB_DATA_LENGTH) {
@ -518,14 +518,14 @@ static int handle_TCP_oob_send(TCP_Server *tcp_server, uint32_t con_id, const ui
const TCP_Secure_Connection *con = &tcp_server->accepted_connection_array[con_id];
const int other_index = get_TCP_connection_index(tcp_server, public_key);
const int other_index = get_tcp_connection_index(tcp_server, public_key);
if (other_index != -1) {
VLA(uint8_t, resp_packet, 1 + CRYPTO_PUBLIC_KEY_SIZE + length);
resp_packet[0] = TCP_PACKET_OOB_RECV;
memcpy(resp_packet + 1, con->public_key, CRYPTO_PUBLIC_KEY_SIZE);
memcpy(resp_packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, data, length);
write_packet_TCP_secure_connection(tcp_server->logger, &tcp_server->accepted_connection_array[other_index].con,
write_packet_tcp_secure_connection(tcp_server->logger, &tcp_server->accepted_connection_array[other_index].con,
resp_packet, SIZEOF_VLA(resp_packet), false);
}
@ -613,7 +613,7 @@ static int handle_onion_recv_1(void *object, const IP_Port *dest, const uint8_t
memcpy(packet + 1, data, length);
packet[0] = TCP_PACKET_ONION_RESPONSE;
if (write_packet_TCP_secure_connection(tcp_server->logger, &con->con, packet, SIZEOF_VLA(packet), false) != 1) {
if (write_packet_tcp_secure_connection(tcp_server->logger, &con->con, packet, SIZEOF_VLA(packet), false) != 1) {
return 1;
}
@ -653,7 +653,7 @@ static bool handle_forward_reply_tcp(void *object, const uint8_t *sendback_data,
memcpy(packet + 1, data, length);
packet[0] = TCP_PACKET_FORWARDING;
return write_packet_TCP_secure_connection(tcp_server->logger, &con->con, packet, SIZEOF_VLA(packet), false) == 1;
return write_packet_tcp_secure_connection(tcp_server->logger, &con->con, packet, SIZEOF_VLA(packet), false) == 1;
}
/**
@ -661,7 +661,7 @@ static bool handle_forward_reply_tcp(void *object, const uint8_t *sendback_data,
* @retval -1 on failure
*/
non_null()
static int handle_TCP_packet(TCP_Server *tcp_server, uint32_t con_id, const uint8_t *data, uint16_t length)
static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint8_t *data, uint16_t length)
{
if (length == 0) {
return -1;
@ -676,7 +676,7 @@ static int handle_TCP_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
}
LOGGER_TRACE(tcp_server->logger, "handling routing request for %d", con_id);
return handle_TCP_routing_req(tcp_server, con_id, data + 1);
return handle_tcp_routing_req(tcp_server, con_id, data + 1);
}
case TCP_PACKET_CONNECTION_NOTIFICATION: {
@ -707,7 +707,7 @@ static int handle_TCP_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
uint8_t response[1 + sizeof(uint64_t)];
response[0] = TCP_PACKET_PONG;
memcpy(response + 1, data + 1, sizeof(uint64_t));
write_packet_TCP_secure_connection(tcp_server->logger, &con->con, response, sizeof(response), true);
write_packet_tcp_secure_connection(tcp_server->logger, &con->con, response, sizeof(response), true);
return 0;
}
@ -739,7 +739,7 @@ static int handle_TCP_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
LOGGER_TRACE(tcp_server->logger, "handling oob send for %d", con_id);
return handle_TCP_oob_send(tcp_server, con_id, data + 1, data + 1 + CRYPTO_PUBLIC_KEY_SIZE,
return handle_tcp_oob_send(tcp_server, con_id, data + 1, data + 1 + CRYPTO_PUBLIC_KEY_SIZE,
length - (1 + CRYPTO_PUBLIC_KEY_SIZE));
}
@ -822,7 +822,7 @@ static int handle_TCP_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
VLA(uint8_t, new_data, length);
memcpy(new_data, data, length);
new_data[0] = other_c_id;
const int ret = write_packet_TCP_secure_connection(tcp_server->logger,
const int ret = write_packet_tcp_secure_connection(tcp_server->logger,
&tcp_server->accepted_connection_array[index].con, new_data, length, false);
if (ret == -1) {
@ -838,20 +838,20 @@ static int handle_TCP_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
non_null()
static int confirm_TCP_connection(TCP_Server *tcp_server, const Mono_Time *mono_time, TCP_Secure_Connection *con,
static int confirm_tcp_connection(TCP_Server *tcp_server, const Mono_Time *mono_time, TCP_Secure_Connection *con,
const uint8_t *data, uint16_t length)
{
const int index = add_accepted(tcp_server, mono_time, con);
if (index == -1) {
LOGGER_DEBUG(tcp_server->logger, "dropping connection %u: not accepted", (unsigned int)con->identifier);
kill_TCP_secure_connection(con);
kill_tcp_secure_connection(con);
return -1;
}
wipe_secure_connection(con);
if (handle_TCP_packet(tcp_server, index, data, length) == -1) {
if (handle_tcp_packet(tcp_server, index, data, length) == -1) {
LOGGER_DEBUG(tcp_server->logger, "dropping connection %u: data packet (len=%d) not handled",
(unsigned int)con->identifier, length);
kill_accepted(tcp_server, index);
@ -888,7 +888,7 @@ static int accept_connection(TCP_Server *tcp_server, Socket sock)
if (conn->status != TCP_STATUS_NO_STATUS) {
LOGGER_DEBUG(tcp_server->logger, "connection %d dropped before accepting", index);
kill_TCP_secure_connection(conn);
kill_tcp_secure_connection(conn);
}
conn->status = TCP_STATUS_CONNECTED;
@ -903,7 +903,7 @@ static int accept_connection(TCP_Server *tcp_server, Socket sock)
}
non_null()
static Socket new_listening_TCP_socket(const Logger *logger, const Network *ns, Family family, uint16_t port)
static Socket new_listening_tcp_socket(const Logger *logger, const Network *ns, Family family, uint16_t port)
{
const Socket sock = net_socket(ns, family, TOX_SOCK_STREAM, TOX_PROTO_TCP);
@ -937,7 +937,7 @@ static Socket new_listening_TCP_socket(const Logger *logger, const Network *ns,
return sock;
}
TCP_Server *new_TCP_server(const Logger *logger, const Memory *mem, const Random *rng, const Network *ns,
TCP_Server *new_tcp_server(const Logger *logger, const Memory *mem, const Random *rng, const Network *ns,
bool ipv6_enabled, uint16_t num_sockets,
const uint16_t *ports, const uint8_t *secret_key, Onion *onion, Forwarding *forwarding)
{
@ -986,7 +986,7 @@ TCP_Server *new_TCP_server(const Logger *logger, const Memory *mem, const Random
const Family family = ipv6_enabled ? net_family_ipv6() : net_family_ipv4();
for (uint32_t i = 0; i < num_sockets; ++i) {
const Socket sock = new_listening_TCP_socket(logger, ns, family, ports[i]);
const Socket sock = new_listening_tcp_socket(logger, ns, family, ports[i]);
if (!sock_valid(sock)) {
continue;
@ -1034,7 +1034,7 @@ TCP_Server *new_TCP_server(const Logger *logger, const Memory *mem, const Random
#ifndef TCP_SERVER_USE_EPOLL
non_null()
static void do_TCP_accept_new(TCP_Server *tcp_server)
static void do_tcp_accept_new(TCP_Server *tcp_server)
{
for (uint32_t sock_idx = 0; sock_idx < tcp_server->num_listening_socks; ++sock_idx) {
@ -1064,7 +1064,7 @@ static int do_incoming(TCP_Server *tcp_server, uint32_t i)
if (ret == -1) {
LOGGER_TRACE(tcp_server->logger, "incoming connection %d dropped due to failed handshake", i);
kill_TCP_secure_connection(conn);
kill_tcp_secure_connection(conn);
return -1;
}
@ -1078,7 +1078,7 @@ static int do_incoming(TCP_Server *tcp_server, uint32_t i)
if (conn_new->status != TCP_STATUS_NO_STATUS) {
LOGGER_ERROR(tcp_server->logger, "incoming connection %d would overwrite existing", i);
kill_TCP_secure_connection(conn_new);
kill_tcp_secure_connection(conn_new);
}
move_secure_connection(conn_new, conn_old);
@ -1099,18 +1099,18 @@ static int do_unconfirmed(TCP_Server *tcp_server, const Mono_Time *mono_time, ui
LOGGER_TRACE(tcp_server->logger, "handling unconfirmed TCP connection %d", i);
uint8_t packet[MAX_PACKET_SIZE];
const int len = read_packet_TCP_secure_connection(tcp_server->logger, conn->con.mem, conn->con.ns, conn->con.sock, &conn->next_packet_length, conn->con.shared_key, conn->recv_nonce, packet, sizeof(packet), &conn->con.ip_port);
const int len = read_packet_tcp_secure_connection(tcp_server->logger, conn->con.mem, conn->con.ns, conn->con.sock, &conn->next_packet_length, conn->con.shared_key, conn->recv_nonce, packet, sizeof(packet), &conn->con.ip_port);
if (len == 0) {
return -1;
}
if (len == -1) {
kill_TCP_secure_connection(conn);
kill_tcp_secure_connection(conn);
return -1;
}
return confirm_TCP_connection(tcp_server, mono_time, conn, packet, len);
return confirm_tcp_connection(tcp_server, mono_time, conn, packet, len);
}
non_null()
@ -1119,7 +1119,7 @@ static bool tcp_process_secure_packet(TCP_Server *tcp_server, uint32_t i)
TCP_Secure_Connection *const conn = &tcp_server->accepted_connection_array[i];
uint8_t packet[MAX_PACKET_SIZE];
const int len = read_packet_TCP_secure_connection(tcp_server->logger, conn->con.mem, conn->con.ns, conn->con.sock, &conn->next_packet_length, conn->con.shared_key, conn->recv_nonce, packet, sizeof(packet), &conn->con.ip_port);
const int len = read_packet_tcp_secure_connection(tcp_server->logger, conn->con.mem, conn->con.ns, conn->con.sock, &conn->next_packet_length, conn->con.shared_key, conn->recv_nonce, packet, sizeof(packet), &conn->con.ip_port);
LOGGER_TRACE(tcp_server->logger, "processing packet for %d: %d", i, len);
if (len == 0) {
@ -1131,7 +1131,7 @@ static bool tcp_process_secure_packet(TCP_Server *tcp_server, uint32_t i)
return false;
}
if (handle_TCP_packet(tcp_server, i, packet, len) == -1) {
if (handle_tcp_packet(tcp_server, i, packet, len) == -1) {
LOGGER_TRACE(tcp_server->logger, "dropping connection %d: data packet (len=%d) not handled", i, len);
kill_accepted(tcp_server, i);
return false;
@ -1151,7 +1151,7 @@ static void do_confirmed_recv(TCP_Server *tcp_server, uint32_t i)
#ifndef TCP_SERVER_USE_EPOLL
non_null()
static void do_TCP_incoming(TCP_Server *tcp_server)
static void do_tcp_incoming(TCP_Server *tcp_server)
{
for (uint32_t i = 0; i < MAX_INCOMING_CONNECTIONS; ++i) {
do_incoming(tcp_server, i);
@ -1159,7 +1159,7 @@ static void do_TCP_incoming(TCP_Server *tcp_server)
}
non_null()
static void do_TCP_unconfirmed(TCP_Server *tcp_server, const Mono_Time *mono_time)
static void do_tcp_unconfirmed(TCP_Server *tcp_server, const Mono_Time *mono_time)
{
for (uint32_t i = 0; i < MAX_INCOMING_CONNECTIONS; ++i) {
do_unconfirmed(tcp_server, mono_time, i);
@ -1168,7 +1168,7 @@ static void do_TCP_unconfirmed(TCP_Server *tcp_server, const Mono_Time *mono_tim
#endif
non_null()
static void do_TCP_confirmed(TCP_Server *tcp_server, const Mono_Time *mono_time)
static void do_tcp_confirmed(TCP_Server *tcp_server, const Mono_Time *mono_time)
{
#ifdef TCP_SERVER_USE_EPOLL
@ -1196,7 +1196,7 @@ static void do_TCP_confirmed(TCP_Server *tcp_server, const Mono_Time *mono_time)
}
memcpy(ping + 1, &ping_id, sizeof(uint64_t));
const int ret = write_packet_TCP_secure_connection(tcp_server->logger, &conn->con, ping, sizeof(ping), true);
const int ret = write_packet_tcp_secure_connection(tcp_server->logger, &conn->con, ping, sizeof(ping), true);
if (ret == 1) {
conn->last_pinged = mono_time_get(mono_time);
@ -1248,13 +1248,13 @@ static bool tcp_epoll_process(TCP_Server *tcp_server, const Mono_Time *mono_time
case TCP_SOCKET_INCOMING: {
LOGGER_TRACE(tcp_server->logger, "incoming connection %d dropped", index);
kill_TCP_secure_connection(&tcp_server->incoming_connection_queue[index]);
kill_tcp_secure_connection(&tcp_server->incoming_connection_queue[index]);
break;
}
case TCP_SOCKET_UNCONFIRMED: {
LOGGER_TRACE(tcp_server->logger, "unconfirmed connection %d dropped", index);
kill_TCP_secure_connection(&tcp_server->unconfirmed_connection_queue[index]);
kill_tcp_secure_connection(&tcp_server->unconfirmed_connection_queue[index]);
break;
}
@ -1297,7 +1297,7 @@ static bool tcp_epoll_process(TCP_Server *tcp_server, const Mono_Time *mono_time
if (epoll_ctl(tcp_server->efd, EPOLL_CTL_ADD, sock_new.sock, &ev) == -1) {
LOGGER_DEBUG(tcp_server->logger, "new connection %d was dropped due to epoll error %d", index, net_error());
kill_TCP_secure_connection(&tcp_server->incoming_connection_queue[index_new]);
kill_tcp_secure_connection(&tcp_server->incoming_connection_queue[index_new]);
continue;
}
}
@ -1315,7 +1315,7 @@ static bool tcp_epoll_process(TCP_Server *tcp_server, const Mono_Time *mono_time
if (epoll_ctl(tcp_server->efd, EPOLL_CTL_MOD, sock.sock, &events[n]) == -1) {
LOGGER_DEBUG(tcp_server->logger, "incoming connection %d was dropped due to epoll error %d", index, net_error());
kill_TCP_secure_connection(&tcp_server->unconfirmed_connection_queue[index_new]);
kill_tcp_secure_connection(&tcp_server->unconfirmed_connection_queue[index_new]);
break;
}
}
@ -1353,7 +1353,7 @@ static bool tcp_epoll_process(TCP_Server *tcp_server, const Mono_Time *mono_time
}
non_null()
static void do_TCP_epoll(TCP_Server *tcp_server, const Mono_Time *mono_time)
static void do_tcp_epoll(TCP_Server *tcp_server, const Mono_Time *mono_time)
{
while (tcp_epoll_process(tcp_server, mono_time)) {
// Keep processing packets until there are no more FDs ready for reading.
@ -1362,21 +1362,21 @@ static void do_TCP_epoll(TCP_Server *tcp_server, const Mono_Time *mono_time)
}
#endif
void do_TCP_server(TCP_Server *tcp_server, const Mono_Time *mono_time)
void do_tcp_server(TCP_Server *tcp_server, const Mono_Time *mono_time)
{
#ifdef TCP_SERVER_USE_EPOLL
do_TCP_epoll(tcp_server, mono_time);
do_tcp_epoll(tcp_server, mono_time);
#else
do_TCP_accept_new(tcp_server);
do_TCP_incoming(tcp_server);
do_TCP_unconfirmed(tcp_server, mono_time);
do_tcp_accept_new(tcp_server);
do_tcp_incoming(tcp_server);
do_tcp_unconfirmed(tcp_server, mono_time);
#endif
do_TCP_confirmed(tcp_server, mono_time);
do_tcp_confirmed(tcp_server, mono_time);
}
void kill_TCP_server(TCP_Server *tcp_server)
void kill_tcp_server(TCP_Server *tcp_server)
{
if (tcp_server == nullptr) {
return;

View File

@ -35,17 +35,17 @@ size_t tcp_server_listen_count(const TCP_Server *tcp_server);
/** Create new TCP server instance. */
non_null(1, 2, 3, 4, 7, 8) nullable(9, 10)
TCP_Server *new_TCP_server(const Logger *logger, const Memory *mem, const Random *rng, const Network *ns,
TCP_Server *new_tcp_server(const Logger *logger, const Memory *mem, const Random *rng, const Network *ns,
bool ipv6_enabled, uint16_t num_sockets, const uint16_t *ports,
const uint8_t *secret_key, Onion *onion, Forwarding *forwarding);
/** Run the TCP_server */
non_null()
void do_TCP_server(TCP_Server *tcp_server, const Mono_Time *mono_time);
void do_tcp_server(TCP_Server *tcp_server, const Mono_Time *mono_time);
/** Kill the TCP server */
nullable(1)
void kill_TCP_server(TCP_Server *tcp_server);
void kill_tcp_server(TCP_Server *tcp_server);
#endif

View File

@ -461,7 +461,7 @@ static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_pub
}
friend_new_connection(fr_c, number);
onion_set_friend_DHT_pubkey(fr_c->onion_c, friend_con->onion_friendnum, dht_public_key);
onion_set_friend_dht_pubkey(fr_c->onion_c, friend_con->onion_friendnum, dht_public_key);
}
non_null()

View File

@ -5691,13 +5691,13 @@ static int handle_gc_handshake_request(GC_Chat *chat, const IP_Port *ipp, const
return -1;
}
if (chat->connection_O_metre >= GC_NEW_PEER_CONNECTION_LIMIT) {
if (chat->connection_o_metre >= GC_NEW_PEER_CONNECTION_LIMIT) {
chat->block_handshakes = true;
LOGGER_DEBUG(chat->log, "Handshake overflow. Blocking handshakes.");
return -1;
}
++chat->connection_O_metre;
++chat->connection_o_metre;
const uint8_t *public_sig_key = data + ENC_PUBLIC_KEY_SIZE;
@ -7015,7 +7015,7 @@ static void do_gc_ping_and_key_rotation(GC_Chat *chat)
non_null()
static void do_new_connection_cooldown(GC_Chat *chat)
{
if (chat->connection_O_metre == 0) {
if (chat->connection_o_metre == 0) {
return;
}
@ -7023,9 +7023,9 @@ static void do_new_connection_cooldown(GC_Chat *chat)
if (chat->connection_cooldown_timer < tm) {
chat->connection_cooldown_timer = tm;
--chat->connection_O_metre;
--chat->connection_o_metre;
if (chat->connection_O_metre == 0 && chat->block_handshakes) {
if (chat->connection_o_metre == 0 && chat->block_handshakes) {
chat->block_handshakes = false;
LOGGER_DEBUG(chat->log, "Unblocking handshakes");
}

View File

@ -292,7 +292,7 @@ typedef struct GC_Chat {
uint64_t last_time_peers_loaded;
/* keeps track of frequency of new inbound connections */
uint8_t connection_O_metre;
uint8_t connection_o_metre;
uint64_t connection_cooldown_timer;
bool block_handshakes;

View File

@ -139,15 +139,15 @@ static const char *inet_ntop6(const struct in6_addr *addr, char *buf, size_t buf
}
non_null()
static int inet_pton4(const char *addrString, struct in_addr *addrbuf)
static int inet_pton4(const char *addr_string, struct in_addr *addrbuf)
{
return inet_pton(AF_INET, addrString, addrbuf);
return inet_pton(AF_INET, addr_string, addrbuf);
}
non_null()
static int inet_pton6(const char *addrString, struct in6_addr *addrbuf)
static int inet_pton6(const char *addr_string, struct in6_addr *addrbuf)
{
return inet_pton(AF_INET6, addrString, addrbuf);
return inet_pton(AF_INET6, addr_string, addrbuf);
}
#else
@ -377,47 +377,47 @@ IP6 get_ip6_loopback(void)
const Socket net_invalid_socket = { (int)INVALID_SOCKET };
Family net_family_unspec()
Family net_family_unspec(void)
{
return family_unspec;
}
Family net_family_ipv4()
Family net_family_ipv4(void)
{
return family_ipv4;
}
Family net_family_ipv6()
Family net_family_ipv6(void)
{
return family_ipv6;
}
Family net_family_tcp_server()
Family net_family_tcp_server(void)
{
return family_tcp_server;
}
Family net_family_tcp_client()
Family net_family_tcp_client(void)
{
return family_tcp_client;
}
Family net_family_tcp_ipv4()
Family net_family_tcp_ipv4(void)
{
return family_tcp_ipv4;
}
Family net_family_tcp_ipv6()
Family net_family_tcp_ipv6(void)
{
return family_tcp_ipv6;
}
Family net_family_tox_tcp_ipv4()
Family net_family_tox_tcp_ipv4(void)
{
return family_tox_tcp_ipv4;
}
Family net_family_tox_tcp_ipv6()
Family net_family_tox_tcp_ipv6(void)
{
return family_tox_tcp_ipv6;
}

View File

@ -1162,7 +1162,7 @@ static int handle_dhtpk_announce(void *object, const uint8_t *source_pubkey, con
onion_c->friends_list[friend_num].dht_pk_callback_number, data + 1 + sizeof(uint64_t), userdata);
}
onion_set_friend_DHT_pubkey(onion_c, friend_num, data + 1 + sizeof(uint64_t));
onion_set_friend_dht_pubkey(onion_c, friend_num, data + 1 + sizeof(uint64_t));
const uint16_t len_nodes = length - DHTPK_DATA_MIN_LENGTH;
@ -1602,7 +1602,7 @@ int onion_dht_pk_callback(Onion_Client *onion_c, int friend_num,
* return -1 on failure.
* return 0 on success.
*/
int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uint8_t *dht_key)
int onion_set_friend_dht_pubkey(Onion_Client *onion_c, int friend_num, const uint8_t *dht_key)
{
if ((uint32_t)friend_num >= onion_c->num_friends) {
return -1;
@ -1629,7 +1629,7 @@ int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uin
* return 0 on failure (no key copied).
* return 1 on success (key copied).
*/
unsigned int onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_num, uint8_t *dht_key)
unsigned int onion_getfriend_dht_pubkey(const Onion_Client *onion_c, int friend_num, uint8_t *dht_key)
{
if ((uint32_t)friend_num >= onion_c->num_friends) {
return 0;
@ -1657,7 +1657,7 @@ int onion_getfriendip(const Onion_Client *onion_c, int friend_num, IP_Port *ip_p
{
uint8_t dht_public_key[CRYPTO_PUBLIC_KEY_SIZE];
if (onion_getfriend_DHT_pubkey(onion_c, friend_num, dht_public_key) == 0) {
if (onion_getfriend_dht_pubkey(onion_c, friend_num, dht_public_key) == 0) {
return -1;
}

View File

@ -165,7 +165,7 @@ int onion_dht_pk_callback(Onion_Client *onion_c, int friend_num, onion_dht_pk_cb
* return 0 on success.
*/
non_null()
int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uint8_t *dht_key);
int onion_set_friend_dht_pubkey(Onion_Client *onion_c, int friend_num, const uint8_t *dht_key);
/** @brief Copy friends DHT public key into dht_key.
*
@ -173,7 +173,7 @@ int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uin
* return 1 on success (key copied).
*/
non_null()
unsigned int onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_num, uint8_t *dht_key);
unsigned int onion_getfriend_dht_pubkey(const Onion_Client *onion_c, int friend_num, uint8_t *dht_key);
#define ONION_DATA_IN_RESPONSE_MIN_SIZE (CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE)
#define ONION_CLIENT_MAX_DATA_SIZE (MAX_DATA_REQUEST_SIZE - ONION_DATA_IN_RESPONSE_MIN_SIZE)