summaryrefslogtreecommitdiff
path: root/core/friend_requests.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-07-27 08:43:36 -0400
committerirungentoo <irungentoo@gmail.com>2013-07-27 08:43:36 -0400
commit14b43651c10b596efc33e11739c22321c3dbc3bf (patch)
tree26310e5bb35b693d607076db57bf682387f4c7df /core/friend_requests.c
parent1a6446266c9727e5c95e18d5e44157fd5a60900f (diff)
Ran the code through: astyle --style=linux
Diffstat (limited to 'core/friend_requests.c')
-rw-r--r--core/friend_requests.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/core/friend_requests.c b/core/friend_requests.c
index 7a2cdc24..f1ffb8d0 100644
--- a/core/friend_requests.c
+++ b/core/friend_requests.c
@@ -1,7 +1,7 @@
1/* friend_requests.c 1/* friend_requests.c
2 * 2 *
3 * Handle friend requests. 3 * Handle friend requests.
4 * 4 *
5 * Copyright (C) 2013 Tox project All Rights Reserved. 5 * Copyright (C) 2013 Tox project All Rights Reserved.
6 * 6 *
7 * This file is part of Tox. 7 * This file is part of Tox.
@@ -18,7 +18,7 @@
18 * 18 *
19 * You should have received a copy of the GNU General Public License 19 * You should have received a copy of the GNU General Public License
20 * along with Tox. If not, see <http://www.gnu.org/licenses/>. 20 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
21 * 21 *
22 */ 22 */
23 23
24#include "friend_requests.h" 24#include "friend_requests.h"
@@ -26,7 +26,7 @@
26uint8_t self_public_key[crypto_box_PUBLICKEYBYTES]; 26uint8_t self_public_key[crypto_box_PUBLICKEYBYTES];
27 27
28/* Try to send a friendrequest to peer with public_key 28/* Try to send a friendrequest to peer with public_key
29 data is the data in the request and length is the length. 29 data is the data in the request and length is the length.
30 return -1 if failure. 30 return -1 if failure.
31 return 0 if it sent the friend request directly to the friend. 31 return 0 if it sent the friend request directly to the friend.
32 return the number of peers it was routed through if it did not send it directly.*/ 32 return the number of peers it was routed through if it did not send it directly.*/
@@ -34,7 +34,7 @@ int send_friendrequest(uint8_t * public_key, uint8_t * data, uint32_t length)
34{ 34{
35 uint8_t packet[MAX_DATA_SIZE]; 35 uint8_t packet[MAX_DATA_SIZE];
36 int len = create_request(packet, public_key, data, length, 32); /* 32 is friend request packet id */ 36 int len = create_request(packet, public_key, data, length, 32); /* 32 is friend request packet id */
37 37
38 if (len == -1) 38 if (len == -1)
39 return -1; 39 return -1;
40 40
@@ -48,7 +48,7 @@ int send_friendrequest(uint8_t * public_key, uint8_t * data, uint32_t length)
48 return 0; 48 return 0;
49 return -1; 49 return -1;
50 } 50 }
51 51
52 int num = route_tofriend(public_key, packet, len); 52 int num = route_tofriend(public_key, packet, len);
53 53
54 if (num == 0) 54 if (num == 0)
@@ -61,7 +61,8 @@ static void (*handle_friendrequest)(uint8_t *, uint8_t *, uint16_t);
61static uint8_t handle_friendrequest_isset = 0; 61static uint8_t handle_friendrequest_isset = 0;
62 62
63/* set the function that will be executed when a friend request is received. */ 63/* set the function that will be executed when a friend request is received. */
64void callback_friendrequest(void (*function)(uint8_t *, uint8_t *, uint16_t)) { 64void callback_friendrequest(void (*function)(uint8_t *, uint8_t *, uint16_t))
65{
65 handle_friendrequest = function; 66 handle_friendrequest = function;
66 handle_friendrequest_isset = 1; 67 handle_friendrequest_isset = 1;
67} 68}
@@ -76,17 +77,19 @@ static uint8_t recieved_requests[MAX_RECIEVED_STORED][crypto_box_PUBLICKEYBYTES]
76static uint16_t recieved_requests_index; 77static uint16_t recieved_requests_index;
77 78
78/*Add to list of recieved friend requests*/ 79/*Add to list of recieved friend requests*/
79static void addto_recievedlist(uint8_t * client_id) { 80static void addto_recievedlist(uint8_t * client_id)
81{
80 if (recieved_requests_index >= MAX_RECIEVED_STORED) 82 if (recieved_requests_index >= MAX_RECIEVED_STORED)
81 recieved_requests_index = 0; 83 recieved_requests_index = 0;
82 84
83 memcpy(recieved_requests[recieved_requests_index], client_id, crypto_box_PUBLICKEYBYTES); 85 memcpy(recieved_requests[recieved_requests_index], client_id, crypto_box_PUBLICKEYBYTES);
84 ++recieved_requests_index; 86 ++recieved_requests_index;
85} 87}
86 88
87/* Check if a friend request was already recieved 89/* Check if a friend request was already recieved
88 return 0 if not, 1 if we did */ 90 return 0 if not, 1 if we did */
89static int request_recieved(uint8_t * client_id) { 91static int request_recieved(uint8_t * client_id)
92{
90 uint32_t i; 93 uint32_t i;
91 94
92 for (i = 0; i < MAX_RECIEVED_STORED; ++i) { 95 for (i = 0; i < MAX_RECIEVED_STORED; ++i) {
@@ -98,7 +101,8 @@ static int request_recieved(uint8_t * client_id) {
98} 101}
99 102
100 103
101int friendreq_handlepacket(uint8_t * packet, uint32_t length, IP_Port source) { 104int friendreq_handlepacket(uint8_t * packet, uint32_t length, IP_Port source)
105{
102 if (packet[0] == 32) { 106 if (packet[0] == 32) {
103 if (length <= crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 + ENCRYPTION_PADDING && 107 if (length <= crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 + ENCRYPTION_PADDING &&
104 length > MAX_DATA_SIZE + ENCRYPTION_PADDING) 108 length > MAX_DATA_SIZE + ENCRYPTION_PADDING)
@@ -118,11 +122,10 @@ int friendreq_handlepacket(uint8_t * packet, uint32_t length, IP_Port source) {
118 122
119 addto_recievedlist(public_key); 123 addto_recievedlist(public_key);
120 (*handle_friendrequest)(public_key, data, len); 124 (*handle_friendrequest)(public_key, data, len);
121 } 125 } else { /* if request is not for us, try routing it. */
122 else {/* if request is not for us, try routing it. */
123 if(route_packet(packet + 1, packet, length) == length) 126 if(route_packet(packet + 1, packet, length) == length)
124 return 0; 127 return 0;
125 } 128 }
126 } 129 }
127 return 1; 130 return 1;
128} 131}