Messenger: New function to check & handle timed-out friend requests

This commit is contained in:
Paul Holden 2013-12-02 03:16:01 -08:00
parent 3c16b0c035
commit c00970eaf7

View File

@ -1538,6 +1538,24 @@ void kill_messenger(Messenger *m)
free(m); free(m);
} }
/* Check for and handle a timed-out friend request. If the request has
* timed-out then the friend status is set back to FRIEND_ADDED.
* i: friendlist index of the timed-out friend
* t: time
*/
static void check_friend_request_timed_out(Messenger *m, uint32_t i, uint64_t t)
{
Friend *f = &m->friendlist[i];
if (f->friendrequest_lastsent + f->friendrequest_timeout < t) {
set_friend_status(m, i, FRIEND_ADDED);
/* Double the default timeout everytime if friendrequest is assumed
* to have been sent unsuccessfully.
*/
f->friendrequest_timeout *= 2;
}
}
/* TODO: Make this function not suck. */ /* TODO: Make this function not suck. */
void do_friends(Messenger *m) void do_friends(Messenger *m)
{ {
@ -1565,13 +1583,7 @@ void do_friends(Messenger *m)
/* If we didn't connect to friend after successfully sending him a friend request the request is deemed /* If we didn't connect to friend after successfully sending him a friend request the request is deemed
* unsuccessful so we set the status back to FRIEND_ADDED and try again. * unsuccessful so we set the status back to FRIEND_ADDED and try again.
*/ */
if (m->friendlist[i].friendrequest_lastsent + m->friendlist[i].friendrequest_timeout < temp_time) { check_friend_request_timed_out(m, i);
set_friend_status(m, i, FRIEND_ADDED);
/* Double the default timeout everytime if friendrequest is assumed to have been
* sent unsuccessfully.
*/
m->friendlist[i].friendrequest_timeout *= 2;
}
} }
IP_Port friendip; IP_Port friendip;