diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-01-28 21:30:39 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-01-30 23:35:50 +0000 |
commit | 92ffad1a72bc8c422426d52ac408bd71242dd047 (patch) | |
tree | f592f353068dd2043525dd2cc04d6124a4ed4bc4 /toxcore/net_crypto.c | |
parent | 623e9ac331df7323660e21c8a2226523a5ee713b (diff) |
Use nullptr as NULL pointer constant instead of NULL or 0.
This changes only code, no string literals or comments.
Diffstat (limited to 'toxcore/net_crypto.c')
-rw-r--r-- | toxcore/net_crypto.c | 134 |
1 files changed, 67 insertions, 67 deletions
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index f03ddb87..5027ce25 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c | |||
@@ -180,7 +180,7 @@ static uint8_t crypt_connection_id_not_valid(const Net_Crypto *c, int crypt_conn | |||
180 | return 1; | 180 | return 1; |
181 | } | 181 | } |
182 | 182 | ||
183 | if (c->crypto_connections == NULL) { | 183 | if (c->crypto_connections == nullptr) { |
184 | return 1; | 184 | return 1; |
185 | } | 185 | } |
186 | 186 | ||
@@ -551,7 +551,7 @@ static int handle_crypto_handshake(const Net_Crypto *c, uint8_t *nonce, uint8_t | |||
551 | static Crypto_Connection *get_crypto_connection(const Net_Crypto *c, int crypt_connection_id) | 551 | static Crypto_Connection *get_crypto_connection(const Net_Crypto *c, int crypt_connection_id) |
552 | { | 552 | { |
553 | if (crypt_connection_id_not_valid(c, crypt_connection_id)) { | 553 | if (crypt_connection_id_not_valid(c, crypt_connection_id)) { |
554 | return 0; | 554 | return nullptr; |
555 | } | 555 | } |
556 | 556 | ||
557 | return &c->crypto_connections[crypt_connection_id]; | 557 | return &c->crypto_connections[crypt_connection_id]; |
@@ -567,7 +567,7 @@ static int add_ip_port_connection(Net_Crypto *c, int crypt_connection_id, IP_Por | |||
567 | { | 567 | { |
568 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 568 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
569 | 569 | ||
570 | if (conn == 0) { | 570 | if (conn == nullptr) { |
571 | return -1; | 571 | return -1; |
572 | } | 572 | } |
573 | 573 | ||
@@ -607,7 +607,7 @@ static IP_Port return_ip_port_connection(Net_Crypto *c, int crypt_connection_id) | |||
607 | 607 | ||
608 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 608 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
609 | 609 | ||
610 | if (conn == 0) { | 610 | if (conn == nullptr) { |
611 | return empty; | 611 | return empty; |
612 | } | 612 | } |
613 | 613 | ||
@@ -647,7 +647,7 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, const uint8_t | |||
647 | // TODO(irungentoo): TCP, etc... | 647 | // TODO(irungentoo): TCP, etc... |
648 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 648 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
649 | 649 | ||
650 | if (conn == 0) { | 650 | if (conn == nullptr) { |
651 | return -1; | 651 | return -1; |
652 | } | 652 | } |
653 | 653 | ||
@@ -659,7 +659,7 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, const uint8_t | |||
659 | // TODO(irungentoo): on bad networks, direct connections might not last indefinitely. | 659 | // TODO(irungentoo): on bad networks, direct connections might not last indefinitely. |
660 | if (ip_port.ip.family != 0) { | 660 | if (ip_port.ip.family != 0) { |
661 | bool direct_connected = 0; | 661 | bool direct_connected = 0; |
662 | crypto_connection_status(c, crypt_connection_id, &direct_connected, NULL); | 662 | crypto_connection_status(c, crypt_connection_id, &direct_connected, nullptr); |
663 | 663 | ||
664 | if (direct_connected) { | 664 | if (direct_connected) { |
665 | if ((uint32_t)sendpacket(dht_get_net(c->dht), ip_port, data, length) == length) { | 665 | if ((uint32_t)sendpacket(dht_get_net(c->dht), ip_port, data, length) == length) { |
@@ -733,7 +733,7 @@ static int add_data_to_buffer(Packets_Array *array, uint32_t number, const Packe | |||
733 | 733 | ||
734 | Packet_Data *new_d = (Packet_Data *)malloc(sizeof(Packet_Data)); | 734 | Packet_Data *new_d = (Packet_Data *)malloc(sizeof(Packet_Data)); |
735 | 735 | ||
736 | if (new_d == NULL) { | 736 | if (new_d == nullptr) { |
737 | return -1; | 737 | return -1; |
738 | } | 738 | } |
739 | 739 | ||
@@ -784,7 +784,7 @@ static int64_t add_data_end_of_buffer(Packets_Array *array, const Packet_Data *d | |||
784 | 784 | ||
785 | Packet_Data *new_d = (Packet_Data *)malloc(sizeof(Packet_Data)); | 785 | Packet_Data *new_d = (Packet_Data *)malloc(sizeof(Packet_Data)); |
786 | 786 | ||
787 | if (new_d == NULL) { | 787 | if (new_d == nullptr) { |
788 | return -1; | 788 | return -1; |
789 | } | 789 | } |
790 | 790 | ||
@@ -816,7 +816,7 @@ static int64_t read_data_beg_buffer(Packets_Array *array, Packet_Data *data) | |||
816 | uint32_t id = array->buffer_start; | 816 | uint32_t id = array->buffer_start; |
817 | ++array->buffer_start; | 817 | ++array->buffer_start; |
818 | free(array->buffer[num]); | 818 | free(array->buffer[num]); |
819 | array->buffer[num] = NULL; | 819 | array->buffer[num] = nullptr; |
820 | return id; | 820 | return id; |
821 | } | 821 | } |
822 | 822 | ||
@@ -840,7 +840,7 @@ static int clear_buffer_until(Packets_Array *array, uint32_t number) | |||
840 | 840 | ||
841 | if (array->buffer[num]) { | 841 | if (array->buffer[num]) { |
842 | free(array->buffer[num]); | 842 | free(array->buffer[num]); |
843 | array->buffer[num] = NULL; | 843 | array->buffer[num] = nullptr; |
844 | } | 844 | } |
845 | } | 845 | } |
846 | 846 | ||
@@ -857,7 +857,7 @@ static int clear_buffer(Packets_Array *array) | |||
857 | 857 | ||
858 | if (array->buffer[num]) { | 858 | if (array->buffer[num]) { |
859 | free(array->buffer[num]); | 859 | free(array->buffer[num]); |
860 | array->buffer[num] = NULL; | 860 | array->buffer[num] = nullptr; |
861 | } | 861 | } |
862 | } | 862 | } |
863 | 863 | ||
@@ -996,7 +996,7 @@ static int handle_request_packet(Packets_Array *send_array, const uint8_t *data, | |||
996 | } | 996 | } |
997 | 997 | ||
998 | free(send_array->buffer[num]); | 998 | free(send_array->buffer[num]); |
999 | send_array->buffer[num] = NULL; | 999 | send_array->buffer[num] = nullptr; |
1000 | } | 1000 | } |
1001 | } | 1001 | } |
1002 | 1002 | ||
@@ -1038,7 +1038,7 @@ static int send_data_packet(Net_Crypto *c, int crypt_connection_id, const uint8_ | |||
1038 | 1038 | ||
1039 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 1039 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
1040 | 1040 | ||
1041 | if (conn == 0) { | 1041 | if (conn == nullptr) { |
1042 | return -1; | 1042 | return -1; |
1043 | } | 1043 | } |
1044 | 1044 | ||
@@ -1087,14 +1087,14 @@ static int reset_max_speed_reached(Net_Crypto *c, int crypt_connection_id) | |||
1087 | { | 1087 | { |
1088 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 1088 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
1089 | 1089 | ||
1090 | if (conn == 0) { | 1090 | if (conn == nullptr) { |
1091 | return -1; | 1091 | return -1; |
1092 | } | 1092 | } |
1093 | 1093 | ||
1094 | /* If last packet send failed, try to send packet again. | 1094 | /* If last packet send failed, try to send packet again. |
1095 | If sending it fails we won't be able to send the new packet. */ | 1095 | If sending it fails we won't be able to send the new packet. */ |
1096 | if (conn->maximum_speed_reached) { | 1096 | if (conn->maximum_speed_reached) { |
1097 | Packet_Data *dt = NULL; | 1097 | Packet_Data *dt = nullptr; |
1098 | uint32_t packet_num = conn->send_array.buffer_end - 1; | 1098 | uint32_t packet_num = conn->send_array.buffer_end - 1; |
1099 | int ret = get_data_pointer(&conn->send_array, &dt, packet_num); | 1099 | int ret = get_data_pointer(&conn->send_array, &dt, packet_num); |
1100 | 1100 | ||
@@ -1133,7 +1133,7 @@ static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, cons | |||
1133 | 1133 | ||
1134 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 1134 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
1135 | 1135 | ||
1136 | if (conn == 0) { | 1136 | if (conn == nullptr) { |
1137 | return -1; | 1137 | return -1; |
1138 | } | 1138 | } |
1139 | 1139 | ||
@@ -1162,7 +1162,7 @@ static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, cons | |||
1162 | } | 1162 | } |
1163 | 1163 | ||
1164 | if (send_data_packet_helper(c, crypt_connection_id, conn->recv_array.buffer_start, packet_num, data, length) == 0) { | 1164 | if (send_data_packet_helper(c, crypt_connection_id, conn->recv_array.buffer_start, packet_num, data, length) == 0) { |
1165 | Packet_Data *dt1 = NULL; | 1165 | Packet_Data *dt1 = nullptr; |
1166 | 1166 | ||
1167 | if (get_data_pointer(&conn->send_array, &dt1, packet_num) == 1) { | 1167 | if (get_data_pointer(&conn->send_array, &dt1, packet_num) == 1) { |
1168 | dt1->sent_time = current_time_monotonic(); | 1168 | dt1->sent_time = current_time_monotonic(); |
@@ -1203,7 +1203,7 @@ static int handle_data_packet(const Net_Crypto *c, int crypt_connection_id, uint | |||
1203 | 1203 | ||
1204 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 1204 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
1205 | 1205 | ||
1206 | if (conn == 0) { | 1206 | if (conn == nullptr) { |
1207 | return -1; | 1207 | return -1; |
1208 | } | 1208 | } |
1209 | 1209 | ||
@@ -1238,7 +1238,7 @@ static int send_request_packet(Net_Crypto *c, int crypt_connection_id) | |||
1238 | { | 1238 | { |
1239 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 1239 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
1240 | 1240 | ||
1241 | if (conn == 0) { | 1241 | if (conn == nullptr) { |
1242 | return -1; | 1242 | return -1; |
1243 | } | 1243 | } |
1244 | 1244 | ||
@@ -1266,7 +1266,7 @@ static int send_requested_packets(Net_Crypto *c, int crypt_connection_id, uint32 | |||
1266 | 1266 | ||
1267 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 1267 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
1268 | 1268 | ||
1269 | if (conn == 0) { | 1269 | if (conn == nullptr) { |
1270 | return -1; | 1270 | return -1; |
1271 | } | 1271 | } |
1272 | 1272 | ||
@@ -1318,13 +1318,13 @@ static int new_temp_packet(const Net_Crypto *c, int crypt_connection_id, const u | |||
1318 | 1318 | ||
1319 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 1319 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
1320 | 1320 | ||
1321 | if (conn == 0) { | 1321 | if (conn == nullptr) { |
1322 | return -1; | 1322 | return -1; |
1323 | } | 1323 | } |
1324 | 1324 | ||
1325 | uint8_t *temp_packet = (uint8_t *)malloc(length); | 1325 | uint8_t *temp_packet = (uint8_t *)malloc(length); |
1326 | 1326 | ||
1327 | if (temp_packet == 0) { | 1327 | if (temp_packet == nullptr) { |
1328 | return -1; | 1328 | return -1; |
1329 | } | 1329 | } |
1330 | 1330 | ||
@@ -1349,7 +1349,7 @@ static int clear_temp_packet(const Net_Crypto *c, int crypt_connection_id) | |||
1349 | { | 1349 | { |
1350 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 1350 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
1351 | 1351 | ||
1352 | if (conn == 0) { | 1352 | if (conn == nullptr) { |
1353 | return -1; | 1353 | return -1; |
1354 | } | 1354 | } |
1355 | 1355 | ||
@@ -1357,7 +1357,7 @@ static int clear_temp_packet(const Net_Crypto *c, int crypt_connection_id) | |||
1357 | free(conn->temp_packet); | 1357 | free(conn->temp_packet); |
1358 | } | 1358 | } |
1359 | 1359 | ||
1360 | conn->temp_packet = 0; | 1360 | conn->temp_packet = nullptr; |
1361 | conn->temp_packet_length = 0; | 1361 | conn->temp_packet_length = 0; |
1362 | conn->temp_packet_sent_time = 0; | 1362 | conn->temp_packet_sent_time = 0; |
1363 | conn->temp_packet_num_sent = 0; | 1363 | conn->temp_packet_num_sent = 0; |
@@ -1374,7 +1374,7 @@ static int send_temp_packet(Net_Crypto *c, int crypt_connection_id) | |||
1374 | { | 1374 | { |
1375 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 1375 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
1376 | 1376 | ||
1377 | if (conn == 0) { | 1377 | if (conn == nullptr) { |
1378 | return -1; | 1378 | return -1; |
1379 | } | 1379 | } |
1380 | 1380 | ||
@@ -1402,7 +1402,7 @@ static int create_send_handshake(Net_Crypto *c, int crypt_connection_id, const u | |||
1402 | { | 1402 | { |
1403 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 1403 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
1404 | 1404 | ||
1405 | if (conn == 0) { | 1405 | if (conn == nullptr) { |
1406 | return -1; | 1406 | return -1; |
1407 | } | 1407 | } |
1408 | 1408 | ||
@@ -1430,7 +1430,7 @@ static int send_kill_packet(Net_Crypto *c, int crypt_connection_id) | |||
1430 | { | 1430 | { |
1431 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 1431 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
1432 | 1432 | ||
1433 | if (conn == 0) { | 1433 | if (conn == nullptr) { |
1434 | return -1; | 1434 | return -1; |
1435 | } | 1435 | } |
1436 | 1436 | ||
@@ -1443,7 +1443,7 @@ static void connection_kill(Net_Crypto *c, int crypt_connection_id, void *userda | |||
1443 | { | 1443 | { |
1444 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 1444 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
1445 | 1445 | ||
1446 | if (conn == 0) { | 1446 | if (conn == nullptr) { |
1447 | return; | 1447 | return; |
1448 | } | 1448 | } |
1449 | 1449 | ||
@@ -1469,7 +1469,7 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const | |||
1469 | 1469 | ||
1470 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 1470 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
1471 | 1471 | ||
1472 | if (conn == 0) { | 1472 | if (conn == nullptr) { |
1473 | return -1; | 1473 | return -1; |
1474 | } | 1474 | } |
1475 | 1475 | ||
@@ -1571,7 +1571,7 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const | |||
1571 | /* conn might get killed in callback. */ | 1571 | /* conn might get killed in callback. */ |
1572 | conn = get_crypto_connection(c, crypt_connection_id); | 1572 | conn = get_crypto_connection(c, crypt_connection_id); |
1573 | 1573 | ||
1574 | if (conn == 0) { | 1574 | if (conn == nullptr) { |
1575 | return -1; | 1575 | return -1; |
1576 | } | 1576 | } |
1577 | } | 1577 | } |
@@ -1616,7 +1616,7 @@ static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, cons | |||
1616 | 1616 | ||
1617 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 1617 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
1618 | 1618 | ||
1619 | if (conn == 0) { | 1619 | if (conn == nullptr) { |
1620 | return -1; | 1620 | return -1; |
1621 | } | 1621 | } |
1622 | 1622 | ||
@@ -1702,14 +1702,14 @@ static int realloc_cryptoconnection(Net_Crypto *c, uint32_t num) | |||
1702 | { | 1702 | { |
1703 | if (num == 0) { | 1703 | if (num == 0) { |
1704 | free(c->crypto_connections); | 1704 | free(c->crypto_connections); |
1705 | c->crypto_connections = NULL; | 1705 | c->crypto_connections = nullptr; |
1706 | return 0; | 1706 | return 0; |
1707 | } | 1707 | } |
1708 | 1708 | ||
1709 | Crypto_Connection *newcrypto_connections = (Crypto_Connection *)realloc(c->crypto_connections, | 1709 | Crypto_Connection *newcrypto_connections = (Crypto_Connection *)realloc(c->crypto_connections, |
1710 | num * sizeof(Crypto_Connection)); | 1710 | num * sizeof(Crypto_Connection)); |
1711 | 1711 | ||
1712 | if (newcrypto_connections == NULL) { | 1712 | if (newcrypto_connections == nullptr) { |
1713 | return -1; | 1713 | return -1; |
1714 | } | 1714 | } |
1715 | 1715 | ||
@@ -1756,7 +1756,7 @@ static int create_crypto_connection(Net_Crypto *c) | |||
1756 | c->crypto_connections[id].packet_send_rate_requested = 0; | 1756 | c->crypto_connections[id].packet_send_rate_requested = 0; |
1757 | c->crypto_connections[id].last_packets_left_requested_rem = 0; | 1757 | c->crypto_connections[id].last_packets_left_requested_rem = 0; |
1758 | 1758 | ||
1759 | if (pthread_mutex_init(&c->crypto_connections[id].mutex, NULL) != 0) { | 1759 | if (pthread_mutex_init(&c->crypto_connections[id].mutex, nullptr) != 0) { |
1760 | pthread_mutex_unlock(&c->connections_mutex); | 1760 | pthread_mutex_unlock(&c->connections_mutex); |
1761 | return -1; | 1761 | return -1; |
1762 | } | 1762 | } |
@@ -1831,7 +1831,7 @@ static int crypto_connection_add_source(Net_Crypto *c, int crypt_connection_id, | |||
1831 | { | 1831 | { |
1832 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 1832 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
1833 | 1833 | ||
1834 | if (conn == 0) { | 1834 | if (conn == nullptr) { |
1835 | return -1; | 1835 | return -1; |
1836 | } | 1836 | } |
1837 | 1837 | ||
@@ -1884,7 +1884,7 @@ static int handle_new_connection_handshake(Net_Crypto *c, IP_Port source, const | |||
1884 | New_Connection n_c; | 1884 | New_Connection n_c; |
1885 | n_c.cookie = (uint8_t *)malloc(COOKIE_LENGTH); | 1885 | n_c.cookie = (uint8_t *)malloc(COOKIE_LENGTH); |
1886 | 1886 | ||
1887 | if (n_c.cookie == NULL) { | 1887 | if (n_c.cookie == nullptr) { |
1888 | return -1; | 1888 | return -1; |
1889 | } | 1889 | } |
1890 | 1890 | ||
@@ -1892,7 +1892,7 @@ static int handle_new_connection_handshake(Net_Crypto *c, IP_Port source, const | |||
1892 | n_c.cookie_length = COOKIE_LENGTH; | 1892 | n_c.cookie_length = COOKIE_LENGTH; |
1893 | 1893 | ||
1894 | if (handle_crypto_handshake(c, n_c.recv_nonce, n_c.peersessionpublic_key, n_c.public_key, n_c.dht_public_key, | 1894 | if (handle_crypto_handshake(c, n_c.recv_nonce, n_c.peersessionpublic_key, n_c.public_key, n_c.dht_public_key, |
1895 | n_c.cookie, data, length, 0) != 0) { | 1895 | n_c.cookie, data, length, nullptr) != 0) { |
1896 | free(n_c.cookie); | 1896 | free(n_c.cookie); |
1897 | return -1; | 1897 | return -1; |
1898 | } | 1898 | } |
@@ -2009,7 +2009,7 @@ int new_crypto_connection(Net_Crypto *c, const uint8_t *real_public_key, const u | |||
2009 | 2009 | ||
2010 | Crypto_Connection *conn = &c->crypto_connections[crypt_connection_id]; | 2010 | Crypto_Connection *conn = &c->crypto_connections[crypt_connection_id]; |
2011 | 2011 | ||
2012 | if (conn == 0) { | 2012 | if (conn == nullptr) { |
2013 | return -1; | 2013 | return -1; |
2014 | } | 2014 | } |
2015 | 2015 | ||
@@ -2059,7 +2059,7 @@ int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port, | |||
2059 | { | 2059 | { |
2060 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 2060 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
2061 | 2061 | ||
2062 | if (conn == 0) { | 2062 | if (conn == nullptr) { |
2063 | return -1; | 2063 | return -1; |
2064 | } | 2064 | } |
2065 | 2065 | ||
@@ -2095,7 +2095,7 @@ static int tcp_data_callback(void *object, int id, const uint8_t *data, uint16_t | |||
2095 | 2095 | ||
2096 | Crypto_Connection *conn = get_crypto_connection(c, id); | 2096 | Crypto_Connection *conn = get_crypto_connection(c, id); |
2097 | 2097 | ||
2098 | if (conn == 0) { | 2098 | if (conn == nullptr) { |
2099 | return -1; | 2099 | return -1; |
2100 | } | 2100 | } |
2101 | 2101 | ||
@@ -2155,7 +2155,7 @@ int add_tcp_relay_peer(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port, | |||
2155 | { | 2155 | { |
2156 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 2156 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
2157 | 2157 | ||
2158 | if (conn == 0) { | 2158 | if (conn == nullptr) { |
2159 | return -1; | 2159 | return -1; |
2160 | } | 2160 | } |
2161 | 2161 | ||
@@ -2239,13 +2239,13 @@ static void do_tcp(Net_Crypto *c, void *userdata) | |||
2239 | for (i = 0; i < c->crypto_connections_length; ++i) { | 2239 | for (i = 0; i < c->crypto_connections_length; ++i) { |
2240 | Crypto_Connection *conn = get_crypto_connection(c, i); | 2240 | Crypto_Connection *conn = get_crypto_connection(c, i); |
2241 | 2241 | ||
2242 | if (conn == 0) { | 2242 | if (conn == nullptr) { |
2243 | return; | 2243 | return; |
2244 | } | 2244 | } |
2245 | 2245 | ||
2246 | if (conn->status == CRYPTO_CONN_ESTABLISHED) { | 2246 | if (conn->status == CRYPTO_CONN_ESTABLISHED) { |
2247 | bool direct_connected = 0; | 2247 | bool direct_connected = 0; |
2248 | crypto_connection_status(c, i, &direct_connected, NULL); | 2248 | crypto_connection_status(c, i, &direct_connected, nullptr); |
2249 | 2249 | ||
2250 | if (direct_connected) { | 2250 | if (direct_connected) { |
2251 | pthread_mutex_lock(&c->tcp_mutex); | 2251 | pthread_mutex_lock(&c->tcp_mutex); |
@@ -2275,7 +2275,7 @@ int connection_status_handler(const Net_Crypto *c, int crypt_connection_id, | |||
2275 | { | 2275 | { |
2276 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 2276 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
2277 | 2277 | ||
2278 | if (conn == 0) { | 2278 | if (conn == nullptr) { |
2279 | return -1; | 2279 | return -1; |
2280 | } | 2280 | } |
2281 | 2281 | ||
@@ -2298,7 +2298,7 @@ int connection_data_handler(const Net_Crypto *c, int crypt_connection_id, int (* | |||
2298 | { | 2298 | { |
2299 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 2299 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
2300 | 2300 | ||
2301 | if (conn == 0) { | 2301 | if (conn == nullptr) { |
2302 | return -1; | 2302 | return -1; |
2303 | } | 2303 | } |
2304 | 2304 | ||
@@ -2322,7 +2322,7 @@ int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id, | |||
2322 | { | 2322 | { |
2323 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 2323 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
2324 | 2324 | ||
2325 | if (conn == 0) { | 2325 | if (conn == nullptr) { |
2326 | return -1; | 2326 | return -1; |
2327 | } | 2327 | } |
2328 | 2328 | ||
@@ -2348,7 +2348,7 @@ int nc_dht_pk_callback(Net_Crypto *c, int crypt_connection_id, void (*function)( | |||
2348 | { | 2348 | { |
2349 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 2349 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
2350 | 2350 | ||
2351 | if (conn == 0) { | 2351 | if (conn == nullptr) { |
2352 | return -1; | 2352 | return -1; |
2353 | } | 2353 | } |
2354 | 2354 | ||
@@ -2405,7 +2405,7 @@ static int udp_handle_packet(void *object, IP_Port source, const uint8_t *packet | |||
2405 | 2405 | ||
2406 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 2406 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
2407 | 2407 | ||
2408 | if (conn == 0) { | 2408 | if (conn == nullptr) { |
2409 | return -1; | 2409 | return -1; |
2410 | } | 2410 | } |
2411 | 2411 | ||
@@ -2449,7 +2449,7 @@ static void send_crypto_packets(Net_Crypto *c) | |||
2449 | for (i = 0; i < c->crypto_connections_length; ++i) { | 2449 | for (i = 0; i < c->crypto_connections_length; ++i) { |
2450 | Crypto_Connection *conn = get_crypto_connection(c, i); | 2450 | Crypto_Connection *conn = get_crypto_connection(c, i); |
2451 | 2451 | ||
2452 | if (conn == 0) { | 2452 | if (conn == nullptr) { |
2453 | return; | 2453 | return; |
2454 | } | 2454 | } |
2455 | 2455 | ||
@@ -2527,7 +2527,7 @@ static void send_crypto_packets(Net_Crypto *c) | |||
2527 | conn->last_num_packets_resent[n_p_pos] = packets_resent; | 2527 | conn->last_num_packets_resent[n_p_pos] = packets_resent; |
2528 | 2528 | ||
2529 | bool direct_connected = 0; | 2529 | bool direct_connected = 0; |
2530 | crypto_connection_status(c, i, &direct_connected, NULL); | 2530 | crypto_connection_status(c, i, &direct_connected, nullptr); |
2531 | 2531 | ||
2532 | if (direct_connected && conn->last_tcp_sent + CONGESTION_EVENT_TIMEOUT > temp_time) { | 2532 | if (direct_connected && conn->last_tcp_sent + CONGESTION_EVENT_TIMEOUT > temp_time) { |
2533 | /* When switching from TCP to UDP, don't change the packet send rate for CONGESTION_EVENT_TIMEOUT ms. */ | 2533 | /* When switching from TCP to UDP, don't change the packet send rate for CONGESTION_EVENT_TIMEOUT ms. */ |
@@ -2688,7 +2688,7 @@ uint32_t crypto_num_free_sendqueue_slots(const Net_Crypto *c, int crypt_connecti | |||
2688 | { | 2688 | { |
2689 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 2689 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
2690 | 2690 | ||
2691 | if (conn == 0) { | 2691 | if (conn == nullptr) { |
2692 | return 0; | 2692 | return 0; |
2693 | } | 2693 | } |
2694 | 2694 | ||
@@ -2725,7 +2725,7 @@ int64_t write_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t | |||
2725 | 2725 | ||
2726 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 2726 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
2727 | 2727 | ||
2728 | if (conn == 0) { | 2728 | if (conn == nullptr) { |
2729 | return -1; | 2729 | return -1; |
2730 | } | 2730 | } |
2731 | 2731 | ||
@@ -2763,7 +2763,7 @@ int cryptpacket_received(Net_Crypto *c, int crypt_connection_id, uint32_t packet | |||
2763 | { | 2763 | { |
2764 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 2764 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
2765 | 2765 | ||
2766 | if (conn == 0) { | 2766 | if (conn == nullptr) { |
2767 | return -1; | 2767 | return -1; |
2768 | } | 2768 | } |
2769 | 2769 | ||
@@ -2872,7 +2872,7 @@ unsigned int crypto_connection_status(const Net_Crypto *c, int crypt_connection_ | |||
2872 | { | 2872 | { |
2873 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 2873 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
2874 | 2874 | ||
2875 | if (conn == 0) { | 2875 | if (conn == nullptr) { |
2876 | return CRYPTO_CONN_NO_CONNECTION; | 2876 | return CRYPTO_CONN_NO_CONNECTION; |
2877 | } | 2877 | } |
2878 | 2878 | ||
@@ -2929,33 +2929,33 @@ Net_Crypto *new_net_crypto(Logger *log, DHT *dht, TCP_Proxy_Info *proxy_info) | |||
2929 | { | 2929 | { |
2930 | unix_time_update(); | 2930 | unix_time_update(); |
2931 | 2931 | ||
2932 | if (dht == NULL) { | 2932 | if (dht == nullptr) { |
2933 | return NULL; | 2933 | return nullptr; |
2934 | } | 2934 | } |
2935 | 2935 | ||
2936 | Net_Crypto *temp = (Net_Crypto *)calloc(1, sizeof(Net_Crypto)); | 2936 | Net_Crypto *temp = (Net_Crypto *)calloc(1, sizeof(Net_Crypto)); |
2937 | 2937 | ||
2938 | if (temp == NULL) { | 2938 | if (temp == nullptr) { |
2939 | return NULL; | 2939 | return nullptr; |
2940 | } | 2940 | } |
2941 | 2941 | ||
2942 | temp->log = log; | 2942 | temp->log = log; |
2943 | 2943 | ||
2944 | temp->tcp_c = new_tcp_connections(dht_get_self_secret_key(dht), proxy_info); | 2944 | temp->tcp_c = new_tcp_connections(dht_get_self_secret_key(dht), proxy_info); |
2945 | 2945 | ||
2946 | if (temp->tcp_c == NULL) { | 2946 | if (temp->tcp_c == nullptr) { |
2947 | free(temp); | 2947 | free(temp); |
2948 | return NULL; | 2948 | return nullptr; |
2949 | } | 2949 | } |
2950 | 2950 | ||
2951 | set_packet_tcp_connection_callback(temp->tcp_c, &tcp_data_callback, temp); | 2951 | set_packet_tcp_connection_callback(temp->tcp_c, &tcp_data_callback, temp); |
2952 | set_oob_packet_tcp_connection_callback(temp->tcp_c, &tcp_oob_callback, temp); | 2952 | set_oob_packet_tcp_connection_callback(temp->tcp_c, &tcp_oob_callback, temp); |
2953 | 2953 | ||
2954 | if (create_recursive_mutex(&temp->tcp_mutex) != 0 || | 2954 | if (create_recursive_mutex(&temp->tcp_mutex) != 0 || |
2955 | pthread_mutex_init(&temp->connections_mutex, NULL) != 0) { | 2955 | pthread_mutex_init(&temp->connections_mutex, nullptr) != 0) { |
2956 | kill_tcp_connections(temp->tcp_c); | 2956 | kill_tcp_connections(temp->tcp_c); |
2957 | free(temp); | 2957 | free(temp); |
2958 | return NULL; | 2958 | return nullptr; |
2959 | } | 2959 | } |
2960 | 2960 | ||
2961 | temp->dht = dht; | 2961 | temp->dht = dht; |
@@ -2983,7 +2983,7 @@ static void kill_timedout(Net_Crypto *c, void *userdata) | |||
2983 | for (i = 0; i < c->crypto_connections_length; ++i) { | 2983 | for (i = 0; i < c->crypto_connections_length; ++i) { |
2984 | Crypto_Connection *conn = get_crypto_connection(c, i); | 2984 | Crypto_Connection *conn = get_crypto_connection(c, i); |
2985 | 2985 | ||
2986 | if (conn == 0) { | 2986 | if (conn == nullptr) { |
2987 | return; | 2987 | return; |
2988 | } | 2988 | } |
2989 | 2989 | ||
@@ -3039,10 +3039,10 @@ void kill_net_crypto(Net_Crypto *c) | |||
3039 | 3039 | ||
3040 | kill_tcp_connections(c->tcp_c); | 3040 | kill_tcp_connections(c->tcp_c); |
3041 | bs_list_free(&c->ip_port_list); | 3041 | bs_list_free(&c->ip_port_list); |
3042 | networking_registerhandler(dht_get_net(c->dht), NET_PACKET_COOKIE_REQUEST, NULL, NULL); | 3042 | networking_registerhandler(dht_get_net(c->dht), NET_PACKET_COOKIE_REQUEST, nullptr, nullptr); |
3043 | networking_registerhandler(dht_get_net(c->dht), NET_PACKET_COOKIE_RESPONSE, NULL, NULL); | 3043 | networking_registerhandler(dht_get_net(c->dht), NET_PACKET_COOKIE_RESPONSE, nullptr, nullptr); |
3044 | networking_registerhandler(dht_get_net(c->dht), NET_PACKET_CRYPTO_HS, NULL, NULL); | 3044 | networking_registerhandler(dht_get_net(c->dht), NET_PACKET_CRYPTO_HS, nullptr, nullptr); |
3045 | networking_registerhandler(dht_get_net(c->dht), NET_PACKET_CRYPTO_DATA, NULL, NULL); | 3045 | networking_registerhandler(dht_get_net(c->dht), NET_PACKET_CRYPTO_DATA, nullptr, nullptr); |
3046 | crypto_memzero(c, sizeof(Net_Crypto)); | 3046 | crypto_memzero(c, sizeof(Net_Crypto)); |
3047 | free(c); | 3047 | free(c); |
3048 | } | 3048 | } |