summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-12-04 14:55:25 -0800
committerirungentoo <irungentoo@gmail.com>2013-12-04 14:55:25 -0800
commit94df395fab0bf4bf7fd50b3283ad6ca5faccb734 (patch)
tree9c56266f4e7e6f35a7f1daede3f4a752c37d3287 /toxcore/Messenger.c
parente6a1754053bdb33ad235ba8a87eb38e828f1a2c1 (diff)
parentbfce8a9d2147453694429c802868a4f9008478c7 (diff)
Merge pull request #671 from palistov/do-friends-cleanup
Clean up do_friends function
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 3617d554..777e6a9e 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, temp_time);
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;