summaryrefslogtreecommitdiff
path: root/core/friend_requests.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-07-26 17:06:03 -0400
committerirungentoo <irungentoo@gmail.com>2013-07-26 17:06:03 -0400
commit056195be410229dde61286c9f316eaec48a7a550 (patch)
tree8211ee5c4962f5b7343bab5e43fceea73cd027bd /core/friend_requests.c
parent9d860fac795b2eeaaec1f027d0fc9d1255d1fd50 (diff)
Fixed the multiple friends request recieved at the same time problem.
Diffstat (limited to 'core/friend_requests.c')
-rw-r--r--core/friend_requests.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/core/friend_requests.c b/core/friend_requests.c
index d24dd4b4..a524797f 100644
--- a/core/friend_requests.c
+++ b/core/friend_requests.c
@@ -70,6 +70,43 @@ void callback_friendrequest(void (*function)(uint8_t *, uint8_t *, uint16_t))
70 handle_friendrequest_isset = 1; 70 handle_friendrequest_isset = 1;
71} 71}
72 72
73
74/*NOTE: the following is just a temporary fix for the multiple friend requests recieved at the same time problem
75 TODO: Make this better (This will most likely tie in with the way we will handle spam.)*/
76
77#define MAX_RECIEVED_STORED 32
78
79static uint8_t recieved_requests[MAX_RECIEVED_STORED][crypto_box_PUBLICKEYBYTES];
80static uint16_t recieved_requests_index;
81
82/*Add to list of recieved friend requests*/
83static void addto_recievedlist(uint8_t * client_id)
84{
85 if(recieved_requests_index >= MAX_RECIEVED_STORED)
86 {
87 recieved_requests_index = 0;
88 }
89
90 memcpy(recieved_requests[recieved_requests_index], client_id, crypto_box_PUBLICKEYBYTES);
91 ++recieved_requests_index;
92}
93
94/* Check if a friend request was already recieved
95 return 0 if not, 1 if we did */
96static int request_recieved(uint8_t * client_id)
97{
98 uint32_t i;
99 for(i = 0; i < MAX_RECIEVED_STORED; ++i)
100 {
101 if(memcmp(recieved_requests[i], client_id, crypto_box_PUBLICKEYBYTES) == 0)
102 {
103 return 1;
104 }
105 }
106 return 0;
107}
108
109
73int friendreq_handlepacket(uint8_t * packet, uint32_t length, IP_Port source) 110int friendreq_handlepacket(uint8_t * packet, uint32_t length, IP_Port source)
74{ 111{
75 112
@@ -93,6 +130,11 @@ int friendreq_handlepacket(uint8_t * packet, uint32_t length, IP_Port source)
93 { 130 {
94 return 1; 131 return 1;
95 } 132 }
133 if(request_recieved(public_key))
134 {
135 return 1;
136 }
137 addto_recievedlist(public_key);
96 (*handle_friendrequest)(public_key, data, len); 138 (*handle_friendrequest)(public_key, data, len);
97 } 139 }
98 else//if request is not for us, try routing it. 140 else//if request is not for us, try routing it.