diff options
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r-- | toxcore/Messenger.c | 64 |
1 files changed, 17 insertions, 47 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index fefc3b17..fd17ab98 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -433,14 +433,19 @@ int m_get_friend_connectionstatus(const Messenger *m, int32_t friendnumber) | |||
433 | return -1; | 433 | return -1; |
434 | 434 | ||
435 | if (m->friendlist[friendnumber].status == FRIEND_ONLINE) { | 435 | if (m->friendlist[friendnumber].status == FRIEND_ONLINE) { |
436 | uint8_t direct_connected = 0; | 436 | _Bool direct_connected = 0; |
437 | unsigned int num_online_relays = 0; | ||
437 | crypto_connection_status(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, | 438 | crypto_connection_status(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, |
438 | m->friendlist[friendnumber].friendcon_id), &direct_connected); | 439 | m->friendlist[friendnumber].friendcon_id), &direct_connected, &num_online_relays); |
439 | 440 | ||
440 | if (direct_connected) { | 441 | if (direct_connected) { |
441 | return CONNECTION_UDP; | 442 | return CONNECTION_UDP; |
442 | } else { | 443 | } else { |
443 | return CONNECTION_TCP; | 444 | if (num_online_relays) { |
445 | return CONNECTION_TCP; | ||
446 | } else { | ||
447 | return CONNECTION_UNKNOWN; | ||
448 | } | ||
444 | } | 449 | } |
445 | } else { | 450 | } else { |
446 | return CONNECTION_NONE; | 451 | return CONNECTION_NONE; |
@@ -493,10 +498,6 @@ int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, con | |||
493 | 498 | ||
494 | uint32_t msg_id = ++m->friendlist[friendnumber].message_id; | 499 | uint32_t msg_id = ++m->friendlist[friendnumber].message_id; |
495 | 500 | ||
496 | if (msg_id == 0) { | ||
497 | msg_id = ++m->friendlist[friendnumber].message_id; // Otherwise, false error | ||
498 | } | ||
499 | |||
500 | add_receipt(m, friendnumber, packet_num, msg_id); | 501 | add_receipt(m, friendnumber, packet_num, msg_id); |
501 | 502 | ||
502 | if (message_id) | 503 | if (message_id) |
@@ -753,25 +754,6 @@ static int send_user_istyping(const Messenger *m, int32_t friendnumber, uint8_t | |||
753 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_TYPING, &typing, sizeof(typing), 0); | 754 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_TYPING, &typing, sizeof(typing), 0); |
754 | } | 755 | } |
755 | 756 | ||
756 | static int send_relays(const Messenger *m, int32_t friendnumber) | ||
757 | { | ||
758 | Node_format nodes[MAX_SHARED_RELAYS]; | ||
759 | uint8_t data[1024]; | ||
760 | int n, length; | ||
761 | |||
762 | n = copy_connected_tcp_relays(m->net_crypto, nodes, MAX_SHARED_RELAYS); | ||
763 | length = pack_nodes(data, sizeof(data), nodes, n); | ||
764 | |||
765 | int ret = write_cryptpacket_id(m, friendnumber, PACKET_ID_SHARE_RELAYS, data, length, 0); | ||
766 | |||
767 | if (ret == 1) | ||
768 | m->friendlist[friendnumber].share_relays_lastsent = unix_time(); | ||
769 | |||
770 | return ret; | ||
771 | } | ||
772 | |||
773 | |||
774 | |||
775 | static int set_friend_statusmessage(const Messenger *m, int32_t friendnumber, const uint8_t *status, uint16_t length) | 757 | static int set_friend_statusmessage(const Messenger *m, int32_t friendnumber, const uint8_t *status, uint16_t length) |
776 | { | 758 | { |
777 | if (friend_not_valid(m, friendnumber)) | 759 | if (friend_not_valid(m, friendnumber)) |
@@ -874,6 +856,14 @@ static void check_friend_tcp_udp(Messenger *m, int32_t friendnumber) | |||
874 | if (ret == -1) | 856 | if (ret == -1) |
875 | return; | 857 | return; |
876 | 858 | ||
859 | if (ret == CONNECTION_UNKNOWN) { | ||
860 | if (last_connection_udp_tcp == CONNECTION_UDP) { | ||
861 | return; | ||
862 | } else { | ||
863 | ret = CONNECTION_TCP; | ||
864 | } | ||
865 | } | ||
866 | |||
877 | if (last_connection_udp_tcp != ret) { | 867 | if (last_connection_udp_tcp != ret) { |
878 | if (m->friend_connectionstatuschange) | 868 | if (m->friend_connectionstatuschange) |
879 | m->friend_connectionstatuschange(m, friendnumber, ret, m->friend_connectionstatuschange_userdata); | 869 | m->friend_connectionstatuschange(m, friendnumber, ret, m->friend_connectionstatuschange_userdata); |
@@ -1350,7 +1340,7 @@ int file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin | |||
1350 | if (m->friendlist[friendnumber].status != FRIEND_ONLINE) | 1340 | if (m->friendlist[friendnumber].status != FRIEND_ONLINE) |
1351 | return -2; | 1341 | return -2; |
1352 | 1342 | ||
1353 | if (filenumber > MAX_CONCURRENT_FILE_PIPES) | 1343 | if (filenumber >= MAX_CONCURRENT_FILE_PIPES) |
1354 | return -3; | 1344 | return -3; |
1355 | 1345 | ||
1356 | struct File_Transfers *ft = &m->friendlist[friendnumber].file_sending[filenumber]; | 1346 | struct File_Transfers *ft = &m->friendlist[friendnumber].file_sending[filenumber]; |
@@ -2178,22 +2168,6 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len) | |||
2178 | break; | 2168 | break; |
2179 | } | 2169 | } |
2180 | 2170 | ||
2181 | case PACKET_ID_SHARE_RELAYS: { | ||
2182 | Node_format nodes[MAX_SHARED_RELAYS]; | ||
2183 | int n; | ||
2184 | |||
2185 | if ((n = unpack_nodes(nodes, MAX_SHARED_RELAYS, NULL, data, data_length, 1)) == -1) | ||
2186 | break; | ||
2187 | |||
2188 | int i; | ||
2189 | |||
2190 | for (i = 0; i < n; i++) { | ||
2191 | add_tcp_relay(m->net_crypto, nodes[i].ip_port, nodes[i].public_key); | ||
2192 | } | ||
2193 | |||
2194 | break; | ||
2195 | } | ||
2196 | |||
2197 | default: { | 2171 | default: { |
2198 | handle_custom_lossless_packet(object, i, temp, len); | 2172 | handle_custom_lossless_packet(object, i, temp, len); |
2199 | break; | 2173 | break; |
@@ -2251,10 +2225,6 @@ void do_friends(Messenger *m) | |||
2251 | m->friendlist[i].user_istyping_sent = 1; | 2225 | m->friendlist[i].user_istyping_sent = 1; |
2252 | } | 2226 | } |
2253 | 2227 | ||
2254 | if (m->friendlist[i].share_relays_lastsent + FRIEND_SHARE_RELAYS_INTERVAL < temp_time) { | ||
2255 | send_relays(m, i); | ||
2256 | } | ||
2257 | |||
2258 | check_friend_tcp_udp(m, i); | 2228 | check_friend_tcp_udp(m, i); |
2259 | do_receipts(m, i); | 2229 | do_receipts(m, i); |
2260 | do_reqchunk_filecb(m, i); | 2230 | do_reqchunk_filecb(m, i); |