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.
16 * @file conversation/test_conversation_api_reject.c
17 * @brief testcase for conversation_api.c
19 * This test performs the operations of a call to a phone
20 * where the phone user immediately hangs up (rejecting the
24 #include "gnunet_util_lib.h"
25 #include "gnunet_testing_lib.h"
26 #include "gnunet_gnsrecord_lib.h"
27 #include "gnunet_conversation_service.h"
28 #include "gnunet_identity_service.h"
29 #include "gnunet_namestore_service.h"
31 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 25)
35 static const struct GNUNET_CONFIGURATION_Handle *cfg;
37 static struct GNUNET_IDENTITY_Handle *id;
39 static struct GNUNET_IDENTITY_Operation *op;
41 static struct GNUNET_CONVERSATION_Phone *phone;
43 static struct GNUNET_NAMESTORE_Handle *ns;
45 static struct GNUNET_CONVERSATION_Call *call;
47 static struct GNUNET_NAMESTORE_QueueEntry *qe;
49 static char *gns_name;
51 static char *gns_caller_id;
55 enable_speaker (void *cls)
64 disable_speaker (void *cls)
84 destroy_speaker (void *cls)
90 static struct GNUNET_SPEAKER_Handle call_speaker = {
100 enable_mic (void *cls,
101 GNUNET_MICROPHONE_RecordedDataCallback rdc,
108 return GNUNET_SYSERR;
113 disable_mic (void *cls)
121 destroy_mic (void *cls)
127 static struct GNUNET_MICROPHONE_Handle call_mic = {
136 * Signature of the main function of a task.
144 GNUNET_SCHEDULER_shutdown ();
147 GNUNET_IDENTITY_cancel (op);
152 GNUNET_CONVERSATION_call_stop (call);
157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
158 "Disconnecting from PHONE service.\n");
159 GNUNET_CONVERSATION_phone_destroy (phone);
164 GNUNET_IDENTITY_disconnect (id);
169 GNUNET_NAMESTORE_cancel (qe);
174 GNUNET_NAMESTORE_disconnect (ns);
181 phone_event_handler (void *cls,
182 enum GNUNET_CONVERSATION_PhoneEventCode code,
183 struct GNUNET_CONVERSATION_Caller *caller,
184 const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id)
186 static enum GNUNET_CONVERSATION_PhoneEventCode expect
187 = GNUNET_CONVERSATION_EC_PHONE_RING;
191 GNUNET_break (code == expect);
194 case GNUNET_CONVERSATION_EC_PHONE_RING:
195 GNUNET_CONVERSATION_caller_hang_up (caller);
198 fprintf (stderr, "Unexpected phone code: %d\n", code);
205 call_event_handler (void *cls,
206 enum GNUNET_CONVERSATION_CallEventCode code)
208 static enum GNUNET_CONVERSATION_CallEventCode expect
209 = GNUNET_CONVERSATION_EC_CALL_RINGING;
212 GNUNET_break (code == expect);
215 case GNUNET_CONVERSATION_EC_CALL_RINGING:
216 expect = GNUNET_CONVERSATION_EC_CALL_HUNG_UP;
218 case GNUNET_CONVERSATION_EC_CALL_HUNG_UP:
221 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);
230 case GNUNET_CONVERSATION_EC_CALL_ERROR:
231 fprintf (stderr, "Unexpected call code: %d\n", code);
239 caller_ego_create_cont (void *cls,
244 GNUNET_assert (NULL == emsg);
249 namestore_put_cont (void *cls,
255 GNUNET_assert (GNUNET_YES == success);
256 GNUNET_assert (NULL == emsg);
257 GNUNET_assert (NULL == op);
258 op = GNUNET_IDENTITY_create (id,
260 &caller_ego_create_cont,
266 identity_cb (void *cls,
267 struct GNUNET_IDENTITY_Ego *ego,
271 struct GNUNET_GNSRECORD_Data rd;
272 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
280 if (0 == strcmp (name, "phone-ego"))
282 GNUNET_IDENTITY_ego_get_public_key (ego, &pub);
283 GNUNET_asprintf (&gns_name,
285 GNUNET_GNSRECORD_pkey_to_zkey (&pub));
286 phone = GNUNET_CONVERSATION_phone_create (cfg,
288 &phone_event_handler,
290 GNUNET_assert (NULL != phone);
291 memset (&rd, 0, sizeof (rd));
292 GNUNET_CONVERSATION_phone_get_record (phone,
294 GNUNET_assert (rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE);
295 rd.expiration_time = UINT64_MAX;
296 qe = GNUNET_NAMESTORE_records_store (ns,
297 GNUNET_IDENTITY_ego_get_private_key (ego),
298 "phone" /* GNS label */,
305 if (0 == strcmp (name, "caller-ego"))
307 GNUNET_IDENTITY_ego_get_public_key (ego, &pub);
308 GNUNET_asprintf (&gns_caller_id,
310 GNUNET_GNSRECORD_pkey_to_zkey (&pub));
311 call = GNUNET_CONVERSATION_call_start (cfg,
324 phone_ego_create_cont (void *cls,
329 GNUNET_assert (NULL == emsg);
335 const struct GNUNET_CONFIGURATION_Handle *c,
336 struct GNUNET_TESTING_Peer *peer)
341 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test,
343 id = GNUNET_IDENTITY_connect (cfg,
346 op = GNUNET_IDENTITY_create (id,
348 &phone_ego_create_cont,
350 ns = GNUNET_NAMESTORE_connect (cfg);
355 main (int argc, char *argv[])
359 if (0 != GNUNET_TESTING_peer_run ("test_conversation_api",
360 "test_conversation.conf",
366 /* end of test_conversation_api_reject.c */