Save some path nodes to speed up joining network on pure TCP.

This commit is contained in:
irungentoo 2014-08-14 16:56:29 -04:00
parent 5376d40f54
commit fb9fc81a35
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98

View File

@ -2537,9 +2537,11 @@ void do_messenger(Messenger *m)
#define MESSENGER_STATE_TYPE_STATUSMESSAGE 5 #define MESSENGER_STATE_TYPE_STATUSMESSAGE 5
#define MESSENGER_STATE_TYPE_STATUS 6 #define MESSENGER_STATE_TYPE_STATUS 6
#define MESSENGER_STATE_TYPE_TCP_RELAY 10 #define MESSENGER_STATE_TYPE_TCP_RELAY 10
#define MESSENGER_STATE_TYPE_PATH_NODE 11
#define SAVED_FRIEND_REQUEST_SIZE 1024 #define SAVED_FRIEND_REQUEST_SIZE 1024
#define NUM_SAVED_TCP_RELAYS 8 #define NUM_SAVED_TCP_RELAYS 8
#define NUM_SAVED_PATH_NODES 8
struct SAVED_FRIEND { struct SAVED_FRIEND {
uint8_t status; uint8_t status;
uint8_t client_id[CLIENT_ID_SIZE]; uint8_t client_id[CLIENT_ID_SIZE];
@ -2653,6 +2655,7 @@ uint32_t messenger_size(const Messenger *m)
+ sizesubhead + m->statusmessage_length // status message + sizesubhead + m->statusmessage_length // status message
+ sizesubhead + 1 // status + sizesubhead + 1 // status
+ sizesubhead + NUM_SAVED_TCP_RELAYS * sizeof(Node_format) //TCP relays + sizesubhead + NUM_SAVED_TCP_RELAYS * sizeof(Node_format) //TCP relays
+ sizesubhead + NUM_SAVED_PATH_NODES * sizeof(Node_format) //saved path nodes
; ;
} }
@ -2725,6 +2728,15 @@ void messenger_save(const Messenger *m, uint8_t *data)
memset(relays, 0, len); memset(relays, 0, len);
copy_connected_tcp_relays(m->net_crypto, relays, NUM_SAVED_TCP_RELAYS); copy_connected_tcp_relays(m->net_crypto, relays, NUM_SAVED_TCP_RELAYS);
memcpy(data, relays, len); memcpy(data, relays, len);
data += len;
Node_format nodes[NUM_SAVED_PATH_NODES];
len = sizeof(nodes);
type = MESSENGER_STATE_TYPE_PATH_NODE;
data = z_state_save_subheader(data, len, type);
memset(nodes, 0, len);
onion_backup_nodes(m->onion_c, nodes, NUM_SAVED_PATH_NODES);
memcpy(data, nodes, len);
} }
static int messenger_load_state_callback(void *outer, const uint8_t *data, uint32_t length, uint16_t type) 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
for (i = 0; i < NUM_SAVED_TCP_RELAYS; ++i) { for (i = 0; i < NUM_SAVED_TCP_RELAYS; ++i) {
add_tcp_relay(m->net_crypto, relays[i].ip_port, relays[i].client_id); add_tcp_relay(m->net_crypto, relays[i].ip_port, relays[i].client_id);
} }
}
break; break;
}
case MESSENGER_STATE_TYPE_PATH_NODE: {
Node_format nodes[NUM_SAVED_PATH_NODES];
if (length != sizeof(nodes)) {
return -1;
}
memcpy(nodes, data, length);
uint32_t i;
for (i = 0; i < NUM_SAVED_PATH_NODES; ++i) {
onion_add_path_node(m->onion_c, nodes[i].ip_port, nodes[i].client_id);
}
break;
}
#ifdef DEBUG #ifdef DEBUG
default: default: