summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.h
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/Messenger.h')
-rw-r--r--toxcore/Messenger.h153
1 files changed, 19 insertions, 134 deletions
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index e6877002..38543b36 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -26,12 +26,9 @@
26#ifndef MESSENGER_H 26#ifndef MESSENGER_H
27#define MESSENGER_H 27#define MESSENGER_H
28 28
29#include "net_crypto.h"
30#include "DHT.h"
31#include "friend_requests.h" 29#include "friend_requests.h"
32#include "LAN_discovery.h" 30#include "LAN_discovery.h"
33#include "group_chats.h" 31#include "friend_connection.h"
34#include "onion_client.h"
35 32
36#define MAX_NAME_LENGTH 128 33#define MAX_NAME_LENGTH 128
37/* TODO: this must depend on other variable. */ 34/* TODO: this must depend on other variable. */
@@ -42,8 +39,7 @@
42 39
43#define FRIEND_ADDRESS_SIZE (crypto_box_PUBLICKEYBYTES + sizeof(uint32_t) + sizeof(uint16_t)) 40#define FRIEND_ADDRESS_SIZE (crypto_box_PUBLICKEYBYTES + sizeof(uint32_t) + sizeof(uint16_t))
44 41
45/* NOTE: Packet ids below 16 must never be used. */ 42/* NOTE: Packet ids below 17 must never be used. */
46#define PACKET_ID_ALIVE 16
47#define PACKET_ID_SHARE_RELAYS 17 43#define PACKET_ID_SHARE_RELAYS 17
48#define PACKET_ID_NICKNAME 48 44#define PACKET_ID_NICKNAME 48
49#define PACKET_ID_STATUSMESSAGE 49 45#define PACKET_ID_STATUSMESSAGE 49
@@ -61,12 +57,9 @@
61#define PACKET_ID_FILE_SENDREQUEST 80 57#define PACKET_ID_FILE_SENDREQUEST 80
62#define PACKET_ID_FILE_CONTROL 81 58#define PACKET_ID_FILE_CONTROL 81
63#define PACKET_ID_FILE_DATA 82 59#define PACKET_ID_FILE_DATA 82
64#define PACKET_ID_INVITE_GROUPCHAT 144 60#define PACKET_ID_INVITE_GROUPCHAT 96
65#define PACKET_ID_JOIN_GROUPCHAT 145 61#define PACKET_ID_MESSAGE_GROUPCHAT 97
66#define PACKET_ID_ACCEPT_GROUPCHAT 146
67 62
68/* Max number of groups we can invite someone at the same time to. */
69#define MAX_INVITED_GROUPS 64
70 63
71/* Max number of tcp relays sent to friends */ 64/* Max number of tcp relays sent to friends */
72#define MAX_SHARED_RELAYS 16 65#define MAX_SHARED_RELAYS 16
@@ -108,15 +101,9 @@ enum {
108/* Default start timeout in seconds between friend requests. */ 101/* Default start timeout in seconds between friend requests. */
109#define FRIENDREQUEST_TIMEOUT 5; 102#define FRIENDREQUEST_TIMEOUT 5;
110 103
111/* Interval between the sending of ping packets. */
112#define FRIEND_PING_INTERVAL 6
113
114/* Interval between the sending of tcp relay information */ 104/* Interval between the sending of tcp relay information */
115#define FRIEND_SHARE_RELAYS_INTERVAL (5 * 60) 105#define FRIEND_SHARE_RELAYS_INTERVAL (5 * 60)
116 106
117/* If no packets are received from friend in this time interval, kill the connection. */
118#define FRIEND_CONNECTION_TIMEOUT (FRIEND_PING_INTERVAL * 3)
119
120/* Must be < MAX_CRYPTO_DATA_SIZE */ 107/* Must be < MAX_CRYPTO_DATA_SIZE */
121#define AVATAR_DATA_MAX_CHUNK_SIZE (MAX_CRYPTO_DATA_SIZE-1) 108#define AVATAR_DATA_MAX_CHUNK_SIZE (MAX_CRYPTO_DATA_SIZE-1)
122 109
@@ -199,9 +186,9 @@ enum {
199}; 186};
200 187
201typedef struct { 188typedef struct {
202 uint8_t client_id[CLIENT_ID_SIZE]; 189 uint8_t client_id[crypto_box_PUBLICKEYBYTES];
203 uint32_t onion_friendnum; 190 int friendcon_id;
204 int crypt_connection_id; 191
205 uint64_t friendrequest_lastsent; // Time at which the last friend request was sent. 192 uint64_t friendrequest_lastsent; // Time at which the last friend request was sent.
206 uint32_t friendrequest_timeout; // The timeout between successful friendrequest sending attempts. 193 uint32_t friendrequest_timeout; // The timeout between successful friendrequest sending attempts.
207 uint8_t status; // 0 if no friend, 1 if added, 2 if friend request sent, 3 if confirmed friend, 4 if online. 194 uint8_t status; // 0 if no friend, 1 if added, 2 if friend request sent, 3 if confirmed friend, 4 if online.
@@ -222,13 +209,10 @@ typedef struct {
222 uint32_t message_id; // a semi-unique id used in read receipts. 209 uint32_t message_id; // a semi-unique id used in read receipts.
223 uint8_t receives_read_receipts; // shall we send read receipts to this person? 210 uint8_t receives_read_receipts; // shall we send read receipts to this person?
224 uint32_t friendrequest_nospam; // The nospam number used in the friend request. 211 uint32_t friendrequest_nospam; // The nospam number used in the friend request.
225 uint64_t ping_lastrecv; 212 uint64_t ping_lastrecv;//TODO remove
226 uint64_t ping_lastsent;
227 uint64_t share_relays_lastsent; 213 uint64_t share_relays_lastsent;
228 struct File_Transfers file_sending[MAX_CONCURRENT_FILE_PIPES]; 214 struct File_Transfers file_sending[MAX_CONCURRENT_FILE_PIPES];
229 struct File_Transfers file_receiving[MAX_CONCURRENT_FILE_PIPES]; 215 struct File_Transfers file_receiving[MAX_CONCURRENT_FILE_PIPES];
230 int invited_groups[MAX_INVITED_GROUPS];
231 uint16_t invited_groups_num;
232 216
233 AVATAR_SENDDATA avatar_send_data; 217 AVATAR_SENDDATA avatar_send_data;
234 AVATAR_RECEIVEDATA *avatar_recv_data; // We are receiving avatar data from this friend. 218 AVATAR_RECEIVEDATA *avatar_recv_data; // We are receiving avatar data from this friend.
@@ -255,6 +239,8 @@ typedef struct Messenger {
255 Onion_Announce *onion_a; 239 Onion_Announce *onion_a;
256 Onion_Client *onion_c; 240 Onion_Client *onion_c;
257 241
242 Friend_Connections *fr_c;
243
258 Friend_Requests fr; 244 Friend_Requests fr;
259 uint8_t name[MAX_NAME_LENGTH]; 245 uint8_t name[MAX_NAME_LENGTH];
260 uint16_t name_length; 246 uint16_t name_length;
@@ -274,9 +260,6 @@ typedef struct Messenger {
274 260
275 uint32_t numonline_friends; 261 uint32_t numonline_friends;
276 262
277 Group_Chat **chats;
278 uint32_t numchats;
279
280 uint64_t last_LANdiscovery; 263 uint64_t last_LANdiscovery;
281 264
282#define NUM_SAVED_TCP_RELAYS 8 265#define NUM_SAVED_TCP_RELAYS 8
@@ -308,14 +291,9 @@ typedef struct Messenger {
308 void *avatar_data_recv_userdata; 291 void *avatar_data_recv_userdata;
309 void (*avatar_data_recv)(struct Messenger *m, int32_t, uint8_t, uint8_t *, uint8_t *, uint32_t, void *); 292 void (*avatar_data_recv)(struct Messenger *m, int32_t, uint8_t, uint8_t *, uint8_t *, uint32_t, void *);
310 293
311 void (*group_invite)(struct Messenger *m, int32_t, const uint8_t *, void *); 294 void *group_chat_object; /* Set by new_groupchats()*/
312 void *group_invite_userdata; 295 void (*group_invite)(struct Messenger *m, int32_t, const uint8_t *, uint16_t);
313 void (*group_message)(struct Messenger *m, int, int, const uint8_t *, uint16_t, void *); 296 void (*group_message)(struct Messenger *m, int32_t, const uint8_t *, uint16_t);
314 void *group_message_userdata;
315 void (*group_action)(struct Messenger *m, int, int, const uint8_t *, uint16_t, void *);
316 void *group_action_userdata;
317 void (*group_namelistchange)(struct Messenger *m, int, int, uint8_t, void *);
318 void *group_namelistchange_userdata;
319 297
320 void (*file_sendrequest)(struct Messenger *m, int32_t, uint8_t, uint64_t, const uint8_t *, uint16_t, void *); 298 void (*file_sendrequest)(struct Messenger *m, int32_t, uint8_t, uint64_t, const uint8_t *, uint16_t, void *);
321 void *file_sendrequest_userdata; 299 void *file_sendrequest_userdata;
@@ -747,97 +725,16 @@ void m_callback_avatar_data(Messenger *m, void (*function)(Messenger *m, int32_t
747 725
748/* Set the callback for group invites. 726/* Set the callback for group invites.
749 * 727 *
750 * Function(Messenger *m, int32_t friendnumber, uint8_t *group_public_key, void *userdata) 728 * Function(Messenger *m, int32_t friendnumber, uint8_t *data, uint16_t length)
751 */
752void m_callback_group_invite(Messenger *m, void (*function)(Messenger *m, int32_t, const uint8_t *, void *),
753 void *userdata);
754
755/* Set the callback for group messages.
756 *
757 * Function(Tox *tox, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata)
758 */
759void m_callback_group_message(Messenger *m, void (*function)(Messenger *m, int, int, const uint8_t *, uint16_t, void *),
760 void *userdata);
761
762/* Set the callback for group actions.
763 *
764 * Function(Tox *tox, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata)
765 */
766void m_callback_group_action(Messenger *m, void (*function)(Messenger *m, int, int, const uint8_t *, uint16_t, void *),
767 void *userdata);
768
769/* Set callback function for peer name list changes.
770 *
771 * It gets called every time the name list changes(new peer/name, deleted peer)
772 * Function(Tox *tox, int groupnumber, void *userdata)
773 */
774void m_callback_group_namelistchange(Messenger *m, void (*function)(Messenger *m, int, int, uint8_t, void *),
775 void *userdata);
776
777/* Creates a new groupchat and puts it in the chats array.
778 *
779 * return group number on success.
780 * return -1 on failure.
781 */
782int add_groupchat(Messenger *m);
783
784/* Delete a groupchat from the chats array.
785 *
786 * return 0 on success.
787 * return -1 if failure.
788 */
789int del_groupchat(Messenger *m, int groupnumber);
790
791/* Copy the name of peernumber who is in groupnumber to name.
792 * name must be at least MAX_NICK_BYTES long.
793 *
794 * return length of name if success
795 * return -1 if failure
796 */
797int m_group_peername(const Messenger *m, int groupnumber, int peernumber, uint8_t *name);
798
799/* invite friendnumber to groupnumber
800 * return 0 on success
801 * return -1 on failure
802 */
803int invite_friend(Messenger *m, int32_t friendnumber, int groupnumber);
804
805/* Join a group (you need to have been invited first.)
806 *
807 * returns group number on success
808 * returns -1 on failure.
809 */
810int join_groupchat(Messenger *m, int32_t friendnumber, const uint8_t *friend_group_public_key);
811
812/* send a group message
813 * return 0 on success
814 * return -1 on failure
815 */
816int group_message_send(const Messenger *m, int groupnumber, const uint8_t *message, uint32_t length);
817
818/* send a group action
819 * return 0 on success
820 * return -1 on failure
821 */
822int group_action_send(const Messenger *m, int groupnumber, const uint8_t *action, uint32_t length);
823
824/* Return the number of peers in the group chat on success.
825 * return -1 on failure
826 */ 729 */
827int group_number_peers(const Messenger *m, int groupnumber); 730void m_callback_group_invite(Messenger *m, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t));
828 731
829/* List all the peers in the group chat. 732/* Send a group invite packet.
830 * 733 *
831 * Copies the names of the peers to the name[length][MAX_NICK_BYTES] array. 734 * return 1 on success
832 * 735 * return 0 on failure
833 * Copies the lengths of the names to lengths[length]
834 *
835 * returns the number of peers on success.
836 *
837 * return -1 on failure.
838 */ 736 */
839int group_names(const Messenger *m, int groupnumber, uint8_t names[][MAX_NICK_BYTES], uint16_t lengths[], 737int send_group_invite_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length);
840 uint16_t length);
841 738
842/****************FILE SENDING*****************/ 739/****************FILE SENDING*****************/
843 740
@@ -1013,16 +910,4 @@ uint32_t copy_friendlist(const Messenger *m, int32_t *out_list, uint32_t list_si
1013 */ 910 */
1014int get_friendlist(const Messenger *m, int **out_list, uint32_t *out_list_length); 911int get_friendlist(const Messenger *m, int **out_list, uint32_t *out_list_length);
1015 912
1016/* Return the number of chats in the instance m.
1017 * You should use this to determine how much memory to allocate
1018 * for copy_chatlist. */
1019uint32_t count_chatlist(const Messenger *m);
1020
1021/* Copy a list of valid chat IDs into the array out_list.
1022 * If out_list is NULL, returns 0.
1023 * Otherwise, returns the number of elements copied.
1024 * If the array was too small, the contents
1025 * of out_list will be truncated to list_size. */
1026uint32_t copy_chatlist(const Messenger *m, int *out_list, uint32_t list_size);
1027
1028#endif 913#endif