summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2016-09-13 22:01:45 +0100
committeriphydf <iphydf@users.noreply.github.com>2016-09-13 22:01:45 +0100
commit45d28904b92c825d1ac88be9edae8baabcd4bba1 (patch)
tree7b1b259ba09d35867c141cf072707e6a0891f97a
parenta8823830d39bdbde8d4f4f34bfcb26dc4bf79741 (diff)
Use <stdbool.h> and replace _Bool with bool.
This header is a requirement for the public API, therefore is assumed to exist. It is a C99 standard library header, and _Bool is not intended to be used directly, except in legacy code that defines bool (and true/false) itself. We don't use or depend on such code. None of our client code uses or depends on such code. There is no reason to not use bool.
-rw-r--r--auto_tests/TCP_test.c4
-rw-r--r--auto_tests/onion_test.c4
-rw-r--r--auto_tests/tox_test.c6
-rw-r--r--toxcore/DHT.c20
-rw-r--r--toxcore/DHT.h8
-rw-r--r--toxcore/LAN_discovery.c2
-rw-r--r--toxcore/LAN_discovery.h2
-rw-r--r--toxcore/Messenger.c6
-rw-r--r--toxcore/Messenger.h4
-rw-r--r--toxcore/TCP_client.c6
-rw-r--r--toxcore/TCP_connection.c12
-rw-r--r--toxcore/TCP_connection.h10
-rw-r--r--toxcore/TCP_server.c6
-rw-r--r--toxcore/friend_connection.c2
-rw-r--r--toxcore/friend_connection.h2
-rw-r--r--toxcore/net_crypto.c18
-rw-r--r--toxcore/net_crypto.h6
-rw-r--r--toxcore/onion.c4
-rw-r--r--toxcore/onion_client.c6
-rw-r--r--toxcore/onion_client.h2
-rw-r--r--toxcore/tox.c2
21 files changed, 67 insertions, 65 deletions
diff --git a/auto_tests/TCP_test.c b/auto_tests/TCP_test.c
index 98edc357..2efed98f 100644
--- a/auto_tests/TCP_test.c
+++ b/auto_tests/TCP_test.c
@@ -522,7 +522,7 @@ END_TEST
522 522
523#include "../toxcore/TCP_connection.h" 523#include "../toxcore/TCP_connection.h"
524 524
525_Bool tcp_data_callback_called; 525bool tcp_data_callback_called;
526static int tcp_data_callback(void *object, int id, const uint8_t *data, uint16_t length, void *userdata) 526static int tcp_data_callback(void *object, int id, const uint8_t *data, uint16_t length, void *userdata)
527{ 527{
528 if (object != (void *)120397) { 528 if (object != (void *)120397) {
@@ -631,7 +631,7 @@ START_TEST(test_tcp_connection)
631} 631}
632END_TEST 632END_TEST
633 633
634_Bool tcp_oobdata_callback_called; 634bool tcp_oobdata_callback_called;
635static int tcp_oobdata_callback(void *object, const uint8_t *public_key, unsigned int id, const uint8_t *data, 635static int tcp_oobdata_callback(void *object, const uint8_t *public_key, unsigned int id, const uint8_t *data,
636 uint16_t length, void *userdata) 636 uint16_t length, void *userdata)
637{ 637{
diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c
index dd5a1946..6e330091 100644
--- a/auto_tests/onion_test.c
+++ b/auto_tests/onion_test.c
@@ -323,7 +323,7 @@ static void kill_onions(Onions *on)
323#define NUM_FIRST 7 323#define NUM_FIRST 7
324#define NUM_LAST 37 324#define NUM_LAST 37
325 325
326static _Bool first_ip, last_ip; 326static bool first_ip, last_ip;
327static void dht_ip_callback(void *object, int32_t number, IP_Port ip_port) 327static void dht_ip_callback(void *object, int32_t number, IP_Port ip_port)
328{ 328{
329 if (NUM_FIRST == number) { 329 if (NUM_FIRST == number) {
@@ -339,7 +339,7 @@ static void dht_ip_callback(void *object, int32_t number, IP_Port ip_port)
339 ck_abort_msg("Error."); 339 ck_abort_msg("Error.");
340} 340}
341 341
342static _Bool first, last; 342static bool first, last;
343static uint8_t first_dht_pk[crypto_box_PUBLICKEYBYTES]; 343static uint8_t first_dht_pk[crypto_box_PUBLICKEYBYTES];
344static uint8_t last_dht_pk[crypto_box_PUBLICKEYBYTES]; 344static uint8_t last_dht_pk[crypto_box_PUBLICKEYBYTES];
345 345
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c
index 7edb0348..219550db 100644
--- a/auto_tests/tox_test.c
+++ b/auto_tests/tox_test.c
@@ -224,9 +224,9 @@ static void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_n
224} 224}
225 225
226static uint64_t max_sending; 226static uint64_t max_sending;
227static _Bool m_send_reached; 227static bool m_send_reached;
228static uint8_t sending_num; 228static uint8_t sending_num;
229static _Bool file_sending_done; 229static bool file_sending_done;
230static void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, 230static void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position,
231 size_t length, 231 size_t length,
232 void *user_data) 232 void *user_data)
@@ -280,7 +280,7 @@ static void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t fi
280 280
281 281
282static uint8_t num; 282static uint8_t num;
283static _Bool file_recv; 283static bool file_recv;
284static void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data, 284static void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data,
285 size_t length, void *user_data) 285 size_t length, void *user_data)
286{ 286{
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index 7e2445b3..e7fd0a9d 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -550,8 +550,8 @@ static int friend_number(const DHT *dht, const uint8_t *public_key)
550 550
551/* Add node to the node list making sure only the nodes closest to cmp_pk are in the list. 551/* Add node to the node list making sure only the nodes closest to cmp_pk are in the list.
552 */ 552 */
553_Bool add_to_list(Node_format *nodes_list, unsigned int length, const uint8_t *pk, IP_Port ip_port, 553bool add_to_list(Node_format *nodes_list, unsigned int length, const uint8_t *pk, IP_Port ip_port,
554 const uint8_t *cmp_pk) 554 const uint8_t *cmp_pk)
555{ 555{
556 uint8_t pk_bak[crypto_box_PUBLICKEYBYTES]; 556 uint8_t pk_bak[crypto_box_PUBLICKEYBYTES];
557 IP_Port ip_port_bak; 557 IP_Port ip_port_bak;
@@ -877,7 +877,7 @@ static int replace_all(Client_data *list,
877 * return -1 on failure. 877 * return -1 on failure.
878 * return 0 on success. 878 * return 0 on success.
879 */ 879 */
880static int add_to_close(DHT *dht, const uint8_t *public_key, IP_Port ip_port, _Bool simulate) 880static int add_to_close(DHT *dht, const uint8_t *public_key, IP_Port ip_port, bool simulate)
881{ 881{
882 unsigned int i; 882 unsigned int i;
883 883
@@ -924,7 +924,7 @@ static int add_to_close(DHT *dht, const uint8_t *public_key, IP_Port ip_port, _B
924 924
925/* Return 1 if node can be added to close list, 0 if it can't. 925/* Return 1 if node can be added to close list, 0 if it can't.
926 */ 926 */
927_Bool node_addable_to_close_list(DHT *dht, const uint8_t *public_key, IP_Port ip_port) 927bool node_addable_to_close_list(DHT *dht, const uint8_t *public_key, IP_Port ip_port)
928{ 928{
929 if (add_to_close(dht, public_key, ip_port, 1) == 0) { 929 if (add_to_close(dht, public_key, ip_port, 1) == 0) {
930 return 1; 930 return 1;
@@ -933,8 +933,8 @@ _Bool node_addable_to_close_list(DHT *dht, const uint8_t *public_key, IP_Port ip
933 return 0; 933 return 0;
934} 934}
935 935
936static _Bool is_pk_in_client_list(Client_data *list, unsigned int client_list_length, const uint8_t *public_key, 936static bool is_pk_in_client_list(Client_data *list, unsigned int client_list_length, const uint8_t *public_key,
937 IP_Port ip_port) 937 IP_Port ip_port)
938{ 938{
939 unsigned int i; 939 unsigned int i;
940 940
@@ -958,7 +958,7 @@ static _Bool is_pk_in_client_list(Client_data *list, unsigned int client_list_le
958 */ 958 */
959static unsigned int ping_node_from_getnodes_ok(DHT *dht, const uint8_t *public_key, IP_Port ip_port) 959static unsigned int ping_node_from_getnodes_ok(DHT *dht, const uint8_t *public_key, IP_Port ip_port)
960{ 960{
961 _Bool ret = 0; 961 bool ret = 0;
962 962
963 if (add_to_close(dht, public_key, ip_port, 1) == 0) { 963 if (add_to_close(dht, public_key, ip_port, 1) == 0) {
964 ret = 1; 964 ret = 1;
@@ -978,7 +978,7 @@ static unsigned int ping_node_from_getnodes_ok(DHT *dht, const uint8_t *public_k
978 unsigned int i; 978 unsigned int i;
979 979
980 for (i = 0; i < dht->num_friends; ++i) { 980 for (i = 0; i < dht->num_friends; ++i) {
981 _Bool store_ok = 0; 981 bool store_ok = 0;
982 982
983 DHT_Friend *friend = &dht->friends_list[i]; 983 DHT_Friend *friend = &dht->friends_list[i];
984 984
@@ -1572,7 +1572,7 @@ int DHT_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port)
1572 1572
1573/* returns number of nodes not in kill-timeout */ 1573/* returns number of nodes not in kill-timeout */
1574static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, const uint8_t *public_key, 1574static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, const uint8_t *public_key,
1575 Client_data *list, uint32_t list_count, uint32_t *bootstrap_times, _Bool sortable) 1575 Client_data *list, uint32_t list_count, uint32_t *bootstrap_times, bool sortable)
1576{ 1576{
1577 uint32_t i; 1577 uint32_t i;
1578 uint8_t not_kill = 0; 1578 uint8_t not_kill = 0;
@@ -1582,7 +1582,7 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co
1582 Client_data *client_list[list_count * 2]; 1582 Client_data *client_list[list_count * 2];
1583 IPPTsPng *assoc_list[list_count * 2]; 1583 IPPTsPng *assoc_list[list_count * 2];
1584 unsigned int sort = 0; 1584 unsigned int sort = 0;
1585 _Bool sort_ok = 0; 1585 bool sort_ok = 0;
1586 1586
1587 for (i = 0; i < list_count; i++) { 1587 for (i = 0; i < list_count; i++) {
1588 /* If node is not dead. */ 1588 /* If node is not dead. */
diff --git a/toxcore/DHT.h b/toxcore/DHT.h
index 9f7f1d9f..c5cde320 100644
--- a/toxcore/DHT.h
+++ b/toxcore/DHT.h
@@ -29,6 +29,8 @@
29#include "network.h" 29#include "network.h"
30#include "ping_array.h" 30#include "ping_array.h"
31 31
32#include <stdbool.h>
33
32/* Maximum number of clients stored per friend. */ 34/* Maximum number of clients stored per friend. */
33#define MAX_FRIEND_CLIENTS 8 35#define MAX_FRIEND_CLIENTS 8
34 36
@@ -311,12 +313,12 @@ int id_closest(const uint8_t *pk, const uint8_t *pk1, const uint8_t *pk2);
311 313
312/* Add node to the node list making sure only the nodes closest to cmp_pk are in the list. 314/* Add node to the node list making sure only the nodes closest to cmp_pk are in the list.
313 */ 315 */
314_Bool add_to_list(Node_format *nodes_list, unsigned int length, const uint8_t *pk, IP_Port ip_port, 316bool add_to_list(Node_format *nodes_list, unsigned int length, const uint8_t *pk, IP_Port ip_port,
315 const uint8_t *cmp_pk); 317 const uint8_t *cmp_pk);
316 318
317/* Return 1 if node can be added to close list, 0 if it can't. 319/* Return 1 if node can be added to close list, 0 if it can't.
318 */ 320 */
319_Bool node_addable_to_close_list(DHT *dht, const uint8_t *public_key, IP_Port ip_port); 321bool node_addable_to_close_list(DHT *dht, const uint8_t *public_key, IP_Port ip_port);
320 322
321/* Get the (maximum MAX_SENT_NODES) closest nodes to public_key we know 323/* Get the (maximum MAX_SENT_NODES) closest nodes to public_key we know
322 * and put them in nodes_list (must be MAX_SENT_NODES big). 324 * and put them in nodes_list (must be MAX_SENT_NODES big).
diff --git a/toxcore/LAN_discovery.c b/toxcore/LAN_discovery.c
index 115b626d..22ea466a 100644
--- a/toxcore/LAN_discovery.c
+++ b/toxcore/LAN_discovery.c
@@ -235,7 +235,7 @@ static IP broadcast_ip(sa_family_t family_socket, sa_family_t family_broadcast)
235} 235}
236 236
237/* Is IP a local ip or not. */ 237/* Is IP a local ip or not. */
238_Bool Local_ip(IP ip) 238bool Local_ip(IP ip)
239{ 239{
240 if (ip.family == AF_INET) { 240 if (ip.family == AF_INET) {
241 IP4 ip4 = ip.ip4; 241 IP4 ip4 = ip.ip4;
diff --git a/toxcore/LAN_discovery.h b/toxcore/LAN_discovery.h
index 65304791..94c987db 100644
--- a/toxcore/LAN_discovery.h
+++ b/toxcore/LAN_discovery.h
@@ -40,7 +40,7 @@ void LANdiscovery_init(DHT *dht);
40void LANdiscovery_kill(DHT *dht); 40void LANdiscovery_kill(DHT *dht);
41 41
42/* Is IP a local ip or not. */ 42/* Is IP a local ip or not. */
43_Bool Local_ip(IP ip); 43bool Local_ip(IP ip);
44 44
45/* checks if a given IP isn't routable 45/* checks if a given IP isn't routable
46 * 46 *
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 8f5432da..3488fcca 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -450,7 +450,7 @@ int m_get_friend_connectionstatus(const Messenger *m, int32_t friendnumber)
450 } 450 }
451 451
452 if (m->friendlist[friendnumber].status == FRIEND_ONLINE) { 452 if (m->friendlist[friendnumber].status == FRIEND_ONLINE) {
453 _Bool direct_connected = 0; 453 bool direct_connected = 0;
454 unsigned int num_online_relays = 0; 454 unsigned int num_online_relays = 0;
455 int crypt_conn_id = friend_connection_crypt_connection_id(m->fr_c, m->friendlist[friendnumber].friendcon_id); 455 int crypt_conn_id = friend_connection_crypt_connection_id(m->fr_c, m->friendlist[friendnumber].friendcon_id);
456 crypto_connection_status(m->net_crypto, crypt_conn_id, &direct_connected, &num_online_relays); 456 crypto_connection_status(m->net_crypto, crypt_conn_id, &direct_connected, &num_online_relays);
@@ -865,7 +865,7 @@ void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, uint32_t
865 m->friend_userstatuschange = function; 865 m->friend_userstatuschange = function;
866} 866}
867 867
868void m_callback_typingchange(Messenger *m, void(*function)(Messenger *m, uint32_t, _Bool, void *)) 868void m_callback_typingchange(Messenger *m, void(*function)(Messenger *m, uint32_t, bool, void *))
869{ 869{
870 m->friend_typingchange = function; 870 m->friend_typingchange = function;
871} 871}
@@ -2141,7 +2141,7 @@ static int handle_packet(void *object, int i, const uint8_t *temp, uint16_t len,
2141 break; 2141 break;
2142 } 2142 }
2143 2143
2144 _Bool typing = !!data[0]; 2144 bool typing = !!data[0];
2145 2145
2146 set_friend_typing(m, i, typing); 2146 set_friend_typing(m, i, typing);
2147 2147
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index 21d9f7b3..59cb401e 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -242,7 +242,7 @@ struct Messenger {
242 void (*friend_namechange)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *); 242 void (*friend_namechange)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *);
243 void (*friend_statusmessagechange)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *); 243 void (*friend_statusmessagechange)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *);
244 void (*friend_userstatuschange)(struct Messenger *m, uint32_t, unsigned int, void *); 244 void (*friend_userstatuschange)(struct Messenger *m, uint32_t, unsigned int, void *);
245 void (*friend_typingchange)(struct Messenger *m, uint32_t, _Bool, void *); 245 void (*friend_typingchange)(struct Messenger *m, uint32_t, bool, void *);
246 void (*read_receipt)(struct Messenger *m, uint32_t, uint32_t, void *); 246 void (*read_receipt)(struct Messenger *m, uint32_t, uint32_t, void *);
247 void (*friend_connectionstatuschange)(struct Messenger *m, uint32_t, unsigned int, void *); 247 void (*friend_connectionstatuschange)(struct Messenger *m, uint32_t, unsigned int, void *);
248 void (*friend_connectionstatuschange_internal)(struct Messenger *m, uint32_t, uint8_t, void *); 248 void (*friend_connectionstatuschange_internal)(struct Messenger *m, uint32_t, uint8_t, void *);
@@ -494,7 +494,7 @@ void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, uint32_t
494/* Set the callback for typing changes. 494/* Set the callback for typing changes.
495 * Function(uint32_t friendnumber, uint8_t is_typing) 495 * Function(uint32_t friendnumber, uint8_t is_typing)
496 */ 496 */
497void m_callback_typingchange(Messenger *m, void(*function)(Messenger *m, uint32_t, _Bool, void *)); 497void m_callback_typingchange(Messenger *m, void(*function)(Messenger *m, uint32_t, bool, void *));
498 498
499/* Set the callback for read receipts. 499/* Set the callback for read receipts.
500 * Function(uint32_t friendnumber, uint32_t receipt) 500 * Function(uint32_t friendnumber, uint32_t receipt)
diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c
index d825cf38..6c5ea0e1 100644
--- a/toxcore/TCP_client.c
+++ b/toxcore/TCP_client.c
@@ -330,7 +330,7 @@ static int send_pending_data(TCP_Client_Connection *con)
330/* return 0 on failure (only if malloc fails) 330/* return 0 on failure (only if malloc fails)
331 * return 1 on success 331 * return 1 on success
332 */ 332 */
333static _Bool add_priority(TCP_Client_Connection *con, const uint8_t *packet, uint16_t size, uint16_t sent) 333static bool add_priority(TCP_Client_Connection *con, const uint8_t *packet, uint16_t size, uint16_t sent)
334{ 334{
335 TCP_Priority_List *p = con->priority_queue_end, *new; 335 TCP_Priority_List *p = con->priority_queue_end, *new;
336 new = malloc(sizeof(TCP_Priority_List) + size); 336 new = malloc(sizeof(TCP_Priority_List) + size);
@@ -370,13 +370,13 @@ static void wipe_priority_list(TCP_Client_Connection *con)
370 * return -1 on failure (connection must be killed). 370 * return -1 on failure (connection must be killed).
371 */ 371 */
372static int write_packet_TCP_secure_connection(TCP_Client_Connection *con, const uint8_t *data, uint16_t length, 372static int write_packet_TCP_secure_connection(TCP_Client_Connection *con, const uint8_t *data, uint16_t length,
373 _Bool priority) 373 bool priority)
374{ 374{
375 if (length + crypto_box_MACBYTES > MAX_PACKET_SIZE) { 375 if (length + crypto_box_MACBYTES > MAX_PACKET_SIZE) {
376 return -1; 376 return -1;
377 } 377 }
378 378
379 _Bool sendpriority = 1; 379 bool sendpriority = 1;
380 380
381 if (send_pending_data(con) == -1) { 381 if (send_pending_data(con) == -1) {
382 if (priority) { 382 if (priority) {
diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c
index 6a0b2c8a..bfd55fa0 100644
--- a/toxcore/TCP_connection.c
+++ b/toxcore/TCP_connection.c
@@ -40,7 +40,7 @@
40/* return 1 if the connections_number is not valid. 40/* return 1 if the connections_number is not valid.
41 * return 0 if the connections_number is valid. 41 * return 0 if the connections_number is valid.
42 */ 42 */
43static _Bool connections_number_not_valid(const TCP_Connections *tcp_c, int connections_number) 43static bool connections_number_not_valid(const TCP_Connections *tcp_c, int connections_number)
44{ 44{
45 if ((unsigned int)connections_number >= tcp_c->connections_length) { 45 if ((unsigned int)connections_number >= tcp_c->connections_length) {
46 return 1; 46 return 1;
@@ -60,7 +60,7 @@ static _Bool connections_number_not_valid(const TCP_Connections *tcp_c, int conn
60/* return 1 if the tcp_connections_number is not valid. 60/* return 1 if the tcp_connections_number is not valid.
61 * return 0 if the tcp_connections_number is valid. 61 * return 0 if the tcp_connections_number is valid.
62 */ 62 */
63static _Bool tcp_connections_number_not_valid(const TCP_Connections *tcp_c, int tcp_connections_number) 63static bool tcp_connections_number_not_valid(const TCP_Connections *tcp_c, int tcp_connections_number)
64{ 64{
65 if ((unsigned int)tcp_connections_number >= tcp_c->tcp_connections_length) { 65 if ((unsigned int)tcp_connections_number >= tcp_c->tcp_connections_length) {
66 return 1; 66 return 1;
@@ -228,7 +228,7 @@ int send_packet_tcp_connection(TCP_Connections *tcp_c, int connections_number, c
228 unsigned int i; 228 unsigned int i;
229 int ret = -1; 229 int ret = -1;
230 230
231 _Bool limit_reached = 0; 231 bool limit_reached = 0;
232 232
233 for (i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) { 233 for (i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) {
234 uint32_t tcp_con_num = con_to->connections[i].tcp_connection; 234 uint32_t tcp_con_num = con_to->connections[i].tcp_connection;
@@ -522,7 +522,7 @@ int kill_tcp_connection_to(TCP_Connections *tcp_c, int connections_number)
522 * return 0 on success. 522 * return 0 on success.
523 * return -1 on failure. 523 * return -1 on failure.
524 */ 524 */
525int set_tcp_connection_to_status(TCP_Connections *tcp_c, int connections_number, _Bool status) 525int set_tcp_connection_to_status(TCP_Connections *tcp_c, int connections_number, bool status)
526{ 526{
527 TCP_Connection_to *con_to = get_connection(tcp_c, connections_number); 527 TCP_Connection_to *con_to = get_connection(tcp_c, connections_number);
528 528
@@ -583,7 +583,7 @@ int set_tcp_connection_to_status(TCP_Connections *tcp_c, int connections_number,
583 return 0; 583 return 0;
584} 584}
585 585
586static _Bool tcp_connection_in_conn(TCP_Connection_to *con_to, unsigned int tcp_connections_number) 586static bool tcp_connection_in_conn(TCP_Connection_to *con_to, unsigned int tcp_connections_number)
587{ 587{
588 unsigned int i; 588 unsigned int i;
589 589
@@ -1253,7 +1253,7 @@ unsigned int tcp_copy_connected_relays(TCP_Connections *tcp_c, Node_format *tcp_
1253 * return 0 on success. 1253 * return 0 on success.
1254 * return -1 on failure. 1254 * return -1 on failure.
1255 */ 1255 */
1256int set_tcp_onion_status(TCP_Connections *tcp_c, _Bool status) 1256int set_tcp_onion_status(TCP_Connections *tcp_c, bool status)
1257{ 1257{
1258 if (tcp_c->onion_status == status) { 1258 if (tcp_c->onion_status == status) {
1259 return -1; 1259 return -1;
diff --git a/toxcore/TCP_connection.h b/toxcore/TCP_connection.h
index e080c7e2..e0a3988e 100644
--- a/toxcore/TCP_connection.h
+++ b/toxcore/TCP_connection.h
@@ -70,12 +70,12 @@ typedef struct {
70 uint64_t connected_time; 70 uint64_t connected_time;
71 uint32_t lock_count; 71 uint32_t lock_count;
72 uint32_t sleep_count; 72 uint32_t sleep_count;
73 _Bool onion; 73 bool onion;
74 74
75 /* Only used when connection is sleeping. */ 75 /* Only used when connection is sleeping. */
76 IP_Port ip_port; 76 IP_Port ip_port;
77 uint8_t relay_pk[crypto_box_PUBLICKEYBYTES]; 77 uint8_t relay_pk[crypto_box_PUBLICKEYBYTES];
78 _Bool unsleep; /* set to 1 to unsleep connection. */ 78 bool unsleep; /* set to 1 to unsleep connection. */
79} TCP_con; 79} TCP_con;
80 80
81typedef struct { 81typedef struct {
@@ -102,7 +102,7 @@ typedef struct {
102 102
103 TCP_Proxy_Info proxy_info; 103 TCP_Proxy_Info proxy_info;
104 104
105 _Bool onion_status; 105 bool onion_status;
106 uint16_t onion_num_conns; 106 uint16_t onion_num_conns;
107} TCP_Connections; 107} TCP_Connections;
108 108
@@ -138,7 +138,7 @@ int tcp_send_onion_request(TCP_Connections *tcp_c, unsigned int tcp_connections_
138 * return 0 on success. 138 * return 0 on success.
139 * return -1 on failure. 139 * return -1 on failure.
140 */ 140 */
141int set_tcp_onion_status(TCP_Connections *tcp_c, _Bool status); 141int set_tcp_onion_status(TCP_Connections *tcp_c, bool status);
142 142
143/* Send an oob packet via the TCP relay corresponding to tcp_connections_number. 143/* Send an oob packet via the TCP relay corresponding to tcp_connections_number.
144 * 144 *
@@ -190,7 +190,7 @@ int kill_tcp_connection_to(TCP_Connections *tcp_c, int connections_number);
190 * return 0 on success. 190 * return 0 on success.
191 * return -1 on failure. 191 * return -1 on failure.
192 */ 192 */
193int set_tcp_connection_to_status(TCP_Connections *tcp_c, int connections_number, _Bool status); 193int set_tcp_connection_to_status(TCP_Connections *tcp_c, int connections_number, bool status);
194 194
195/* return number of online tcp relays tied to the connection on success. 195/* return number of online tcp relays tied to the connection on success.
196 * return 0 on failure. 196 * return 0 on failure.
diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c
index 0a347342..13e4da45 100644
--- a/toxcore/TCP_server.c
+++ b/toxcore/TCP_server.c
@@ -369,7 +369,7 @@ static int send_pending_data(TCP_Secure_Connection *con)
369/* return 0 on failure (only if malloc fails) 369/* return 0 on failure (only if malloc fails)
370 * return 1 on success 370 * return 1 on success
371 */ 371 */
372static _Bool add_priority(TCP_Secure_Connection *con, const uint8_t *packet, uint16_t size, uint16_t sent) 372static bool add_priority(TCP_Secure_Connection *con, const uint8_t *packet, uint16_t size, uint16_t sent)
373{ 373{
374 TCP_Priority_List *p = con->priority_queue_end, *new; 374 TCP_Priority_List *p = con->priority_queue_end, *new;
375 new = malloc(sizeof(TCP_Priority_List) + size); 375 new = malloc(sizeof(TCP_Priority_List) + size);
@@ -398,13 +398,13 @@ static _Bool add_priority(TCP_Secure_Connection *con, const uint8_t *packet, uin
398 * return -1 on failure (connection must be killed). 398 * return -1 on failure (connection must be killed).
399 */ 399 */
400static int write_packet_TCP_secure_connection(TCP_Secure_Connection *con, const uint8_t *data, uint16_t length, 400static int write_packet_TCP_secure_connection(TCP_Secure_Connection *con, const uint8_t *data, uint16_t length,
401 _Bool priority) 401 bool priority)
402{ 402{
403 if (length + crypto_box_MACBYTES > MAX_PACKET_SIZE) { 403 if (length + crypto_box_MACBYTES > MAX_PACKET_SIZE) {
404 return -1; 404 return -1;
405 } 405 }
406 406
407 _Bool sendpriority = 1; 407 bool sendpriority = 1;
408 408
409 if (send_pending_data(con) == -1) { 409 if (send_pending_data(con) == -1) {
410 if (priority) { 410 if (priority) {
diff --git a/toxcore/friend_connection.c b/toxcore/friend_connection.c
index fa88f1bc..314f4e61 100644
--- a/toxcore/friend_connection.c
+++ b/toxcore/friend_connection.c
@@ -332,7 +332,7 @@ static int handle_status(void *object, int number, uint8_t status, void *userdat
332 return -1; 332 return -1;
333 } 333 }
334 334
335 _Bool call_cb = 0; 335 bool call_cb = 0;
336 336
337 if (status) { /* Went online. */ 337 if (status) { /* Went online. */
338 call_cb = 1; 338 call_cb = 1;
diff --git a/toxcore/friend_connection.h b/toxcore/friend_connection.h
index df017c1f..4bc5250a 100644
--- a/toxcore/friend_connection.h
+++ b/toxcore/friend_connection.h
@@ -96,7 +96,7 @@ typedef struct {
96 Node_format tcp_relays[FRIEND_MAX_STORED_TCP_RELAYS]; 96 Node_format tcp_relays[FRIEND_MAX_STORED_TCP_RELAYS];
97 uint16_t tcp_relay_counter; 97 uint16_t tcp_relay_counter;
98 98
99 _Bool hosting_tcp_relay; 99 bool hosting_tcp_relay;
100} Friend_Conn; 100} Friend_Conn;
101 101
102 102
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index b93b5cde..a354c36b 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -473,7 +473,7 @@ static IP_Port return_ip_port_connection(Net_Crypto *c, int crypt_connection_id)
473 } 473 }
474 474
475 uint64_t current_time = unix_time(); 475 uint64_t current_time = unix_time();
476 _Bool v6 = 0, v4 = 0; 476 bool v6 = 0, v4 = 0;
477 477
478 if ((UDP_DIRECT_TIMEOUT + conn->direct_lastrecv_timev4) > current_time) { 478 if ((UDP_DIRECT_TIMEOUT + conn->direct_lastrecv_timev4) > current_time) {
479 v4 = 1; 479 v4 = 1;
@@ -519,7 +519,7 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, const uint8_t
519 519
520 //TODO: on bad networks, direct connections might not last indefinitely. 520 //TODO: on bad networks, direct connections might not last indefinitely.
521 if (ip_port.ip.family != 0) { 521 if (ip_port.ip.family != 0) {
522 _Bool direct_connected = 0; 522 bool direct_connected = 0;
523 crypto_connection_status(c, crypt_connection_id, &direct_connected, NULL); 523 crypto_connection_status(c, crypt_connection_id, &direct_connected, NULL);
524 524
525 if (direct_connected) { 525 if (direct_connected) {
@@ -1322,7 +1322,7 @@ static void connection_kill(Net_Crypto *c, int crypt_connection_id, void *userda
1322 * return 0 on success. 1322 * return 0 on success.
1323 */ 1323 */
1324static int handle_data_packet_helper(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length, 1324static int handle_data_packet_helper(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length,
1325 _Bool udp, void *userdata) 1325 bool udp, void *userdata)
1326{ 1326{
1327 if (length > MAX_CRYPTO_PACKET_SIZE || length <= CRYPTO_DATA_PACKET_MIN_SIZE) { 1327 if (length > MAX_CRYPTO_PACKET_SIZE || length <= CRYPTO_DATA_PACKET_MIN_SIZE) {
1328 return -1; 1328 return -1;
@@ -1469,7 +1469,7 @@ static int handle_data_packet_helper(Net_Crypto *c, int crypt_connection_id, con
1469 * return 0 on success. 1469 * return 0 on success.
1470 */ 1470 */
1471static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length, 1471static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length,
1472 _Bool udp, void *userdata) 1472 bool udp, void *userdata)
1473{ 1473{
1474 if (length == 0 || length > MAX_CRYPTO_PACKET_SIZE) { 1474 if (length == 0 || length > MAX_CRYPTO_PACKET_SIZE) {
1475 return -1; 1475 return -1;
@@ -1911,7 +1911,7 @@ int new_crypto_connection(Net_Crypto *c, const uint8_t *real_public_key, const u
1911 * return -1 on failure. 1911 * return -1 on failure.
1912 * return 0 on success. 1912 * return 0 on success.
1913 */ 1913 */
1914int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port, _Bool connected) 1914int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port, bool connected)
1915{ 1915{
1916 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 1916 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
1917 1917
@@ -2098,7 +2098,7 @@ static void do_tcp(Net_Crypto *c, void *userdata)
2098 } 2098 }
2099 2099
2100 if (conn->status == CRYPTO_CONN_ESTABLISHED) { 2100 if (conn->status == CRYPTO_CONN_ESTABLISHED) {
2101 _Bool direct_connected = 0; 2101 bool direct_connected = 0;
2102 crypto_connection_status(c, i, &direct_connected, NULL); 2102 crypto_connection_status(c, i, &direct_connected, NULL);
2103 2103
2104 if (direct_connected) { 2104 if (direct_connected) {
@@ -2380,7 +2380,7 @@ static void send_crypto_packets(Net_Crypto *c)
2380 conn->last_num_packets_sent[n_p_pos] = packets_sent; 2380 conn->last_num_packets_sent[n_p_pos] = packets_sent;
2381 conn->last_num_packets_resent[n_p_pos] = packets_resent; 2381 conn->last_num_packets_resent[n_p_pos] = packets_resent;
2382 2382
2383 _Bool direct_connected = 0; 2383 bool direct_connected = 0;
2384 crypto_connection_status(c, i, &direct_connected, NULL); 2384 crypto_connection_status(c, i, &direct_connected, NULL);
2385 2385
2386 if (direct_connected && conn->last_tcp_sent + CONGESTION_EVENT_TIMEOUT > temp_time) { 2386 if (direct_connected && conn->last_tcp_sent + CONGESTION_EVENT_TIMEOUT > temp_time) {
@@ -2530,7 +2530,7 @@ static void send_crypto_packets(Net_Crypto *c)
2530/* Return 1 if max speed was reached for this connection (no more data can be physically through the pipe). 2530/* Return 1 if max speed was reached for this connection (no more data can be physically through the pipe).
2531 * Return 0 if it wasn't reached. 2531 * Return 0 if it wasn't reached.
2532 */ 2532 */
2533_Bool max_speed_reached(Net_Crypto *c, int crypt_connection_id) 2533bool max_speed_reached(Net_Crypto *c, int crypt_connection_id)
2534{ 2534{
2535 return reset_max_speed_reached(c, crypt_connection_id) != 0; 2535 return reset_max_speed_reached(c, crypt_connection_id) != 0;
2536} 2536}
@@ -2721,7 +2721,7 @@ int crypto_kill(Net_Crypto *c, int crypt_connection_id)
2721 * sets direct_connected to 1 if connection connects directly to other, 0 if it isn't. 2721 * sets direct_connected to 1 if connection connects directly to other, 0 if it isn't.
2722 * sets online_tcp_relays to the number of connected tcp relays this connection has. 2722 * sets online_tcp_relays to the number of connected tcp relays this connection has.
2723 */ 2723 */
2724unsigned int crypto_connection_status(const Net_Crypto *c, int crypt_connection_id, _Bool *direct_connected, 2724unsigned int crypto_connection_status(const Net_Crypto *c, int crypt_connection_id, bool *direct_connected,
2725 unsigned int *online_tcp_relays) 2725 unsigned int *online_tcp_relays)
2726{ 2726{
2727 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 2727 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h
index 7d2644f4..b27a05e7 100644
--- a/toxcore/net_crypto.h
+++ b/toxcore/net_crypto.h
@@ -252,7 +252,7 @@ int new_crypto_connection(Net_Crypto *c, const uint8_t *real_public_key, const u
252 * return -1 on failure. 252 * return -1 on failure.
253 * return 0 on success. 253 * return 0 on success.
254 */ 254 */
255int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port, _Bool connected); 255int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port, bool connected);
256 256
257/* Set function to be called when connection with crypt_connection_id goes connects/disconnects. 257/* Set function to be called when connection with crypt_connection_id goes connects/disconnects.
258 * 258 *
@@ -313,7 +313,7 @@ uint32_t crypto_num_free_sendqueue_slots(const Net_Crypto *c, int crypt_connecti
313/* Return 1 if max speed was reached for this connection (no more data can be physically through the pipe). 313/* Return 1 if max speed was reached for this connection (no more data can be physically through the pipe).
314 * Return 0 if it wasn't reached. 314 * Return 0 if it wasn't reached.
315 */ 315 */
316_Bool max_speed_reached(Net_Crypto *c, int crypt_connection_id); 316bool max_speed_reached(Net_Crypto *c, int crypt_connection_id);
317 317
318/* Sends a lossless cryptopacket. 318/* Sends a lossless cryptopacket.
319 * 319 *
@@ -391,7 +391,7 @@ int crypto_kill(Net_Crypto *c, int crypt_connection_id);
391 * sets direct_connected to 1 if connection connects directly to other, 0 if it isn't. 391 * sets direct_connected to 1 if connection connects directly to other, 0 if it isn't.
392 * sets online_tcp_relays to the number of connected tcp relays this connection has. 392 * sets online_tcp_relays to the number of connected tcp relays this connection has.
393 */ 393 */
394unsigned int crypto_connection_status(const Net_Crypto *c, int crypt_connection_id, _Bool *direct_connected, 394unsigned int crypto_connection_status(const Net_Crypto *c, int crypt_connection_id, bool *direct_connected,
395 unsigned int *online_tcp_relays); 395 unsigned int *online_tcp_relays);
396 396
397/* Generate our public and private keys. 397/* Generate our public and private keys.
diff --git a/toxcore/onion.c b/toxcore/onion.c
index ba3f1f4a..5e5fd135 100644
--- a/toxcore/onion.c
+++ b/toxcore/onion.c
@@ -62,7 +62,7 @@ static void ip_pack(uint8_t *data, IP source)
62} 62}
63 63
64/* return 0 on success, -1 on failure. */ 64/* return 0 on success, -1 on failure. */
65static int ip_unpack(IP *target, const uint8_t *data, unsigned int data_size, _Bool disable_family_check) 65static int ip_unpack(IP *target, const uint8_t *data, unsigned int data_size, bool disable_family_check)
66{ 66{
67 if (data_size < (1 + SIZE_IP6)) { 67 if (data_size < (1 + SIZE_IP6)) {
68 return -1; 68 return -1;
@@ -91,7 +91,7 @@ static void ipport_pack(uint8_t *data, const IP_Port *source)
91} 91}
92 92
93/* return 0 on success, -1 on failure. */ 93/* return 0 on success, -1 on failure. */
94static int ipport_unpack(IP_Port *target, const uint8_t *data, unsigned int data_size, _Bool disable_family_check) 94static int ipport_unpack(IP_Port *target, const uint8_t *data, unsigned int data_size, bool disable_family_check)
95{ 95{
96 if (data_size < (SIZE_IP + SIZE_PORT)) { 96 if (data_size < (SIZE_IP + SIZE_PORT)) {
97 return -1; 97 return -1;
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c
index 0dca8525..04822cc1 100644
--- a/toxcore/onion_client.c
+++ b/toxcore/onion_client.c
@@ -213,7 +213,7 @@ static int is_path_used(const Onion_Client_Paths *onion_paths, const Node_format
213} 213}
214 214
215/* is path timed out */ 215/* is path timed out */
216static _Bool path_timed_out(Onion_Client_Paths *onion_paths, uint32_t pathnum) 216static bool path_timed_out(Onion_Client_Paths *onion_paths, uint32_t pathnum)
217{ 217{
218 pathnum = pathnum % NUMBER_ONION_PATHS; 218 pathnum = pathnum % NUMBER_ONION_PATHS;
219 219
@@ -275,7 +275,7 @@ static int random_path(const Onion_Client *onion_c, Onion_Client_Paths *onion_pa
275} 275}
276 276
277/* Does path with path_num exist. */ 277/* Does path with path_num exist. */
278static _Bool path_exists(Onion_Client_Paths *onion_paths, uint32_t path_num) 278static bool path_exists(Onion_Client_Paths *onion_paths, uint32_t path_num)
279{ 279{
280 if (path_timed_out(onion_paths, path_num)) { 280 if (path_timed_out(onion_paths, path_num)) {
281 return 0; 281 return 0;
@@ -1577,7 +1577,7 @@ void do_onion_client(Onion_Client *onion_c)
1577 } 1577 }
1578 } 1578 }
1579 1579
1580 _Bool UDP_connected = DHT_non_lan_connected(onion_c->dht); 1580 bool UDP_connected = DHT_non_lan_connected(onion_c->dht);
1581 1581
1582 if (is_timeout(onion_c->first_run, ONION_CONNECTION_SECONDS * 2)) { 1582 if (is_timeout(onion_c->first_run, ONION_CONNECTION_SECONDS * 2)) {
1583 set_tcp_onion_status(onion_c->c->tcp_c, !UDP_connected); 1583 set_tcp_onion_status(onion_c->c->tcp_c, !UDP_connected);
diff --git a/toxcore/onion_client.h b/toxcore/onion_client.h
index 9c37c66f..47d08eca 100644
--- a/toxcore/onion_client.h
+++ b/toxcore/onion_client.h
@@ -160,7 +160,7 @@ typedef struct {
160 uint64_t last_packet_recv; 160 uint64_t last_packet_recv;
161 161
162 unsigned int onion_connected; 162 unsigned int onion_connected;
163 _Bool UDP_connected; 163 bool UDP_connected;
164} Onion_Client; 164} Onion_Client;
165 165
166 166
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 9ec472c0..463238b5 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -179,7 +179,7 @@ Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error)
179{ 179{
180 Messenger_Options m_options = {0}; 180 Messenger_Options m_options = {0};
181 181
182 _Bool load_savedata_sk = 0, load_savedata_tox = 0; 182 bool load_savedata_sk = 0, load_savedata_tox = 0;
183 183
184 if (options == NULL) { 184 if (options == NULL) {
185 m_options.ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; 185 m_options.ipv6enabled = TOX_ENABLE_IPV6_DEFAULT;