2 This file is part of GNUnet.
3 Copyright (C) 2013, 2014, 2018 GNUnet e.V.
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.
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.
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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
21 * @file conversation/test_conversation_api_reject.c
22 * @brief testcase for conversation_api.c
24 * This test performs the operations of a call to a phone
25 * where the phone user immediately hangs up (rejecting the
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"
36 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 25)
40 static const struct GNUNET_CONFIGURATION_Handle *cfg;
42 static struct GNUNET_IDENTITY_Handle *id;
44 static struct GNUNET_IDENTITY_Operation *op;
46 static struct GNUNET_CONVERSATION_Phone *phone;
48 static struct GNUNET_NAMESTORE_Handle *ns;
50 static struct GNUNET_CONVERSATION_Call *call;
52 static struct GNUNET_NAMESTORE_QueueEntry *qe;
54 static char *gns_name;
56 static char *gns_caller_id;
60 enable_speaker (void *cls)
69 disable_speaker (void *cls)
89 destroy_speaker (void *cls)
95 static struct GNUNET_SPEAKER_Handle call_speaker = {
105 enable_mic (void *cls,
106 GNUNET_MICROPHONE_RecordedDataCallback rdc,
113 return GNUNET_SYSERR;
118 disable_mic (void *cls)
126 destroy_mic (void *cls)
132 static struct GNUNET_MICROPHONE_Handle call_mic = {
141 * Signature of the main function of a task.
149 GNUNET_SCHEDULER_shutdown ();
152 GNUNET_IDENTITY_cancel (op);
157 GNUNET_CONVERSATION_call_stop (call);
162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
163 "Disconnecting from PHONE service.\n");
164 GNUNET_CONVERSATION_phone_destroy (phone);
169 GNUNET_IDENTITY_disconnect (id);
174 GNUNET_NAMESTORE_cancel (qe);
179 GNUNET_NAMESTORE_disconnect (ns);
186 phone_event_handler (void *cls,
187 enum GNUNET_CONVERSATION_PhoneEventCode code,
188 struct GNUNET_CONVERSATION_Caller *caller,
189 const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id)
191 static enum GNUNET_CONVERSATION_PhoneEventCode expect
192 = GNUNET_CONVERSATION_EC_PHONE_RING;
196 GNUNET_break (code == expect);
199 case GNUNET_CONVERSATION_EC_PHONE_RING:
200 GNUNET_CONVERSATION_caller_hang_up (caller);
203 fprintf (stderr, "Unexpected phone code: %d\n", code);
210 call_event_handler (void *cls,
211 enum GNUNET_CONVERSATION_CallEventCode code)
213 static enum GNUNET_CONVERSATION_CallEventCode expect
214 = GNUNET_CONVERSATION_EC_CALL_RINGING;
217 GNUNET_break (code == expect);
220 case GNUNET_CONVERSATION_EC_CALL_RINGING:
221 expect = GNUNET_CONVERSATION_EC_CALL_HUNG_UP;
223 case GNUNET_CONVERSATION_EC_CALL_HUNG_UP:
226 GNUNET_SCHEDULER_shutdown ();
229 case GNUNET_CONVERSATION_EC_CALL_PICKED_UP:
230 case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL:
231 case GNUNET_CONVERSATION_EC_CALL_SUSPENDED:
232 case GNUNET_CONVERSATION_EC_CALL_RESUMED:
233 fprintf (stderr, "Unexpected call code: %d\n", code);
235 case GNUNET_CONVERSATION_EC_CALL_ERROR:
236 fprintf (stderr, "Unexpected call code: %d\n", code);
244 caller_ego_create_cont (void *cls,
249 GNUNET_assert (NULL == emsg);
254 namestore_put_cont (void *cls,
260 GNUNET_assert (GNUNET_YES == success);
261 GNUNET_assert (NULL == emsg);
262 GNUNET_assert (NULL == op);
263 op = GNUNET_IDENTITY_create (id,
265 &caller_ego_create_cont,
271 identity_cb (void *cls,
272 struct GNUNET_IDENTITY_Ego *ego,
276 struct GNUNET_GNSRECORD_Data rd;
277 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
285 if (0 == strcmp (name, "phone-ego"))
287 GNUNET_IDENTITY_ego_get_public_key (ego, &pub);
288 GNUNET_asprintf (&gns_name,
290 GNUNET_GNSRECORD_pkey_to_zkey (&pub));
291 phone = GNUNET_CONVERSATION_phone_create (cfg,
293 &phone_event_handler,
295 GNUNET_assert (NULL != phone);
296 memset (&rd, 0, sizeof (rd));
297 GNUNET_CONVERSATION_phone_get_record (phone,
299 GNUNET_assert (rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE);
300 rd.expiration_time = UINT64_MAX;
301 qe = GNUNET_NAMESTORE_records_store (ns,
302 GNUNET_IDENTITY_ego_get_private_key (ego),
303 "phone" /* GNS label */,
310 if (0 == strcmp (name, "caller-ego"))
312 GNUNET_IDENTITY_ego_get_public_key (ego, &pub);
313 GNUNET_asprintf (&gns_caller_id,
315 GNUNET_GNSRECORD_pkey_to_zkey (&pub));
316 call = GNUNET_CONVERSATION_call_start (cfg,
329 phone_ego_create_cont (void *cls,
334 GNUNET_assert (NULL == emsg);
340 const struct GNUNET_CONFIGURATION_Handle *c,
341 struct GNUNET_TESTING_Peer *peer)
346 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test,
348 id = GNUNET_IDENTITY_connect (cfg,
351 op = GNUNET_IDENTITY_create (id,
353 &phone_ego_create_cont,
355 ns = GNUNET_NAMESTORE_connect (cfg);
360 main (int argc, char *argv[])
364 if (0 != GNUNET_TESTING_peer_run ("test_conversation_api",
365 "test_conversation.conf",
371 /* end of test_conversation_api_reject.c */