mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Fixed the multiple friends request recieved at the same time problem.
This commit is contained in:
parent
9d860fac79
commit
056195be41
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "LAN_discovery.h"
|
#include "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 <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,6 +28,9 @@
|
||||||
|
|
||||||
#include "DHT.h"
|
#include "DHT.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
/*Send a LAN discovery pcaket to the broadcast address with port port*/
|
/*Send a LAN discovery pcaket to the broadcast address with port port*/
|
||||||
int send_LANdiscovery(uint16_t 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
|
#endif
|
||||||
|
|
|
@ -70,6 +70,43 @@ void callback_friendrequest(void (*function)(uint8_t *, uint8_t *, uint16_t))
|
||||||
handle_friendrequest_isset = 1;
|
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)
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
if(request_recieved(public_key))
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
addto_recievedlist(public_key);
|
||||||
(*handle_friendrequest)(public_key, data, len);
|
(*handle_friendrequest)(public_key, data, len);
|
||||||
}
|
}
|
||||||
else//if request is not for us, try routing it.
|
else//if request is not for us, try routing it.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user