diff options
Diffstat (limited to 'toxcore/group.h')
-rw-r--r-- | toxcore/group.h | 113 |
1 files changed, 63 insertions, 50 deletions
diff --git a/toxcore/group.h b/toxcore/group.h index 6eeeeff8..947c7035 100644 --- a/toxcore/group.h +++ b/toxcore/group.h | |||
@@ -26,20 +26,20 @@ | |||
26 | 26 | ||
27 | #include "Messenger.h" | 27 | #include "Messenger.h" |
28 | 28 | ||
29 | enum { | 29 | typedef enum Groupchat_Status { |
30 | GROUPCHAT_STATUS_NONE, | 30 | GROUPCHAT_STATUS_NONE, |
31 | GROUPCHAT_STATUS_VALID, | 31 | GROUPCHAT_STATUS_VALID, |
32 | GROUPCHAT_STATUS_CONNECTED | 32 | GROUPCHAT_STATUS_CONNECTED |
33 | }; | 33 | } Groupchat_Status; |
34 | 34 | ||
35 | enum { | 35 | typedef enum Groupchat_Type { |
36 | GROUPCHAT_TYPE_TEXT, | 36 | GROUPCHAT_TYPE_TEXT, |
37 | GROUPCHAT_TYPE_AV | 37 | GROUPCHAT_TYPE_AV |
38 | }; | 38 | } Groupchat_Type; |
39 | 39 | ||
40 | #define MAX_LOSSY_COUNT 256 | 40 | #define MAX_LOSSY_COUNT 256 |
41 | 41 | ||
42 | typedef struct { | 42 | typedef struct Group_Peer { |
43 | uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE]; | 43 | uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE]; |
44 | uint8_t temp_pk[CRYPTO_PUBLIC_KEY_SIZE]; | 44 | uint8_t temp_pk[CRYPTO_PUBLIC_KEY_SIZE]; |
45 | 45 | ||
@@ -52,40 +52,49 @@ typedef struct { | |||
52 | uint16_t peer_number; | 52 | uint16_t peer_number; |
53 | 53 | ||
54 | uint8_t recv_lossy[MAX_LOSSY_COUNT]; | 54 | uint8_t recv_lossy[MAX_LOSSY_COUNT]; |
55 | uint16_t bottom_lossy_number, top_lossy_number; | 55 | uint16_t bottom_lossy_number; |
56 | uint16_t top_lossy_number; | ||
56 | 57 | ||
57 | void *object; | 58 | void *object; |
58 | } Group_Peer; | 59 | } Group_Peer; |
59 | 60 | ||
60 | #define DESIRED_CLOSE_CONNECTIONS 4 | 61 | #define DESIRED_CLOSE_CONNECTIONS 4 |
61 | #define MAX_GROUP_CONNECTIONS 16 | 62 | #define MAX_GROUP_CONNECTIONS 16 |
62 | #define GROUP_IDENTIFIER_LENGTH (1 + CRYPTO_SYMMETRIC_KEY_SIZE) /* type + CRYPTO_SYMMETRIC_KEY_SIZE so we can use new_symmetric_key(...) to fill it */ | 63 | #define GROUP_IDENTIFIER_LENGTH (1 + CRYPTO_SYMMETRIC_KEY_SIZE) // type + CRYPTO_SYMMETRIC_KEY_SIZE so we can use new_symmetric_key(...) to fill it |
63 | 64 | ||
64 | enum { | 65 | typedef enum Groupchat_Close_Type { |
65 | GROUPCHAT_CLOSE_NONE, | 66 | GROUPCHAT_CLOSE_NONE, |
66 | GROUPCHAT_CLOSE_CONNECTION, | 67 | GROUPCHAT_CLOSE_CONNECTION, |
67 | GROUPCHAT_CLOSE_ONLINE | 68 | GROUPCHAT_CLOSE_ONLINE |
68 | }; | 69 | } Groupchat_Close_Type; |
69 | 70 | ||
70 | typedef struct { | 71 | typedef struct Groupchat_Close { |
72 | uint8_t type; /* GROUPCHAT_CLOSE_* */ | ||
73 | uint8_t closest; | ||
74 | uint32_t number; | ||
75 | uint16_t group_number; | ||
76 | } Groupchat_Close; | ||
77 | |||
78 | typedef struct Groupchat_Close_Connection { | ||
79 | uint8_t entry; | ||
80 | uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE]; | ||
81 | uint8_t temp_pk[CRYPTO_PUBLIC_KEY_SIZE]; | ||
82 | } Groupchat_Close_Connection; | ||
83 | |||
84 | typedef void peer_on_join_cb(void *object, uint32_t conference_number, uint32_t peer_number); | ||
85 | typedef void peer_on_leave_cb(void *object, uint32_t conference_number, void *peer_object); | ||
86 | typedef void group_on_delete_cb(void *object, uint32_t conference_number); | ||
87 | |||
88 | typedef struct Group_c { | ||
71 | uint8_t status; | 89 | uint8_t status; |
72 | 90 | ||
73 | Group_Peer *group; | 91 | Group_Peer *group; |
74 | uint32_t numpeers; | 92 | uint32_t numpeers; |
75 | 93 | ||
76 | struct { | 94 | Groupchat_Close close[MAX_GROUP_CONNECTIONS]; |
77 | uint8_t type; /* GROUPCHAT_CLOSE_* */ | ||
78 | uint8_t closest; | ||
79 | uint32_t number; | ||
80 | uint16_t group_number; | ||
81 | } close[MAX_GROUP_CONNECTIONS]; | ||
82 | 95 | ||
83 | uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE]; | 96 | uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE]; |
84 | struct { | 97 | Groupchat_Close_Connection closest_peers[DESIRED_CLOSE_CONNECTIONS]; |
85 | uint8_t entry; | ||
86 | uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE]; | ||
87 | uint8_t temp_pk[CRYPTO_PUBLIC_KEY_SIZE]; | ||
88 | } closest_peers[DESIRED_CLOSE_CONNECTIONS]; | ||
89 | uint8_t changed; | 98 | uint8_t changed; |
90 | 99 | ||
91 | uint8_t identifier[GROUP_IDENTIFIER_LENGTH]; | 100 | uint8_t identifier[GROUP_IDENTIFIER_LENGTH]; |
@@ -103,15 +112,28 @@ typedef struct { | |||
103 | 112 | ||
104 | void *object; | 113 | void *object; |
105 | 114 | ||
106 | void (*peer_on_join)(void *, uint32_t, uint32_t); | 115 | peer_on_join_cb *peer_on_join; |
107 | void (*peer_on_leave)(void *, uint32_t, void *); | 116 | peer_on_leave_cb *peer_on_leave; |
108 | void (*group_on_delete)(void *, uint32_t); | 117 | group_on_delete_cb *group_on_delete; |
109 | } Group_c; | 118 | } Group_c; |
110 | 119 | ||
111 | typedef void g_conference_invite_cb(Messenger *, uint32_t, int, const uint8_t *, size_t, void *); | 120 | typedef void g_conference_invite_cb(Messenger *m, uint32_t friend_number, int type, const uint8_t *cookie, |
112 | typedef void g_conference_message_cb(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, size_t, void *); | 121 | size_t length, void *user_data); |
113 | 122 | typedef void g_conference_message_cb(Messenger *m, uint32_t conference_number, uint32_t peer_number, int type, | |
114 | typedef struct { | 123 | const uint8_t *message, size_t length, void *user_data); |
124 | typedef void peer_name_cb(Messenger *m, uint32_t conference_number, uint32_t peer_number, const uint8_t *name, | ||
125 | size_t length, void *user_data); | ||
126 | typedef void peer_list_changed_cb(Messenger *m, uint32_t conference_number, void *user_data); | ||
127 | typedef void title_cb(Messenger *m, uint32_t conference_number, uint32_t peer_number, const uint8_t *title, | ||
128 | size_t length, void *user_data); | ||
129 | typedef int lossy_packet_cb(void *object, uint32_t conference_number, uint32_t peer_number, void *peer_object, | ||
130 | const uint8_t *packet, uint16_t length); | ||
131 | |||
132 | typedef struct Group_Lossy_Handler { | ||
133 | lossy_packet_cb *function; | ||
134 | } Group_Lossy_Handler; | ||
135 | |||
136 | typedef struct Group_Chats { | ||
115 | Messenger *m; | 137 | Messenger *m; |
116 | Friend_Connections *fr_c; | 138 | Friend_Connections *fr_c; |
117 | 139 | ||
@@ -120,13 +142,11 @@ typedef struct { | |||
120 | 142 | ||
121 | g_conference_invite_cb *invite_callback; | 143 | g_conference_invite_cb *invite_callback; |
122 | g_conference_message_cb *message_callback; | 144 | g_conference_message_cb *message_callback; |
123 | void (*peer_name_callback)(Messenger *m, uint32_t, uint32_t, const uint8_t *, size_t, void *); | 145 | peer_name_cb *peer_name_callback; |
124 | void (*peer_list_changed_callback)(Messenger *m, uint32_t, void *); | 146 | peer_list_changed_cb *peer_list_changed_callback; |
125 | void (*title_callback)(Messenger *m, uint32_t, uint32_t, const uint8_t *, size_t, void *); | 147 | title_cb *title_callback; |
126 | 148 | ||
127 | struct { | 149 | Group_Lossy_Handler lossy_packethandlers[256]; |
128 | int (*function)(void *, uint32_t, uint32_t, void *, const uint8_t *, uint16_t); | ||
129 | } lossy_packethandlers[256]; | ||
130 | } Group_Chats; | 150 | } Group_Chats; |
131 | 151 | ||
132 | /* Set the callback for group invites. | 152 | /* Set the callback for group invites. |
@@ -135,15 +155,13 @@ typedef struct { | |||
135 | * | 155 | * |
136 | * data of length is what needs to be passed to join_groupchat(). | 156 | * data of length is what needs to be passed to join_groupchat(). |
137 | */ | 157 | */ |
138 | void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, int, const uint8_t *, | 158 | void g_callback_group_invite(Group_Chats *g_c, g_conference_invite_cb *function); |
139 | size_t, void *)); | ||
140 | 159 | ||
141 | /* Set the callback for group messages. | 160 | /* Set the callback for group messages. |
142 | * | 161 | * |
143 | * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t friendgroupnumber, uint8_t * message, uint16_t length, void *userdata) | 162 | * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t friendgroupnumber, uint8_t * message, uint16_t length, void *userdata) |
144 | */ | 163 | */ |
145 | void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, | 164 | void g_callback_group_message(Group_Chats *g_c, g_conference_message_cb *function); |
146 | size_t, void *)); | ||
147 | 165 | ||
148 | 166 | ||
149 | /* Set callback function for title changes. | 167 | /* Set callback function for title changes. |
@@ -151,23 +169,21 @@ void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, u | |||
151 | * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t friendgroupnumber, uint8_t * title, uint8_t length, void *userdata) | 169 | * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t friendgroupnumber, uint8_t * title, uint8_t length, void *userdata) |
152 | * if friendgroupnumber == -1, then author is unknown (e.g. initial joining the group) | 170 | * if friendgroupnumber == -1, then author is unknown (e.g. initial joining the group) |
153 | */ | 171 | */ |
154 | void g_callback_group_title(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, const uint8_t *, | 172 | void g_callback_group_title(Group_Chats *g_c, title_cb *function); |
155 | size_t, void *)); | ||
156 | 173 | ||
157 | /* Set callback function for peer nickname changes. | 174 | /* Set callback function for peer nickname changes. |
158 | * | 175 | * |
159 | * It gets called every time a peer changes their nickname. | 176 | * It gets called every time a peer changes their nickname. |
160 | * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber, const uint8_t *nick, size_t nick_len, void *userdata) | 177 | * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber, const uint8_t *nick, size_t nick_len, void *userdata) |
161 | */ | 178 | */ |
162 | void g_callback_peer_name(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, const uint8_t *, | 179 | void g_callback_peer_name(Group_Chats *g_c, peer_name_cb *function); |
163 | size_t, void *)); | ||
164 | 180 | ||
165 | /* Set callback function for peer list changes. | 181 | /* Set callback function for peer list changes. |
166 | * | 182 | * |
167 | * It gets called every time the name list changes(new peer, deleted peer) | 183 | * It gets called every time the name list changes(new peer, deleted peer) |
168 | * Function(Group_Chats *g_c, uint32_t groupnumber, void *userdata) | 184 | * Function(Group_Chats *g_c, uint32_t groupnumber, void *userdata) |
169 | */ | 185 | */ |
170 | void g_callback_peer_list_changed(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, void *)); | 186 | void g_callback_peer_list_changed(Group_Chats *g_c, peer_list_changed_cb *function); |
171 | 187 | ||
172 | /* Creates a new groupchat and puts it in the chats array. | 188 | /* Creates a new groupchat and puts it in the chats array. |
173 | * | 189 | * |
@@ -302,9 +318,7 @@ int group_names(const Group_Chats *g_c, uint32_t groupnumber, uint8_t names[][MA | |||
302 | * | 318 | * |
303 | * Function(void *group object (set with group_set_object), uint32_t groupnumber, uint32_t friendgroupnumber, void *group peer object (set with group_peer_set_object), const uint8_t *packet, uint16_t length) | 319 | * Function(void *group object (set with group_set_object), uint32_t groupnumber, uint32_t friendgroupnumber, void *group peer object (set with group_peer_set_object), const uint8_t *packet, uint16_t length) |
304 | */ | 320 | */ |
305 | void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*function)(void *, uint32_t, uint32_t, | 321 | void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, lossy_packet_cb *function); |
306 | void *, | ||
307 | const uint8_t *, uint16_t)); | ||
308 | 322 | ||
309 | /* High level function to send custom lossy packets. | 323 | /* High level function to send custom lossy packets. |
310 | * | 324 | * |
@@ -372,8 +386,7 @@ void *group_peer_get_object(const Group_Chats *g_c, uint32_t groupnumber, int pe | |||
372 | * return 0 on success. | 386 | * return 0 on success. |
373 | * return -1 on failure. | 387 | * return -1 on failure. |
374 | */ | 388 | */ |
375 | int callback_groupchat_peer_new(const Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t, | 389 | int callback_groupchat_peer_new(const Group_Chats *g_c, uint32_t groupnumber, peer_on_join_cb *function); |
376 | uint32_t)); | ||
377 | 390 | ||
378 | /* Set a function to be called when a peer leaves a group chat. | 391 | /* Set a function to be called when a peer leaves a group chat. |
379 | * | 392 | * |
@@ -382,7 +395,7 @@ int callback_groupchat_peer_new(const Group_Chats *g_c, uint32_t groupnumber, vo | |||
382 | * return 0 on success. | 395 | * return 0 on success. |
383 | * return -1 on failure. | 396 | * return -1 on failure. |
384 | */ | 397 | */ |
385 | int callback_groupchat_peer_delete(Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t, void *)); | 398 | int callback_groupchat_peer_delete(Group_Chats *g_c, uint32_t groupnumber, peer_on_leave_cb *function); |
386 | 399 | ||
387 | /* Set a function to be called when the group chat is deleted. | 400 | /* Set a function to be called when the group chat is deleted. |
388 | * | 401 | * |
@@ -391,7 +404,7 @@ int callback_groupchat_peer_delete(Group_Chats *g_c, uint32_t groupnumber, void | |||
391 | * return 0 on success. | 404 | * return 0 on success. |
392 | * return -1 on failure. | 405 | * return -1 on failure. |
393 | */ | 406 | */ |
394 | int callback_groupchat_delete(Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t)); | 407 | int callback_groupchat_delete(Group_Chats *g_c, uint32_t groupnumber, group_on_delete_cb *function); |
395 | 408 | ||
396 | /* Create new groupchat instance. */ | 409 | /* Create new groupchat instance. */ |
397 | Group_Chats *new_groupchats(Messenger *m); | 410 | Group_Chats *new_groupchats(Messenger *m); |