diff options
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r-- | toxcore/DHT.c | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 60e8b88f..2f468632 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -1706,75 +1706,6 @@ void kill_DHT(DHT *dht) | |||
1706 | free(dht); | 1706 | free(dht); |
1707 | } | 1707 | } |
1708 | 1708 | ||
1709 | /* Get the size of the DHT (for saving). */ | ||
1710 | uint32_t DHT_size_old(DHT *dht) | ||
1711 | { | ||
1712 | return sizeof(dht->close_clientlist) + sizeof(DHT_Friend) * dht->num_friends; | ||
1713 | } | ||
1714 | |||
1715 | /* Save the DHT in data where data is an array of size DHT_size(). */ | ||
1716 | void DHT_save_old(DHT *dht, uint8_t *data) | ||
1717 | { | ||
1718 | memcpy(data, dht->close_clientlist, sizeof(dht->close_clientlist)); | ||
1719 | memcpy(data + sizeof(dht->close_clientlist), dht->friends_list, sizeof(DHT_Friend) * dht->num_friends); | ||
1720 | } | ||
1721 | |||
1722 | /* Load the DHT from data of size size. | ||
1723 | * | ||
1724 | * return -1 if failure. | ||
1725 | * return 0 if success. | ||
1726 | */ | ||
1727 | int DHT_load_old(DHT *dht, uint8_t *data, uint32_t size) | ||
1728 | { | ||
1729 | size_t clientlist_oldsize = sizeof(Client_data_old) * LCLIENT_LIST; | ||
1730 | |||
1731 | if (size < clientlist_oldsize) { | ||
1732 | #ifdef DEBUG | ||
1733 | fprintf(stderr, "DHT_load: Expected at least %u bytes, got %u.\n", sizeof(dht->close_clientlist), size); | ||
1734 | #endif | ||
1735 | return -1; | ||
1736 | } | ||
1737 | |||
1738 | uint32_t friendlistsize = size - clientlist_oldsize; | ||
1739 | |||
1740 | if (friendlistsize % sizeof(DHT_Friend_old) != 0) { | ||
1741 | #ifdef DEBUG | ||
1742 | fprintf(stderr, "DHT_load: Expected a multiple of %u, got %u.\n", sizeof(DHT_Friend), friendlistsize); | ||
1743 | #endif | ||
1744 | return -1; | ||
1745 | } | ||
1746 | |||
1747 | uint32_t i, j; | ||
1748 | Client_data_old *client; | ||
1749 | uint16_t friends_num = friendlistsize / sizeof(DHT_Friend_old); | ||
1750 | |||
1751 | if (friends_num != 0) { | ||
1752 | DHT_Friend_old *tempfriends_list = (DHT_Friend_old *)(data + sizeof(dht->close_clientlist)); | ||
1753 | |||
1754 | for (i = 0; i < friends_num; ++i) { | ||
1755 | DHT_addfriend(dht, tempfriends_list[i].client_id); | ||
1756 | |||
1757 | for (j = 0; j < MAX_FRIEND_CLIENTS; ++j) { | ||
1758 | client = &tempfriends_list[i].client_list[j]; | ||
1759 | |||
1760 | if (client->assoc.timestamp != 0) | ||
1761 | getnodes(dht, client->assoc.ip_port, client->client_id, tempfriends_list[i].client_id, NULL); | ||
1762 | } | ||
1763 | } | ||
1764 | } | ||
1765 | |||
1766 | Client_data_old *tempclose_clientlist = (Client_data_old *)data; | ||
1767 | |||
1768 | for (i = 0; i < LCLIENT_LIST; ++i) { | ||
1769 | if (tempclose_clientlist[i].assoc.timestamp != 0) | ||
1770 | DHT_bootstrap(dht, tempclose_clientlist[i].assoc.ip_port, | ||
1771 | tempclose_clientlist[i].client_id ); | ||
1772 | } | ||
1773 | |||
1774 | return 0; | ||
1775 | } | ||
1776 | |||
1777 | |||
1778 | /* new DHT format for load/save, more robust and forward compatible */ | 1709 | /* new DHT format for load/save, more robust and forward compatible */ |
1779 | 1710 | ||
1780 | #define DHT_STATE_COOKIE_GLOBAL 0x159000d | 1711 | #define DHT_STATE_COOKIE_GLOBAL 0x159000d |