2 This file is part of GNUnet.
3 Copyright (C) 2013, 2014 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
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)
68 disable_speaker (void *cls)
84 destroy_speaker (void *cls)
89 static struct GNUNET_SPEAKER_Handle call_speaker = {
99 enable_mic (void *cls,
100 GNUNET_MICROPHONE_RecordedDataCallback rdc,
104 return GNUNET_SYSERR;
109 disable_mic (void *cls)
116 destroy_mic (void *cls)
121 static struct GNUNET_MICROPHONE_Handle call_mic = {
130 * Signature of the main function of a task.
133 * @param tc context information (why was this task triggered now)
136 end_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
138 GNUNET_SCHEDULER_shutdown ();
141 GNUNET_IDENTITY_cancel (op);
146 GNUNET_CONVERSATION_call_stop (call);
151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from PHONE service.\n");
152 GNUNET_CONVERSATION_phone_destroy (phone);
157 GNUNET_IDENTITY_disconnect (id);
162 GNUNET_NAMESTORE_cancel (qe);
167 GNUNET_NAMESTORE_disconnect (ns);
174 phone_event_handler (void *cls,
175 enum GNUNET_CONVERSATION_PhoneEventCode code,
176 struct GNUNET_CONVERSATION_Caller *caller,
177 const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id)
179 static enum GNUNET_CONVERSATION_PhoneEventCode expect
180 = GNUNET_CONVERSATION_EC_PHONE_RING;
182 GNUNET_break (code == expect);
185 case GNUNET_CONVERSATION_EC_PHONE_RING:
186 GNUNET_CONVERSATION_caller_hang_up (caller);
189 fprintf (stderr, "Unexpected phone code: %d\n", code);
196 call_event_handler (void *cls,
197 enum GNUNET_CONVERSATION_CallEventCode code)
199 static enum GNUNET_CONVERSATION_CallEventCode expect
200 = GNUNET_CONVERSATION_EC_CALL_RINGING;
202 GNUNET_break (code == expect);
205 case GNUNET_CONVERSATION_EC_CALL_RINGING:
206 expect = GNUNET_CONVERSATION_EC_CALL_HUNG_UP;
208 case GNUNET_CONVERSATION_EC_CALL_HUNG_UP:
211 GNUNET_SCHEDULER_shutdown ();
214 case GNUNET_CONVERSATION_EC_CALL_PICKED_UP:
215 case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL:
216 case GNUNET_CONVERSATION_EC_CALL_SUSPENDED:
217 case GNUNET_CONVERSATION_EC_CALL_RESUMED:
218 case GNUNET_CONVERSATION_EC_CALL_ERROR:
219 fprintf (stderr, "Unexpected call code: %d\n", code);
226 caller_ego_create_cont (void *cls,
230 GNUNET_assert (NULL == emsg);
235 namestore_put_cont (void *cls,
240 GNUNET_assert (GNUNET_YES == success);
241 GNUNET_assert (NULL == emsg);
242 GNUNET_assert (NULL == op);
243 op = GNUNET_IDENTITY_create (id, "caller-ego",
244 &caller_ego_create_cont, NULL);
249 identity_cb (void *cls,
250 struct GNUNET_IDENTITY_Ego *ego,
254 struct GNUNET_GNSRECORD_Data rd;
255 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
261 if (0 == strcmp (name, "phone-ego"))
263 GNUNET_IDENTITY_ego_get_public_key (ego, &pub);
264 GNUNET_asprintf (&gns_name,
266 GNUNET_GNSRECORD_pkey_to_zkey (&pub));
267 phone = GNUNET_CONVERSATION_phone_create (cfg,
269 &phone_event_handler,
271 GNUNET_assert (NULL != phone);
272 memset (&rd, 0, sizeof (rd));
273 GNUNET_CONVERSATION_phone_get_record (phone,
275 GNUNET_assert (rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE);
276 rd.expiration_time = UINT64_MAX;
277 qe = GNUNET_NAMESTORE_records_store (ns,
278 GNUNET_IDENTITY_ego_get_private_key (ego),
279 "phone" /* GNS label */,
286 if (0 == strcmp (name, "caller-ego"))
288 GNUNET_IDENTITY_ego_get_public_key (ego, &pub);
289 GNUNET_asprintf (&gns_caller_id,
291 GNUNET_GNSRECORD_pkey_to_zkey (&pub));
292 call = GNUNET_CONVERSATION_call_start (cfg,
306 phone_ego_create_cont (void *cls,
310 GNUNET_assert (NULL == emsg);
316 const struct GNUNET_CONFIGURATION_Handle *c,
317 struct GNUNET_TESTING_Peer *peer)
320 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test,
322 id = GNUNET_IDENTITY_connect (cfg,
325 op = GNUNET_IDENTITY_create (id, "phone-ego", &phone_ego_create_cont, NULL);
326 ns = GNUNET_NAMESTORE_connect (cfg);
331 main (int argc, char *argv[])
333 if (0 != GNUNET_TESTING_peer_run ("test_conversation_api",
334 "test_conversation.conf",
340 /* end of test_conversation_api_reject.c */