diff options
author | iphydf <iphydf@users.noreply.github.com> | 2016-09-18 01:31:55 +0100 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2016-09-24 21:53:50 +0100 |
commit | 15cb4261665bab4ef02a5b1b9db48b9477c9b87a (patch) | |
tree | d0c40a45afa19fff26ce1eb5bb703e18a9acdd4a /toxcore/DHT.c | |
parent | 0d347c2b2e69aa09b079f6daaa00007fef4fe52f (diff) |
Make toxcore code C++ compatible.
It is still C code, so still compatible with C compilers as well. This
change lets us see more clearly where implicit conversions occur by
making them explicit.
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r-- | toxcore/DHT.c | 141 |
1 files changed, 70 insertions, 71 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 2f078314..ed03fac8 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -985,24 +985,24 @@ static unsigned int ping_node_from_getnodes_ok(DHT *dht, const uint8_t *public_k | |||
985 | for (i = 0; i < dht->num_friends; ++i) { | 985 | for (i = 0; i < dht->num_friends; ++i) { |
986 | bool store_ok = 0; | 986 | bool store_ok = 0; |
987 | 987 | ||
988 | DHT_Friend *friend = &dht->friends_list[i]; | 988 | DHT_Friend *dht_friend = &dht->friends_list[i]; |
989 | 989 | ||
990 | if (store_node_ok(&friend->client_list[1], public_key, friend->public_key)) { | 990 | if (store_node_ok(&dht_friend->client_list[1], public_key, dht_friend->public_key)) { |
991 | store_ok = 1; | 991 | store_ok = 1; |
992 | } | 992 | } |
993 | 993 | ||
994 | if (store_node_ok(&friend->client_list[0], public_key, friend->public_key)) { | 994 | if (store_node_ok(&dht_friend->client_list[0], public_key, dht_friend->public_key)) { |
995 | store_ok = 1; | 995 | store_ok = 1; |
996 | } | 996 | } |
997 | 997 | ||
998 | if (store_ok && !client_in_nodelist(friend->to_bootstrap, friend->num_to_bootstrap, public_key) | 998 | if (store_ok && !client_in_nodelist(dht_friend->to_bootstrap, dht_friend->num_to_bootstrap, public_key) |
999 | && !is_pk_in_client_list(friend->client_list, MAX_FRIEND_CLIENTS, public_key, ip_port)) { | 999 | && !is_pk_in_client_list(dht_friend->client_list, MAX_FRIEND_CLIENTS, public_key, ip_port)) { |
1000 | if (friend->num_to_bootstrap < MAX_SENT_NODES) { | 1000 | if (dht_friend->num_to_bootstrap < MAX_SENT_NODES) { |
1001 | memcpy(friend->to_bootstrap[friend->num_to_bootstrap].public_key, public_key, crypto_box_PUBLICKEYBYTES); | 1001 | memcpy(dht_friend->to_bootstrap[dht_friend->num_to_bootstrap].public_key, public_key, crypto_box_PUBLICKEYBYTES); |
1002 | friend->to_bootstrap[friend->num_to_bootstrap].ip_port = ip_port; | 1002 | dht_friend->to_bootstrap[dht_friend->num_to_bootstrap].ip_port = ip_port; |
1003 | ++friend->num_to_bootstrap; | 1003 | ++dht_friend->num_to_bootstrap; |
1004 | } else { | 1004 | } else { |
1005 | add_to_list(friend->to_bootstrap, MAX_SENT_NODES, public_key, ip_port, friend->public_key); | 1005 | add_to_list(dht_friend->to_bootstrap, MAX_SENT_NODES, public_key, ip_port, dht_friend->public_key); |
1006 | } | 1006 | } |
1007 | 1007 | ||
1008 | ret = 1; | 1008 | ret = 1; |
@@ -1046,19 +1046,19 @@ int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *public_key) | |||
1046 | if (replace_all(dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, | 1046 | if (replace_all(dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, |
1047 | public_key, ip_port, dht->friends_list[i].public_key)) { | 1047 | public_key, ip_port, dht->friends_list[i].public_key)) { |
1048 | 1048 | ||
1049 | DHT_Friend *friend = &dht->friends_list[i]; | 1049 | DHT_Friend *dht_friend = &dht->friends_list[i]; |
1050 | 1050 | ||
1051 | if (public_key_cmp(public_key, friend->public_key) == 0) { | 1051 | if (public_key_cmp(public_key, dht_friend->public_key) == 0) { |
1052 | friend_foundip = friend; | 1052 | friend_foundip = dht_friend; |
1053 | } | 1053 | } |
1054 | 1054 | ||
1055 | used++; | 1055 | used++; |
1056 | } | 1056 | } |
1057 | } else { | 1057 | } else { |
1058 | DHT_Friend *friend = &dht->friends_list[i]; | 1058 | DHT_Friend *dht_friend = &dht->friends_list[i]; |
1059 | 1059 | ||
1060 | if (public_key_cmp(public_key, friend->public_key) == 0) { | 1060 | if (public_key_cmp(public_key, dht_friend->public_key) == 0) { |
1061 | friend_foundip = friend; | 1061 | friend_foundip = dht_friend; |
1062 | } | 1062 | } |
1063 | 1063 | ||
1064 | used++; | 1064 | used++; |
@@ -1282,7 +1282,7 @@ static int handle_getnodes(void *object, IP_Port source, const uint8_t *packet, | |||
1282 | return 1; | 1282 | return 1; |
1283 | } | 1283 | } |
1284 | 1284 | ||
1285 | DHT *dht = object; | 1285 | DHT *dht = (DHT *)object; |
1286 | 1286 | ||
1287 | /* Check if packet is from ourself. */ | 1287 | /* Check if packet is from ourself. */ |
1288 | if (id_equal(packet + 1, dht->self_public_key)) { | 1288 | if (id_equal(packet + 1, dht->self_public_key)) { |
@@ -1341,7 +1341,7 @@ static int send_hardening_getnode_res(const DHT *dht, const Node_format *sendto, | |||
1341 | static int handle_sendnodes_core(void *object, IP_Port source, const uint8_t *packet, uint16_t length, | 1341 | static int handle_sendnodes_core(void *object, IP_Port source, const uint8_t *packet, uint16_t length, |
1342 | Node_format *plain_nodes, uint16_t size_plain_nodes, uint32_t *num_nodes_out) | 1342 | Node_format *plain_nodes, uint16_t size_plain_nodes, uint32_t *num_nodes_out) |
1343 | { | 1343 | { |
1344 | DHT *dht = object; | 1344 | DHT *dht = (DHT *)object; |
1345 | uint32_t cid_size = 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES + 1 + sizeof(uint64_t) + crypto_box_MACBYTES; | 1345 | uint32_t cid_size = 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES + 1 + sizeof(uint64_t) + crypto_box_MACBYTES; |
1346 | 1346 | ||
1347 | if (length < cid_size) { /* too short */ | 1347 | if (length < cid_size) { /* too short */ |
@@ -1411,7 +1411,7 @@ static int handle_sendnodes_core(void *object, IP_Port source, const uint8_t *pa | |||
1411 | 1411 | ||
1412 | static int handle_sendnodes_ipv6(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) | 1412 | static int handle_sendnodes_ipv6(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
1413 | { | 1413 | { |
1414 | DHT *dht = object; | 1414 | DHT *dht = (DHT *)object; |
1415 | Node_format plain_nodes[MAX_SENT_NODES]; | 1415 | Node_format plain_nodes[MAX_SENT_NODES]; |
1416 | uint32_t num_nodes; | 1416 | uint32_t num_nodes; |
1417 | 1417 | ||
@@ -1447,17 +1447,17 @@ int DHT_addfriend(DHT *dht, const uint8_t *public_key, void (*ip_callback)(void | |||
1447 | uint16_t lock_num; | 1447 | uint16_t lock_num; |
1448 | 1448 | ||
1449 | if (friend_num != -1) { /* Is friend already in DHT? */ | 1449 | if (friend_num != -1) { /* Is friend already in DHT? */ |
1450 | DHT_Friend *friend = &dht->friends_list[friend_num]; | 1450 | DHT_Friend *dht_friend = &dht->friends_list[friend_num]; |
1451 | 1451 | ||
1452 | if (friend->lock_count == DHT_FRIEND_MAX_LOCKS) { | 1452 | if (dht_friend->lock_count == DHT_FRIEND_MAX_LOCKS) { |
1453 | return -1; | 1453 | return -1; |
1454 | } | 1454 | } |
1455 | 1455 | ||
1456 | lock_num = friend->lock_count; | 1456 | lock_num = dht_friend->lock_count; |
1457 | ++friend->lock_count; | 1457 | ++dht_friend->lock_count; |
1458 | friend->callbacks[lock_num].ip_callback = ip_callback; | 1458 | dht_friend->callbacks[lock_num].ip_callback = ip_callback; |
1459 | friend->callbacks[lock_num].data = data; | 1459 | dht_friend->callbacks[lock_num].data = data; |
1460 | friend->callbacks[lock_num].number = number; | 1460 | dht_friend->callbacks[lock_num].number = number; |
1461 | 1461 | ||
1462 | if (lock_count) { | 1462 | if (lock_count) { |
1463 | *lock_count = lock_num + 1; | 1463 | *lock_count = lock_num + 1; |
@@ -1466,32 +1466,31 @@ int DHT_addfriend(DHT *dht, const uint8_t *public_key, void (*ip_callback)(void | |||
1466 | return 0; | 1466 | return 0; |
1467 | } | 1467 | } |
1468 | 1468 | ||
1469 | DHT_Friend *temp; | 1469 | DHT_Friend *temp = (DHT_Friend *)realloc(dht->friends_list, sizeof(DHT_Friend) * (dht->num_friends + 1)); |
1470 | temp = realloc(dht->friends_list, sizeof(DHT_Friend) * (dht->num_friends + 1)); | ||
1471 | 1470 | ||
1472 | if (temp == NULL) { | 1471 | if (temp == NULL) { |
1473 | return -1; | 1472 | return -1; |
1474 | } | 1473 | } |
1475 | 1474 | ||
1476 | dht->friends_list = temp; | 1475 | dht->friends_list = temp; |
1477 | DHT_Friend *friend = &dht->friends_list[dht->num_friends]; | 1476 | DHT_Friend *dht_friend = &dht->friends_list[dht->num_friends]; |
1478 | memset(friend, 0, sizeof(DHT_Friend)); | 1477 | memset(dht_friend, 0, sizeof(DHT_Friend)); |
1479 | memcpy(friend->public_key, public_key, crypto_box_PUBLICKEYBYTES); | 1478 | memcpy(dht_friend->public_key, public_key, crypto_box_PUBLICKEYBYTES); |
1480 | 1479 | ||
1481 | friend->nat.NATping_id = random_64b(); | 1480 | dht_friend->nat.NATping_id = random_64b(); |
1482 | ++dht->num_friends; | 1481 | ++dht->num_friends; |
1483 | 1482 | ||
1484 | lock_num = friend->lock_count; | 1483 | lock_num = dht_friend->lock_count; |
1485 | ++friend->lock_count; | 1484 | ++dht_friend->lock_count; |
1486 | friend->callbacks[lock_num].ip_callback = ip_callback; | 1485 | dht_friend->callbacks[lock_num].ip_callback = ip_callback; |
1487 | friend->callbacks[lock_num].data = data; | 1486 | dht_friend->callbacks[lock_num].data = data; |
1488 | friend->callbacks[lock_num].number = number; | 1487 | dht_friend->callbacks[lock_num].number = number; |
1489 | 1488 | ||
1490 | if (lock_count) { | 1489 | if (lock_count) { |
1491 | *lock_count = lock_num + 1; | 1490 | *lock_count = lock_num + 1; |
1492 | } | 1491 | } |
1493 | 1492 | ||
1494 | friend->num_to_bootstrap = get_close_nodes(dht, friend->public_key, friend->to_bootstrap, 0, 1, 0); | 1493 | dht_friend->num_to_bootstrap = get_close_nodes(dht, dht_friend->public_key, dht_friend->to_bootstrap, 0, 1, 0); |
1495 | 1494 | ||
1496 | return 0; | 1495 | return 0; |
1497 | } | 1496 | } |
@@ -1504,19 +1503,17 @@ int DHT_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count) | |||
1504 | return -1; | 1503 | return -1; |
1505 | } | 1504 | } |
1506 | 1505 | ||
1507 | DHT_Friend *friend = &dht->friends_list[friend_num]; | 1506 | DHT_Friend *dht_friend = &dht->friends_list[friend_num]; |
1508 | --friend->lock_count; | 1507 | --dht_friend->lock_count; |
1509 | 1508 | ||
1510 | if (friend->lock_count && lock_count) { /* DHT friend is still in use.*/ | 1509 | if (dht_friend->lock_count && lock_count) { /* DHT friend is still in use.*/ |
1511 | --lock_count; | 1510 | --lock_count; |
1512 | friend->callbacks[lock_count].ip_callback = NULL; | 1511 | dht_friend->callbacks[lock_count].ip_callback = NULL; |
1513 | friend->callbacks[lock_count].data = NULL; | 1512 | dht_friend->callbacks[lock_count].data = NULL; |
1514 | friend->callbacks[lock_count].number = 0; | 1513 | dht_friend->callbacks[lock_count].number = 0; |
1515 | return 0; | 1514 | return 0; |
1516 | } | 1515 | } |
1517 | 1516 | ||
1518 | DHT_Friend *temp; | ||
1519 | |||
1520 | --dht->num_friends; | 1517 | --dht->num_friends; |
1521 | 1518 | ||
1522 | if (dht->num_friends != friend_num) { | 1519 | if (dht->num_friends != friend_num) { |
@@ -1531,7 +1528,7 @@ int DHT_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count) | |||
1531 | return 0; | 1528 | return 0; |
1532 | } | 1529 | } |
1533 | 1530 | ||
1534 | temp = realloc(dht->friends_list, sizeof(DHT_Friend) * (dht->num_friends)); | 1531 | DHT_Friend *temp = (DHT_Friend *)realloc(dht->friends_list, sizeof(DHT_Friend) * (dht->num_friends)); |
1535 | 1532 | ||
1536 | if (temp == NULL) { | 1533 | if (temp == NULL) { |
1537 | return -1; | 1534 | return -1; |
@@ -1650,16 +1647,18 @@ static void do_DHT_friends(DHT *dht) | |||
1650 | unsigned int i, j; | 1647 | unsigned int i, j; |
1651 | 1648 | ||
1652 | for (i = 0; i < dht->num_friends; ++i) { | 1649 | for (i = 0; i < dht->num_friends; ++i) { |
1653 | DHT_Friend *friend = &dht->friends_list[i]; | 1650 | DHT_Friend *dht_friend = &dht->friends_list[i]; |
1654 | 1651 | ||
1655 | for (j = 0; j < friend->num_to_bootstrap; ++j) { | 1652 | for (j = 0; j < dht_friend->num_to_bootstrap; ++j) { |
1656 | getnodes(dht, friend->to_bootstrap[j].ip_port, friend->to_bootstrap[j].public_key, friend->public_key, NULL); | 1653 | getnodes(dht, dht_friend->to_bootstrap[j].ip_port, dht_friend->to_bootstrap[j].public_key, dht_friend->public_key, |
1654 | NULL); | ||
1657 | } | 1655 | } |
1658 | 1656 | ||
1659 | friend->num_to_bootstrap = 0; | 1657 | dht_friend->num_to_bootstrap = 0; |
1660 | 1658 | ||
1661 | do_ping_and_sendnode_requests(dht, &friend->lastgetnode, friend->public_key, friend->client_list, MAX_FRIEND_CLIENTS, | 1659 | do_ping_and_sendnode_requests(dht, &dht_friend->lastgetnode, dht_friend->public_key, dht_friend->client_list, |
1662 | &friend->bootstrap_times, 1); | 1660 | MAX_FRIEND_CLIENTS, |
1661 | &dht_friend->bootstrap_times, 1); | ||
1663 | } | 1662 | } |
1664 | } | 1663 | } |
1665 | 1664 | ||
@@ -1791,7 +1790,7 @@ static int friend_iplist(const DHT *dht, IP_Port *ip_portlist, uint16_t friend_n | |||
1791 | return -1; | 1790 | return -1; |
1792 | } | 1791 | } |
1793 | 1792 | ||
1794 | DHT_Friend *friend = &dht->friends_list[friend_num]; | 1793 | DHT_Friend *dht_friend = &dht->friends_list[friend_num]; |
1795 | Client_data *client; | 1794 | Client_data *client; |
1796 | IP_Port ipv4s[MAX_FRIEND_CLIENTS]; | 1795 | IP_Port ipv4s[MAX_FRIEND_CLIENTS]; |
1797 | int num_ipv4s = 0; | 1796 | int num_ipv4s = 0; |
@@ -1800,7 +1799,7 @@ static int friend_iplist(const DHT *dht, IP_Port *ip_portlist, uint16_t friend_n | |||
1800 | int i; | 1799 | int i; |
1801 | 1800 | ||
1802 | for (i = 0; i < MAX_FRIEND_CLIENTS; ++i) { | 1801 | for (i = 0; i < MAX_FRIEND_CLIENTS; ++i) { |
1803 | client = &(friend->client_list[i]); | 1802 | client = &(dht_friend->client_list[i]); |
1804 | 1803 | ||
1805 | /* If ip is not zero and node is good. */ | 1804 | /* If ip is not zero and node is good. */ |
1806 | if (ip_isset(&client->assoc4.ret_ip_port.ip) && !is_timeout(client->assoc4.ret_timestamp, BAD_NODE_TIMEOUT)) { | 1805 | if (ip_isset(&client->assoc4.ret_ip_port.ip) && !is_timeout(client->assoc4.ret_timestamp, BAD_NODE_TIMEOUT)) { |
@@ -1813,7 +1812,7 @@ static int friend_iplist(const DHT *dht, IP_Port *ip_portlist, uint16_t friend_n | |||
1813 | ++num_ipv6s; | 1812 | ++num_ipv6s; |
1814 | } | 1813 | } |
1815 | 1814 | ||
1816 | if (id_equal(client->public_key, friend->public_key)) { | 1815 | if (id_equal(client->public_key, dht_friend->public_key)) { |
1817 | if (!is_timeout(client->assoc6.timestamp, BAD_NODE_TIMEOUT) | 1816 | if (!is_timeout(client->assoc6.timestamp, BAD_NODE_TIMEOUT) |
1818 | || !is_timeout(client->assoc4.timestamp, BAD_NODE_TIMEOUT)) { | 1817 | || !is_timeout(client->assoc4.timestamp, BAD_NODE_TIMEOUT)) { |
1819 | return 0; /* direct connectivity */ | 1818 | return 0; /* direct connectivity */ |
@@ -1877,7 +1876,7 @@ int route_tofriend(const DHT *dht, const uint8_t *friend_id, const uint8_t *pack | |||
1877 | return 0; /* Reason for that? */ | 1876 | return 0; /* Reason for that? */ |
1878 | } | 1877 | } |
1879 | 1878 | ||
1880 | DHT_Friend *friend = &dht->friends_list[num]; | 1879 | DHT_Friend *dht_friend = &dht->friends_list[num]; |
1881 | Client_data *client; | 1880 | Client_data *client; |
1882 | 1881 | ||
1883 | /* extra legwork, because having the outside allocating the space for us | 1882 | /* extra legwork, because having the outside allocating the space for us |
@@ -1890,7 +1889,7 @@ int route_tofriend(const DHT *dht, const uint8_t *friend_id, const uint8_t *pack | |||
1890 | continue; | 1889 | continue; |
1891 | } | 1890 | } |
1892 | 1891 | ||
1893 | client = &friend->client_list[i]; | 1892 | client = &dht_friend->client_list[i]; |
1894 | IPPTsPng *assoc = NULL; | 1893 | IPPTsPng *assoc = NULL; |
1895 | 1894 | ||
1896 | if (!a) { | 1895 | if (!a) { |
@@ -1927,7 +1926,7 @@ static int routeone_tofriend(DHT *dht, const uint8_t *friend_id, const uint8_t * | |||
1927 | return 0; | 1926 | return 0; |
1928 | } | 1927 | } |
1929 | 1928 | ||
1930 | DHT_Friend *friend = &dht->friends_list[num]; | 1929 | DHT_Friend *dht_friend = &dht->friends_list[num]; |
1931 | Client_data *client; | 1930 | Client_data *client; |
1932 | 1931 | ||
1933 | IP_Port ip_list[MAX_FRIEND_CLIENTS * 2]; | 1932 | IP_Port ip_list[MAX_FRIEND_CLIENTS * 2]; |
@@ -1940,7 +1939,7 @@ static int routeone_tofriend(DHT *dht, const uint8_t *friend_id, const uint8_t * | |||
1940 | 1939 | ||
1941 | for (a = 0; a < 2; a++) { | 1940 | for (a = 0; a < 2; a++) { |
1942 | for (i = 0; i < MAX_FRIEND_CLIENTS; ++i) { | 1941 | for (i = 0; i < MAX_FRIEND_CLIENTS; ++i) { |
1943 | client = &friend->client_list[i]; | 1942 | client = &dht_friend->client_list[i]; |
1944 | IPPTsPng *assoc = NULL; | 1943 | IPPTsPng *assoc = NULL; |
1945 | 1944 | ||
1946 | if (!a) { | 1945 | if (!a) { |
@@ -2011,7 +2010,7 @@ static int handle_NATping(void *object, IP_Port source, const uint8_t *source_pu | |||
2011 | return 1; | 2010 | return 1; |
2012 | } | 2011 | } |
2013 | 2012 | ||
2014 | DHT *dht = object; | 2013 | DHT *dht = (DHT *)object; |
2015 | uint64_t ping_id; | 2014 | uint64_t ping_id; |
2016 | memcpy(&ping_id, packet + 1, sizeof(uint64_t)); | 2015 | memcpy(&ping_id, packet + 1, sizeof(uint64_t)); |
2017 | 2016 | ||
@@ -2021,19 +2020,19 @@ static int handle_NATping(void *object, IP_Port source, const uint8_t *source_pu | |||
2021 | return 1; | 2020 | return 1; |
2022 | } | 2021 | } |
2023 | 2022 | ||
2024 | DHT_Friend *friend = &dht->friends_list[friendnumber]; | 2023 | DHT_Friend *dht_friend = &dht->friends_list[friendnumber]; |
2025 | 2024 | ||
2026 | if (packet[0] == NAT_PING_REQUEST) { | 2025 | if (packet[0] == NAT_PING_REQUEST) { |
2027 | /* 1 is reply */ | 2026 | /* 1 is reply */ |
2028 | send_NATping(dht, source_pubkey, ping_id, NAT_PING_RESPONSE); | 2027 | send_NATping(dht, source_pubkey, ping_id, NAT_PING_RESPONSE); |
2029 | friend->nat.recvNATping_timestamp = unix_time(); | 2028 | dht_friend->nat.recvNATping_timestamp = unix_time(); |
2030 | return 0; | 2029 | return 0; |
2031 | } | 2030 | } |
2032 | 2031 | ||
2033 | if (packet[0] == NAT_PING_RESPONSE) { | 2032 | if (packet[0] == NAT_PING_RESPONSE) { |
2034 | if (friend->nat.NATping_id == ping_id) { | 2033 | if (dht_friend->nat.NATping_id == ping_id) { |
2035 | friend->nat.NATping_id = random_64b(); | 2034 | dht_friend->nat.NATping_id = random_64b(); |
2036 | friend->nat.hole_punching = 1; | 2035 | dht_friend->nat.hole_punching = 1; |
2037 | return 0; | 2036 | return 0; |
2038 | } | 2037 | } |
2039 | } | 2038 | } |
@@ -2308,7 +2307,7 @@ static uint32_t have_nodes_closelist(DHT *dht, Node_format *nodes, uint16_t num) | |||
2308 | static int handle_hardening(void *object, IP_Port source, const uint8_t *source_pubkey, const uint8_t *packet, | 2307 | static int handle_hardening(void *object, IP_Port source, const uint8_t *source_pubkey, const uint8_t *packet, |
2309 | uint16_t length, void *userdata) | 2308 | uint16_t length, void *userdata) |
2310 | { | 2309 | { |
2311 | DHT *dht = object; | 2310 | DHT *dht = (DHT *)object; |
2312 | 2311 | ||
2313 | if (length < 2) { | 2312 | if (length < 2) { |
2314 | return 1; | 2313 | return 1; |
@@ -2547,7 +2546,7 @@ void cryptopacket_registerhandler(DHT *dht, uint8_t byte, cryptopacket_handler_c | |||
2547 | 2546 | ||
2548 | static int cryptopacket_handle(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) | 2547 | static int cryptopacket_handle(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
2549 | { | 2548 | { |
2550 | DHT *dht = object; | 2549 | DHT *dht = (DHT *)object; |
2551 | 2550 | ||
2552 | if (packet[0] == NET_PACKET_CRYPTO) { | 2551 | if (packet[0] == NET_PACKET_CRYPTO) { |
2553 | if (length <= crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 + crypto_box_MACBYTES || | 2552 | if (length <= crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 + crypto_box_MACBYTES || |
@@ -2595,7 +2594,7 @@ DHT *new_DHT(Logger *log, Networking_Core *net) | |||
2595 | return NULL; | 2594 | return NULL; |
2596 | } | 2595 | } |
2597 | 2596 | ||
2598 | DHT *dht = calloc(1, sizeof(DHT)); | 2597 | DHT *dht = (DHT *)calloc(1, sizeof(DHT)); |
2599 | 2598 | ||
2600 | if (dht == NULL) { | 2599 | if (dht == NULL) { |
2601 | return NULL; | 2600 | return NULL; |
@@ -2813,7 +2812,7 @@ int DHT_connect_after_load(DHT *dht) | |||
2813 | 2812 | ||
2814 | static int dht_load_state_callback(void *outer, const uint8_t *data, uint32_t length, uint16_t type) | 2813 | static int dht_load_state_callback(void *outer, const uint8_t *data, uint32_t length, uint16_t type) |
2815 | { | 2814 | { |
2816 | DHT *dht = outer; | 2815 | DHT *dht = (DHT *)outer; |
2817 | 2816 | ||
2818 | switch (type) { | 2817 | switch (type) { |
2819 | case DHT_STATE_TYPE_NODES: | 2818 | case DHT_STATE_TYPE_NODES: |
@@ -2824,7 +2823,7 @@ static int dht_load_state_callback(void *outer, const uint8_t *data, uint32_t le | |||
2824 | { | 2823 | { |
2825 | free(dht->loaded_nodes_list); | 2824 | free(dht->loaded_nodes_list); |
2826 | // Copy to loaded_clients_list | 2825 | // Copy to loaded_clients_list |
2827 | dht->loaded_nodes_list = calloc(MAX_SAVED_DHT_NODES, sizeof(Node_format)); | 2826 | dht->loaded_nodes_list = (Node_format *)calloc(MAX_SAVED_DHT_NODES, sizeof(Node_format)); |
2828 | 2827 | ||
2829 | int num = unpack_nodes(dht->loaded_nodes_list, MAX_SAVED_DHT_NODES, NULL, data, length, 0); | 2828 | int num = unpack_nodes(dht->loaded_nodes_list, MAX_SAVED_DHT_NODES, NULL, data, length, 0); |
2830 | 2829 | ||