diff options
author | Michael Rose <michael_rose@gmx.de> | 2013-08-19 14:40:15 +0200 |
---|---|---|
committer | Michael Rose <michael_rose@gmx.de> | 2013-08-19 14:40:15 +0200 |
commit | 0aabb5bc49eb86c4168bbf4f369f72fa97d50c53 (patch) | |
tree | 7f68fd93e728f7de5f350ad1bc9e4f6a467cd08a /core/Messenger.c | |
parent | d6ae8dce983925a3f1462d111b5243fff3be31ec (diff) | |
parent | 4b480381ee7e1b5bbf3c253c0c4bf045e43f0a0e (diff) |
Merge with upstream
Diffstat (limited to 'core/Messenger.c')
-rw-r--r-- | core/Messenger.c | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/core/Messenger.c b/core/Messenger.c index 66ae4f41..7fd6a569 100644 --- a/core/Messenger.c +++ b/core/Messenger.c | |||
@@ -482,6 +482,12 @@ static int send_userstatus(Messenger *m, int friendnumber, USERSTATUS status) | |||
482 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_USERSTATUS, &stat, sizeof(stat)); | 482 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_USERSTATUS, &stat, sizeof(stat)); |
483 | } | 483 | } |
484 | 484 | ||
485 | static int send_ping(Messenger *m, int friendnumber) | ||
486 | { | ||
487 | m->friendlist[friendnumber].ping_lastsent = unix_time(); | ||
488 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_PING, 0, 0); | ||
489 | } | ||
490 | |||
485 | static int set_friend_statusmessage(Messenger *m, int friendnumber, uint8_t *status, uint16_t length) | 491 | static int set_friend_statusmessage(Messenger *m, int friendnumber, uint8_t *status, uint16_t length) |
486 | { | 492 | { |
487 | if (friendnumber >= m->numfriends || friendnumber < 0) | 493 | if (friendnumber >= m->numfriends || friendnumber < 0) |
@@ -596,7 +602,10 @@ int write_cryptpacket_id(Messenger *m, int friendnumber, uint8_t packet_id, uint | |||
596 | 602 | ||
597 | uint8_t packet[length + 1]; | 603 | uint8_t packet[length + 1]; |
598 | packet[0] = packet_id; | 604 | packet[0] = packet_id; |
599 | memcpy(packet + 1, data, length); | 605 | |
606 | if (length != 0) | ||
607 | memcpy(packet + 1, data, length); | ||
608 | |||
600 | return write_cryptpacket(m->friendlist[friendnumber].crypt_connection_id, packet, length + 1); | 609 | return write_cryptpacket(m->friendlist[friendnumber].crypt_connection_id, packet, length + 1); |
601 | } | 610 | } |
602 | 611 | ||
@@ -659,6 +668,7 @@ void doFriends(Messenger *m) | |||
659 | uint32_t i; | 668 | uint32_t i; |
660 | int len; | 669 | int len; |
661 | uint8_t temp[MAX_DATA_SIZE]; | 670 | uint8_t temp[MAX_DATA_SIZE]; |
671 | uint64_t temp_time = unix_time(); | ||
662 | 672 | ||
663 | for (i = 0; i < m->numfriends; ++i) { | 673 | for (i = 0; i < m->numfriends; ++i) { |
664 | if (m->friendlist[i].status == FRIEND_ADDED) { | 674 | if (m->friendlist[i].status == FRIEND_ADDED) { |
@@ -667,7 +677,7 @@ void doFriends(Messenger *m) | |||
667 | 677 | ||
668 | if (fr >= 0) { | 678 | if (fr >= 0) { |
669 | set_friend_status(m, i, FRIEND_REQUESTED); | 679 | set_friend_status(m, i, FRIEND_REQUESTED); |
670 | m->friendlist[i].friendrequest_lastsent = unix_time(); | 680 | m->friendlist[i].friendrequest_lastsent = temp_time; |
671 | } | 681 | } |
672 | } | 682 | } |
673 | 683 | ||
@@ -676,7 +686,7 @@ void doFriends(Messenger *m) | |||
676 | if (m->friendlist[i].status == FRIEND_REQUESTED) { | 686 | if (m->friendlist[i].status == FRIEND_REQUESTED) { |
677 | /* If we didn't connect to friend after successfully sending him a friend request the request is deemed | 687 | /* If we didn't connect to friend after successfully sending him a friend request the request is deemed |
678 | unsuccessful so we set the status back to FRIEND_ADDED and try again.*/ | 688 | unsuccessful so we set the status back to FRIEND_ADDED and try again.*/ |
679 | if (m->friendlist[i].friendrequest_lastsent + m->friendlist[i].friendrequest_timeout < unix_time()) { | 689 | if (m->friendlist[i].friendrequest_lastsent + m->friendlist[i].friendrequest_timeout < temp_time) { |
680 | set_friend_status(m, i, FRIEND_ADDED); | 690 | set_friend_status(m, i, FRIEND_ADDED); |
681 | /* Double the default timeout everytime if friendrequest is assumed to have been | 691 | /* Double the default timeout everytime if friendrequest is assumed to have been |
682 | sent unsuccessfully. */ | 692 | sent unsuccessfully. */ |
@@ -698,6 +708,7 @@ void doFriends(Messenger *m) | |||
698 | m->friendlist[i].name_sent = 0; | 708 | m->friendlist[i].name_sent = 0; |
699 | m->friendlist[i].userstatus_sent = 0; | 709 | m->friendlist[i].userstatus_sent = 0; |
700 | m->friendlist[i].statusmessage_sent = 0; | 710 | m->friendlist[i].statusmessage_sent = 0; |
711 | m->friendlist[i].ping_lastrecv = temp_time; | ||
701 | break; | 712 | break; |
702 | 713 | ||
703 | case 4: | 714 | case 4: |
@@ -726,6 +737,10 @@ void doFriends(Messenger *m) | |||
726 | m->friendlist[i].userstatus_sent = 1; | 737 | m->friendlist[i].userstatus_sent = 1; |
727 | } | 738 | } |
728 | 739 | ||
740 | if (m->friendlist[i].ping_lastsent + FRIEND_PING_INTERVAL < temp_time) { | ||
741 | send_ping(m, i); | ||
742 | } | ||
743 | |||
729 | len = read_cryptpacket(m->friendlist[i].crypt_connection_id, temp); | 744 | len = read_cryptpacket(m->friendlist[i].crypt_connection_id, temp); |
730 | uint8_t packet_id = temp[0]; | 745 | uint8_t packet_id = temp[0]; |
731 | uint8_t *data = temp + 1; | 746 | uint8_t *data = temp + 1; |
@@ -733,6 +748,11 @@ void doFriends(Messenger *m) | |||
733 | 748 | ||
734 | if (len > 0) { | 749 | if (len > 0) { |
735 | switch (packet_id) { | 750 | switch (packet_id) { |
751 | case PACKET_ID_PING: { | ||
752 | m->friendlist[i].ping_lastrecv = temp_time; | ||
753 | break; | ||
754 | } | ||
755 | |||
736 | case PACKET_ID_NICKNAME: { | 756 | case PACKET_ID_NICKNAME: { |
737 | if (data_length >= MAX_NAME_LENGTH || data_length == 0) | 757 | if (data_length >= MAX_NAME_LENGTH || data_length == 0) |
738 | break; | 758 | break; |
@@ -821,6 +841,13 @@ void doFriends(Messenger *m) | |||
821 | 841 | ||
822 | break; | 842 | break; |
823 | } | 843 | } |
844 | |||
845 | if (m->friendlist[i].ping_lastrecv + FRIEND_CONNECTION_TIMEOUT < temp_time) { | ||
846 | /* if we stopped recieving ping packets kill it */ | ||
847 | crypto_kill(m->friendlist[i].crypt_connection_id); | ||
848 | m->friendlist[i].crypt_connection_id = -1; | ||
849 | set_friend_status(m, i, FRIEND_CONFIRMED); | ||
850 | } | ||
824 | } | 851 | } |
825 | } | 852 | } |
826 | } | 853 | } |