summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
diff options
context:
space:
mode:
authorPaul Holden <paulholden2@gmail.com>2013-12-02 03:16:01 -0800
committerPaul Holden <paulholden2@gmail.com>2013-12-02 03:31:48 -0800
commitc00970eaf769bdc03217e95411719c8f289c285a (patch)
tree3a5c97f5389909035b1bd85ac273f0ce8c0fece4 /toxcore/Messenger.c
parent3c16b0c0359c54fec2f4253d8855d8f02fea6a26 (diff)
Messenger: New function to check & handle timed-out friend requests
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r--toxcore/Messenger.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 10e36746..2c7274ca 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -1538,6 +1538,24 @@ void kill_messenger(Messenger *m)
1538 free(m); 1538 free(m);
1539} 1539}
1540 1540
1541/* Check for and handle a timed-out friend request. If the request has
1542 * timed-out then the friend status is set back to FRIEND_ADDED.
1543 * i: friendlist index of the timed-out friend
1544 * t: time
1545 */
1546static void check_friend_request_timed_out(Messenger *m, uint32_t i, uint64_t t)
1547{
1548 Friend *f = &m->friendlist[i];
1549
1550 if (f->friendrequest_lastsent + f->friendrequest_timeout < t) {
1551 set_friend_status(m, i, FRIEND_ADDED);
1552 /* Double the default timeout everytime if friendrequest is assumed
1553 * to have been sent unsuccessfully.
1554 */
1555 f->friendrequest_timeout *= 2;
1556 }
1557}
1558
1541/* TODO: Make this function not suck. */ 1559/* TODO: Make this function not suck. */
1542void do_friends(Messenger *m) 1560void do_friends(Messenger *m)
1543{ 1561{
@@ -1565,13 +1583,7 @@ void do_friends(Messenger *m)
1565 /* If we didn't connect to friend after successfully sending him a friend request the request is deemed 1583 /* If we didn't connect to friend after successfully sending him a friend request the request is deemed
1566 * unsuccessful so we set the status back to FRIEND_ADDED and try again. 1584 * unsuccessful so we set the status back to FRIEND_ADDED and try again.
1567 */ 1585 */
1568 if (m->friendlist[i].friendrequest_lastsent + m->friendlist[i].friendrequest_timeout < temp_time) { 1586 check_friend_request_timed_out(m, i);
1569 set_friend_status(m, i, FRIEND_ADDED);
1570 /* Double the default timeout everytime if friendrequest is assumed to have been
1571 * sent unsuccessfully.
1572 */
1573 m->friendlist[i].friendrequest_timeout *= 2;
1574 }
1575 } 1587 }
1576 1588
1577 IP_Port friendip; 1589 IP_Port friendip;