summaryrefslogtreecommitdiff
path: root/core/Messenger.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-08-16 18:57:00 -0400
committerirungentoo <irungentoo@gmail.com>2013-08-16 18:57:00 -0400
commit1207304f0b66385b2131a3dd0badf41bd25561a4 (patch)
tree19049d138b98f9182d54c8602fd616d3ced63dab /core/Messenger.c
parent88ff81d9def5efe69cbaf91aa41906177ba7dde9 (diff)
Metadata collection prevention part 2 of ???
Improved friend request sending. As a side effect friend requests should now be routed less than before. See added comments for details.
Diffstat (limited to 'core/Messenger.c')
-rw-r--r--core/Messenger.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/core/Messenger.c b/core/Messenger.c
index 09032067..d88fe51a 100644
--- a/core/Messenger.c
+++ b/core/Messenger.c
@@ -172,7 +172,8 @@ int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length)
172 DHT_addfriend(client_id); 172 DHT_addfriend(client_id);
173 m->friendlist[i].status = FRIEND_ADDED; 173 m->friendlist[i].status = FRIEND_ADDED;
174 m->friendlist[i].crypt_connection_id = -1; 174 m->friendlist[i].crypt_connection_id = -1;
175 m->friendlist[i].friend_request_id = -1; 175 m->friendlist[i].friendrequest_lastsent = 0;
176 m->friendlist[i].friendrequest_timeout = FRIENDREQUEST_TIMEOUT;
176 memcpy(m->friendlist[i].client_id, client_id, CLIENT_ID_SIZE); 177 memcpy(m->friendlist[i].client_id, client_id, CLIENT_ID_SIZE);
177 m->friendlist[i].statusmessage = calloc(1, 1); 178 m->friendlist[i].statusmessage = calloc(1, 1);
178 m->friendlist[i].statusmessage_length = 1; 179 m->friendlist[i].statusmessage_length = 1;
@@ -205,9 +206,9 @@ int m_addfriend_norequest(Messenger *m, uint8_t *client_id)
205 for (i = 0; i <= m->numfriends; ++i) { 206 for (i = 0; i <= m->numfriends; ++i) {
206 if (m->friendlist[i].status == NOFRIEND) { 207 if (m->friendlist[i].status == NOFRIEND) {
207 DHT_addfriend(client_id); 208 DHT_addfriend(client_id);
208 m->friendlist[i].status = FRIEND_REQUESTED; 209 m->friendlist[i].status = FRIEND_CONFIRMED;
209 m->friendlist[i].crypt_connection_id = -1; 210 m->friendlist[i].crypt_connection_id = -1;
210 m->friendlist[i].friend_request_id = -1; 211 m->friendlist[i].friendrequest_lastsent = 0;
211 memcpy(m->friendlist[i].client_id, client_id, CLIENT_ID_SIZE); 212 memcpy(m->friendlist[i].client_id, client_id, CLIENT_ID_SIZE);
212 m->friendlist[i].statusmessage = calloc(1, 1); 213 m->friendlist[i].statusmessage = calloc(1, 1);
213 m->friendlist[i].statusmessage_length = 1; 214 m->friendlist[i].statusmessage_length = 1;
@@ -622,6 +623,7 @@ Messenger *initMessenger(void)
622 LANdiscovery_init(); 623 LANdiscovery_init();
623 set_nospam(random_int()); 624 set_nospam(random_int());
624 625
626 send_LANdiscovery(htons(PORT));
625 timer_single(&LANdiscovery, 0, LAN_DISCOVERY_INTERVAL); 627 timer_single(&LANdiscovery, 0, LAN_DISCOVERY_INTERVAL);
626 628
627 return m; 629 return m;
@@ -650,19 +652,22 @@ void doFriends(Messenger *m)
650 int fr = send_friendrequest(m->friendlist[i].client_id, m->friendlist[i].friendrequest_nospam, m->friendlist[i].info, 652 int fr = send_friendrequest(m->friendlist[i].client_id, m->friendlist[i].friendrequest_nospam, m->friendlist[i].info,
651 m->friendlist[i].info_size); 653 m->friendlist[i].info_size);
652 654
653 if (fr == 0) /* TODO: This needs to be fixed so that it sends the friend requests a couple of times in case of packet loss */ 655 if (fr >= 0) {
654 set_friend_status(m, i, FRIEND_REQUESTED);
655 else if (fr > 0)
656 set_friend_status(m, i, FRIEND_REQUESTED); 656 set_friend_status(m, i, FRIEND_REQUESTED);
657 m->friendlist[i].friendrequest_lastsent = unix_time();
658 }
657 } 659 }
658 660
659 if (m->friendlist[i].status == FRIEND_REQUESTED 661 if (m->friendlist[i].status == FRIEND_REQUESTED
660 || m->friendlist[i].status == FRIEND_CONFIRMED) { /* friend is not online */ 662 || m->friendlist[i].status == FRIEND_CONFIRMED) { /* friend is not online */
661 if (m->friendlist[i].status == FRIEND_REQUESTED) { 663 if (m->friendlist[i].status == FRIEND_REQUESTED) {
662 if (m->friendlist[i].friend_request_id + 10 < unix_time()) { /*I know this is hackish but it should work.*/ 664 /* If we didn't connect to friend after successfully sending him a friend request the request is deemed
663 send_friendrequest(m->friendlist[i].client_id, m->friendlist[i].friendrequest_nospam, m->friendlist[i].info, 665 unsuccessful so we set the status back to FRIEND_ADDED and try again.*/
664 m->friendlist[i].info_size); 666 if (m->friendlist[i].friendrequest_lastsent + m->friendlist[i].friendrequest_timeout < unix_time()) {
665 m->friendlist[i].friend_request_id = unix_time(); 667 set_friend_status(m, i, FRIEND_ADDED);
668 /* Double the default timeout everytime if friendrequest is assumed to have been
669 sent unsuccessfully. */
670 m->friendlist[i].friendrequest_timeout *= 2;
666 } 671 }
667 } 672 }
668 673