Skip to content

Commit

Permalink
cleanup: Enforce stricter identifier naming using clang-tidy.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Aug 31, 2023
1 parent a549807 commit 2d3ee43
Show file tree
Hide file tree
Showing 23 changed files with 282 additions and 242 deletions.
3 changes: 1 addition & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
30 changes: 30 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -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
128 changes: 64 additions & 64 deletions auto_tests/TCP_test.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion auto_tests/auto_test_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions other/DHT_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);

Expand Down
13 changes: 12 additions & 1 deletion other/analysis/run-clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand All @@ -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[@]}" \
Expand All @@ -84,4 +93,6 @@ run() {
toxencryptsave/*.c
}

cmake . -B_build -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

. other/analysis/variants.sh
14 changes: 7 additions & 7 deletions other/bootstrap_daemon/src/tox-bootstrapd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
40 changes: 20 additions & 20 deletions toxcore/DHT.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion toxcore/DHT.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions toxcore/Messenger.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 2d3ee43

Please sign in to comment.