summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-07-16 22:58:47 -0400
committerirungentoo <irungentoo@gmail.com>2015-07-16 22:58:47 -0400
commit6ecf2941ac71e36d6978539b0dd24b7ad1ecf8f1 (patch)
tree8957e7e117c4c5a6423bd8e4ded8b0bd2ec8f1d1 /toxcore/Messenger.c
parent17af629d1f7fd7f35f8f54bc9b24444439950886 (diff)
Pack connected TCP relay nodes.
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r--toxcore/Messenger.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index d27e3ae5..2240ff5c 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -2545,7 +2545,7 @@ uint32_t messenger_size(const Messenger *m)
2545 + sizesubhead + m->name_length // Own nickname. 2545 + sizesubhead + m->name_length // Own nickname.
2546 + sizesubhead + m->statusmessage_length // status message 2546 + sizesubhead + m->statusmessage_length // status message
2547 + sizesubhead + 1 // status 2547 + sizesubhead + 1 // status
2548 + sizesubhead + NUM_SAVED_TCP_RELAYS * sizeof(Node_format) //TCP relays 2548 + sizesubhead + NUM_SAVED_TCP_RELAYS * packed_node_size(TCP_INET6) //TCP relays
2549 + sizesubhead + NUM_SAVED_PATH_NODES * sizeof(Node_format) //saved path nodes 2549 + sizesubhead + NUM_SAVED_PATH_NODES * sizeof(Node_format) //saved path nodes
2550 ; 2550 ;
2551} 2551}
@@ -2612,12 +2612,12 @@ void messenger_save(const Messenger *m, uint8_t *data)
2612 data += len; 2612 data += len;
2613 2613
2614 Node_format relays[NUM_SAVED_TCP_RELAYS]; 2614 Node_format relays[NUM_SAVED_TCP_RELAYS];
2615 len = sizeof(relays);
2616 type = MESSENGER_STATE_TYPE_TCP_RELAY; 2615 type = MESSENGER_STATE_TYPE_TCP_RELAY;
2617 data = z_state_save_subheader(data, len, type); 2616 uint8_t *temp_data = data;
2618 memset(relays, 0, len); 2617 data = z_state_save_subheader(temp_data, 0, type);
2619 copy_connected_tcp_relays(m->net_crypto, relays, NUM_SAVED_TCP_RELAYS); 2618 unsigned int num = copy_connected_tcp_relays(m->net_crypto, relays, NUM_SAVED_TCP_RELAYS);
2620 memcpy(data, relays, len); 2619 len = pack_nodes(data, NUM_SAVED_TCP_RELAYS * packed_node_size(TCP_INET6), relays, num);
2620 data = z_state_save_subheader(temp_data, len, type);
2621 data += len; 2621 data += len;
2622 2622
2623 Node_format nodes[NUM_SAVED_PATH_NODES]; 2623 Node_format nodes[NUM_SAVED_PATH_NODES];
@@ -2677,11 +2677,11 @@ static int messenger_load_state_callback(void *outer, const uint8_t *data, uint3
2677 break; 2677 break;
2678 2678
2679 case MESSENGER_STATE_TYPE_TCP_RELAY: { 2679 case MESSENGER_STATE_TYPE_TCP_RELAY: {
2680 if (length != sizeof(m->loaded_relays)) { 2680 if (length == 0) {
2681 return -1; 2681 break;
2682 } 2682 }
2683 2683
2684 memcpy(m->loaded_relays, data, length); 2684 unpack_nodes(m->loaded_relays, NUM_SAVED_TCP_RELAYS, 0, data, length, 1);
2685 m->has_added_relays = 0; 2685 m->has_added_relays = 0;
2686 2686
2687 break; 2687 break;