diff --git a/.circleci/config.yml b/.circleci/config.yml index 27d396fe2a7..a34a2dd9d07 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -144,10 +144,9 @@ jobs: - run: apt-get install -y --no-install-recommends ca-certificates - clang-tidy-12 + clang-tidy - 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 || diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 00000000000..1e8d0db5dc4 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,30 @@ +# vim:ft=yaml +CheckOptions: + - key: readability-identifier-naming.ClassCase + value: Camel_Snake_Case + - 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" + - 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 diff --git a/auto_tests/TCP_test.c b/auto_tests/TCP_test.c index d5455cf0e83..41e1d04ae60 100644 --- a/auto_tests/TCP_test.c +++ b/auto_tests/TCP_test.c @@ -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); @@ -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,7 +257,7 @@ 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); @@ -316,7 +316,7 @@ 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."); @@ -333,7 +333,7 @@ static void test_some(void) memcpy(requ_p + 1, con1->public_key, CRYPTO_PUBLIC_KEY_SIZE); 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]; @@ -356,7 +356,7 @@ static void test_some(void) 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); ck_assert_msg(len == 2, "wrong len %d", len); @@ -381,7 +381,7 @@ static void test_some(void) 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); + 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], @@ -398,7 +398,7 @@ static void test_some(void) 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)); - 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); ck_assert_msg(len == sizeof(ping_packet), "wrong len %d", len); @@ -406,10 +406,10 @@ static void test_some(void) 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; 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. } - 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); diff --git a/auto_tests/auto_test_support.c b/auto_tests/auto_test_support.c index cb409738ef4..6143c6353c1 100644 --- a/auto_tests/auto_test_support.c +++ b/auto_tests/auto_test_support.c @@ -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, diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index e59f9eedea2..330acb10d26 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c @@ -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"); @@ -247,7 +247,7 @@ int main(int argc, char *argv[]) } #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); diff --git a/other/analysis/run-clang-tidy b/other/analysis/run-clang-tidy index dd5320bdb1b..9a40f5ccb54 100755 --- a/other/analysis/run-clang-tidy +++ b/other/analysis/run-clang-tidy @@ -6,6 +6,12 @@ CHECKS="*" CHECKS="$CHECKS,-clang-diagnostic-pointer-bool-conversion" CHECKS="$CHECKS,-clang-diagnostic-tautological-pointer-compare" +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" + # TODO(iphydf): We might want some of these. For the ones we don't want, add a # comment explaining why not. CHECKS="$CHECKS,-altera-unroll-loops" @@ -50,6 +56,9 @@ CHECKS="$CHECKS,-cppcoreguidelines-narrowing-conversions" CHECKS="$CHECKS,-google-readability-casting" CHECKS="$CHECKS,-misc-no-recursion" +# TODO(iphydf): Probably fix these. +CHECKS="$CHECKS,-modernize-macro-to-enum" + ERRORS="*" # TODO(iphydf): Fix these. @@ -70,7 +79,7 @@ run() { for i in "${!EXTRA_ARGS[@]}"; do EXTRA_ARGS[$i]="--extra-arg=${EXTRA_ARGS[$i]}" done - clang-tidy-12 \ + clang-tidy \ -p=_build \ --extra-arg=-DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE \ "${EXTRA_ARGS[@]}" \ @@ -84,4 +93,6 @@ run() { toxencryptsave/*.c } +cmake . -B_build -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + . other/analysis/variants.sh diff --git a/other/bootstrap_daemon/src/tox-bootstrapd.c b/other/bootstrap_daemon/src/tox-bootstrapd.c index 7efd2c889d3..2d86e9d26eb 100644 --- a/other/bootstrap_daemon/src/tox-bootstrapd.c +++ b/other/bootstrap_daemon/src/tox-bootstrapd.c @@ -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); diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 1b4062cbbe4..ca96dbe37da 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -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); } diff --git a/toxcore/DHT.h b/toxcore/DHT.h index 95f442e79fa..d4fc33dc4d5 100644 --- a/toxcore/DHT.h +++ b/toxcore/DHT.h @@ -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. diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index f5ae68a0f21..fc28e0c069b 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -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); diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c index 5aec2337f5b..aeb722f660e 100644 --- a/toxcore/TCP_client.c +++ b/toxcore/TCP_client.c @@ -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; diff --git a/toxcore/TCP_client.h b/toxcore/TCP_client.h index b020aaad91a..eceed047b7a 100644 --- a/toxcore/TCP_client.h +++ b/toxcore/TCP_client.h @@ -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); diff --git a/toxcore/TCP_common.c b/toxcore/TCP_common.c index 36a751f386d..5d0019486c0 100644 --- a/toxcore/TCP_common.c +++ b/toxcore/TCP_common.c @@ -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; diff --git a/toxcore/TCP_common.h b/toxcore/TCP_common.h index 44dc2e71e0d..7891168f727 100644 --- a/toxcore/TCP_common.h +++ b/toxcore/TCP_common.h @@ -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, diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c index 2c75e74ea5f..f274376c1cd 100644 --- a/toxcore/TCP_connection.c +++ b/toxcore/TCP_connection.c @@ -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)); diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c index 80a1f0165aa..905d2bb4341 100644 --- a/toxcore/TCP_server.c +++ b/toxcore/TCP_server.c @@ -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; diff --git a/toxcore/TCP_server.h b/toxcore/TCP_server.h index 090e821607d..0349f60b9e8 100644 --- a/toxcore/TCP_server.h +++ b/toxcore/TCP_server.h @@ -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 diff --git a/toxcore/friend_connection.c b/toxcore/friend_connection.c index 7b8537c7207..49fed514657 100644 --- a/toxcore/friend_connection.c +++ b/toxcore/friend_connection.c @@ -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() diff --git a/toxcore/group_chats.c b/toxcore/group_chats.c index a18ba1494c9..23eca0a909f 100644 --- a/toxcore/group_chats.c +++ b/toxcore/group_chats.c @@ -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"); } diff --git a/toxcore/group_common.h b/toxcore/group_common.h index 34d67dc8d62..2475d256440 100644 --- a/toxcore/group_common.h +++ b/toxcore/group_common.h @@ -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; diff --git a/toxcore/network.c b/toxcore/network.c index 5ccf068f53c..90b3d2d919a 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -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; } diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 6aef15ec3a8..c15eb555642 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -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; } diff --git a/toxcore/onion_client.h b/toxcore/onion_client.h index 6498f8c5c39..d8a2e875283 100644 --- a/toxcore/onion_client.h +++ b/toxcore/onion_client.h @@ -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)