cleanup: Remove implicit bool conversions.

This commit is contained in:
iphydf 2024-01-31 19:25:54 +00:00
parent 4e2dba4d9f
commit b7404f24f6
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
18 changed files with 140 additions and 140 deletions

View File

@ -125,7 +125,7 @@ static void print_log(void *context, Logger_Level level, const char *file, int l
int main(int argc, char *argv[])
{
if (argc == 2 && !tox_strncasecmp(argv[1], "-h", 3)) {
if (argc == 2 && tox_strncasecmp(argv[1], "-h", 3) == 0) {
printf("Usage (connected) : %s [--ipv4|--ipv6] IP PORT KEY\n", argv[0]);
printf("Usage (unconnected): %s [--ipv4|--ipv6]\n", argv[0]);
return 0;
@ -167,7 +167,7 @@ int main(int argc, char *argv[])
bootstrap_set_callbacks(dht_get_net(dht), (uint32_t)DAEMON_VERSION_NUMBER, (const uint8_t *) motd_str, strlen(motd_str) + 1);
#endif
if (!(onion && forwarding && onion_a)) {
if (onion == nullptr || forwarding == nullptr || onion_a == nullptr) {
printf("Something failed to initialize.\n");
// cppcheck-suppress resourceLeak
return 1;
@ -229,7 +229,7 @@ int main(int argc, char *argv[])
const uint16_t port = net_htons((uint16_t)port_conv);
uint8_t *bootstrap_key = hex_string_to_bin(argv[argvoffset + 3]);
int res = dht_bootstrap_from_address(dht, argv[argvoffset + 1],
const bool res = dht_bootstrap_from_address(dht, argv[argvoffset + 1],
ipv6enabled, port, bootstrap_key);
free(bootstrap_key);
@ -239,17 +239,17 @@ int main(int argc, char *argv[])
}
}
int is_waiting_for_dht_connection = 1;
bool is_waiting_for_dht_connection = true;
uint64_t last_lan_discovery = 0;
const Broadcast_Info *broadcast = lan_discovery_init(ns);
while (1) {
while (true) {
mono_time_update(mono_time);
if (is_waiting_for_dht_connection && dht_isconnected(dht)) {
printf("Connected to other bootstrap node successfully.\n");
is_waiting_for_dht_connection = 0;
is_waiting_for_dht_connection = false;
}
do_dht(dht);

View File

@ -134,7 +134,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
}
}
int get_general_config(const char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port,
bool get_general_config(const char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port,
int *enable_ipv6, int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay,
uint16_t **tcp_relay_ports, int *tcp_relay_port_count, int *enable_motd, char **motd)
{
@ -156,7 +156,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
if (config_read_file(&cfg, cfg_file_path) == CONFIG_FALSE) {
log_write(LOG_LEVEL_ERROR, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg));
config_destroy(&cfg);
return 0;
return false;
}
// Get port
@ -223,7 +223,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
*enable_tcp_relay = DEFAULT_ENABLE_TCP_RELAY;
}
if (*enable_tcp_relay) {
if (*enable_tcp_relay != 0) {
parse_tcp_relay_ports_config(&cfg, tcp_relay_ports, tcp_relay_port_count);
} else {
*tcp_relay_port_count = 0;
@ -237,7 +237,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
*enable_motd = DEFAULT_ENABLE_MOTD;
}
if (*enable_motd) {
if (*enable_motd != 0) {
// Get MOTD
const char *tmp_motd;
@ -259,14 +259,14 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_PID_FILE_PATH, *pid_file_path);
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_KEYS_FILE_PATH, *keys_file_path);
log_write(LOG_LEVEL_INFO, "'%s': %d\n", NAME_PORT, *port);
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_IPV6, *enable_ipv6 ? "true" : "false");
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_IPV4_FALLBACK, *enable_ipv4_fallback ? "true" : "false");
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery ? "true" : "false");
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_IPV6, *enable_ipv6 != 0 ? "true" : "false");
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_IPV4_FALLBACK, *enable_ipv4_fallback != 0 ? "true" : "false");
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery != 0 ? "true" : "false");
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_TCP_RELAY, *enable_tcp_relay ? "true" : "false");
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_TCP_RELAY, *enable_tcp_relay != 0 ? "true" : "false");
// Show info about tcp ports only if tcp relay is enabled
if (*enable_tcp_relay) {
if (*enable_tcp_relay != 0) {
if (*tcp_relay_port_count == 0) {
log_write(LOG_LEVEL_ERROR, "No TCP ports could be read.\n");
} else {
@ -278,13 +278,13 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
}
}
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_MOTD, *enable_motd ? "true" : "false");
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_MOTD, *enable_motd != 0 ? "true" : "false");
if (*enable_motd) {
if (*enable_motd != 0) {
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_MOTD, *motd);
}
return 1;
return true;
}
/**
@ -316,7 +316,7 @@ static uint8_t *bootstrap_hex_string_to_bin(const char *hex_string)
return ret;
}
int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
bool bootstrap_from_config(const char *cfg_file_path, DHT *dht, bool enable_ipv6)
{
const char *const NAME_BOOTSTRAP_NODES = "bootstrap_nodes";
@ -331,7 +331,7 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
if (config_read_file(&cfg, cfg_file_path) == CONFIG_FALSE) {
log_write(LOG_LEVEL_ERROR, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg));
config_destroy(&cfg);
return 0;
return false;
}
config_setting_t *node_list = config_lookup(&cfg, NAME_BOOTSTRAP_NODES);
@ -340,13 +340,13 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
log_write(LOG_LEVEL_WARNING, "No '%s' setting in the configuration file. Skipping bootstrapping.\n",
NAME_BOOTSTRAP_NODES);
config_destroy(&cfg);
return 1;
return true;
}
if (config_setting_length(node_list) == 0) {
log_write(LOG_LEVEL_WARNING, "No bootstrap nodes found. Skipping bootstrapping.\n");
config_destroy(&cfg);
return 1;
return true;
}
int bs_port;
@ -357,15 +357,15 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
int i = 0;
while (config_setting_length(node_list)) {
int address_resolved;
while (config_setting_length(node_list) != 0) {
bool address_resolved;
uint8_t *bs_public_key_bin;
node = config_setting_get_elem(node_list, 0);
if (node == nullptr) {
config_destroy(&cfg);
return 0;
return false;
}
// Check that all settings are present
@ -421,5 +421,5 @@ next:
config_destroy(&cfg);
return 1;
return true;
}

View File

@ -19,19 +19,19 @@
* also, iff `tcp_relay_ports_count` > 0, then you are responsible for freeing `tcp_relay_ports`
* and also `motd` iff `enable_motd` is set.
*
* @return 1 on success,
* 0 on failure, doesn't modify any data pointed by arguments.
* @return true on success,
* false on failure, doesn't modify any data pointed by arguments.
*/
int get_general_config(const char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port,
bool get_general_config(const char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port,
int *enable_ipv6, int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay,
uint16_t **tcp_relay_ports, int *tcp_relay_port_count, int *enable_motd, char **motd);
/**
* Bootstraps off nodes listed in the config file.
*
* @return 1 on success, some or no bootstrap nodes were added
* 0 on failure, an error occurred while parsing the config file.
* @return true on success, some or no bootstrap nodes were added
* false on failure, an error occurred while parsing the config file.
*/
int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6);
bool bootstrap_from_config(const char *cfg_file_path, DHT *dht, bool enable_ipv6);
#endif // C_TOXCORE_OTHER_BOOTSTRAP_DAEMON_SRC_CONFIG_H

View File

@ -60,10 +60,10 @@ static void sleep_milliseconds(uint32_t ms)
// Uses the already existing key or creates one if it didn't exist
//
// returns 1 on success
// 0 on failure - no keys were read or stored
// returns true on success
// false on failure - no keys were read or stored
static int manage_keys(DHT *dht, const char *keys_file_path)
static bool manage_keys(DHT *dht, const char *keys_file_path)
{
enum { KEYS_SIZE = CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE };
uint8_t keys[KEYS_SIZE];
@ -76,7 +76,7 @@ static int manage_keys(DHT *dht, const char *keys_file_path)
if (read_size != KEYS_SIZE) {
fclose(keys_file);
return 0;
return false;
}
dht_set_self_public_key(dht, keys);
@ -88,21 +88,21 @@ static int manage_keys(DHT *dht, const char *keys_file_path)
keys_file = fopen(keys_file_path, "wb");
if (!keys_file) {
return 0;
if (keys_file == nullptr) {
return false;
}
const size_t write_size = fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keys_file);
if (write_size != KEYS_SIZE) {
fclose(keys_file);
return 0;
return false;
}
}
fclose(keys_file);
return 1;
return true;
}
// Prints public key
@ -220,7 +220,7 @@ int main(int argc, char *argv[])
bool run_in_foreground = false;
// Choose backend for printing command line argument parsing output based on whether the daemon is being run from a terminal
LOG_BACKEND log_backend = isatty(STDOUT_FILENO) ? LOG_BACKEND_STDOUT : LOG_BACKEND_SYSLOG;
LOG_BACKEND log_backend = isatty(STDOUT_FILENO) != 0 ? LOG_BACKEND_STDOUT : LOG_BACKEND_SYSLOG;
log_open(log_backend);
switch (handle_command_line_arguments(argc, argv, &cfg_file_path, &log_backend, &run_in_foreground)) {
@ -281,7 +281,7 @@ int main(int argc, char *argv[])
free(pid_file_path);
IP ip;
ip_init(&ip, enable_ipv6);
ip_init(&ip, enable_ipv6 != 0);
Logger *logger = logger_new();
@ -296,10 +296,10 @@ int main(int argc, char *argv[])
Networking_Core *net = new_networking_ex(logger, mem, ns, &ip, start_port, end_port, nullptr);
if (net == nullptr) {
if (enable_ipv6 && enable_ipv4_fallback) {
if (enable_ipv6 != 0 && enable_ipv4_fallback != 0) {
log_write(LOG_LEVEL_WARNING, "Couldn't initialize IPv6 networking. Falling back to using IPv4.\n");
enable_ipv6 = 0;
ip_init(&ip, enable_ipv6);
ip_init(&ip, enable_ipv6 != 0);
net = new_networking_ex(logger, mem, ns, &ip, start_port, end_port, nullptr);
if (net == nullptr) {
@ -334,7 +334,7 @@ int main(int argc, char *argv[])
mono_time_update(mono_time);
DHT *const dht = new_dht(logger, mem, rng, ns, mono_time, net, true, enable_lan_discovery);
DHT *const dht = new_dht(logger, mem, rng, ns, mono_time, net, true, enable_lan_discovery != 0);
if (dht == nullptr) {
log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox DHT instance. Exiting.\n");
@ -394,7 +394,7 @@ int main(int argc, char *argv[])
Onion *onion = new_onion(logger, mem, mono_time, rng, dht);
if (!onion) {
if (onion == nullptr) {
log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox Onion. Exiting.\n");
kill_gca(group_announce);
kill_announcements(announce);
@ -411,7 +411,7 @@ int main(int argc, char *argv[])
Onion_Announce *onion_a = new_onion_announce(logger, mem, rng, mono_time, dht);
if (!onion_a) {
if (onion_a == nullptr) {
log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox Onion Announce. Exiting.\n");
kill_gca(group_announce);
kill_onion(onion);
@ -429,7 +429,7 @@ int main(int argc, char *argv[])
gca_onion_init(group_announce, onion_a);
if (enable_motd) {
if (enable_motd != 0) {
if (bootstrap_set_callbacks(dht_get_net(dht), DAEMON_VERSION_NUMBER, (uint8_t *)motd, strlen(motd) + 1) == 0) {
log_write(LOG_LEVEL_INFO, "Set MOTD successfully.\n");
free(motd);
@ -472,7 +472,7 @@ int main(int argc, char *argv[])
TCP_Server *tcp_server = nullptr;
if (enable_tcp_relay) {
if (enable_tcp_relay != 0) {
if (tcp_relay_port_count == 0) {
log_write(LOG_LEVEL_ERROR, "No TCP relay ports read. Exiting.\n");
kill_onion_announce(onion_a);
@ -488,7 +488,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 != 0,
tcp_relay_port_count, tcp_relay_ports,
dht_get_self_secret_key(dht), onion, forwarding);
@ -504,7 +504,7 @@ int main(int argc, char *argv[])
assert(rlim_suggested >= rlim_min);
if (!getrlimit(RLIMIT_NOFILE, &limit)) {
if (getrlimit(RLIMIT_NOFILE, &limit) == 0) {
if (limit.rlim_cur < limit.rlim_max) {
// Some systems have a hard limit of over 1000000 open file descriptors, so let's cap it at something reasonable
// so that we don't set it to an unreasonably high number.
@ -513,7 +513,7 @@ int main(int argc, char *argv[])
}
}
if (!getrlimit(RLIMIT_NOFILE, &limit) && limit.rlim_cur < rlim_min) {
if (getrlimit(RLIMIT_NOFILE, &limit) == 0 && limit.rlim_cur < rlim_min) {
log_write(LOG_LEVEL_WARNING,
"Current limit on the number of files this process can open (%ju) is rather low for the proper functioning of the TCP server. "
"Consider raising the limit to at least %ju or the recommended %ju. "
@ -535,7 +535,7 @@ int main(int argc, char *argv[])
}
}
if (bootstrap_from_config(cfg_file_path, dht, enable_ipv6)) {
if (bootstrap_from_config(cfg_file_path, dht, enable_ipv6 != 0)) {
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);
@ -557,11 +557,11 @@ int main(int argc, char *argv[])
uint64_t last_lan_discovery = 0;
const uint16_t net_htons_port = net_htons(start_port);
int waiting_for_dht_connection = 1;
bool waiting_for_dht_connection = true;
Broadcast_Info *broadcast = nullptr;
if (enable_lan_discovery) {
if (enable_lan_discovery != 0) {
broadcast = lan_discovery_init(ns);
log_write(LOG_LEVEL_INFO, "Initialized LAN discovery successfully.\n");
}
@ -576,25 +576,25 @@ int main(int argc, char *argv[])
// Prevent the signal handler from being called again before it returns
sigfillset(&sa.sa_mask);
if (sigaction(SIGINT, &sa, nullptr)) {
if (sigaction(SIGINT, &sa, nullptr) != 0) {
log_write(LOG_LEVEL_WARNING, "Couldn't set signal handler for SIGINT. Continuing without the signal handler set.\n");
}
if (sigaction(SIGTERM, &sa, nullptr)) {
if (sigaction(SIGTERM, &sa, nullptr) != 0) {
log_write(LOG_LEVEL_WARNING, "Couldn't set signal handler for SIGTERM. Continuing without the signal handler set.\n");
}
while (!caught_signal) {
while (caught_signal == 0) {
mono_time_update(mono_time);
do_dht(dht);
if (enable_lan_discovery && mono_time_is_timeout(mono_time, last_lan_discovery, LAN_DISCOVERY_INTERVAL)) {
if (enable_lan_discovery != 0 && 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_lan_discovery = mono_time_get(mono_time);
}
if (enable_tcp_relay) {
if (enable_tcp_relay != 0) {
do_tcp_server(tcp_server, mono_time);
}
@ -602,7 +602,7 @@ int main(int argc, char *argv[])
if (waiting_for_dht_connection && dht_isconnected(dht)) {
log_write(LOG_LEVEL_INFO, "Connected to another bootstrap node successfully.\n");
waiting_for_dht_connection = 0;
waiting_for_dht_connection = false;
}
sleep_milliseconds(30);

View File

@ -120,7 +120,7 @@ int main(int argc, char *argv[])
const uint16_t port = net_htons((uint16_t)port_conv);
uint8_t *bootstrap_key = hex_string_to_bin(argv[argvoffset + 3]);
int res = dht_bootstrap_from_address(m->dht, argv[argvoffset + 1],
bool res = dht_bootstrap_from_address(m->dht, argv[argvoffset + 1],
ipv6enabled, port, bootstrap_key);
free(bootstrap_key);

View File

@ -64,7 +64,7 @@ static bool invoke_callback(MSICall *call, MSICallbackID cb);
static MSICall *get_call(MSISession *session, uint32_t friend_number);
static MSICall *new_call(MSISession *session, uint32_t friend_number);
static void kill_call(MSICall *call);
static void on_peer_status(Messenger *m, uint32_t friend_number, uint8_t connection_status, void *user_data);
static void on_peer_status(Messenger *m, uint32_t friend_number, bool is_online, void *user_data);
static void handle_init(MSICall *call, const MSIMessage *msg);
static void handle_push(MSICall *call, const MSIMessage *msg);
static void handle_pop(MSICall *call, const MSIMessage *msg);
@ -648,11 +648,11 @@ CLEAR_CONTAINER:
free(call);
session->calls = nullptr;
}
static void on_peer_status(Messenger *m, uint32_t friend_number, uint8_t connection_status, void *user_data)
static void on_peer_status(Messenger *m, uint32_t friend_number, bool is_online, void *user_data)
{
MSISession *session = (MSISession *)user_data;
if (connection_status != 0) {
if (is_online) {
// Friend is online.
return;
}

View File

@ -1840,7 +1840,7 @@ bool dht_bootstrap(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key)
return dht_getnodes(dht, ip_port, public_key, dht->self_public_key);
}
int dht_bootstrap_from_address(DHT *dht, const char *address, bool ipv6enabled,
bool dht_bootstrap_from_address(DHT *dht, const char *address, bool ipv6enabled,
uint16_t port, const uint8_t *public_key)
{
IP_Port ip_port_v64;
@ -1864,10 +1864,10 @@ int dht_bootstrap_from_address(DHT *dht, const char *address, bool ipv6enabled,
dht_bootstrap(dht, &ip_port_v4, public_key);
}
return 1;
return true;
}
return 0;
return false;
}
int route_packet(const DHT *dht, const uint8_t *public_key, const uint8_t *packet, uint16_t length)
@ -2658,21 +2658,21 @@ uint32_t dht_size(const DHT *dht)
uint32_t numv6 = 0;
for (uint32_t i = 0; i < dht->loaded_num_nodes; ++i) {
numv4 += net_family_is_ipv4(dht->loaded_nodes_list[i].ip_port.ip.family);
numv6 += net_family_is_ipv6(dht->loaded_nodes_list[i].ip_port.ip.family);
numv4 += net_family_is_ipv4(dht->loaded_nodes_list[i].ip_port.ip.family) ? 1 : 0;
numv6 += net_family_is_ipv6(dht->loaded_nodes_list[i].ip_port.ip.family) ? 1 : 0;
}
for (uint32_t i = 0; i < LCLIENT_LIST; ++i) {
numv4 += dht->close_clientlist[i].assoc4.timestamp != 0;
numv6 += dht->close_clientlist[i].assoc6.timestamp != 0;
numv4 += dht->close_clientlist[i].assoc4.timestamp != 0 ? 1 : 0;
numv6 += dht->close_clientlist[i].assoc6.timestamp != 0 ? 1 : 0;
}
for (uint32_t i = 0; i < DHT_FAKE_FRIEND_NUMBER && i < dht->num_friends; ++i) {
const DHT_Friend *const fr = &dht->friends_list[i];
for (uint32_t j = 0; j < MAX_FRIEND_CLIENTS; ++j) {
numv4 += fr->client_list[j].assoc4.timestamp != 0;
numv6 += fr->client_list[j].assoc6.timestamp != 0;
numv4 += fr->client_list[j].assoc4.timestamp != 0 ? 1 : 0;
numv6 += fr->client_list[j].assoc6.timestamp != 0 ? 1 : 0;
}
}

View File

@ -418,11 +418,11 @@ bool dht_bootstrap(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key);
* @param ipv6enabled if false, the resolving sticks STRICTLY to IPv4 addresses.
* Otherwise, the resolving looks for IPv6 addresses first, then IPv4 addresses.
*
* @retval 1 if the address could be converted into an IP address
* @retval 0 otherwise
* @retval true if the address could be converted into an IP address
* @retval false otherwise
*/
non_null()
int dht_bootstrap_from_address(DHT *dht, const char *address, bool ipv6enabled,
bool dht_bootstrap_from_address(DHT *dht, const char *address, bool ipv6enabled,
uint16_t port, const uint8_t *public_key);
/** @brief Start sending packets after DHT loaded_friends_list and loaded_clients_list are set.

View File

@ -473,7 +473,7 @@ int m_delfriend(Messenger *m, int32_t friendnumber)
}
if (m->friend_connectionstatuschange_internal != nullptr) {
m->friend_connectionstatuschange_internal(m, friendnumber, 0, m->friend_connectionstatuschange_internal_userdata);
m->friend_connectionstatuschange_internal(m, friendnumber, false, m->friend_connectionstatuschange_internal_userdata);
}
clear_receipts(m, friendnumber);
@ -2588,7 +2588,7 @@ static bool self_announce_group(const Messenger *m, GC_Chat *chat, Onion_Friend
}
announce.base_announce.tcp_relays_count = (uint8_t)tcp_num;
announce.base_announce.ip_port_is_set = (uint8_t)(ip_port_is_set ? 1 : 0);
announce.base_announce.ip_port_is_set = ip_port_is_set;
if (ip_port_is_set) {
memcpy(&announce.base_announce.ip_port, &chat->self_ip_port, sizeof(IP_Port));

View File

@ -200,7 +200,7 @@ typedef void m_friend_lossy_packet_cb(Messenger *m, uint32_t friend_number, uint
typedef void m_friend_lossless_packet_cb(Messenger *m, uint32_t friend_number, uint8_t packet_id, const uint8_t *data,
size_t length, void *user_data);
typedef void m_friend_connectionstatuschange_internal_cb(Messenger *m, uint32_t friend_number,
uint8_t connection_status, void *user_data);
bool is_online, void *user_data);
typedef void m_conference_invite_cb(Messenger *m, uint32_t friend_number, const uint8_t *cookie, uint16_t length,
void *user_data);
typedef void m_group_invite_cb(const Messenger *m, uint32_t friend_number, const uint8_t *invite_data, size_t length,

View File

@ -749,7 +749,7 @@ int set_tcp_connection_to_status(const TCP_Connections *tcp_c, int connections_n
}
if (tcp_con->status == TCP_CONN_SLEEPING) {
tcp_con->unsleep = 1;
tcp_con->unsleep = true;
}
}
}
@ -945,14 +945,14 @@ static int reconnect_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connec
if (tcp_con->onion) {
--tcp_c->onion_num_conns;
tcp_con->onion = 0;
tcp_con->onion = false;
}
tcp_con->lock_count = 0;
tcp_con->sleep_count = 0;
tcp_con->connected_time = 0;
tcp_con->status = TCP_CONN_VALID;
tcp_con->unsleep = 0;
tcp_con->unsleep = false;
return 0;
}
@ -990,14 +990,14 @@ static int sleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connection
if (tcp_con->onion) {
--tcp_c->onion_num_conns;
tcp_con->onion = 0;
tcp_con->onion = false;
}
tcp_con->lock_count = 0;
tcp_con->sleep_count = 0;
tcp_con->connected_time = 0;
tcp_con->status = TCP_CONN_SLEEPING;
tcp_con->unsleep = 0;
tcp_con->unsleep = false;
return 0;
}
@ -1028,7 +1028,7 @@ static int unsleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connecti
tcp_con->sleep_count = 0;
tcp_con->connected_time = 0;
tcp_con->status = TCP_CONN_VALID;
tcp_con->unsleep = 0;
tcp_con->unsleep = false;
return 0;
}
@ -1283,7 +1283,7 @@ static int tcp_relay_on_online(TCP_Connections *tcp_c, int tcp_connections_numbe
}
if (tcp_c->onion_status && tcp_c->onion_num_conns < NUM_ONION_TCP_CONNECTIONS) {
tcp_con->onion = 1;
tcp_con->onion = true;
++tcp_c->onion_num_conns;
}
@ -1369,7 +1369,7 @@ int add_tcp_number_relay_connection(const TCP_Connections *tcp_c, int connection
}
if (con_to->status != TCP_CONN_SLEEPING && tcp_con->status == TCP_CONN_SLEEPING) {
tcp_con->unsleep = 1;
tcp_con->unsleep = true;
}
if (add_tcp_connection_to_conn(con_to, tcp_connections_number) == -1) {
@ -1537,7 +1537,7 @@ int set_tcp_onion_status(TCP_Connections *tcp_c, bool status)
if (tcp_con != nullptr) {
if (tcp_con->status == TCP_CONN_CONNECTED && !tcp_con->onion) {
++tcp_c->onion_num_conns;
tcp_con->onion = 1;
tcp_con->onion = true;
}
}
@ -1554,7 +1554,7 @@ int set_tcp_onion_status(TCP_Connections *tcp_c, bool status)
if (tcp_con != nullptr) {
if (tcp_con->status == TCP_CONN_SLEEPING) {
tcp_con->unsleep = 1;
tcp_con->unsleep = true;
}
}
@ -1564,7 +1564,7 @@ int set_tcp_onion_status(TCP_Connections *tcp_c, bool status)
}
}
tcp_c->onion_status = 1;
tcp_c->onion_status = true;
} else {
for (uint32_t i = 0; i < tcp_c->tcp_connections_length; ++i) {
TCP_con *tcp_con = get_tcp_connection(tcp_c, i);
@ -1572,12 +1572,12 @@ int set_tcp_onion_status(TCP_Connections *tcp_c, bool status)
if (tcp_con != nullptr) {
if (tcp_con->onion) {
--tcp_c->onion_num_conns;
tcp_con->onion = 0;
tcp_con->onion = false;
}
}
}
tcp_c->onion_status = 0;
tcp_c->onion_status = false;
}
return 0;

View File

@ -354,7 +354,7 @@ static int create_reply_plain_data_search_request(Announcements *announce,
to_auth, to_auth_length, p);
p += TIMED_AUTH_SIZE;
*p = would_accept_store_request(announce, data_public_key);
*p = would_accept_store_request(announce, data_public_key) ? 1 : 0;
++p;
Node_format nodes_list[MAX_SENT_NODES];

View File

@ -136,11 +136,7 @@ bool crypto_memlock(void *data, size_t length)
return false;
#else
if (sodium_mlock(data, length) != 0) {
return false;
}
return true;
return sodium_mlock(data, length) == 0;
#endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */
}
@ -150,11 +146,7 @@ bool crypto_memunlock(void *data, size_t length)
return false;
#else
if (sodium_munlock(data, length) != 0) {
return false;
}
return true;
return sodium_munlock(data, length) == 0;
#endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */
}

View File

@ -246,7 +246,7 @@ static int friend_add_tcp_relay(Friend_Connections *fr_c, int friendcon_id, cons
if (!net_family_is_unspec(friend_con->dht_ip_port.ip.family)) {
ipp_copy.ip = friend_con->dht_ip_port.ip;
} else {
friend_con->hosting_tcp_relay = 0;
friend_con->hosting_tcp_relay = false;
}
}
@ -370,7 +370,7 @@ static void dht_ip_callback(void *object, int32_t number, const IP_Port *ip_port
if (friend_con->hosting_tcp_relay) {
friend_add_tcp_relay(fr_c, number, ip_port, friend_con->dht_temp_pk);
friend_con->hosting_tcp_relay = 0;
friend_con->hosting_tcp_relay = false;
}
}
@ -424,7 +424,7 @@ static int handle_status(void *object, int id, bool status, void *userdata)
friend_con->status = FRIENDCONN_STATUS_CONNECTING;
friend_con->crypt_connection_id = -1;
friend_con->hosting_tcp_relay = 0;
friend_con->hosting_tcp_relay = false;
}
if (status_changed) {

View File

@ -2014,7 +2014,7 @@ int32_t net_getipport(const Memory *mem, const char *node, IP_Port **res, int to
size_t count = 0;
for (struct addrinfo *cur = infos; count < max_count && cur != nullptr; cur = cur->ai_next) {
if (cur->ai_socktype && type > 0 && cur->ai_socktype != type) {
if (cur->ai_socktype != 0 && type > 0 && cur->ai_socktype != type) {
continue;
}
@ -2043,7 +2043,7 @@ int32_t net_getipport(const Memory *mem, const char *node, IP_Port **res, int to
*res = ip_port;
for (struct addrinfo *cur = infos; cur != nullptr; cur = cur->ai_next) {
if (cur->ai_socktype && type > 0 && cur->ai_socktype != type) {
if (cur->ai_socktype != 0 && type > 0 && cur->ai_socktype != type) {
continue;
}

View File

@ -483,17 +483,6 @@ static int random_path(const Onion_Client *onion_c, Onion_Client_Paths *onion_pa
return 0;
}
/** Does path with path_num exist. */
non_null()
static bool path_exists(const Mono_Time *mono_time, const Onion_Client_Paths *onion_paths, uint32_t path_num)
{
if (path_timed_out(mono_time, onion_paths, path_num)) {
return false;
}
return onion_paths->paths[path_num % NUMBER_ONION_PATHS].path_num == path_num;
}
/** Set path timeouts, return the path number. */
non_null()
static uint32_t set_path_timeouts(Onion_Client *onion_c, uint32_t num, uint32_t path_num)
@ -1917,6 +1906,33 @@ static bool key_list_contains(const uint8_t *const *keys, uint16_t keys_size, co
return false;
}
/** Does path with path_num exist. */
non_null()
static bool path_exists(const Mono_Time *mono_time, const Onion_Client_Paths *onion_paths, uint32_t path_num)
{
if (path_timed_out(mono_time, onion_paths, path_num)) {
return false;
}
return onion_paths->paths[path_num % NUMBER_ONION_PATHS].path_num == path_num;
}
/**
* A node/path is considered "stable" if it has survived for at least TIME_TO_STABLE
* and the latest packets sent to it are not timing out.
*/
non_null()
static bool path_is_stable(const Mono_Time *mono_time, const Onion_Client_Paths *paths,
uint32_t pathnum, const Onion_Node *node)
{
return mono_time_is_timeout(mono_time, node->added_time, TIME_TO_STABLE)
&& !(node->pings_since_last_response > 0
&& mono_time_is_timeout(mono_time, node->last_pinged, ONION_NODE_TIMEOUT))
&& mono_time_is_timeout(mono_time, paths->path_creation_time[pathnum], TIME_TO_STABLE)
&& !(paths->last_path_used_times[pathnum] > 0
&& mono_time_is_timeout(mono_time, paths->last_path_used[pathnum], ONION_PATH_TIMEOUT));
}
non_null()
static void do_announce(Onion_Client *onion_c)
{
@ -1948,16 +1964,8 @@ static void do_announce(Onion_Client *onion_c)
const uint32_t pathnum = node_list[i].path_used % NUMBER_ONION_PATHS;
/* A node/path is considered "stable", and can be pinged less
* aggressively, if it has survived for at least TIME_TO_STABLE
* and the latest packets sent to it are not timing out.
*/
if (mono_time_is_timeout(onion_c->mono_time, node_list[i].added_time, TIME_TO_STABLE)
&& !(node_list[i].pings_since_last_response > 0
&& mono_time_is_timeout(onion_c->mono_time, node_list[i].last_pinged, ONION_NODE_TIMEOUT))
&& mono_time_is_timeout(onion_c->mono_time, onion_c->onion_paths_self.path_creation_time[pathnum], TIME_TO_STABLE)
&& !(onion_c->onion_paths_self.last_path_used_times[pathnum] > 0
&& mono_time_is_timeout(onion_c->mono_time, onion_c->onion_paths_self.last_path_used[pathnum], ONION_PATH_TIMEOUT))) {
/* If a node/path is considered "stable", it can be pinged less aggressively. */
if (path_is_stable(onion_c->mono_time, &onion_c->onion_paths_self, pathnum, &node_list[i])) {
interval = ANNOUNCE_INTERVAL_STABLE;
}
}

View File

@ -670,7 +670,7 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error)
return nullptr;
}
Messenger_Options m_options = {0};
Messenger_Options m_options = {false};
bool load_savedata_sk = false;
bool load_savedata_tox = false;

View File

@ -288,7 +288,7 @@ void tox_options_set_savedata_data(Tox_Options *options, const uint8_t *savedata
void tox_options_default(Tox_Options *options)
{
if (options != nullptr) {
const Tox_Options default_options = {0};
const Tox_Options default_options = {false};
*options = default_options;
tox_options_set_ipv6_enabled(options, true);
tox_options_set_udp_enabled(options, true);