summaryrefslogtreecommitdiff
path: root/testing/experiment/group_chats.h
diff options
context:
space:
mode:
Diffstat (limited to 'testing/experiment/group_chats.h')
-rw-r--r--testing/experiment/group_chats.h109
1 files changed, 109 insertions, 0 deletions
diff --git a/testing/experiment/group_chats.h b/testing/experiment/group_chats.h
new file mode 100644
index 00000000..527610d8
--- /dev/null
+++ b/testing/experiment/group_chats.h
@@ -0,0 +1,109 @@
1/* group_chats.h
2 *
3 * An implementation of massive text only group chats.
4 *
5 *
6 * Copyright (C) 2013 Tox project All Rights Reserved.
7 *
8 * This file is part of Tox.
9 *
10 * Tox is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * Tox is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
22 *
23 */
24
25#ifndef GROUP_CHATS_H
26#define GROUP_CHATS_H
27
28#include "../../toxcore/net_crypto.h"
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34typedef struct {
35 uint8_t client_id[crypto_box_PUBLICKEYBYTES];
36 uint64_t last_recv;
37 uint64_t pingid;
38 uint64_t last_pinged;
39 uint32_t last_message_number;
40} Group_Peer;
41
42typedef struct {
43 uint8_t client_id[crypto_box_PUBLICKEYBYTES];
44 IP_Port ip_port;
45 uint64_t last_recv;
46
47} Group_Close;
48
49#define GROUP_CLOSE_CONNECTIONS 6
50
51typedef struct Group_Chat {
52 Networking_Core *net;
53 uint8_t self_public_key[crypto_box_PUBLICKEYBYTES];
54 uint8_t self_secret_key[crypto_box_SECRETKEYBYTES];
55
56 Group_Peer *group;
57 Group_Close close[GROUP_CLOSE_CONNECTIONS];
58 uint32_t numpeers;
59
60 uint32_t message_number;
61 void (*group_message)(struct Group_Chat *m, int, uint8_t *, uint16_t, void *);
62 void *group_message_userdata;
63
64} Group_Chat;
65
66/*
67 * Set callback function for chat messages.
68 *
69 * format of function is: function(Group_Chat *chat, peer number, message, message length, userdata)
70 */
71
72void callback_groupmessage(Group_Chat *chat, void (*function)(Group_Chat *chat, int, uint8_t *, uint16_t, void *),
73 void *userdata);
74
75/*
76 * Send a message to the group.
77 *
78 */
79uint32_t m_sendmessage(Group_Chat *chat, uint8_t *message, uint32_t length);
80
81/* Create a new group chat.
82 *
83 * Returns a new group chat instance if success.
84 *
85 * Returns a NULL pointer if fail.
86 */
87Group_Chat *new_groupchat(Networking_Core *net);
88
89
90/* Kill a group chat
91 *
92 * Frees the memory and everything.
93 */
94void kill_groupchat(Group_Chat *chat);
95
96
97/* if we receive a group chat packet we call this function so it can be handled.
98 return 0 if packet is handled correctly.
99 return 1 if it didn't handle the packet or if the packet was shit. */
100int handle_groupchatpacket(Group_Chat *chat, IP_Port source, uint8_t *packet, uint32_t length);
101
102
103void chat_bootstrap(Group_Chat *chat, IP_Port ip_port, int peernum);
104
105#ifdef __cplusplus
106}
107#endif
108
109#endif