Pack connected TCP relay nodes.

This commit is contained in:
irungentoo 2015-07-16 22:58:47 -04:00
parent 17af629d1f
commit 6ecf2941ac
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98

View File

@ -2545,7 +2545,7 @@ uint32_t messenger_size(const Messenger *m)
+ sizesubhead + m->name_length // Own nickname. + sizesubhead + m->name_length // Own nickname.
+ 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 * packed_node_size(TCP_INET6) //TCP relays
+ sizesubhead + NUM_SAVED_PATH_NODES * sizeof(Node_format) //saved path nodes + sizesubhead + NUM_SAVED_PATH_NODES * sizeof(Node_format) //saved path nodes
; ;
} }
@ -2612,12 +2612,12 @@ void messenger_save(const Messenger *m, uint8_t *data)
data += len; data += len;
Node_format relays[NUM_SAVED_TCP_RELAYS]; Node_format relays[NUM_SAVED_TCP_RELAYS];
len = sizeof(relays);
type = MESSENGER_STATE_TYPE_TCP_RELAY; type = MESSENGER_STATE_TYPE_TCP_RELAY;
data = z_state_save_subheader(data, len, type); uint8_t *temp_data = data;
memset(relays, 0, len); data = z_state_save_subheader(temp_data, 0, type);
copy_connected_tcp_relays(m->net_crypto, relays, NUM_SAVED_TCP_RELAYS); unsigned int num = copy_connected_tcp_relays(m->net_crypto, relays, NUM_SAVED_TCP_RELAYS);
memcpy(data, relays, len); len = pack_nodes(data, NUM_SAVED_TCP_RELAYS * packed_node_size(TCP_INET6), relays, num);
data = z_state_save_subheader(temp_data, len, type);
data += len; data += len;
Node_format nodes[NUM_SAVED_PATH_NODES]; Node_format nodes[NUM_SAVED_PATH_NODES];
@ -2677,11 +2677,11 @@ static int messenger_load_state_callback(void *outer, const uint8_t *data, uint3
break; break;
case MESSENGER_STATE_TYPE_TCP_RELAY: { case MESSENGER_STATE_TYPE_TCP_RELAY: {
if (length != sizeof(m->loaded_relays)) { if (length == 0) {
return -1; break;
} }
memcpy(m->loaded_relays, data, length); unpack_nodes(m->loaded_relays, NUM_SAVED_TCP_RELAYS, 0, data, length, 1);
m->has_added_relays = 0; m->has_added_relays = 0;
break; break;