summaryrefslogtreecommitdiff
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
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.
-rw-r--r--core/DHT.c20
-rw-r--r--core/Messenger.c25
-rw-r--r--core/Messenger.h6
3 files changed, 35 insertions, 16 deletions
diff --git a/core/DHT.c b/core/DHT.c
index 226a38ca..55f34994 100644
--- a/core/DHT.c
+++ b/core/DHT.c
@@ -741,8 +741,8 @@ IP_Port DHT_getfriendip(uint8_t *client_id)
741 return empty; 741 return empty;
742} 742}
743 743
744/* Ping each client in the "friends" list every 60 seconds. Send a get nodes request 744/* Ping each client in the "friends" list every PING_INTERVAL seconds. Send a get nodes request
745 * every 20 seconds to a random good node for each "friend" in our "friends" list. 745 * every GET_NODE_INTERVAL seconds to a random good node for each "friend" in our "friends" list.
746 */ 746 */
747static void doDHTFriends(void) 747static void doDHTFriends(void)
748{ 748{
@@ -783,8 +783,8 @@ static void doDHTFriends(void)
783 783
784static uint64_t close_lastgetnodes; 784static uint64_t close_lastgetnodes;
785 785
786/* Ping each client in the close nodes list every 60 seconds. 786/* Ping each client in the close nodes list every PING_INTERVAL seconds.
787 * Send a get nodes request every 20 seconds to a random good node in the list. 787 * Send a get nodes request every GET_NODE_INTERVAL seconds to a random good node in the list.
788 */ 788 */
789static void doClose(void) 789static void doClose(void)
790{ 790{
@@ -823,6 +823,7 @@ static void doClose(void)
823void DHT_bootstrap(IP_Port ip_port, uint8_t *public_key) 823void DHT_bootstrap(IP_Port ip_port, uint8_t *public_key)
824{ 824{
825 getnodes(ip_port, public_key, self_public_key); 825 getnodes(ip_port, public_key, self_public_key);
826 send_ping_request(ip_port, (clientid_t *) public_key);
826} 827}
827 828
828/* send the given packet to node with client_id 829/* send the given packet to node with client_id
@@ -875,8 +876,11 @@ static int friend_iplist(IP_Port *ip_portlist, uint16_t friend_num)
875 return num_ips; 876 return num_ips;
876} 877}
877 878
879
878/* Send the following packet to everyone who tells us they are connected to friend_id 880/* Send the following packet to everyone who tells us they are connected to friend_id
879 * returns the number of nodes it sent the packet to 881 * returns the number of nodes it sent the packet to
882 *
883 * Only works if more than (MAX_FRIEND_CLIENTS / 2) return an ip for friend.
880 */ 884 */
881int route_tofriend(uint8_t *friend_id, uint8_t *packet, uint32_t length) 885int route_tofriend(uint8_t *friend_id, uint8_t *packet, uint32_t length)
882{ 886{
@@ -886,6 +890,13 @@ int route_tofriend(uint8_t *friend_id, uint8_t *packet, uint32_t length)
886 return 0; 890 return 0;
887 891
888 uint32_t i, sent = 0; 892 uint32_t i, sent = 0;
893
894 IP_Port ip_list[MAX_FRIEND_CLIENTS];
895 int ip_num = friend_iplist(ip_list, num);
896
897 if (ip_num < (MAX_FRIEND_CLIENTS / 2))
898 return 0;
899
889 uint64_t temp_time = unix_time(); 900 uint64_t temp_time = unix_time();
890 Friend *friend = &friends_list[num]; 901 Friend *friend = &friends_list[num];
891 Client_data *client; 902 Client_data *client;
@@ -895,7 +906,6 @@ int route_tofriend(uint8_t *friend_id, uint8_t *packet, uint32_t length)
895 906
896 /*If ip is not zero and node is good */ 907 /*If ip is not zero and node is good */
897 if (client->ret_ip_port.ip.i != 0 && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) { 908 if (client->ret_ip_port.ip.i != 0 && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) {
898
899 if (sendpacket(client->ip_port, packet, length) == length) 909 if (sendpacket(client->ip_port, packet, length) == length)
900 ++sent; 910 ++sent;
901 } 911 }
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
diff --git a/core/Messenger.h b/core/Messenger.h
index cd9e6e63..20ea33fb 100644
--- a/core/Messenger.h
+++ b/core/Messenger.h
@@ -68,6 +68,9 @@ extern "C" {
68/* don't assume MAX_STATUSMESSAGE_LENGTH will stay at 128, it may be increased 68/* don't assume MAX_STATUSMESSAGE_LENGTH will stay at 128, it may be increased
69 to an absurdly large number later */ 69 to an absurdly large number later */
70 70
71/* Default start timeout in seconds between friend requests */
72#define FRIENDREQUEST_TIMEOUT 5;
73
71/* USERSTATUS 74/* USERSTATUS
72 * Represents userstatuses someone can have. */ 75 * Represents userstatuses someone can have. */
73 76
@@ -82,7 +85,8 @@ USERSTATUS;
82typedef struct { 85typedef struct {
83 uint8_t client_id[CLIENT_ID_SIZE]; 86 uint8_t client_id[CLIENT_ID_SIZE];
84 int crypt_connection_id; 87 int crypt_connection_id;
85 uint64_t friend_request_id; /* id of the friend request corresponding to the current friend request to the current friend. */ 88 uint64_t friendrequest_lastsent; /* time at which the last friend request was sent. */
89 uint32_t friendrequest_timeout; /* The timeout between successful friendrequest sending attempts */
86 uint8_t status; /* 0 if no friend, 1 if added, 2 if friend request sent, 3 if confirmed friend, 4 if online. */ 90 uint8_t status; /* 0 if no friend, 1 if added, 2 if friend request sent, 3 if confirmed friend, 4 if online. */
87 uint8_t info[MAX_DATA_SIZE]; /* the data that is sent during the friend requests we do */ 91 uint8_t info[MAX_DATA_SIZE]; /* the data that is sent during the friend requests we do */
88 uint8_t name[MAX_NAME_LENGTH]; 92 uint8_t name[MAX_NAME_LENGTH];