diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/Messenger.c | 11 | ||||
-rw-r--r-- | toxcore/assoc.c | 18 | ||||
-rw-r--r-- | toxcore/group.c | 2 | ||||
-rw-r--r-- | toxcore/net_crypto.c | 4 | ||||
-rw-r--r-- | toxcore/tox.c | 61 | ||||
-rw-r--r-- | toxcore/tox.h | 67 |
6 files changed, 111 insertions, 52 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index dc0e605a..4d4b82c1 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -384,12 +384,12 @@ int m_delfriend(Messenger *m, int32_t friendnumber) | |||
384 | clear_receipts(m, friendnumber); | 384 | clear_receipts(m, friendnumber); |
385 | remove_request_received(&(m->fr), m->friendlist[friendnumber].real_pk); | 385 | remove_request_received(&(m->fr), m->friendlist[friendnumber].real_pk); |
386 | friend_connection_callbacks(m->fr_c, m->friendlist[friendnumber].friendcon_id, MESSENGER_CALLBACK_INDEX, 0, 0, 0, 0, 0); | 386 | friend_connection_callbacks(m->fr_c, m->friendlist[friendnumber].friendcon_id, MESSENGER_CALLBACK_INDEX, 0, 0, 0, 0, 0); |
387 | kill_friend_connection(m->fr_c, m->friendlist[friendnumber].friendcon_id); | ||
388 | 387 | ||
389 | if (friend_con_connected(m->fr_c, m->friendlist[friendnumber].friendcon_id) == FRIENDCONN_STATUS_CONNECTED) { | 388 | if (friend_con_connected(m->fr_c, m->friendlist[friendnumber].friendcon_id) == FRIENDCONN_STATUS_CONNECTED) { |
390 | send_offline_packet(m, m->friendlist[friendnumber].friendcon_id); | 389 | send_offline_packet(m, m->friendlist[friendnumber].friendcon_id); |
391 | } | 390 | } |
392 | 391 | ||
392 | kill_friend_connection(m->fr_c, m->friendlist[friendnumber].friendcon_id); | ||
393 | memset(&(m->friendlist[friendnumber]), 0, sizeof(Friend)); | 393 | memset(&(m->friendlist[friendnumber]), 0, sizeof(Friend)); |
394 | uint32_t i; | 394 | uint32_t i; |
395 | 395 | ||
@@ -864,6 +864,11 @@ static void check_friend_connectionstatus(Messenger *m, int32_t friendnumber, ui | |||
864 | if (was_online) { | 864 | if (was_online) { |
865 | break_files(m, friendnumber); | 865 | break_files(m, friendnumber); |
866 | clear_receipts(m, friendnumber); | 866 | clear_receipts(m, friendnumber); |
867 | } else { | ||
868 | m->friendlist[friendnumber].name_sent = 0; | ||
869 | m->friendlist[friendnumber].userstatus_sent = 0; | ||
870 | m->friendlist[friendnumber].statusmessage_sent = 0; | ||
871 | m->friendlist[friendnumber].user_istyping_sent = 0; | ||
867 | } | 872 | } |
868 | 873 | ||
869 | m->friendlist[friendnumber].status = status; | 874 | m->friendlist[friendnumber].status = status; |
@@ -1891,10 +1896,6 @@ static int handle_status(void *object, int i, uint8_t status) | |||
1891 | 1896 | ||
1892 | if (status) { /* Went online. */ | 1897 | if (status) { /* Went online. */ |
1893 | send_online_packet(m, i); | 1898 | send_online_packet(m, i); |
1894 | m->friendlist[i].name_sent = 0; | ||
1895 | m->friendlist[i].userstatus_sent = 0; | ||
1896 | m->friendlist[i].statusmessage_sent = 0; | ||
1897 | m->friendlist[i].user_istyping_sent = 0; | ||
1898 | } else { /* Went offline. */ | 1899 | } else { /* Went offline. */ |
1899 | if (m->friendlist[i].status == FRIEND_ONLINE) { | 1900 | if (m->friendlist[i].status == FRIEND_ONLINE) { |
1900 | set_friend_status(m, i, FRIEND_CONFIRMED); | 1901 | set_friend_status(m, i, FRIEND_CONFIRMED); |
diff --git a/toxcore/assoc.c b/toxcore/assoc.c index 3dbeba51..2e03dabe 100644 --- a/toxcore/assoc.c +++ b/toxcore/assoc.c | |||
@@ -510,20 +510,18 @@ static uint8_t candidates_create_new(const Assoc *assoc, hash_t hash, const uint | |||
510 | 510 | ||
511 | static void client_id_self_update(Assoc *assoc) | 511 | static void client_id_self_update(Assoc *assoc) |
512 | { | 512 | { |
513 | if (assoc->self_hash || !assoc->self_client_id) | 513 | if (assoc->self_hash) |
514 | return; | 514 | return; |
515 | 515 | ||
516 | if (!assoc->self_hash) { | 516 | size_t i, sum = 0; |
517 | size_t i, sum = 0; | ||
518 | 517 | ||
519 | for (i = 0; i < crypto_box_PUBLICKEYBYTES; i++) | 518 | for (i = 0; i < crypto_box_PUBLICKEYBYTES; i++) |
520 | sum |= assoc->self_client_id[i]; | 519 | sum |= assoc->self_client_id[i]; |
521 | 520 | ||
522 | if (!sum) | 521 | if (!sum) |
523 | return; | 522 | return; |
524 | 523 | ||
525 | assoc->self_hash = id_hash(assoc, assoc->self_client_id); | 524 | assoc->self_hash = id_hash(assoc, assoc->self_client_id); |
526 | } | ||
527 | 525 | ||
528 | LOGGER_DEBUG("id is now set, purging cache of self-references"); | 526 | LOGGER_DEBUG("id is now set, purging cache of self-references"); |
529 | 527 | ||
@@ -532,7 +530,7 @@ static void client_id_self_update(Assoc *assoc) | |||
532 | */ | 530 | */ |
533 | bucket_t b_id = candidates_id_bucket(assoc, assoc->self_client_id); | 531 | bucket_t b_id = candidates_id_bucket(assoc, assoc->self_client_id); |
534 | candidates_bucket *cnd_bckt = &assoc->candidates[b_id]; | 532 | candidates_bucket *cnd_bckt = &assoc->candidates[b_id]; |
535 | size_t i, pos = assoc->self_hash % assoc->candidates_bucket_size; | 533 | size_t pos = assoc->self_hash % assoc->candidates_bucket_size; |
536 | 534 | ||
537 | for (i = 0; i < HASH_COLLIDE_COUNT; pos = hash_collide(assoc, pos), i++) { | 535 | for (i = 0; i < HASH_COLLIDE_COUNT; pos = hash_collide(assoc, pos), i++) { |
538 | Client_entry *entry = &cnd_bckt->list[pos]; | 536 | Client_entry *entry = &cnd_bckt->list[pos]; |
diff --git a/toxcore/group.c b/toxcore/group.c index c688ccff..af2cb492 100644 --- a/toxcore/group.c +++ b/toxcore/group.c | |||
@@ -1149,7 +1149,7 @@ int group_new_peer_send(const Group_Chats *g_c, int groupnumber, uint16_t peer_n | |||
1149 | * return 0 on success | 1149 | * return 0 on success |
1150 | * return -1 on failure | 1150 | * return -1 on failure |
1151 | */ | 1151 | */ |
1152 | int group_kill_peer_send(const Group_Chats *g_c, int groupnumber, uint16_t peer_num) | 1152 | static int group_kill_peer_send(const Group_Chats *g_c, int groupnumber, uint16_t peer_num) |
1153 | { | 1153 | { |
1154 | uint8_t packet[GROUP_MESSAGE_KILL_PEER_LENGTH]; | 1154 | uint8_t packet[GROUP_MESSAGE_KILL_PEER_LENGTH]; |
1155 | 1155 | ||
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 6d4f6a9b..96be059d 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c | |||
@@ -2006,7 +2006,7 @@ static int udp_handle_packet(void *object, IP_Port source, const uint8_t *packet | |||
2006 | #define PACKET_RESEND_MULTIPLIER 2 | 2006 | #define PACKET_RESEND_MULTIPLIER 2 |
2007 | 2007 | ||
2008 | /* Timeout for increasing speed after congestion event (in ms). */ | 2008 | /* Timeout for increasing speed after congestion event (in ms). */ |
2009 | #define CONGESTION_EVENT_TIMEOUT 4000 | 2009 | #define CONGESTION_EVENT_TIMEOUT 2000 |
2010 | 2010 | ||
2011 | static void send_crypto_packets(Net_Crypto *c) | 2011 | static void send_crypto_packets(Net_Crypto *c) |
2012 | { | 2012 | { |
@@ -2086,7 +2086,7 @@ static void send_crypto_packets(Net_Crypto *c) | |||
2086 | PACKET_COUNTER_AVERAGE_INTERVAL)); | 2086 | PACKET_COUNTER_AVERAGE_INTERVAL)); |
2087 | 2087 | ||
2088 | if (conn->last_congestion_event + CONGESTION_EVENT_TIMEOUT < temp_time) { | 2088 | if (conn->last_congestion_event + CONGESTION_EVENT_TIMEOUT < temp_time) { |
2089 | conn->packet_send_rate = min_speed * 1.2; | 2089 | conn->packet_send_rate = min_speed * 1.25; |
2090 | } else { | 2090 | } else { |
2091 | conn->packet_send_rate = min_speed; | 2091 | conn->packet_send_rate = min_speed; |
2092 | } | 2092 | } |
diff --git a/toxcore/tox.c b/toxcore/tox.c index de615768..3e9db766 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -121,33 +121,46 @@ void tox_options_free(struct Tox_Options *options) | |||
121 | free(options); | 121 | free(options); |
122 | } | 122 | } |
123 | 123 | ||
124 | Tox *tox_new(const struct Tox_Options *options, const uint8_t *data, size_t length, TOX_ERR_NEW *error) | 124 | Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error) |
125 | { | 125 | { |
126 | if (!logger_get_global()) | 126 | if (!logger_get_global()) |
127 | logger_set_global(logger_new(LOGGER_OUTPUT_FILE, LOGGER_LEVEL, "toxcore")); | 127 | logger_set_global(logger_new(LOGGER_OUTPUT_FILE, LOGGER_LEVEL, "toxcore")); |
128 | 128 | ||
129 | if (data == NULL && length != 0) { | ||
130 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_NULL); | ||
131 | return NULL; | ||
132 | } | ||
133 | |||
134 | if (data && length) { | ||
135 | if (length < TOX_ENC_SAVE_MAGIC_LENGTH) { | ||
136 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT); | ||
137 | return NULL; | ||
138 | } | ||
139 | |||
140 | if (memcmp(data, TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) == 0) { | ||
141 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_ENCRYPTED); | ||
142 | return NULL; | ||
143 | } | ||
144 | } | ||
145 | |||
146 | Messenger_Options m_options = {0}; | 129 | Messenger_Options m_options = {0}; |
147 | 130 | ||
131 | _Bool load_savedata_sk = 0, load_savedata_tox = 0; | ||
132 | |||
148 | if (options == NULL) { | 133 | if (options == NULL) { |
149 | m_options.ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; | 134 | m_options.ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; |
150 | } else { | 135 | } else { |
136 | if (options->savedata_type != TOX_SAVEDATA_TYPE_NONE) { | ||
137 | if (options->savedata_data == NULL || options->savedata_length == 0) { | ||
138 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT); | ||
139 | return NULL; | ||
140 | } | ||
141 | } | ||
142 | |||
143 | if (options->savedata_type == TOX_SAVEDATA_TYPE_SECRET_KEY) { | ||
144 | if (options->savedata_length != TOX_SECRET_KEY_SIZE) { | ||
145 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT); | ||
146 | return NULL; | ||
147 | } | ||
148 | |||
149 | load_savedata_sk = 1; | ||
150 | } else if (options->savedata_type == TOX_SAVEDATA_TYPE_TOX_SAVE) { | ||
151 | if (options->savedata_length < TOX_ENC_SAVE_MAGIC_LENGTH) { | ||
152 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT); | ||
153 | return NULL; | ||
154 | } | ||
155 | |||
156 | if (memcmp(options->savedata_data, TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) == 0) { | ||
157 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_ENCRYPTED); | ||
158 | return NULL; | ||
159 | } | ||
160 | |||
161 | load_savedata_tox = 1; | ||
162 | } | ||
163 | |||
151 | m_options.ipv6enabled = options->ipv6_enabled; | 164 | m_options.ipv6enabled = options->ipv6_enabled; |
152 | m_options.udp_disabled = !options->udp_enabled; | 165 | m_options.udp_disabled = !options->udp_enabled; |
153 | m_options.port_range[0] = options->start_port; | 166 | m_options.port_range[0] = options->start_port; |
@@ -201,6 +214,8 @@ Tox *tox_new(const struct Tox_Options *options, const uint8_t *data, size_t leng | |||
201 | 214 | ||
202 | if (m_error == MESSENGER_ERROR_PORT) { | 215 | if (m_error == MESSENGER_ERROR_PORT) { |
203 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PORT_ALLOC); | 216 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PORT_ALLOC); |
217 | } else if (m_error == MESSENGER_ERROR_TCP_SERVER) { | ||
218 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PORT_ALLOC); | ||
204 | } else { | 219 | } else { |
205 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_MALLOC); | 220 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_MALLOC); |
206 | } | 221 | } |
@@ -208,8 +223,11 @@ Tox *tox_new(const struct Tox_Options *options, const uint8_t *data, size_t leng | |||
208 | return NULL; | 223 | return NULL; |
209 | } | 224 | } |
210 | 225 | ||
211 | if (data && length && messenger_load(m, data, length) == -1) { | 226 | if (load_savedata_tox && messenger_load(m, options->savedata_data, options->savedata_length) == -1) { |
212 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT); | 227 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT); |
228 | } else if (load_savedata_sk) { | ||
229 | load_secret_key(m->net_crypto, options->savedata_data); | ||
230 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_OK); | ||
213 | } else { | 231 | } else { |
214 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_OK); | 232 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_OK); |
215 | } | 233 | } |
@@ -993,6 +1011,11 @@ void tox_callback_file_recv_control(Tox *tox, tox_file_recv_control_cb *function | |||
993 | bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_number, uint8_t *file_id, | 1011 | bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_number, uint8_t *file_id, |
994 | TOX_ERR_FILE_GET *error) | 1012 | TOX_ERR_FILE_GET *error) |
995 | { | 1013 | { |
1014 | if (!file_id) { | ||
1015 | SET_ERROR_PARAMETER(error, TOX_ERR_FILE_GET_NULL); | ||
1016 | return 0; | ||
1017 | } | ||
1018 | |||
996 | const Messenger *m = tox; | 1019 | const Messenger *m = tox; |
997 | int ret = file_get_id(m, friend_number, file_number, file_id); | 1020 | int ret = file_get_id(m, friend_number, file_number, file_id); |
998 | 1021 | ||
diff --git a/toxcore/tox.h b/toxcore/tox.h index 4afdf7c3..14c9f616 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -352,6 +352,29 @@ typedef enum TOX_PROXY_TYPE { | |||
352 | 352 | ||
353 | 353 | ||
354 | /** | 354 | /** |
355 | * Type of savedata to create the Tox instance from. | ||
356 | */ | ||
357 | typedef enum TOX_SAVEDATA_TYPE { | ||
358 | |||
359 | /** | ||
360 | * No savedata. | ||
361 | */ | ||
362 | TOX_SAVEDATA_TYPE_NONE, | ||
363 | |||
364 | /** | ||
365 | * Savedata is one that was obtained from tox_get_savedata | ||
366 | */ | ||
367 | TOX_SAVEDATA_TYPE_TOX_SAVE, | ||
368 | |||
369 | /** | ||
370 | * Savedata is a secret key of length TOX_SECRET_KEY_SIZE | ||
371 | */ | ||
372 | TOX_SAVEDATA_TYPE_SECRET_KEY, | ||
373 | |||
374 | } TOX_SAVEDATA_TYPE; | ||
375 | |||
376 | |||
377 | /** | ||
355 | * This struct contains all the startup options for Tox. You can either allocate | 378 | * This struct contains all the startup options for Tox. You can either allocate |
356 | * this object yourself, and pass it to tox_options_default, or call | 379 | * this object yourself, and pass it to tox_options_default, or call |
357 | * tox_options_new to get a new default options object. | 380 | * tox_options_new to get a new default options object. |
@@ -432,6 +455,24 @@ struct Tox_Options { | |||
432 | */ | 455 | */ |
433 | uint16_t tcp_port; | 456 | uint16_t tcp_port; |
434 | 457 | ||
458 | |||
459 | /** | ||
460 | * The type of savedata to load from. | ||
461 | */ | ||
462 | TOX_SAVEDATA_TYPE savedata_type; | ||
463 | |||
464 | |||
465 | /** | ||
466 | * The savedata. | ||
467 | */ | ||
468 | const uint8_t *savedata_data; | ||
469 | |||
470 | |||
471 | /** | ||
472 | * The length of the savedata. | ||
473 | */ | ||
474 | size_t savedata_length; | ||
475 | |||
435 | }; | 476 | }; |
436 | 477 | ||
437 | 478 | ||
@@ -561,21 +602,17 @@ typedef enum TOX_ERR_NEW { | |||
561 | * This function will bring the instance into a valid state. Running the event | 602 | * This function will bring the instance into a valid state. Running the event |
562 | * loop with a new instance will operate correctly. | 603 | * loop with a new instance will operate correctly. |
563 | * | 604 | * |
564 | * If the data parameter is not NULL, this function will load the Tox instance | ||
565 | * from a byte array previously filled by tox_get_savedata. | ||
566 | * | ||
567 | * If loading failed or succeeded only partially, the new or partially loaded | 605 | * If loading failed or succeeded only partially, the new or partially loaded |
568 | * instance is returned and an error code is set. | 606 | * instance is returned and an error code is set. |
569 | * | 607 | * |
570 | * @param options An options object as described above. If this parameter is | 608 | * @param options An options object as described above. If this parameter is |
571 | * NULL, the default options are used. | 609 | * NULL, the default options are used. |
572 | * @param data A byte array containing data previously stored by tox_get_savedata. | ||
573 | * @param length The length of the byte array data. If this parameter is 0, the | ||
574 | * data parameter is ignored. | ||
575 | * | 610 | * |
576 | * @see tox_iterate for the event loop. | 611 | * @see tox_iterate for the event loop. |
612 | * | ||
613 | * @return A new Tox instance pointer on success or NULL on failure. | ||
577 | */ | 614 | */ |
578 | Tox *tox_new(const struct Tox_Options *options, const uint8_t *data, size_t length, TOX_ERR_NEW *error); | 615 | Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error); |
579 | 616 | ||
580 | /** | 617 | /** |
581 | * Releases all resources associated with the Tox instance and disconnects from | 618 | * Releases all resources associated with the Tox instance and disconnects from |
@@ -642,13 +679,8 @@ typedef enum TOX_ERR_BOOTSTRAP { | |||
642 | * Sends a "get nodes" request to the given bootstrap node with IP, port, and | 679 | * Sends a "get nodes" request to the given bootstrap node with IP, port, and |
643 | * public key to setup connections. | 680 | * public key to setup connections. |
644 | * | 681 | * |
645 | * This function will attempt to connect to the node using UDP and TCP at the | 682 | * This function will attempt to connect to the node using UDP. You must use |
646 | * same time. | 683 | * this function even if Tox_Options.udp_enabled was set to false. |
647 | * | ||
648 | * Tox will use the node as a TCP relay in case Tox_Options.udp_enabled was | ||
649 | * false, and also to connect to friends that are in TCP-only mode. Tox will | ||
650 | * also use the TCP connection when NAT hole punching is slow, and later switch | ||
651 | * to UDP if hole punching succeeds. | ||
652 | * | 684 | * |
653 | * @param address The hostname or IP address (IPv4 or IPv6) of the node. | 685 | * @param address The hostname or IP address (IPv4 or IPv6) of the node. |
654 | * @param port The port on the host on which the bootstrap Tox instance is | 686 | * @param port The port on the host on which the bootstrap Tox instance is |
@@ -1559,7 +1591,7 @@ enum TOX_FILE_KIND { | |||
1559 | TOX_FILE_KIND_DATA, | 1591 | TOX_FILE_KIND_DATA, |
1560 | 1592 | ||
1561 | /** | 1593 | /** |
1562 | * Avatar filename. This consists of tox_hash(image). | 1594 | * Avatar file_id. This consists of tox_hash(image). |
1563 | * Avatar data. This consists of the image data. | 1595 | * Avatar data. This consists of the image data. |
1564 | * | 1596 | * |
1565 | * Avatars can be sent at any time the client wishes. Generally, a client will | 1597 | * Avatars can be sent at any time the client wishes. Generally, a client will |
@@ -1749,6 +1781,11 @@ typedef enum TOX_ERR_FILE_GET { | |||
1749 | TOX_ERR_FILE_GET_OK, | 1781 | TOX_ERR_FILE_GET_OK, |
1750 | 1782 | ||
1751 | /** | 1783 | /** |
1784 | * One of the arguments to the function was NULL when it was not expected. | ||
1785 | */ | ||
1786 | TOX_ERR_FILE_GET_NULL, | ||
1787 | |||
1788 | /** | ||
1752 | * The friend_number passed did not designate a valid friend. | 1789 | * The friend_number passed did not designate a valid friend. |
1753 | */ | 1790 | */ |
1754 | TOX_ERR_FILE_GET_FRIEND_NOT_FOUND, | 1791 | TOX_ERR_FILE_GET_FRIEND_NOT_FOUND, |