diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2023-10-19 11:36:32 +0200 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2023-10-19 11:36:32 +0200 |
commit | b56e4e05ad919c7191260fcf1d78b1f8d739871a (patch) | |
tree | 88a8aa4c82d664666c10c5099654bbfc295ab139 /src/conversation/test_conversation_api_reject.c | |
parent | 7c7d819e8e03dadb91935d5ae91aa921cc7b86c7 (diff) | |
download | gnunet-b56e4e05ad919c7191260fcf1d78b1f8d739871a.tar.gz gnunet-b56e4e05ad919c7191260fcf1d78b1f8d739871a.zip |
BUILD: Move conversation to contrib/service
Diffstat (limited to 'src/conversation/test_conversation_api_reject.c')
-rw-r--r-- | src/conversation/test_conversation_api_reject.c | 363 |
1 files changed, 0 insertions, 363 deletions
diff --git a/src/conversation/test_conversation_api_reject.c b/src/conversation/test_conversation_api_reject.c deleted file mode 100644 index 37192f5b8..000000000 --- a/src/conversation/test_conversation_api_reject.c +++ /dev/null | |||
@@ -1,363 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2013, 2014, 2018 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 | * @file conversation/test_conversation_api_reject.c | ||
22 | * @brief testcase for conversation_api.c | ||
23 | * | ||
24 | * This test performs the operations of a call to a phone | ||
25 | * where the phone user immediately hangs up (rejecting the | ||
26 | * call). | ||
27 | */ | ||
28 | #include "platform.h" | ||
29 | #include "gnunet_util_lib.h" | ||
30 | #include "gnunet_testing_lib.h" | ||
31 | #include "gnunet_gnsrecord_lib.h" | ||
32 | #include "gnunet_conversation_service.h" | ||
33 | #include "gnunet_identity_service.h" | ||
34 | #include "gnunet_namestore_service.h" | ||
35 | |||
36 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 25) | ||
37 | |||
38 | static int ok = 1; | ||
39 | |||
40 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
41 | |||
42 | static struct GNUNET_IDENTITY_Handle *id; | ||
43 | |||
44 | static struct GNUNET_IDENTITY_Operation *op; | ||
45 | |||
46 | static struct GNUNET_CONVERSATION_Phone *phone; | ||
47 | |||
48 | static struct GNUNET_NAMESTORE_Handle *ns; | ||
49 | |||
50 | static struct GNUNET_CONVERSATION_Call *call; | ||
51 | |||
52 | static struct GNUNET_NAMESTORE_QueueEntry *qe; | ||
53 | |||
54 | static char *gns_name; | ||
55 | |||
56 | static char *gns_caller_id; | ||
57 | |||
58 | |||
59 | static int | ||
60 | enable_speaker (void *cls) | ||
61 | { | ||
62 | (void) cls; | ||
63 | GNUNET_break (0); | ||
64 | return GNUNET_SYSERR; | ||
65 | } | ||
66 | |||
67 | |||
68 | static void | ||
69 | disable_speaker (void *cls) | ||
70 | { | ||
71 | (void) cls; | ||
72 | GNUNET_break (0); | ||
73 | } | ||
74 | |||
75 | |||
76 | static void | ||
77 | play (void *cls, size_t data_size, const void *data) | ||
78 | { | ||
79 | (void) cls; | ||
80 | (void) data_size; | ||
81 | (void) data; | ||
82 | GNUNET_break (0); | ||
83 | } | ||
84 | |||
85 | |||
86 | static void | ||
87 | destroy_speaker (void *cls) | ||
88 | { | ||
89 | (void) cls; | ||
90 | } | ||
91 | |||
92 | |||
93 | static struct GNUNET_SPEAKER_Handle call_speaker = { &enable_speaker, | ||
94 | &play, | ||
95 | &disable_speaker, | ||
96 | &destroy_speaker, | ||
97 | "caller" }; | ||
98 | |||
99 | |||
100 | static int | ||
101 | enable_mic (void *cls, | ||
102 | GNUNET_MICROPHONE_RecordedDataCallback rdc, | ||
103 | void *rdc_cls) | ||
104 | { | ||
105 | (void) cls; | ||
106 | (void) rdc; | ||
107 | (void) rdc_cls; | ||
108 | GNUNET_break (0); | ||
109 | return GNUNET_SYSERR; | ||
110 | } | ||
111 | |||
112 | |||
113 | static void | ||
114 | disable_mic (void *cls) | ||
115 | { | ||
116 | (void) cls; | ||
117 | GNUNET_break (0); | ||
118 | } | ||
119 | |||
120 | |||
121 | static void | ||
122 | destroy_mic (void *cls) | ||
123 | { | ||
124 | (void) cls; | ||
125 | } | ||
126 | |||
127 | |||
128 | static struct GNUNET_MICROPHONE_Handle call_mic = { &enable_mic, | ||
129 | &disable_mic, | ||
130 | &destroy_mic, | ||
131 | "caller" }; | ||
132 | |||
133 | |||
134 | /** | ||
135 | * Signature of the main function of a task. | ||
136 | * | ||
137 | * @param cls closure | ||
138 | */ | ||
139 | static void | ||
140 | end_test (void *cls) | ||
141 | { | ||
142 | (void) cls; | ||
143 | GNUNET_SCHEDULER_shutdown (); | ||
144 | if (NULL != op) | ||
145 | { | ||
146 | GNUNET_IDENTITY_cancel (op); | ||
147 | op = NULL; | ||
148 | } | ||
149 | if (NULL != call) | ||
150 | { | ||
151 | GNUNET_CONVERSATION_call_stop (call); | ||
152 | call = NULL; | ||
153 | } | ||
154 | if (NULL != phone) | ||
155 | { | ||
156 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from PHONE service.\n"); | ||
157 | GNUNET_CONVERSATION_phone_destroy (phone); | ||
158 | phone = NULL; | ||
159 | } | ||
160 | if (NULL != id) | ||
161 | { | ||
162 | GNUNET_IDENTITY_disconnect (id); | ||
163 | id = NULL; | ||
164 | } | ||
165 | if (NULL != qe) | ||
166 | { | ||
167 | GNUNET_NAMESTORE_cancel (qe); | ||
168 | qe = NULL; | ||
169 | } | ||
170 | if (NULL != ns) | ||
171 | { | ||
172 | GNUNET_NAMESTORE_disconnect (ns); | ||
173 | ns = NULL; | ||
174 | } | ||
175 | } | ||
176 | |||
177 | |||
178 | static void | ||
179 | phone_event_handler (void *cls, | ||
180 | enum GNUNET_CONVERSATION_PhoneEventCode code, | ||
181 | struct GNUNET_CONVERSATION_Caller *caller, | ||
182 | const struct GNUNET_CRYPTO_PublicKey *caller_id) | ||
183 | { | ||
184 | static enum GNUNET_CONVERSATION_PhoneEventCode expect = | ||
185 | GNUNET_CONVERSATION_EC_PHONE_RING; | ||
186 | |||
187 | (void) cls; | ||
188 | (void) caller_id; | ||
189 | GNUNET_break (code == expect); | ||
190 | switch (code) | ||
191 | { | ||
192 | case GNUNET_CONVERSATION_EC_PHONE_RING: | ||
193 | GNUNET_CONVERSATION_caller_hang_up (caller); | ||
194 | break; | ||
195 | |||
196 | default: | ||
197 | fprintf (stderr, "Unexpected phone code: %d\n", code); | ||
198 | break; | ||
199 | } | ||
200 | } | ||
201 | |||
202 | |||
203 | static void | ||
204 | call_event_handler (void *cls, enum GNUNET_CONVERSATION_CallEventCode code) | ||
205 | { | ||
206 | static enum GNUNET_CONVERSATION_CallEventCode expect = | ||
207 | GNUNET_CONVERSATION_EC_CALL_RINGING; | ||
208 | |||
209 | (void) cls; | ||
210 | GNUNET_break (code == expect); | ||
211 | switch (code) | ||
212 | { | ||
213 | case GNUNET_CONVERSATION_EC_CALL_RINGING: | ||
214 | expect = GNUNET_CONVERSATION_EC_CALL_HUNG_UP; | ||
215 | break; | ||
216 | |||
217 | case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: | ||
218 | call = NULL; | ||
219 | ok = 0; | ||
220 | GNUNET_SCHEDULER_shutdown (); | ||
221 | expect = -1; | ||
222 | break; | ||
223 | |||
224 | case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: | ||
225 | case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: | ||
226 | case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: | ||
227 | case GNUNET_CONVERSATION_EC_CALL_RESUMED: | ||
228 | fprintf (stderr, "Unexpected call code: %d\n", code); | ||
229 | break; | ||
230 | |||
231 | case GNUNET_CONVERSATION_EC_CALL_ERROR: | ||
232 | fprintf (stderr, "Unexpected call code: %d\n", code); | ||
233 | call = NULL; | ||
234 | break; | ||
235 | } | ||
236 | } | ||
237 | |||
238 | |||
239 | static void | ||
240 | caller_ego_create_cont (void *cls, | ||
241 | const struct GNUNET_CRYPTO_PrivateKey *pk, | ||
242 | enum GNUNET_ErrorCode ec) | ||
243 | { | ||
244 | (void) cls; | ||
245 | op = NULL; | ||
246 | GNUNET_assert (GNUNET_EC_NONE == ec); | ||
247 | } | ||
248 | |||
249 | |||
250 | static void | ||
251 | namestore_put_cont (void *cls, enum GNUNET_ErrorCode ec) | ||
252 | { | ||
253 | (void) cls; | ||
254 | qe = NULL; | ||
255 | GNUNET_assert (GNUNET_EC_NONE == ec); | ||
256 | GNUNET_assert (NULL == op); | ||
257 | op = GNUNET_IDENTITY_create (id, "caller-ego", NULL, | ||
258 | GNUNET_PUBLIC_KEY_TYPE_ECDSA, | ||
259 | &caller_ego_create_cont, | ||
260 | NULL); | ||
261 | } | ||
262 | |||
263 | |||
264 | static void | ||
265 | identity_cb (void *cls, | ||
266 | struct GNUNET_IDENTITY_Ego *ego, | ||
267 | void **ctx, | ||
268 | const char *name) | ||
269 | { | ||
270 | struct GNUNET_GNSRECORD_Data rd; | ||
271 | struct GNUNET_CRYPTO_PublicKey pub; | ||
272 | |||
273 | (void) cls; | ||
274 | (void) ctx; | ||
275 | if (NULL == name) | ||
276 | return; | ||
277 | if (NULL == ego) | ||
278 | return; | ||
279 | if (0 == strcmp (name, "phone-ego")) | ||
280 | { | ||
281 | GNUNET_IDENTITY_ego_get_public_key (ego, &pub); | ||
282 | GNUNET_asprintf (&gns_name, | ||
283 | "phone.%s", | ||
284 | GNUNET_GNSRECORD_pkey_to_zkey (&pub)); | ||
285 | phone = | ||
286 | GNUNET_CONVERSATION_phone_create (cfg, ego, &phone_event_handler, NULL); | ||
287 | GNUNET_assert (NULL != phone); | ||
288 | memset (&rd, 0, sizeof(rd)); | ||
289 | GNUNET_CONVERSATION_phone_get_record (phone, &rd); | ||
290 | GNUNET_assert (rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE); | ||
291 | rd.expiration_time = UINT64_MAX; | ||
292 | qe = | ||
293 | GNUNET_NAMESTORE_records_store (ns, | ||
294 | GNUNET_IDENTITY_ego_get_private_key (ego), | ||
295 | "phone" /* GNS label */, | ||
296 | 1, | ||
297 | &rd, | ||
298 | &namestore_put_cont, | ||
299 | NULL); | ||
300 | return; | ||
301 | } | ||
302 | if (0 == strcmp (name, "caller-ego")) | ||
303 | { | ||
304 | GNUNET_IDENTITY_ego_get_public_key (ego, &pub); | ||
305 | GNUNET_asprintf (&gns_caller_id, | ||
306 | "%s", | ||
307 | GNUNET_GNSRECORD_pkey_to_zkey (&pub)); | ||
308 | call = GNUNET_CONVERSATION_call_start (cfg, | ||
309 | ego, | ||
310 | gns_name, | ||
311 | &call_speaker, | ||
312 | &call_mic, | ||
313 | &call_event_handler, | ||
314 | NULL); | ||
315 | return; | ||
316 | } | ||
317 | } | ||
318 | |||
319 | |||
320 | static void | ||
321 | phone_ego_create_cont (void *cls, | ||
322 | const struct GNUNET_CRYPTO_PrivateKey *pk, | ||
323 | enum GNUNET_ErrorCode ec) | ||
324 | { | ||
325 | (void) cls; | ||
326 | op = NULL; | ||
327 | GNUNET_assert (GNUNET_EC_NONE == ec); | ||
328 | } | ||
329 | |||
330 | |||
331 | static void | ||
332 | run (void *cls, | ||
333 | const struct GNUNET_CONFIGURATION_Handle *c, | ||
334 | struct GNUNET_TESTING_Peer *peer) | ||
335 | { | ||
336 | (void) cls; | ||
337 | (void) peer; | ||
338 | cfg = c; | ||
339 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL); | ||
340 | id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL); | ||
341 | op = GNUNET_IDENTITY_create (id, "phone-ego", NULL, | ||
342 | GNUNET_PUBLIC_KEY_TYPE_ECDSA, | ||
343 | &phone_ego_create_cont, | ||
344 | NULL); | ||
345 | ns = GNUNET_NAMESTORE_connect (cfg); | ||
346 | } | ||
347 | |||
348 | |||
349 | int | ||
350 | main (int argc, char *argv[]) | ||
351 | { | ||
352 | (void) argc; | ||
353 | (void) argv; | ||
354 | if (0 != GNUNET_TESTING_peer_run ("test_conversation_api", | ||
355 | "test_conversation.conf", | ||
356 | &run, | ||
357 | NULL)) | ||
358 | return 1; | ||
359 | return ok; | ||
360 | } | ||
361 | |||
362 | |||
363 | /* end of test_conversation_api_reject.c */ | ||