summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r--toxcore/Messenger.c245
1 files changed, 31 insertions, 214 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 8faa7f03..04830260 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -153,73 +153,9 @@ void getaddress(const Messenger *m, uint8_t *address)
153 memcpy(address + crypto_box_PUBLICKEYBYTES + sizeof(nospam), &checksum, sizeof(checksum)); 153 memcpy(address + crypto_box_PUBLICKEYBYTES + sizeof(nospam), &checksum, sizeof(checksum));
154} 154}
155 155
156/* callback for recv TCP relay nodes. */ 156static int handle_status(void *object, int i, uint8_t status);
157static int tcp_relay_node_callback(void *object, uint32_t number, IP_Port ip_port, const uint8_t *public_key) 157static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len);
158{ 158static int handle_custom_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length);
159 Messenger *m = object;
160
161 if (friend_not_valid(m, number))
162 return -1;
163
164 if (m->friendlist[number].crypt_connection_id != -1) {
165 return add_tcp_relay_peer(m->net_crypto, m->friendlist[number].crypt_connection_id, ip_port, public_key);
166 } else {
167 return add_tcp_relay(m->net_crypto, ip_port, public_key);
168 }
169}
170
171static int friend_new_connection(Messenger *m, int32_t friendnumber, const uint8_t *real_public_key);
172/* Callback for DHT ip_port changes. */
173static void dht_ip_callback(void *data, int32_t number, IP_Port ip_port)
174{
175 Messenger *m = data;
176
177 if (friend_not_valid(m, number))
178 return;
179
180 if (m->friendlist[number].crypt_connection_id == -1) {
181 friend_new_connection(m, number, m->friendlist[number].client_id);
182 }
183
184 set_direct_ip_port(m->net_crypto, m->friendlist[number].crypt_connection_id, ip_port);
185 m->friendlist[number].dht_ip_port = ip_port;
186 m->friendlist[number].dht_ip_port_lastrecv = unix_time();
187}
188
189/* Callback for dht public key changes. */
190static void dht_pk_callback(void *data, int32_t number, const uint8_t *dht_public_key)
191{
192 Messenger *m = data;
193
194 if (friend_not_valid(m, number))
195 return;
196
197 m->friendlist[number].dht_ping_lastrecv = unix_time();
198
199 if (memcmp(m->friendlist[number].dht_temp_pk, dht_public_key, crypto_box_PUBLICKEYBYTES) == 0)
200 return;
201
202 if (m->friendlist[number].dht_lock) {
203 if (DHT_delfriend(m->dht, m->friendlist[number].dht_temp_pk, m->friendlist[number].dht_lock) != 0) {
204 printf("a. Could not delete dht peer. Please report this.\n");
205 return;
206 }
207
208 m->friendlist[number].dht_lock = 0;
209 }
210
211 DHT_addfriend(m->dht, dht_public_key, dht_ip_callback, data, number, &m->friendlist[number].dht_lock);
212
213 if (m->friendlist[number].crypt_connection_id == -1) {
214 friend_new_connection(m, number, m->friendlist[number].client_id);
215 }
216
217 set_connection_dht_public_key(m->net_crypto, m->friendlist[number].crypt_connection_id, dht_public_key);
218 onion_set_friend_DHT_pubkey(m->onion_c, m->friendlist[number].onion_friendnum, dht_public_key);
219
220 memcpy(m->friendlist[number].dht_temp_pk, dht_public_key, crypto_box_PUBLICKEYBYTES);
221}
222
223 159
224/* 160/*
225 * Add a friend. 161 * Add a friend.
@@ -283,18 +219,17 @@ int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, u
283 219
284 memset(&(m->friendlist[m->numfriends]), 0, sizeof(Friend)); 220 memset(&(m->friendlist[m->numfriends]), 0, sizeof(Friend));
285 221
286 int32_t onion_friendnum = onion_addfriend(m->onion_c, client_id); 222 int friendcon_id = new_friend_connection(m->fr_c, client_id);
287 223
288 if (onion_friendnum == -1) 224 if (friendcon_id == -1)
289 return FAERR_UNKNOWN; 225 return -1;
290 226
291 uint32_t i; 227 uint32_t i;
292 228
293 for (i = 0; i <= m->numfriends; ++i) { 229 for (i = 0; i <= m->numfriends; ++i) {
294 if (m->friendlist[i].status == NOFRIEND) { 230 if (m->friendlist[i].status == NOFRIEND) {
295 m->friendlist[i].onion_friendnum = onion_friendnum;
296 m->friendlist[i].status = FRIEND_ADDED; 231 m->friendlist[i].status = FRIEND_ADDED;
297 m->friendlist[i].crypt_connection_id = -1; 232 m->friendlist[i].friendcon_id = friendcon_id;
298 m->friendlist[i].friendrequest_lastsent = 0; 233 m->friendlist[i].friendrequest_lastsent = 0;
299 m->friendlist[i].friendrequest_timeout = FRIENDREQUEST_TIMEOUT; 234 m->friendlist[i].friendrequest_timeout = FRIENDREQUEST_TIMEOUT;
300 id_copy(m->friendlist[i].client_id, client_id); 235 id_copy(m->friendlist[i].client_id, client_id);
@@ -311,8 +246,9 @@ int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, u
311 m->friendlist[i].message_id = 0; 246 m->friendlist[i].message_id = 0;
312 m->friendlist[i].receives_read_receipts = 1; /* Default: YES. */ 247 m->friendlist[i].receives_read_receipts = 1; /* Default: YES. */
313 memcpy(&(m->friendlist[i].friendrequest_nospam), address + crypto_box_PUBLICKEYBYTES, sizeof(uint32_t)); 248 memcpy(&(m->friendlist[i].friendrequest_nospam), address + crypto_box_PUBLICKEYBYTES, sizeof(uint32_t));
314 recv_tcp_relay_handler(m->onion_c, onion_friendnum, &tcp_relay_node_callback, m, i); 249 friend_connection_callbacks(m->fr_c, friendcon_id, MESSENGER_CALLBACK_INDEX, &handle_status, &handle_packet,
315 onion_dht_pk_callback(m->onion_c, onion_friendnum, &dht_pk_callback, m, i); 250 &handle_custom_lossy_packet, m, i);
251
316 252
317 if (m->numfriends == i) 253 if (m->numfriends == i)
318 ++m->numfriends; 254 ++m->numfriends;
@@ -341,18 +277,17 @@ int32_t m_addfriend_norequest(Messenger *m, const uint8_t *client_id)
341 277
342 memset(&(m->friendlist[m->numfriends]), 0, sizeof(Friend)); 278 memset(&(m->friendlist[m->numfriends]), 0, sizeof(Friend));
343 279
344 int32_t onion_friendnum = onion_addfriend(m->onion_c, client_id); 280 int friendcon_id = new_friend_connection(m->fr_c, client_id);
345 281
346 if (onion_friendnum == -1) 282 if (friendcon_id == -1)
347 return -1; 283 return -1;
348 284
349 uint32_t i; 285 uint32_t i;
350 286
351 for (i = 0; i <= m->numfriends; ++i) { 287 for (i = 0; i <= m->numfriends; ++i) {
352 if (m->friendlist[i].status == NOFRIEND) { 288 if (m->friendlist[i].status == NOFRIEND) {
353 m->friendlist[i].onion_friendnum = onion_friendnum;
354 m->friendlist[i].status = FRIEND_CONFIRMED; 289 m->friendlist[i].status = FRIEND_CONFIRMED;
355 m->friendlist[i].crypt_connection_id = -1; 290 m->friendlist[i].friendcon_id = friendcon_id;
356 m->friendlist[i].friendrequest_lastsent = 0; 291 m->friendlist[i].friendrequest_lastsent = 0;
357 id_copy(m->friendlist[i].client_id, client_id); 292 id_copy(m->friendlist[i].client_id, client_id);
358 m->friendlist[i].statusmessage = calloc(1, 1); 293 m->friendlist[i].statusmessage = calloc(1, 1);
@@ -365,8 +300,8 @@ int32_t m_addfriend_norequest(Messenger *m, const uint8_t *client_id)
365 m->friendlist[i].is_typing = 0; 300 m->friendlist[i].is_typing = 0;
366 m->friendlist[i].message_id = 0; 301 m->friendlist[i].message_id = 0;
367 m->friendlist[i].receives_read_receipts = 1; /* Default: YES. */ 302 m->friendlist[i].receives_read_receipts = 1; /* Default: YES. */
368 recv_tcp_relay_handler(m->onion_c, onion_friendnum, &tcp_relay_node_callback, m, i); 303 friend_connection_callbacks(m->fr_c, friendcon_id, MESSENGER_CALLBACK_INDEX, &handle_status, &handle_packet,
369 onion_dht_pk_callback(m->onion_c, onion_friendnum, &dht_pk_callback, m, i); 304 &handle_custom_lossy_packet, m, i);
370 305
371 if (m->numfriends == i) 306 if (m->numfriends == i)
372 ++m->numfriends; 307 ++m->numfriends;
@@ -391,16 +326,11 @@ int m_delfriend(Messenger *m, int32_t friendnumber)
391 if (m->friendlist[friendnumber].status == FRIEND_ONLINE) 326 if (m->friendlist[friendnumber].status == FRIEND_ONLINE)
392 remove_online_friend(m, friendnumber); 327 remove_online_friend(m, friendnumber);
393 328
394 onion_delfriend(m->onion_c, m->friendlist[friendnumber].onion_friendnum);
395
396 if (m->friendlist[friendnumber].dht_lock) {
397 DHT_delfriend(m->dht, m->friendlist[friendnumber].dht_temp_pk, m->friendlist[friendnumber].dht_lock);
398 }
399
400 crypto_kill(m->net_crypto, m->friendlist[friendnumber].crypt_connection_id);
401 free(m->friendlist[friendnumber].statusmessage); 329 free(m->friendlist[friendnumber].statusmessage);
402 free(m->friendlist[friendnumber].avatar_recv_data); 330 free(m->friendlist[friendnumber].avatar_recv_data);
403 remove_request_received(&(m->fr), m->friendlist[friendnumber].client_id); 331 remove_request_received(&(m->fr), m->friendlist[friendnumber].client_id);
332 friend_connection_callbacks(m->fr_c, m->friendlist[friendnumber].friendcon_id, MESSENGER_CALLBACK_INDEX, 0, 0, 0, 0, 0);
333 kill_friend_connection(m->fr_c, m->friendlist[friendnumber].friendcon_id);
404 memset(&(m->friendlist[friendnumber]), 0, sizeof(Friend)); 334 memset(&(m->friendlist[friendnumber]), 0, sizeof(Friend));
405 uint32_t i; 335 uint32_t i;
406 336
@@ -867,16 +797,6 @@ static int send_user_istyping(const Messenger *m, int32_t friendnumber, uint8_t
867 return write_cryptpacket_id(m, friendnumber, PACKET_ID_TYPING, &typing, sizeof(typing), 0); 797 return write_cryptpacket_id(m, friendnumber, PACKET_ID_TYPING, &typing, sizeof(typing), 0);
868} 798}
869 799
870static int send_ping(const Messenger *m, int32_t friendnumber)
871{
872 int ret = write_cryptpacket_id(m, friendnumber, PACKET_ID_ALIVE, 0, 0, 0);
873
874 if (ret == 1)
875 m->friendlist[friendnumber].ping_lastsent = unix_time();
876
877 return ret;
878}
879
880static int send_relays(const Messenger *m, int32_t friendnumber) 800static int send_relays(const Messenger *m, int32_t friendnumber)
881{ 801{
882 Node_format nodes[MAX_SHARED_RELAYS]; 802 Node_format nodes[MAX_SHARED_RELAYS];
@@ -1023,8 +943,6 @@ static void check_friend_connectionstatus(Messenger *m, int32_t friendnumber, ui
1023 const uint8_t was_online = m->friendlist[friendnumber].status == FRIEND_ONLINE; 943 const uint8_t was_online = m->friendlist[friendnumber].status == FRIEND_ONLINE;
1024 const uint8_t is_online = status == FRIEND_ONLINE; 944 const uint8_t is_online = status == FRIEND_ONLINE;
1025 945
1026 onion_set_friend_online(m->onion_c, m->friendlist[friendnumber].onion_friendnum, is_online);
1027
1028 if (is_online != was_online) { 946 if (is_online != was_online) {
1029 if (was_online) { 947 if (was_online) {
1030 break_files(m, friendnumber); 948 break_files(m, friendnumber);
@@ -1065,8 +983,8 @@ static int write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8_
1065 if (length != 0) 983 if (length != 0)
1066 memcpy(packet + 1, data, length); 984 memcpy(packet + 1, data, length);
1067 985
1068 return write_cryptpacket(m->net_crypto, m->friendlist[friendnumber].crypt_connection_id, packet, length + 1, 986 return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c,
1069 congestion_control) != -1; 987 m->friendlist[friendnumber].friendcon_id), packet, length + 1, congestion_control) != -1;
1070} 988}
1071 989
1072/**********GROUP CHATS************/ 990/**********GROUP CHATS************/
@@ -1311,8 +1229,8 @@ int file_data(const Messenger *m, int32_t friendnumber, uint8_t filenumber, cons
1311 if (m->friendlist[friendnumber].file_sending[filenumber].status != FILESTATUS_TRANSFERRING) 1229 if (m->friendlist[friendnumber].file_sending[filenumber].status != FILESTATUS_TRANSFERRING)
1312 return -1; 1230 return -1;
1313 1231
1314 /* Prevent file sending from filling up the entire buffer preventing messages from being sent. */ 1232 /* Prevent file sending from filling up the entire buffer preventing messages from being sent. TODO: remove */
1315 if (crypto_num_free_sendqueue_slots(m->net_crypto, m->friendlist[friendnumber].crypt_connection_id) < MIN_SLOTS_FREE) 1233 if (crypto_num_free_sendqueue_slots(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, m->friendlist[friendnumber].friendcon_id)) < MIN_SLOTS_FREE)
1316 return -1; 1234 return -1;
1317 1235
1318 uint8_t packet[MAX_CRYPTO_DATA_SIZE]; 1236 uint8_t packet[MAX_CRYPTO_DATA_SIZE];
@@ -1518,10 +1436,8 @@ int send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uin
1518 if (m->friendlist[friendnumber].status != FRIEND_ONLINE) 1436 if (m->friendlist[friendnumber].status != FRIEND_ONLINE)
1519 return -1; 1437 return -1;
1520 1438
1521 if (m->friendlist[friendnumber].crypt_connection_id == -1) 1439 return send_lossy_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c,
1522 return -1; 1440 m->friendlist[friendnumber].friendcon_id), data, length);
1523
1524 return send_lossy_cryptpacket(m->net_crypto, m->friendlist[friendnumber].crypt_connection_id, data, length);
1525} 1441}
1526 1442
1527static int handle_custom_lossless_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length) 1443static int handle_custom_lossless_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length)
@@ -1579,10 +1495,8 @@ int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const
1579 if (m->friendlist[friendnumber].status != FRIEND_ONLINE) 1495 if (m->friendlist[friendnumber].status != FRIEND_ONLINE)
1580 return -1; 1496 return -1;
1581 1497
1582 if (m->friendlist[friendnumber].crypt_connection_id == -1) 1498 if (write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c,
1583 return -1; 1499 m->friendlist[friendnumber].friendcon_id), data, length, 1) == -1) {
1584
1585 if (write_cryptpacket(m->net_crypto, m->friendlist[friendnumber].crypt_connection_id, data, length, 1) == -1) {
1586 return -1; 1500 return -1;
1587 } else { 1501 } else {
1588 return 0; 1502 return 0;
@@ -1609,42 +1523,6 @@ static void LANdiscovery(Messenger *m)
1609 } 1523 }
1610} 1524}
1611 1525
1612static int handle_status(void *object, int i, uint8_t status);
1613static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len);
1614
1615static int handle_new_connections(void *object, New_Connection *n_c)
1616{
1617 Messenger *m = object;
1618 int friend_id = getfriend_id(m, n_c->public_key);
1619
1620 if (friend_id != -1) {
1621 if (m->friendlist[friend_id].crypt_connection_id != -1)
1622 return -1;
1623
1624 int id = accept_crypto_connection(m->net_crypto, n_c);
1625 connection_status_handler(m->net_crypto, id, &handle_status, m, friend_id);
1626 connection_data_handler(m->net_crypto, id, &handle_packet, m, friend_id);
1627 connection_lossy_data_handler(m->net_crypto, id, &handle_custom_lossy_packet, m, friend_id);
1628 m->friendlist[friend_id].crypt_connection_id = id;
1629 set_friend_status(m, friend_id, FRIEND_CONFIRMED);
1630
1631 if (n_c->source.ip.family != AF_INET && n_c->source.ip.family != AF_INET6) {
1632 set_direct_ip_port(m->net_crypto, m->friendlist[friend_id].crypt_connection_id, m->friendlist[friend_id].dht_ip_port);
1633 } else {
1634 m->friendlist[friend_id].dht_ip_port = n_c->source;
1635 m->friendlist[friend_id].dht_ip_port_lastrecv = unix_time();
1636 }
1637
1638 dht_pk_callback(m, friend_id, n_c->dht_public_key);
1639
1640 nc_dht_pk_callback(m->net_crypto, id, &dht_pk_callback, m, friend_id);
1641 return 0;
1642 }
1643
1644 return -1;
1645}
1646
1647
1648/* Run this at startup. */ 1526/* Run this at startup. */
1649Messenger *new_messenger(Messenger_Options *options) 1527Messenger *new_messenger(Messenger_Options *options)
1650{ 1528{
@@ -1691,13 +1569,13 @@ Messenger *new_messenger(Messenger_Options *options)
1691 return NULL; 1569 return NULL;
1692 } 1570 }
1693 1571
1694 new_connection_handler(m->net_crypto, &handle_new_connections, m);
1695
1696 m->onion = new_onion(m->dht); 1572 m->onion = new_onion(m->dht);
1697 m->onion_a = new_onion_announce(m->dht); 1573 m->onion_a = new_onion_announce(m->dht);
1698 m->onion_c = new_onion_client(m->net_crypto); 1574 m->onion_c = new_onion_client(m->net_crypto);
1575 m->fr_c = new_friend_connections(m->onion_c);
1699 1576
1700 if (!(m->onion && m->onion_a && m->onion_c)) { 1577 if (!(m->onion && m->onion_a && m->onion_c)) {
1578 kill_friend_connections(m->fr_c);
1701 kill_onion(m->onion); 1579 kill_onion(m->onion);
1702 kill_onion_announce(m->onion_a); 1580 kill_onion_announce(m->onion_a);
1703 kill_onion_client(m->onion_c); 1581 kill_onion_client(m->onion_c);
@@ -1722,6 +1600,7 @@ void kill_messenger(Messenger *m)
1722{ 1600{
1723 uint32_t i; 1601 uint32_t i;
1724 1602
1603 kill_friend_connections(m->fr_c);
1725 kill_onion(m->onion); 1604 kill_onion(m->onion);
1726 kill_onion_announce(m->onion_a); 1605 kill_onion_announce(m->onion_a);
1727 kill_onion_client(m->onion_c); 1606 kill_onion_client(m->onion_c);
@@ -1769,10 +1648,6 @@ static int handle_status(void *object, int i, uint8_t status)
1769 m->friendlist[i].statusmessage_sent = 0; 1648 m->friendlist[i].statusmessage_sent = 0;
1770 m->friendlist[i].ping_lastrecv = temp_time; 1649 m->friendlist[i].ping_lastrecv = temp_time;
1771 } else { /* Went offline. */ 1650 } else { /* Went offline. */
1772 m->friendlist[i].crypt_connection_id = -1;
1773
1774 m->friendlist[i].dht_ping_lastrecv = temp_time;
1775
1776 if (m->friendlist[i].status == FRIEND_ONLINE) { 1651 if (m->friendlist[i].status == FRIEND_ONLINE) {
1777 set_friend_status(m, i, FRIEND_CONFIRMED); 1652 set_friend_status(m, i, FRIEND_CONFIRMED);
1778 } 1653 }
@@ -2072,11 +1947,6 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len)
2072 return -1; 1947 return -1;
2073 1948
2074 switch (packet_id) { 1949 switch (packet_id) {
2075 case PACKET_ID_ALIVE: {
2076 m->friendlist[i].ping_lastrecv = temp_time;
2077 break;
2078 }
2079
2080 case PACKET_ID_NICKNAME: { 1950 case PACKET_ID_NICKNAME: {
2081 if (data_length > MAX_NAME_LENGTH || data_length == 0) 1951 if (data_length > MAX_NAME_LENGTH || data_length == 0)
2082 break; 1952 break;
@@ -2359,29 +2229,6 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len)
2359 return 0; 2229 return 0;
2360} 2230}
2361 2231
2362static int friend_new_connection(Messenger *m, int32_t friendnumber, const uint8_t *real_public_key)
2363{
2364 if (friend_not_valid(m, friendnumber))
2365 return -1;
2366
2367 if (m->friendlist[friendnumber].crypt_connection_id != -1) {
2368 return -1;
2369 }
2370
2371 int id = new_crypto_connection(m->net_crypto, real_public_key);
2372
2373 if (id == -1)
2374 return -1;
2375
2376 m->friendlist[friendnumber].crypt_connection_id = id;
2377 connection_status_handler(m->net_crypto, id, &handle_status, m, friendnumber);
2378 connection_data_handler(m->net_crypto, id, &handle_packet, m, friendnumber);
2379 connection_lossy_data_handler(m->net_crypto, id, &handle_custom_lossy_packet, m, friendnumber);
2380 nc_dht_pk_callback(m->net_crypto, id, &dht_pk_callback, m, friendnumber);
2381
2382 return 0;
2383}
2384
2385/* TODO: Make this function not suck. */ 2232/* TODO: Make this function not suck. */
2386void do_friends(Messenger *m) 2233void do_friends(Messenger *m)
2387{ 2234{
@@ -2407,27 +2254,7 @@ void do_friends(Messenger *m)
2407 * unsuccessful so we set the status back to FRIEND_ADDED and try again. 2254 * unsuccessful so we set the status back to FRIEND_ADDED and try again.
2408 */ 2255 */
2409 check_friend_request_timed_out(m, i, temp_time); 2256 check_friend_request_timed_out(m, i, temp_time);
2410
2411 } else {
2412 if (m->friendlist[i].dht_ping_lastrecv + FRIEND_DHT_TIMEOUT < temp_time) {
2413 if (m->friendlist[i].dht_lock) {
2414 DHT_delfriend(m->dht, m->friendlist[i].dht_temp_pk, m->friendlist[i].dht_lock);
2415 m->friendlist[i].dht_lock = 0;
2416 }
2417 }
2418
2419 if (m->friendlist[i].dht_ip_port_lastrecv + FRIEND_DHT_TIMEOUT < temp_time) {
2420 m->friendlist[i].dht_ip_port.ip.family = 0;
2421 }
2422 } 2257 }
2423
2424 if (friend_new_connection(m, i, m->friendlist[i].client_id) == 0) {
2425 if (m->friendlist[i].dht_lock)
2426 set_connection_dht_public_key(m->net_crypto, m->friendlist[i].crypt_connection_id, m->friendlist[i].dht_temp_pk);
2427
2428 set_direct_ip_port(m->net_crypto, m->friendlist[i].crypt_connection_id, m->friendlist[i].dht_ip_port);
2429 }
2430
2431 } 2258 }
2432 2259
2433 if (m->friendlist[i].status == FRIEND_ONLINE) { /* friend is online. */ 2260 if (m->friendlist[i].status == FRIEND_ONLINE) { /* friend is online. */
@@ -2456,17 +2283,6 @@ void do_friends(Messenger *m)
2456 m->friendlist[i].user_istyping_sent = 1; 2283 m->friendlist[i].user_istyping_sent = 1;
2457 } 2284 }
2458 2285
2459 if (m->friendlist[i].ping_lastsent + FRIEND_PING_INTERVAL < temp_time) {
2460 send_ping(m, i);
2461 }
2462
2463 if (m->friendlist[i].ping_lastrecv + FRIEND_CONNECTION_TIMEOUT < temp_time) {
2464 /* If we stopped receiving ping packets, kill it. */
2465 crypto_kill(m->net_crypto, m->friendlist[i].crypt_connection_id);
2466 m->friendlist[i].crypt_connection_id = -1;
2467 set_friend_status(m, i, FRIEND_CONFIRMED);
2468 }
2469
2470 if (m->friendlist[i].share_relays_lastsent + FRIEND_SHARE_RELAYS_INTERVAL < temp_time) { 2286 if (m->friendlist[i].share_relays_lastsent + FRIEND_SHARE_RELAYS_INTERVAL < temp_time) {
2471 send_relays(m, i); 2287 send_relays(m, i);
2472 } 2288 }
@@ -2536,6 +2352,7 @@ void do_messenger(Messenger *m)
2536 2352
2537 do_net_crypto(m->net_crypto); 2353 do_net_crypto(m->net_crypto);
2538 do_onion_client(m->onion_c); 2354 do_onion_client(m->onion_c);
2355 do_friend_connections(m->fr_c);
2539 do_friends(m); 2356 do_friends(m);
2540 LANdiscovery(m); 2357 LANdiscovery(m);
2541 2358
@@ -2616,8 +2433,8 @@ void do_messenger(Messenger *m)
2616 if (ping_lastrecv > 999) 2433 if (ping_lastrecv > 999)
2617 ping_lastrecv = 999; 2434 ping_lastrecv = 999;
2618 2435
2619 LOGGER_INFO("F[%2u:%2u] <%s> %02i [%03u] %s", 2436 LOGGER_INFO("F[%2u:%2u] <%s> [%03u] %s",
2620 dht2m[friend], friend, msgfptr->name, msgfptr->crypt_connection_id, 2437 dht2m[friend], friend, msgfptr->name,
2621 ping_lastrecv, ID2String(msgfptr->client_id)); 2438 ping_lastrecv, ID2String(msgfptr->client_id));
2622 } else { 2439 } else {
2623 LOGGER_INFO("F[--:%2u] %s", friend, ID2String(dhtfptr->client_id)); 2440 LOGGER_INFO("F[--:%2u] %s", friend, ID2String(dhtfptr->client_id));