summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-07-19 11:50:08 -0400
committerirungentoo <irungentoo@gmail.com>2015-07-19 11:50:08 -0400
commit05ad1234d29f8b1cd4fde83b6c893223d39d69d0 (patch)
treee1c506ece56e47e3bb9c1a769b497e6bf99204d8
parentdefdc879f0472eb4c4be0d1dbff5478fd02f1686 (diff)
Pack onion path nodes in save.
-rw-r--r--toxcore/Messenger.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index b2592c26..3fb15022 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -2547,7 +2547,7 @@ uint32_t messenger_size(const Messenger *m)
2547 + sizesubhead + m->statusmessage_length // status message 2547 + sizesubhead + m->statusmessage_length // status message
2548 + sizesubhead + 1 // status 2548 + sizesubhead + 1 // status
2549 + sizesubhead + NUM_SAVED_TCP_RELAYS * packed_node_size(TCP_INET6) //TCP relays 2549 + sizesubhead + NUM_SAVED_TCP_RELAYS * packed_node_size(TCP_INET6) //TCP relays
2550 + sizesubhead + NUM_SAVED_PATH_NODES * sizeof(Node_format) //saved path nodes 2550 + sizesubhead + NUM_SAVED_PATH_NODES * packed_node_size(TCP_INET6) //saved path nodes
2551 + sizesubhead; 2551 + sizesubhead;
2552} 2552}
2553 2553
@@ -2628,13 +2628,18 @@ void messenger_save(const Messenger *m, uint8_t *data)
2628 } 2628 }
2629 2629
2630 Node_format nodes[NUM_SAVED_PATH_NODES]; 2630 Node_format nodes[NUM_SAVED_PATH_NODES];
2631 len = sizeof(nodes);
2632 type = MESSENGER_STATE_TYPE_PATH_NODE; 2631 type = MESSENGER_STATE_TYPE_PATH_NODE;
2633 data = z_state_save_subheader(data, len, type); 2632 temp_data = data;
2634 memset(nodes, 0, len); 2633 data = z_state_save_subheader(data, 0, type);
2635 onion_backup_nodes(m->onion_c, nodes, NUM_SAVED_PATH_NODES); 2634 memset(nodes, 0, sizeof(nodes));
2636 memcpy(data, nodes, len); 2635 num = onion_backup_nodes(m->onion_c, nodes, NUM_SAVED_PATH_NODES);
2637 data += len; 2636 l = pack_nodes(data, NUM_SAVED_PATH_NODES * packed_node_size(TCP_INET6), nodes, num);
2637
2638 if (l > 0) {
2639 len = l;
2640 data = z_state_save_subheader(temp_data, len, type);
2641 data += len;
2642 }
2638 2643
2639 z_state_save_subheader(data, 0, MESSENGER_STATE_TYPE_END); 2644 z_state_save_subheader(data, 0, MESSENGER_STATE_TYPE_END);
2640} 2645}
@@ -2704,10 +2709,9 @@ static int messenger_load_state_callback(void *outer, const uint8_t *data, uint3
2704 return -1; 2709 return -1;
2705 } 2710 }
2706 2711
2707 memcpy(nodes, data, length); 2712 int i, num = unpack_nodes(nodes, NUM_SAVED_PATH_NODES, 0, data, length, 0);
2708 uint32_t i;
2709 2713
2710 for (i = 0; i < NUM_SAVED_PATH_NODES; ++i) { 2714 for (i = 0; i < num; ++i) {
2711 onion_add_bs_path_node(m->onion_c, nodes[i].ip_port, nodes[i].public_key); 2715 onion_add_bs_path_node(m->onion_c, nodes[i].ip_port, nodes[i].public_key);
2712 } 2716 }
2713 2717