2013-07-23 02:52:42 +08:00
|
|
|
/* friend_requests.h
|
2013-07-27 20:43:36 +08:00
|
|
|
*
|
2013-07-23 02:52:42 +08:00
|
|
|
* Handle friend requests.
|
2013-07-27 20:43:36 +08:00
|
|
|
*
|
2013-07-26 09:45:56 +08:00
|
|
|
* 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/>.
|
2013-07-27 20:43:36 +08:00
|
|
|
*
|
2013-07-23 02:52:42 +08:00
|
|
|
*/
|
|
|
|
|
2013-07-27 20:43:36 +08:00
|
|
|
#ifndef FRIEND_REQUESTS_H
|
|
|
|
#define FRIEND_REQUESTS_H
|
2013-07-23 02:52:42 +08:00
|
|
|
|
|
|
|
#include "DHT.h"
|
|
|
|
#include "net_crypto.h"
|
|
|
|
|
|
|
|
|
2013-08-21 00:08:55 +08:00
|
|
|
typedef struct {
|
|
|
|
uint32_t nospam;
|
|
|
|
void (*handle_friendrequest)(uint8_t *, uint8_t *, uint16_t, void *);
|
|
|
|
uint8_t handle_friendrequest_isset;
|
|
|
|
void *handle_friendrequest_userdata;
|
|
|
|
|
2013-08-30 05:55:58 +08:00
|
|
|
/* NOTE: The following is just a temporary fix for the multiple friend requests received at the same time problem.
|
|
|
|
* TODO: Make this better (This will most likely tie in with the way we will handle spam.)
|
|
|
|
*/
|
2013-08-21 00:08:55 +08:00
|
|
|
|
2013-08-21 07:37:05 +08:00
|
|
|
#define MAX_RECEIVED_STORED 32
|
2013-08-21 00:08:55 +08:00
|
|
|
|
|
|
|
uint8_t received_requests[MAX_RECEIVED_STORED][crypto_box_PUBLICKEYBYTES];
|
|
|
|
uint16_t received_requests_index;
|
|
|
|
} Friend_Requests;
|
|
|
|
|
2013-08-30 05:17:51 +08:00
|
|
|
/* Try to send a friendrequest to peer with public_key.
|
|
|
|
* data is the data in the request and length is the length.
|
2013-08-13 21:32:31 +08:00
|
|
|
*/
|
2013-08-30 05:17:51 +08:00
|
|
|
int send_friendrequest(DHT *dht, uint8_t *public_key, uint32_t nospam_num, uint8_t *data, uint32_t length);
|
|
|
|
/* Set and get the nospam variable used to prevent one type of friend request spam. */
|
2013-08-21 00:08:55 +08:00
|
|
|
void set_nospam(Friend_Requests *fr, uint32_t num);
|
|
|
|
uint32_t get_nospam(Friend_Requests *fr);
|
2013-07-27 20:48:50 +08:00
|
|
|
|
2013-08-30 05:17:51 +08:00
|
|
|
/* Set the function that will be executed when a friend request for us is received.
|
|
|
|
* Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length)
|
|
|
|
*/
|
2013-08-21 07:37:05 +08:00
|
|
|
void callback_friendrequest(Friend_Requests *fr, void (*function)(uint8_t *, uint8_t *, uint16_t, void *),
|
|
|
|
void *userdata);
|
2013-07-27 20:48:50 +08:00
|
|
|
|
2013-08-30 05:17:51 +08:00
|
|
|
/* Sets up friendreq packet handlers. */
|
2013-08-21 00:08:55 +08:00
|
|
|
void friendreq_init(Friend_Requests *fr, Net_Crypto *c);
|
2013-07-23 02:52:42 +08:00
|
|
|
|
|
|
|
|
2013-07-31 02:39:04 +08:00
|
|
|
#endif
|