summaryrefslogtreecommitdiff
path: root/toxcore/DHT.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r--toxcore/DHT.c17
1 files changed, 4 insertions, 13 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index 682b962f..a1025300 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -2823,26 +2823,16 @@ uint32_t dht_size(const DHT *dht)
2823 return size32 + sizesubhead + packed_node_size(net_family_ipv4) * numv4 + packed_node_size(net_family_ipv6) * numv6; 2823 return size32 + sizesubhead + packed_node_size(net_family_ipv4) * numv4 + packed_node_size(net_family_ipv6) * numv6;
2824} 2824}
2825 2825
2826static uint8_t *dht_save_subheader(uint8_t *data, uint32_t len, uint16_t type)
2827{
2828 host_to_lendian32(data, len);
2829 data += sizeof(uint32_t);
2830 host_to_lendian32(data, (host_tolendian16(DHT_STATE_COOKIE_TYPE) << 16) | host_tolendian16(type));
2831 data += sizeof(uint32_t);
2832 return data;
2833}
2834
2835
2836/* Save the DHT in data where data is an array of size dht_size(). */ 2826/* Save the DHT in data where data is an array of size dht_size(). */
2837void dht_save(const DHT *dht, uint8_t *data) 2827void dht_save(const DHT *dht, uint8_t *data)
2838{ 2828{
2839 host_to_lendian32(data, DHT_STATE_COOKIE_GLOBAL); 2829 host_to_lendian32(data, DHT_STATE_COOKIE_GLOBAL);
2840 data += sizeof(uint32_t); 2830 data += sizeof(uint32_t);
2841 2831
2842 uint8_t *const old_data = data; 2832 uint8_t *const old_data = data;
2843 2833
2844 /* get right offset. we write the actual header later. */ 2834 /* get right offset. we write the actual header later. */
2845 data = dht_save_subheader(data, 0, 0); 2835 data = state_write_section_header(data, DHT_STATE_COOKIE_TYPE, 0, 0);
2846 2836
2847 Node_format clients[MAX_SAVED_DHT_NODES]; 2837 Node_format clients[MAX_SAVED_DHT_NODES];
2848 2838
@@ -2880,7 +2870,8 @@ void dht_save(const DHT *dht, uint8_t *data)
2880 } 2870 }
2881 } 2871 }
2882 2872
2883 dht_save_subheader(old_data, pack_nodes(data, sizeof(Node_format) * num, clients, num), DHT_STATE_TYPE_NODES); 2873 state_write_section_header(old_data, DHT_STATE_COOKIE_TYPE, pack_nodes(data, sizeof(Node_format) * num, clients, num),
2874 DHT_STATE_TYPE_NODES);
2884} 2875}
2885 2876
2886/* Bootstrap from this number of nodes every time dht_connect_after_load() is called */ 2877/* Bootstrap from this number of nodes every time dht_connect_after_load() is called */