diff options
-rw-r--r-- | core/LAN_discovery.c | 21 | ||||
-rw-r--r-- | core/LAN_discovery.h | 28 | ||||
-rw-r--r-- | core/friend_requests.c | 42 |
3 files changed, 86 insertions, 5 deletions
diff --git a/core/LAN_discovery.c b/core/LAN_discovery.c index 4ff2fcbf..3cfcb067 100644 --- a/core/LAN_discovery.c +++ b/core/LAN_discovery.c | |||
@@ -1,7 +1,24 @@ | |||
1 | /* LAN_discovery.c | 1 | /* LAN_discovery.c |
2 | * | 2 | * |
3 | * LAN discovery implementation. | 3 | * LAN discovery implementation. |
4 | * | 4 | * |
5 | * Copyright (C) 2013 Tox project All Rights Reserved. | ||
6 | * | ||
7 | * This file is part of Tox. | ||
8 | * | ||
9 | * Tox is free software: you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation, either version 3 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * Tox is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
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/>. | ||
21 | * | ||
5 | */ | 22 | */ |
6 | 23 | ||
7 | #include "LAN_discovery.h" | 24 | #include "LAN_discovery.h" |
diff --git a/core/LAN_discovery.h b/core/LAN_discovery.h index 7448abac..655830f9 100644 --- a/core/LAN_discovery.h +++ b/core/LAN_discovery.h | |||
@@ -1,7 +1,24 @@ | |||
1 | /* LAN_discovery.h | 1 | /* LAN_discovery.h |
2 | * | 2 | * |
3 | * LAN discovery implementation. | 3 | * LAN discovery implementation. |
4 | * | 4 | * |
5 | * Copyright (C) 2013 Tox project All Rights Reserved. | ||
6 | * | ||
7 | * This file is part of Tox. | ||
8 | * | ||
9 | * Tox is free software: you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation, either version 3 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * Tox is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
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/>. | ||
21 | * | ||
5 | */ | 22 | */ |
6 | 23 | ||
7 | 24 | ||
@@ -11,6 +28,9 @@ | |||
11 | 28 | ||
12 | #include "DHT.h" | 29 | #include "DHT.h" |
13 | 30 | ||
31 | #ifdef __cplusplus | ||
32 | extern "C" { | ||
33 | #endif | ||
14 | 34 | ||
15 | /*Send a LAN discovery pcaket to the broadcast address with port port*/ | 35 | /*Send a LAN discovery pcaket to the broadcast address with port port*/ |
16 | int send_LANdiscovery(uint16_t port); | 36 | int send_LANdiscovery(uint16_t port); |
@@ -23,6 +43,8 @@ int LANdiscovery_handlepacket(uint8_t * packet, uint32_t length, IP_Port source) | |||
23 | 43 | ||
24 | 44 | ||
25 | 45 | ||
26 | 46 | #ifdef __cplusplus | |
47 | } | ||
48 | #endif | ||
27 | 49 | ||
28 | #endif | 50 | #endif |
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 | |||
79 | static uint8_t recieved_requests[MAX_RECIEVED_STORED][crypto_box_PUBLICKEYBYTES]; | ||
80 | static uint16_t recieved_requests_index; | ||
81 | |||
82 | /*Add to list of recieved friend requests*/ | ||
83 | static 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 */ | ||
96 | static 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 | |||
73 | int friendreq_handlepacket(uint8_t * packet, uint32_t length, IP_Port source) | 110 | int 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. |