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)
77 play (void *cls, size_t data_size, const void *data)
87 destroy_speaker (void *cls)
93 static struct GNUNET_SPEAKER_Handle call_speaker = { &enable_speaker,
101 enable_mic (void *cls,
102 GNUNET_MICROPHONE_RecordedDataCallback rdc,
109 return GNUNET_SYSERR;
114 disable_mic (void *cls)
122 destroy_mic (void *cls)
128 static struct GNUNET_MICROPHONE_Handle call_mic = { &enable_mic,
135 * Signature of the main function of a task.
143 GNUNET_SCHEDULER_shutdown ();
146 GNUNET_IDENTITY_cancel (op);
151 GNUNET_CONVERSATION_call_stop (call);
156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from PHONE service.\n");
157 GNUNET_CONVERSATION_phone_destroy (phone);
162 GNUNET_IDENTITY_disconnect (id);
167 GNUNET_NAMESTORE_cancel (qe);
172 GNUNET_NAMESTORE_disconnect (ns);
179 phone_event_handler (void *cls,
180 enum GNUNET_CONVERSATION_PhoneEventCode code,
181 struct GNUNET_CONVERSATION_Caller *caller,
182 const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id)
184 static enum GNUNET_CONVERSATION_PhoneEventCode expect =
185 GNUNET_CONVERSATION_EC_PHONE_RING;
189 GNUNET_break (code == expect);
192 case GNUNET_CONVERSATION_EC_PHONE_RING:
193 GNUNET_CONVERSATION_caller_hang_up (caller);
197 fprintf (stderr, "Unexpected phone code: %d\n", code);
204 call_event_handler (void *cls, enum GNUNET_CONVERSATION_CallEventCode code)
206 static enum GNUNET_CONVERSATION_CallEventCode expect =
207 GNUNET_CONVERSATION_EC_CALL_RINGING;
210 GNUNET_break (code == expect);
213 case GNUNET_CONVERSATION_EC_CALL_RINGING:
214 expect = GNUNET_CONVERSATION_EC_CALL_HUNG_UP;
217 case GNUNET_CONVERSATION_EC_CALL_HUNG_UP:
220 GNUNET_SCHEDULER_shutdown ();
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);
231 case GNUNET_CONVERSATION_EC_CALL_ERROR:
232 fprintf (stderr, "Unexpected call code: %d\n", code);
240 caller_ego_create_cont (void *cls,
241 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk,
246 GNUNET_assert (NULL == emsg);
251 namestore_put_cont (void *cls, int32_t success, const char *emsg)
255 GNUNET_assert (GNUNET_YES == success);
256 GNUNET_assert (NULL == emsg);
257 GNUNET_assert (NULL == op);
258 op = GNUNET_IDENTITY_create (id, "caller-ego", NULL, &caller_ego_create_cont, NULL);
263 identity_cb (void *cls,
264 struct GNUNET_IDENTITY_Ego *ego,
268 struct GNUNET_GNSRECORD_Data rd;
269 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
277 if (0 == strcmp (name, "phone-ego"))
279 GNUNET_IDENTITY_ego_get_public_key (ego, &pub);
280 GNUNET_asprintf (&gns_name,
282 GNUNET_GNSRECORD_pkey_to_zkey (&pub));
284 GNUNET_CONVERSATION_phone_create (cfg, ego, &phone_event_handler, NULL);
285 GNUNET_assert (NULL != phone);
286 memset (&rd, 0, sizeof(rd));
287 GNUNET_CONVERSATION_phone_get_record (phone, &rd);
288 GNUNET_assert (rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE);
289 rd.expiration_time = UINT64_MAX;
291 GNUNET_NAMESTORE_records_store (ns,
292 GNUNET_IDENTITY_ego_get_private_key (ego),
293 "phone" /* GNS label */,
300 if (0 == strcmp (name, "caller-ego"))
302 GNUNET_IDENTITY_ego_get_public_key (ego, &pub);
303 GNUNET_asprintf (&gns_caller_id,
305 GNUNET_GNSRECORD_pkey_to_zkey (&pub));
306 call = GNUNET_CONVERSATION_call_start (cfg,
319 phone_ego_create_cont (void *cls,
320 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk,
325 GNUNET_assert (NULL == emsg);
331 const struct GNUNET_CONFIGURATION_Handle *c,
332 struct GNUNET_TESTING_Peer *peer)
337 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL);
338 id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL);
339 op = GNUNET_IDENTITY_create (id, "phone-ego", NULL, &phone_ego_create_cont, NULL);
340 ns = GNUNET_NAMESTORE_connect (cfg);
345 main (int argc, char *argv[])
349 if (0 != GNUNET_TESTING_peer_run ("test_conversation_api",
350 "test_conversation.conf",
358 /* end of test_conversation_api_reject.c */