summaryrefslogtreecommitdiff
path: root/toxcore/friend_requests.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-10-04 16:49:17 -0400
committerirungentoo <irungentoo@gmail.com>2014-10-04 16:49:17 -0400
commit5555f01e279a1e514584a62e709c4ef1b8d57ecd (patch)
tree4f682b902ce248e8652db372e4a5b8001aef4954 /toxcore/friend_requests.c
parentcafbdd5d9443aa61094af99e609f369671466447 (diff)
Send friend request with connection if for some reason (groupchats) we
are already connected to the friend but they have not added us yet.
Diffstat (limited to 'toxcore/friend_requests.c')
-rw-r--r--toxcore/friend_requests.c35
1 files changed, 2 insertions, 33 deletions
diff --git a/toxcore/friend_requests.c b/toxcore/friend_requests.c
index a662b629..a7a1bcba 100644
--- a/toxcore/friend_requests.c
+++ b/toxcore/friend_requests.c
@@ -28,37 +28,6 @@
28#include "friend_requests.h" 28#include "friend_requests.h"
29#include "util.h" 29#include "util.h"
30 30
31/* Try to send a friend request to peer with public_key.
32 * data is the data in the request and length is the length.
33 *
34 * return -1 if failure.
35 * return 0 if it sent the friend request directly to the friend.
36 * return the number of peers it was routed through if it did not send it directly.
37 */
38int send_friendrequest(const Onion_Client *onion_c, const uint8_t *public_key, uint32_t nospam_num, const uint8_t *data,
39 uint32_t length)
40{
41 if (1 + sizeof(nospam_num) + length > ONION_CLIENT_MAX_DATA_SIZE || length == 0)
42 return -1;
43
44 uint8_t temp[1 + sizeof(nospam_num) + length];
45 temp[0] = CRYPTO_PACKET_FRIEND_REQ;
46 memcpy(temp + 1, &nospam_num, sizeof(nospam_num));
47 memcpy(temp + 1 + sizeof(nospam_num), data, length);
48
49 int friend_num = onion_friend_num(onion_c, public_key);
50
51 if (friend_num == -1)
52 return -1;
53
54 int num = send_onion_data(onion_c, friend_num, temp, sizeof(temp));
55
56 if (num <= 0)
57 return -1;
58
59 return num;
60}
61
62 31
63/* Set and get the nospam variable used to prevent one type of friend request spam. */ 32/* Set and get the nospam variable used to prevent one type of friend request spam. */
64void set_nospam(Friend_Requests *fr, uint32_t num) 33void set_nospam(Friend_Requests *fr, uint32_t num)
@@ -169,7 +138,7 @@ static int friendreq_handlepacket(void *object, const uint8_t *source_pubkey, co
169 return 0; 138 return 0;
170} 139}
171 140
172void friendreq_init(Friend_Requests *fr, Onion_Client *onion_c) 141void friendreq_init(Friend_Requests *fr, Friend_Connections *fr_c)
173{ 142{
174 oniondata_registerhandler(onion_c, CRYPTO_PACKET_FRIEND_REQ, &friendreq_handlepacket, fr); 143 set_friend_request_callback(fr_c, &friendreq_handlepacket, fr);
175} 144}