diff options
author | irungentoo <irungentoo@gmail.com> | 2014-08-14 16:56:29 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2014-08-14 16:56:29 -0400 |
commit | fb9fc81a3510074bcfaa3caeee2aa19ddca8657f (patch) | |
tree | ef8738dde15c19f72cc7858a2e26c387403262e8 | |
parent | 5376d40f546bea84d25134a92f8d6e759189663e (diff) |
Save some path nodes to speed up joining network on pure TCP.
-rw-r--r-- | toxcore/Messenger.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index d92ebdc6..5dea7b08 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -2537,9 +2537,11 @@ void do_messenger(Messenger *m) | |||
2537 | #define MESSENGER_STATE_TYPE_STATUSMESSAGE 5 | 2537 | #define MESSENGER_STATE_TYPE_STATUSMESSAGE 5 |
2538 | #define MESSENGER_STATE_TYPE_STATUS 6 | 2538 | #define MESSENGER_STATE_TYPE_STATUS 6 |
2539 | #define MESSENGER_STATE_TYPE_TCP_RELAY 10 | 2539 | #define MESSENGER_STATE_TYPE_TCP_RELAY 10 |
2540 | #define MESSENGER_STATE_TYPE_PATH_NODE 11 | ||
2540 | 2541 | ||
2541 | #define SAVED_FRIEND_REQUEST_SIZE 1024 | 2542 | #define SAVED_FRIEND_REQUEST_SIZE 1024 |
2542 | #define NUM_SAVED_TCP_RELAYS 8 | 2543 | #define NUM_SAVED_TCP_RELAYS 8 |
2544 | #define NUM_SAVED_PATH_NODES 8 | ||
2543 | struct SAVED_FRIEND { | 2545 | struct SAVED_FRIEND { |
2544 | uint8_t status; | 2546 | uint8_t status; |
2545 | uint8_t client_id[CLIENT_ID_SIZE]; | 2547 | uint8_t client_id[CLIENT_ID_SIZE]; |
@@ -2653,6 +2655,7 @@ uint32_t messenger_size(const Messenger *m) | |||
2653 | + sizesubhead + m->statusmessage_length // status message | 2655 | + sizesubhead + m->statusmessage_length // status message |
2654 | + sizesubhead + 1 // status | 2656 | + sizesubhead + 1 // status |
2655 | + sizesubhead + NUM_SAVED_TCP_RELAYS * sizeof(Node_format) //TCP relays | 2657 | + sizesubhead + NUM_SAVED_TCP_RELAYS * sizeof(Node_format) //TCP relays |
2658 | + sizesubhead + NUM_SAVED_PATH_NODES * sizeof(Node_format) //saved path nodes | ||
2656 | ; | 2659 | ; |
2657 | } | 2660 | } |
2658 | 2661 | ||
@@ -2725,6 +2728,15 @@ void messenger_save(const Messenger *m, uint8_t *data) | |||
2725 | memset(relays, 0, len); | 2728 | memset(relays, 0, len); |
2726 | copy_connected_tcp_relays(m->net_crypto, relays, NUM_SAVED_TCP_RELAYS); | 2729 | copy_connected_tcp_relays(m->net_crypto, relays, NUM_SAVED_TCP_RELAYS); |
2727 | memcpy(data, relays, len); | 2730 | memcpy(data, relays, len); |
2731 | data += len; | ||
2732 | |||
2733 | Node_format nodes[NUM_SAVED_PATH_NODES]; | ||
2734 | len = sizeof(nodes); | ||
2735 | type = MESSENGER_STATE_TYPE_PATH_NODE; | ||
2736 | data = z_state_save_subheader(data, len, type); | ||
2737 | memset(nodes, 0, len); | ||
2738 | onion_backup_nodes(m->onion_c, nodes, NUM_SAVED_PATH_NODES); | ||
2739 | memcpy(data, nodes, len); | ||
2728 | } | 2740 | } |
2729 | 2741 | ||
2730 | static int messenger_load_state_callback(void *outer, const uint8_t *data, uint32_t length, uint16_t type) | 2742 | static int messenger_load_state_callback(void *outer, const uint8_t *data, uint32_t length, uint16_t type) |
@@ -2789,8 +2801,27 @@ static int messenger_load_state_callback(void *outer, const uint8_t *data, uint3 | |||
2789 | for (i = 0; i < NUM_SAVED_TCP_RELAYS; ++i) { | 2801 | for (i = 0; i < NUM_SAVED_TCP_RELAYS; ++i) { |
2790 | add_tcp_relay(m->net_crypto, relays[i].ip_port, relays[i].client_id); | 2802 | add_tcp_relay(m->net_crypto, relays[i].ip_port, relays[i].client_id); |
2791 | } | 2803 | } |
2804 | |||
2805 | break; | ||
2792 | } | 2806 | } |
2793 | break; | 2807 | |
2808 | case MESSENGER_STATE_TYPE_PATH_NODE: { | ||
2809 | Node_format nodes[NUM_SAVED_PATH_NODES]; | ||
2810 | |||
2811 | if (length != sizeof(nodes)) { | ||
2812 | return -1; | ||
2813 | } | ||
2814 | |||
2815 | memcpy(nodes, data, length); | ||
2816 | uint32_t i; | ||
2817 | |||
2818 | for (i = 0; i < NUM_SAVED_PATH_NODES; ++i) { | ||
2819 | onion_add_path_node(m->onion_c, nodes[i].ip_port, nodes[i].client_id); | ||
2820 | } | ||
2821 | |||
2822 | break; | ||
2823 | } | ||
2824 | |||
2794 | #ifdef DEBUG | 2825 | #ifdef DEBUG |
2795 | 2826 | ||
2796 | default: | 2827 | default: |