From 056195be410229dde61286c9f316eaec48a7a550 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Fri, 26 Jul 2013 17:06:03 -0400 Subject: [PATCH] Fixed the multiple friends request recieved at the same time problem. --- core/LAN_discovery.c | 21 +++++++++++++++++++-- core/LAN_discovery.h | 28 +++++++++++++++++++++++++--- 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 @@ -/* LAN_discovery.c +/* LAN_discovery.c * - * LAN discovery implementation. + * LAN discovery implementation. * + * Copyright (C) 2013 Tox project All Rights Reserved. + * + * This file is part of Tox. + * + * Tox is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tox is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tox. If not, see . + * */ #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 @@ -/* LAN_discovery.h +/* LAN_discovery.h * - * LAN discovery implementation. + * LAN discovery implementation. * + * Copyright (C) 2013 Tox project All Rights Reserved. + * + * This file is part of Tox. + * + * Tox is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tox is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tox. If not, see . + * */ @@ -11,6 +28,9 @@ #include "DHT.h" +#ifdef __cplusplus +extern "C" { +#endif /*Send a LAN discovery pcaket to the broadcast address with port port*/ int send_LANdiscovery(uint16_t port); @@ -23,6 +43,8 @@ int LANdiscovery_handlepacket(uint8_t * packet, uint32_t length, IP_Port source) - +#ifdef __cplusplus +} +#endif #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)) handle_friendrequest_isset = 1; } + +/*NOTE: the following is just a temporary fix for the multiple friend requests recieved at the same time problem + TODO: Make this better (This will most likely tie in with the way we will handle spam.)*/ + +#define MAX_RECIEVED_STORED 32 + +static uint8_t recieved_requests[MAX_RECIEVED_STORED][crypto_box_PUBLICKEYBYTES]; +static uint16_t recieved_requests_index; + +/*Add to list of recieved friend requests*/ +static void addto_recievedlist(uint8_t * client_id) +{ + if(recieved_requests_index >= MAX_RECIEVED_STORED) + { + recieved_requests_index = 0; + } + + memcpy(recieved_requests[recieved_requests_index], client_id, crypto_box_PUBLICKEYBYTES); + ++recieved_requests_index; +} + +/* Check if a friend request was already recieved + return 0 if not, 1 if we did */ +static int request_recieved(uint8_t * client_id) +{ + uint32_t i; + for(i = 0; i < MAX_RECIEVED_STORED; ++i) + { + if(memcmp(recieved_requests[i], client_id, crypto_box_PUBLICKEYBYTES) == 0) + { + return 1; + } + } + return 0; +} + + int friendreq_handlepacket(uint8_t * packet, uint32_t length, IP_Port source) { @@ -93,6 +130,11 @@ int friendreq_handlepacket(uint8_t * packet, uint32_t length, IP_Port source) { return 1; } + if(request_recieved(public_key)) + { + return 1; + } + addto_recievedlist(public_key); (*handle_friendrequest)(public_key, data, len); } else//if request is not for us, try routing it.