summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/DHT.c69
-rw-r--r--toxcore/DHT.h26
2 files changed, 0 insertions, 95 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). */
1710uint32_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(). */
1716void 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 */
1727int 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
diff --git a/toxcore/DHT.h b/toxcore/DHT.h
index b3ab5f89..ac02710f 100644
--- a/toxcore/DHT.h
+++ b/toxcore/DHT.h
@@ -50,11 +50,6 @@ typedef struct {
50 50
51typedef struct { 51typedef struct {
52 uint8_t client_id[CLIENT_ID_SIZE]; 52 uint8_t client_id[CLIENT_ID_SIZE];
53 IPPTsPng assoc;
54} Client_data_old; /* required to load old state files */
55
56typedef struct {
57 uint8_t client_id[CLIENT_ID_SIZE];
58 IPPTsPng assoc4; 53 IPPTsPng assoc4;
59 IPPTsPng assoc6; 54 IPPTsPng assoc6;
60} Client_data; 55} Client_data;
@@ -88,18 +83,6 @@ typedef struct {
88 83
89typedef struct { 84typedef struct {
90 uint8_t client_id[CLIENT_ID_SIZE]; 85 uint8_t client_id[CLIENT_ID_SIZE];
91 Client_data_old client_list[MAX_FRIEND_CLIENTS];
92
93 /* Time at which the last get_nodes request was sent. */
94 uint64_t lastgetnode;
95
96 Hardening hardening;
97 /* Symetric NAT hole punching stuff. */
98 NAT nat;
99} DHT_Friend_old; /* required to load old state files */
100
101typedef struct {
102 uint8_t client_id[CLIENT_ID_SIZE];
103 Client_data client_list[MAX_FRIEND_CLIENTS]; 86 Client_data client_list[MAX_FRIEND_CLIENTS];
104 87
105 /* Time at which the last get_nodes request was sent. */ 88 /* Time at which the last get_nodes request was sent. */
@@ -249,15 +232,6 @@ DHT *new_DHT(Net_Crypto *c);
249 232
250void kill_DHT(DHT *dht); 233void kill_DHT(DHT *dht);
251 234
252/* Load the DHT from data of size size.
253 * old/new: version of config file
254 *
255 * return -1 if failure.
256 * return 0 if success.
257 */
258int DHT_load_old(DHT *dht, uint8_t *data, uint32_t size);
259int DHT_load_new(DHT *dht, uint8_t *data, uint32_t size);
260
261/* return 0 if we are not connected to the DHT. 235/* return 0 if we are not connected to the DHT.
262 * return 1 if we are. 236 * return 1 if we are.
263 */ 237 */