diff options
Diffstat (limited to 'src/messenger/messenger_api_handle.h')
-rw-r--r-- | src/messenger/messenger_api_handle.h | 174 |
1 files changed, 174 insertions, 0 deletions
diff --git a/src/messenger/messenger_api_handle.h b/src/messenger/messenger_api_handle.h new file mode 100644 index 000000000..d6cde0106 --- /dev/null +++ b/src/messenger/messenger_api_handle.h | |||
@@ -0,0 +1,174 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /** | ||
21 | * @author Tobias Frisch | ||
22 | * @file src/messenger/messenger_api_handle.h | ||
23 | * @brief messenger api: client implementation of GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_MESSENGER_API_HANDLE_H | ||
27 | #define GNUNET_MESSENGER_API_HANDLE_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_cadet_service.h" | ||
31 | #include "gnunet_container_lib.h" | ||
32 | #include "gnunet_crypto_lib.h" | ||
33 | #include "gnunet_identity_service.h" | ||
34 | #include "gnunet_peer_lib.h" | ||
35 | |||
36 | #include "gnunet_messenger_service.h" | ||
37 | |||
38 | #include "messenger_api_contact.h" | ||
39 | #include "messenger_api_room.h" | ||
40 | |||
41 | struct GNUNET_MESSENGER_Handle | ||
42 | { | ||
43 | const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
44 | |||
45 | struct GNUNET_MQ_Handle *mq; | ||
46 | |||
47 | GNUNET_MESSENGER_IdentityCallback identity_callback; | ||
48 | void *identity_cls; | ||
49 | |||
50 | GNUNET_MESSENGER_MessageCallback msg_callback; | ||
51 | void *msg_cls; | ||
52 | |||
53 | char *name; | ||
54 | struct GNUNET_IDENTITY_PublicKey *pubkey; | ||
55 | |||
56 | struct GNUNET_TIME_Relative reconnect_time; | ||
57 | struct GNUNET_SCHEDULER_Task *reconnect_task; | ||
58 | |||
59 | struct GNUNET_CONTAINER_MultiHashMap *rooms; | ||
60 | struct GNUNET_CONTAINER_MultiHashMap *contacts; | ||
61 | }; | ||
62 | |||
63 | /** | ||
64 | * Creates and allocates a new handle using a given configuration and a custom message callback | ||
65 | * with a given closure for the client API. | ||
66 | * | ||
67 | * @param cfg Configuration | ||
68 | * @param msg_callback Message callback | ||
69 | * @param msg_cls Closure | ||
70 | * @return New handle | ||
71 | */ | ||
72 | struct GNUNET_MESSENGER_Handle* | ||
73 | create_handle (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_MESSENGER_IdentityCallback identity_callback, | ||
74 | void *identity_cls, GNUNET_MESSENGER_MessageCallback msg_callback, void *msg_cls); | ||
75 | |||
76 | /** | ||
77 | * Destroys a <i>handle</i> and frees its memory fully from the client API. | ||
78 | * | ||
79 | * @param handle Handle | ||
80 | */ | ||
81 | void | ||
82 | destroy_handle (struct GNUNET_MESSENGER_Handle *handle); | ||
83 | |||
84 | /** | ||
85 | * Sets the name of a <i>handle</i> to a specific <i>name</i>. | ||
86 | * | ||
87 | * @param handle Handle | ||
88 | * @param name New name | ||
89 | */ | ||
90 | void | ||
91 | set_handle_name (struct GNUNET_MESSENGER_Handle *handle, const char *name); | ||
92 | |||
93 | /** | ||
94 | * Returns the current name of a given <i>handle</i> or NULL if no valid name was assigned yet. | ||
95 | * | ||
96 | * @param handle Handle | ||
97 | * @return Name of the handle or NULL | ||
98 | */ | ||
99 | const char* | ||
100 | get_handle_name (const struct GNUNET_MESSENGER_Handle *handle); | ||
101 | |||
102 | /** | ||
103 | * Sets the public key of a given <i>handle</i> to a specific public key. | ||
104 | * | ||
105 | * @param handle Handle | ||
106 | * @param pubkey Public key | ||
107 | */ | ||
108 | void | ||
109 | set_handle_key (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_IDENTITY_PublicKey *pubkey); | ||
110 | |||
111 | /** | ||
112 | * Returns the public key of a given <i>handle</i>. | ||
113 | * | ||
114 | * @param handle Handle | ||
115 | * @return Public key of the handle | ||
116 | */ | ||
117 | const struct GNUNET_IDENTITY_PublicKey* | ||
118 | get_handle_key (const struct GNUNET_MESSENGER_Handle *handle); | ||
119 | |||
120 | /** | ||
121 | * Returns a contact known to a <i>handle</i> identified by a given public key. If not matching | ||
122 | * contact is found, NULL gets returned. | ||
123 | * | ||
124 | * @param handle Handle | ||
125 | * @param pubkey Public key of EGO | ||
126 | * @return Contact or NULL | ||
127 | */ | ||
128 | struct GNUNET_MESSENGER_Contact* | ||
129 | get_handle_contact_by_pubkey (const struct GNUNET_MESSENGER_Handle *handle, | ||
130 | const struct GNUNET_IDENTITY_PublicKey *pubkey); | ||
131 | |||
132 | /** | ||
133 | * Changes the public key for a <i>contact</i> known to a <i>handle</i> to a specific public key and | ||
134 | * updates local map entries to access the contact by its updated key. | ||
135 | * | ||
136 | * @param handle Handle | ||
137 | * @param contact Contact | ||
138 | * @param pubkey Public key of EGO | ||
139 | */ | ||
140 | void | ||
141 | swap_handle_contact_by_pubkey (struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Contact *contact, | ||
142 | const struct GNUNET_IDENTITY_PublicKey *pubkey); | ||
143 | |||
144 | /** | ||
145 | * Marks a room known to a <i>handle</i> identified by a given <i>key</i> as open. | ||
146 | * | ||
147 | * @param handle Handle | ||
148 | * @param key Key of room | ||
149 | */ | ||
150 | void | ||
151 | open_handle_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key); | ||
152 | |||
153 | /** | ||
154 | * Adds a tunnel for a room known to a <i>handle</i> identified by a given <i>key</i> to a | ||
155 | * list of opened connections. | ||
156 | * | ||
157 | * @param handle Handle | ||
158 | * @param door Peer identity | ||
159 | * @param key Key of room | ||
160 | */ | ||
161 | void | ||
162 | entry_handle_room_at (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_PeerIdentity *door, | ||
163 | const struct GNUNET_HashCode *key); | ||
164 | |||
165 | /** | ||
166 | * Destroys and so implicitly closes a room known to a <i>handle</i> identified by a given <i>key</i>. | ||
167 | * | ||
168 | * @param handle Handle | ||
169 | * @param key Key of room | ||
170 | */ | ||
171 | void | ||
172 | close_handle_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key); | ||
173 | |||
174 | #endif //GNUNET_MESSENGER_API_HANDLE_H | ||