aboutsummaryrefslogtreecommitdiff
path: root/src/conversation
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-06-03 00:44:25 +0200
committerChristian Grothoff <christian@grothoff.org>2019-06-03 00:44:25 +0200
commit34c8bfb80b82a1a7f7d3db3c41e705b09a1fad7e (patch)
tree601520ce682cf786bc4f34b6e4d95a9061bd48af /src/conversation
parent3d9f1acfb62cd53fc7d1441eb33e1341c9ff3790 (diff)
downloadgnunet-34c8bfb80b82a1a7f7d3db3c41e705b09a1fad7e.tar.gz
gnunet-34c8bfb80b82a1a7f7d3db3c41e705b09a1fad7e.zip
fix build issues
Diffstat (limited to 'src/conversation')
-rw-r--r--src/conversation/test_conversation_api.c174
-rw-r--r--src/conversation/test_conversation_api_reject.c96
-rw-r--r--src/conversation/test_conversation_api_twocalls.c205
3 files changed, 172 insertions, 303 deletions
diff --git a/src/conversation/test_conversation_api.c b/src/conversation/test_conversation_api.c
index 0e3dd975b..a51570127 100644
--- a/src/conversation/test_conversation_api.c
+++ b/src/conversation/test_conversation_api.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -82,8 +82,7 @@ phone_send (void *cls)
82 GNUNET_assert (NULL != phone_rdc); 82 GNUNET_assert (NULL != phone_rdc);
83 GNUNET_snprintf (buf, sizeof (buf), "phone-%u", i++); 83 GNUNET_snprintf (buf, sizeof (buf), "phone-%u", i++);
84 phone_rdc (phone_rdc_cls, strlen (buf) + 1, buf); 84 phone_rdc (phone_rdc_cls, strlen (buf) + 1, buf);
85 phone_task = GNUNET_SCHEDULER_add_delayed (FREQ, 85 phone_task = GNUNET_SCHEDULER_add_delayed (FREQ, &phone_send, NULL);
86 &phone_send, NULL);
87} 86}
88 87
89 88
@@ -97,8 +96,7 @@ call_send (void *cls)
97 GNUNET_assert (NULL != call_rdc); 96 GNUNET_assert (NULL != call_rdc);
98 GNUNET_snprintf (buf, sizeof (buf), "call-%u", i++); 97 GNUNET_snprintf (buf, sizeof (buf), "call-%u", i++);
99 call_rdc (call_rdc_cls, strlen (buf) + 1, buf); 98 call_rdc (call_rdc_cls, strlen (buf) + 1, buf);
100 call_task = GNUNET_SCHEDULER_add_delayed (FREQ, 99 call_task = GNUNET_SCHEDULER_add_delayed (FREQ, &call_send, NULL);
101 &call_send, NULL);
102} 100}
103 101
104 102
@@ -107,9 +105,7 @@ enable_speaker (void *cls)
107{ 105{
108 const char *origin = cls; 106 const char *origin = cls;
109 107
110 fprintf (stderr, 108 fprintf (stderr, "Speaker %s enabled\n", origin);
111 "Speaker %s enabled\n",
112 origin);
113 return GNUNET_OK; 109 return GNUNET_OK;
114} 110}
115 111
@@ -119,16 +115,12 @@ disable_speaker (void *cls)
119{ 115{
120 const char *origin = cls; 116 const char *origin = cls;
121 117
122 fprintf (stderr, 118 fprintf (stderr, "Speaker %s disabled\n", origin);
123 "Speaker %s disabled\n",
124 origin);
125} 119}
126 120
127 121
128static void 122static void
129play (void *cls, 123play (void *cls, size_t data_size, const void *data)
130 size_t data_size,
131 const void *data)
132{ 124{
133 const char *origin = cls; 125 const char *origin = cls;
134 static unsigned int phone_i = 1; 126 static unsigned int phone_i = 1;
@@ -136,17 +128,10 @@ play (void *cls,
136 char buf[32]; 128 char buf[32];
137 129
138 if (0 == strcmp (origin, "phone")) 130 if (0 == strcmp (origin, "phone"))
139 GNUNET_snprintf (buf, 131 GNUNET_snprintf (buf, sizeof (buf), "call-%u", call_i++);
140 sizeof (buf),
141 "call-%u",
142 call_i++);
143 else 132 else
144 GNUNET_snprintf (buf, 133 GNUNET_snprintf (buf, sizeof (buf), "phone-%u", phone_i++);
145 sizeof (buf), 134 if ((data_size != strlen (buf) + 1) || (0 != strncmp (buf, data, data_size)))
146 "phone-%u",
147 phone_i++);
148 if ( (data_size != strlen (buf) + 1) ||
149 (0 != strncmp (buf, data, data_size)) )
150 { 135 {
151 fprintf (stderr, 136 fprintf (stderr,
152 "Expected %s, received %.*s\n", 137 "Expected %s, received %.*s\n",
@@ -158,9 +143,7 @@ play (void *cls,
158 { 143 {
159 fprintf (stderr, "."); 144 fprintf (stderr, ".");
160 } 145 }
161 if ( (20 < call_i) && 146 if ((20 < call_i) && (20 < phone_i) && (NULL != call))
162 (20 < phone_i) &&
163 (NULL != call) )
164 { 147 {
165 /* time to hang up ... */ 148 /* time to hang up ... */
166 GNUNET_CONVERSATION_call_stop (call); 149 GNUNET_CONVERSATION_call_stop (call);
@@ -178,22 +161,18 @@ destroy_speaker (void *cls)
178} 161}
179 162
180 163
181static struct GNUNET_SPEAKER_Handle call_speaker = { 164static struct GNUNET_SPEAKER_Handle call_speaker = {&enable_speaker,
182 &enable_speaker, 165 &play,
183 &play, 166 &disable_speaker,
184 &disable_speaker, 167 &destroy_speaker,
185 &destroy_speaker, 168 "caller"};
186 "caller"
187};
188 169
189 170
190static struct GNUNET_SPEAKER_Handle phone_speaker = { 171static struct GNUNET_SPEAKER_Handle phone_speaker = {&enable_speaker,
191 &enable_speaker, 172 &play,
192 &play, 173 &disable_speaker,
193 &disable_speaker, 174 &destroy_speaker,
194 &destroy_speaker, 175 "phone"};
195 "phone"
196};
197 176
198 177
199static int 178static int
@@ -203,9 +182,7 @@ enable_mic (void *cls,
203{ 182{
204 const char *origin = cls; 183 const char *origin = cls;
205 184
206 fprintf (stderr, 185 fprintf (stderr, "Mic %s enabled\n", origin);
207 "Mic %s enabled\n",
208 origin);
209 if (0 == strcmp (origin, "phone")) 186 if (0 == strcmp (origin, "phone"))
210 { 187 {
211 phone_rdc = rdc; 188 phone_rdc = rdc;
@@ -227,9 +204,7 @@ disable_mic (void *cls)
227{ 204{
228 const char *origin = cls; 205 const char *origin = cls;
229 206
230 fprintf (stderr, 207 fprintf (stderr, "Mic %s disabled\n", origin);
231 "Mic %s disabled\n",
232 origin);
233 if (0 == strcmp (origin, "phone")) 208 if (0 == strcmp (origin, "phone"))
234 { 209 {
235 phone_rdc = NULL; 210 phone_rdc = NULL;
@@ -252,26 +227,20 @@ destroy_mic (void *cls)
252{ 227{
253 const char *origin = cls; 228 const char *origin = cls;
254 229
255 fprintf (stderr, 230 fprintf (stderr, "Mic %s destroyed\n", origin);
256 "Mic %s destroyed\n",
257 origin);
258} 231}
259 232
260 233
261static struct GNUNET_MICROPHONE_Handle call_mic = { 234static struct GNUNET_MICROPHONE_Handle call_mic = {&enable_mic,
262 &enable_mic, 235 &disable_mic,
263 &disable_mic, 236 &destroy_mic,
264 &destroy_mic, 237 "caller"};
265 "caller"
266};
267 238
268 239
269static struct GNUNET_MICROPHONE_Handle phone_mic = { 240static struct GNUNET_MICROPHONE_Handle phone_mic = {&enable_mic,
270 &enable_mic, 241 &disable_mic,
271 &disable_mic, 242 &destroy_mic,
272 &destroy_mic, 243 "phone"};
273 "phone"
274};
275 244
276 245
277/** 246/**
@@ -319,17 +288,14 @@ end_test (void *cls)
319 288
320 289
321static void 290static void
322caller_event_handler (void *cls, 291caller_event_handler (void *cls, enum GNUNET_CONVERSATION_CallerEventCode code)
323 enum GNUNET_CONVERSATION_CallerEventCode code)
324{ 292{
325 (void) cls; 293 (void) cls;
326 switch (code) 294 switch (code)
327 { 295 {
328 case GNUNET_CONVERSATION_EC_CALLER_SUSPEND: 296 case GNUNET_CONVERSATION_EC_CALLER_SUSPEND:
329 case GNUNET_CONVERSATION_EC_CALLER_RESUME: 297 case GNUNET_CONVERSATION_EC_CALLER_RESUME:
330 fprintf (stderr, 298 fprintf (stderr, "Unexpected caller code: %d\n", code);
331 "Unexpected caller code: %d\n",
332 code);
333 break; 299 break;
334 } 300 }
335} 301}
@@ -341,8 +307,8 @@ phone_event_handler (void *cls,
341 struct GNUNET_CONVERSATION_Caller *caller, 307 struct GNUNET_CONVERSATION_Caller *caller,
342 const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id) 308 const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id)
343{ 309{
344 static enum GNUNET_CONVERSATION_PhoneEventCode expect 310 static enum GNUNET_CONVERSATION_PhoneEventCode expect =
345 = GNUNET_CONVERSATION_EC_PHONE_RING; 311 GNUNET_CONVERSATION_EC_PHONE_RING;
346 312
347 (void) cls; 313 (void) cls;
348 (void) caller_id; 314 (void) caller_id;
@@ -366,20 +332,17 @@ phone_event_handler (void *cls,
366 GNUNET_SCHEDULER_shutdown (); 332 GNUNET_SCHEDULER_shutdown ();
367 break; 333 break;
368 default: 334 default:
369 fprintf (stderr, 335 fprintf (stderr, "Unexpected phone code: %d\n", code);
370 "Unexpected phone code: %d\n",
371 code);
372 break; 336 break;
373 } 337 }
374} 338}
375 339
376 340
377static void 341static void
378call_event_handler (void *cls, 342call_event_handler (void *cls, enum GNUNET_CONVERSATION_CallEventCode code)
379 enum GNUNET_CONVERSATION_CallEventCode code)
380{ 343{
381 static enum GNUNET_CONVERSATION_CallEventCode expect 344 static enum GNUNET_CONVERSATION_CallEventCode expect =
382 = GNUNET_CONVERSATION_EC_CALL_RINGING; 345 GNUNET_CONVERSATION_EC_CALL_RINGING;
383 346
384 (void) cls; 347 (void) cls;
385 GNUNET_break (code == expect); 348 GNUNET_break (code == expect);
@@ -416,6 +379,7 @@ call_event_handler (void *cls,
416 379
417static void 380static void
418caller_ego_create_cont (void *cls, 381caller_ego_create_cont (void *cls,
382 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk,
419 const char *emsg) 383 const char *emsg)
420{ 384{
421 (void) cls; 385 (void) cls;
@@ -425,19 +389,14 @@ caller_ego_create_cont (void *cls,
425 389
426 390
427static void 391static void
428namestore_put_cont (void *cls, 392namestore_put_cont (void *cls, int32_t success, const char *emsg)
429 int32_t success,
430 const char *emsg)
431{ 393{
432 (void) cls; 394 (void) cls;
433 qe = NULL; 395 qe = NULL;
434 GNUNET_assert (GNUNET_YES == success); 396 GNUNET_assert (GNUNET_YES == success);
435 GNUNET_assert (NULL == emsg); 397 GNUNET_assert (NULL == emsg);
436 GNUNET_assert (NULL == op); 398 GNUNET_assert (NULL == op);
437 op = GNUNET_IDENTITY_create (id, 399 op = GNUNET_IDENTITY_create (id, "caller-ego", &caller_ego_create_cont, NULL);
438 "caller-ego",
439 &caller_ego_create_cont,
440 NULL);
441} 400}
442 401
443 402
@@ -462,23 +421,21 @@ identity_cb (void *cls,
462 GNUNET_asprintf (&gns_name, 421 GNUNET_asprintf (&gns_name,
463 "phone.%s", 422 "phone.%s",
464 GNUNET_GNSRECORD_pkey_to_zkey (&pub)); 423 GNUNET_GNSRECORD_pkey_to_zkey (&pub));
465 phone = GNUNET_CONVERSATION_phone_create (cfg, 424 phone =
466 ego, 425 GNUNET_CONVERSATION_phone_create (cfg, ego, &phone_event_handler, NULL);
467 &phone_event_handler,
468 NULL);
469 GNUNET_assert (NULL != phone); 426 GNUNET_assert (NULL != phone);
470 memset (&rd, 0, sizeof (rd)); 427 memset (&rd, 0, sizeof (rd));
471 GNUNET_CONVERSATION_phone_get_record (phone, 428 GNUNET_CONVERSATION_phone_get_record (phone, &rd);
472 &rd);
473 GNUNET_assert (rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE); 429 GNUNET_assert (rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE);
474 rd.expiration_time = UINT64_MAX; 430 rd.expiration_time = UINT64_MAX;
475 qe = GNUNET_NAMESTORE_records_store (ns, 431 qe =
476 GNUNET_IDENTITY_ego_get_private_key (ego), 432 GNUNET_NAMESTORE_records_store (ns,
477 "phone" /* GNS label */, 433 GNUNET_IDENTITY_ego_get_private_key (ego),
478 1, 434 "phone" /* GNS label */,
479 &rd, 435 1,
480 &namestore_put_cont, 436 &rd,
481 NULL); 437 &namestore_put_cont,
438 NULL);
482 return; 439 return;
483 } 440 }
484 if (0 == strcmp (name, "caller-ego")) 441 if (0 == strcmp (name, "caller-ego"))
@@ -500,8 +457,7 @@ identity_cb (void *cls,
500 457
501 458
502static void 459static void
503phone_ego_create_cont (void *cls, 460phone_ego_create_cont (void *cls, const char *emsg)
504 const char *emsg)
505{ 461{
506 (void) cls; 462 (void) cls;
507 op = NULL; 463 op = NULL;
@@ -517,30 +473,22 @@ run (void *cls,
517 (void) cls; 473 (void) cls;
518 (void) peer; 474 (void) peer;
519 cfg = c; 475 cfg = c;
520 GNUNET_SCHEDULER_add_delayed (TIMEOUT, 476 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL);
521 &end_test, 477 id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL);
522 NULL); 478 op = GNUNET_IDENTITY_create (id, "phone-ego", &phone_ego_create_cont, NULL);
523 id = GNUNET_IDENTITY_connect (cfg,
524 &identity_cb,
525 NULL);
526 op = GNUNET_IDENTITY_create (id,
527 "phone-ego",
528 &phone_ego_create_cont,
529 NULL);
530 ns = GNUNET_NAMESTORE_connect (cfg); 479 ns = GNUNET_NAMESTORE_connect (cfg);
531} 480}
532 481
533 482
534int 483int
535main (int argc, 484main (int argc, char *argv[])
536 char *argv[])
537{ 485{
538 (void) argc; 486 (void) argc;
539 (void) argv; 487 (void) argv;
540 if (0 != GNUNET_TESTING_peer_run ("test_conversation_api", 488 if (0 != GNUNET_TESTING_peer_run ("test_conversation_api",
541 "test_conversation.conf", 489 "test_conversation.conf",
542 &run, 490 &run,
543 NULL)) 491 NULL))
544 return 1; 492 return 1;
545 return ok; 493 return ok;
546} 494}
diff --git a/src/conversation/test_conversation_api_reject.c b/src/conversation/test_conversation_api_reject.c
index dc4785258..49dc854ed 100644
--- a/src/conversation/test_conversation_api_reject.c
+++ b/src/conversation/test_conversation_api_reject.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -74,9 +74,7 @@ disable_speaker (void *cls)
74 74
75 75
76static void 76static void
77play (void *cls, 77play (void *cls, size_t data_size, const void *data)
78 size_t data_size,
79 const void *data)
80{ 78{
81 (void) cls; 79 (void) cls;
82 (void) data_size; 80 (void) data_size;
@@ -92,13 +90,11 @@ destroy_speaker (void *cls)
92} 90}
93 91
94 92
95static struct GNUNET_SPEAKER_Handle call_speaker = { 93static struct GNUNET_SPEAKER_Handle call_speaker = {&enable_speaker,
96 &enable_speaker, 94 &play,
97 &play, 95 &disable_speaker,
98 &disable_speaker, 96 &destroy_speaker,
99 &destroy_speaker, 97 "caller"};
100 "caller"
101};
102 98
103 99
104static int 100static int
@@ -129,12 +125,10 @@ destroy_mic (void *cls)
129} 125}
130 126
131 127
132static struct GNUNET_MICROPHONE_Handle call_mic = { 128static struct GNUNET_MICROPHONE_Handle call_mic = {&enable_mic,
133 &enable_mic, 129 &disable_mic,
134 &disable_mic, 130 &destroy_mic,
135 &destroy_mic, 131 "caller"};
136 "caller"
137};
138 132
139 133
140/** 134/**
@@ -159,8 +153,7 @@ end_test (void *cls)
159 } 153 }
160 if (NULL != phone) 154 if (NULL != phone)
161 { 155 {
162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from PHONE service.\n");
163 "Disconnecting from PHONE service.\n");
164 GNUNET_CONVERSATION_phone_destroy (phone); 157 GNUNET_CONVERSATION_phone_destroy (phone);
165 phone = NULL; 158 phone = NULL;
166 } 159 }
@@ -188,8 +181,8 @@ phone_event_handler (void *cls,
188 struct GNUNET_CONVERSATION_Caller *caller, 181 struct GNUNET_CONVERSATION_Caller *caller,
189 const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id) 182 const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id)
190{ 183{
191 static enum GNUNET_CONVERSATION_PhoneEventCode expect 184 static enum GNUNET_CONVERSATION_PhoneEventCode expect =
192 = GNUNET_CONVERSATION_EC_PHONE_RING; 185 GNUNET_CONVERSATION_EC_PHONE_RING;
193 186
194 (void) cls; 187 (void) cls;
195 (void) caller_id; 188 (void) caller_id;
@@ -207,11 +200,10 @@ phone_event_handler (void *cls,
207 200
208 201
209static void 202static void
210call_event_handler (void *cls, 203call_event_handler (void *cls, enum GNUNET_CONVERSATION_CallEventCode code)
211 enum GNUNET_CONVERSATION_CallEventCode code)
212{ 204{
213 static enum GNUNET_CONVERSATION_CallEventCode expect 205 static enum GNUNET_CONVERSATION_CallEventCode expect =
214 = GNUNET_CONVERSATION_EC_CALL_RINGING; 206 GNUNET_CONVERSATION_EC_CALL_RINGING;
215 207
216 (void) cls; 208 (void) cls;
217 GNUNET_break (code == expect); 209 GNUNET_break (code == expect);
@@ -242,6 +234,7 @@ call_event_handler (void *cls,
242 234
243static void 235static void
244caller_ego_create_cont (void *cls, 236caller_ego_create_cont (void *cls,
237 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk,
245 const char *emsg) 238 const char *emsg)
246{ 239{
247 (void) cls; 240 (void) cls;
@@ -251,19 +244,14 @@ caller_ego_create_cont (void *cls,
251 244
252 245
253static void 246static void
254namestore_put_cont (void *cls, 247namestore_put_cont (void *cls, int32_t success, const char *emsg)
255 int32_t success,
256 const char *emsg)
257{ 248{
258 (void) cls; 249 (void) cls;
259 qe = NULL; 250 qe = NULL;
260 GNUNET_assert (GNUNET_YES == success); 251 GNUNET_assert (GNUNET_YES == success);
261 GNUNET_assert (NULL == emsg); 252 GNUNET_assert (NULL == emsg);
262 GNUNET_assert (NULL == op); 253 GNUNET_assert (NULL == op);
263 op = GNUNET_IDENTITY_create (id, 254 op = GNUNET_IDENTITY_create (id, "caller-ego", &caller_ego_create_cont, NULL);
264 "caller-ego",
265 &caller_ego_create_cont,
266 NULL);
267} 255}
268 256
269 257
@@ -288,23 +276,21 @@ identity_cb (void *cls,
288 GNUNET_asprintf (&gns_name, 276 GNUNET_asprintf (&gns_name,
289 "phone.%s", 277 "phone.%s",
290 GNUNET_GNSRECORD_pkey_to_zkey (&pub)); 278 GNUNET_GNSRECORD_pkey_to_zkey (&pub));
291 phone = GNUNET_CONVERSATION_phone_create (cfg, 279 phone =
292 ego, 280 GNUNET_CONVERSATION_phone_create (cfg, ego, &phone_event_handler, NULL);
293 &phone_event_handler,
294 NULL);
295 GNUNET_assert (NULL != phone); 281 GNUNET_assert (NULL != phone);
296 memset (&rd, 0, sizeof (rd)); 282 memset (&rd, 0, sizeof (rd));
297 GNUNET_CONVERSATION_phone_get_record (phone, 283 GNUNET_CONVERSATION_phone_get_record (phone, &rd);
298 &rd);
299 GNUNET_assert (rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE); 284 GNUNET_assert (rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE);
300 rd.expiration_time = UINT64_MAX; 285 rd.expiration_time = UINT64_MAX;
301 qe = GNUNET_NAMESTORE_records_store (ns, 286 qe =
302 GNUNET_IDENTITY_ego_get_private_key (ego), 287 GNUNET_NAMESTORE_records_store (ns,
303 "phone" /* GNS label */, 288 GNUNET_IDENTITY_ego_get_private_key (ego),
304 1, 289 "phone" /* GNS label */,
305 &rd, 290 1,
306 &namestore_put_cont, 291 &rd,
307 NULL); 292 &namestore_put_cont,
293 NULL);
308 return; 294 return;
309 } 295 }
310 if (0 == strcmp (name, "caller-ego")) 296 if (0 == strcmp (name, "caller-ego"))
@@ -326,8 +312,7 @@ identity_cb (void *cls,
326 312
327 313
328static void 314static void
329phone_ego_create_cont (void *cls, 315phone_ego_create_cont (void *cls, const char *emsg)
330 const char *emsg)
331{ 316{
332 (void) cls; 317 (void) cls;
333 op = NULL; 318 op = NULL;
@@ -343,15 +328,9 @@ run (void *cls,
343 (void) cls; 328 (void) cls;
344 (void) peer; 329 (void) peer;
345 cfg = c; 330 cfg = c;
346 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, 331 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL);
347 NULL); 332 id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL);
348 id = GNUNET_IDENTITY_connect (cfg, 333 op = GNUNET_IDENTITY_create (id, "phone-ego", &phone_ego_create_cont, NULL);
349 &identity_cb,
350 NULL);
351 op = GNUNET_IDENTITY_create (id,
352 "phone-ego",
353 &phone_ego_create_cont,
354 NULL);
355 ns = GNUNET_NAMESTORE_connect (cfg); 334 ns = GNUNET_NAMESTORE_connect (cfg);
356} 335}
357 336
@@ -362,8 +341,9 @@ main (int argc, char *argv[])
362 (void) argc; 341 (void) argc;
363 (void) argv; 342 (void) argv;
364 if (0 != GNUNET_TESTING_peer_run ("test_conversation_api", 343 if (0 != GNUNET_TESTING_peer_run ("test_conversation_api",
365 "test_conversation.conf", 344 "test_conversation.conf",
366 &run, NULL)) 345 &run,
346 NULL))
367 return 1; 347 return 1;
368 return ok; 348 return ok;
369} 349}
diff --git a/src/conversation/test_conversation_api_twocalls.c b/src/conversation/test_conversation_api_twocalls.c
index 0b19f4783..c0768f590 100644
--- a/src/conversation/test_conversation_api_twocalls.c
+++ b/src/conversation/test_conversation_api_twocalls.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -39,11 +39,9 @@
39 39
40#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 25) 40#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 25)
41 41
42#define LOG(kind,...) \ 42#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
43 GNUNET_log (kind, __VA_ARGS__)
44 43
45#define LOG_DEBUG(...) \ 44#define LOG_DEBUG(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
46 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
47 45
48static const struct GNUNET_CONFIGURATION_Handle *cfg; 46static const struct GNUNET_CONFIGURATION_Handle *cfg;
49 47
@@ -97,7 +95,7 @@ static const char *phone0 = "phone";
97#define CALLER2 &caller2 95#define CALLER2 &caller2
98#define PHONE0 &phone0 96#define PHONE0 &phone0
99 97
100#define CLS_STR(caller) (*((char **)caller)) 98#define CLS_STR(caller) (*((char **) caller))
101 99
102 100
103/** 101/**
@@ -116,8 +114,7 @@ struct MicContext
116 114
117 void *rdc_cls; 115 void *rdc_cls;
118 116
119 struct GNUNET_SCHEDULER_Task * call_task; 117 struct GNUNET_SCHEDULER_Task *call_task;
120
121}; 118};
122 119
123static struct MicContext call1_mic_ctx; 120static struct MicContext call1_mic_ctx;
@@ -133,12 +130,8 @@ phone_send (void *cls)
133 (void) cls; 130 (void) cls;
134 GNUNET_assert (NULL != phone_rdc); 131 GNUNET_assert (NULL != phone_rdc);
135 GNUNET_snprintf (buf, sizeof (buf), "phone"); 132 GNUNET_snprintf (buf, sizeof (buf), "phone");
136 phone_rdc (phone_rdc_cls, 133 phone_rdc (phone_rdc_cls, strlen (buf) + 1, buf);
137 strlen (buf) + 1, 134 phone_task = GNUNET_SCHEDULER_add_delayed (FREQ, &phone_send, NULL);
138 buf);
139 phone_task = GNUNET_SCHEDULER_add_delayed (FREQ,
140 &phone_send,
141 NULL);
142} 135}
143 136
144 137
@@ -150,15 +143,9 @@ call_send (void *cls)
150 143
151 (void) cls; 144 (void) cls;
152 GNUNET_assert (NULL != mc->rdc); 145 GNUNET_assert (NULL != mc->rdc);
153 GNUNET_snprintf (buf, 146 GNUNET_snprintf (buf, sizeof (buf), "call");
154 sizeof (buf), 147 mc->rdc (mc->rdc_cls, strlen (buf) + 1, buf);
155 "call"); 148 mc->call_task = GNUNET_SCHEDULER_add_delayed (FREQ, &call_send, mc);
156 mc->rdc (mc->rdc_cls,
157 strlen (buf) + 1,
158 buf);
159 mc->call_task = GNUNET_SCHEDULER_add_delayed (FREQ,
160 &call_send,
161 mc);
162} 149}
163 150
164 151
@@ -168,8 +155,7 @@ enable_speaker (void *cls)
168 const char *origin = CLS_STR (cls); 155 const char *origin = CLS_STR (cls);
169 156
170 (void) cls; 157 (void) cls;
171 LOG_DEBUG ("Speaker %s enabled\n", 158 LOG_DEBUG ("Speaker %s enabled\n", origin);
172 origin);
173 return GNUNET_OK; 159 return GNUNET_OK;
174} 160}
175 161
@@ -180,15 +166,12 @@ disable_speaker (void *cls)
180 const char *origin = CLS_STR (cls); 166 const char *origin = CLS_STR (cls);
181 167
182 (void) cls; 168 (void) cls;
183 LOG_DEBUG ("Speaker %s disabled\n", 169 LOG_DEBUG ("Speaker %s disabled\n", origin);
184 origin);
185} 170}
186 171
187 172
188static void 173static void
189play (void *cls, 174play (void *cls, size_t data_size, const void *data)
190 size_t data_size,
191 const void *data)
192{ 175{
193 static unsigned int phone_i; 176 static unsigned int phone_i;
194 static unsigned int call_i; 177 static unsigned int call_i;
@@ -206,9 +189,7 @@ play (void *cls,
206 (const char *) data); 189 (const char *) data);
207 } 190 }
208 191
209 if ( (20 < call_i) && 192 if ((20 < call_i) && (20 < phone_i) && (CALLER2 == cls))
210 (20 < phone_i) &&
211 (CALLER2 == cls) )
212 { 193 {
213 /* time to hang up ... */ 194 /* time to hang up ... */
214 GNUNET_CONVERSATION_call_stop (call2); 195 GNUNET_CONVERSATION_call_stop (call2);
@@ -218,9 +199,7 @@ play (void *cls,
218 phone_i = 0; 199 phone_i = 0;
219 call2_finished = GNUNET_YES; 200 call2_finished = GNUNET_YES;
220 } 201 }
221 if ( (20 < call_i) && 202 if ((20 < call_i) && (20 < phone_i) && (CALLER1 == cls))
222 (20 < phone_i) &&
223 (CALLER1 == cls) )
224 { 203 {
225 /* time to hang up ... */ 204 /* time to hang up ... */
226 GNUNET_CONVERSATION_call_stop (call1); 205 GNUNET_CONVERSATION_call_stop (call1);
@@ -241,31 +220,25 @@ destroy_speaker (void *cls)
241} 220}
242 221
243 222
244static struct GNUNET_SPEAKER_Handle call1_speaker = { 223static struct GNUNET_SPEAKER_Handle call1_speaker = {&enable_speaker,
245 &enable_speaker, 224 &play,
246 &play, 225 &disable_speaker,
247 &disable_speaker, 226 &destroy_speaker,
248 &destroy_speaker, 227 CALLER1};
249 CALLER1
250};
251 228
252 229
253static struct GNUNET_SPEAKER_Handle call2_speaker = { 230static struct GNUNET_SPEAKER_Handle call2_speaker = {&enable_speaker,
254 &enable_speaker, 231 &play,
255 &play, 232 &disable_speaker,
256 &disable_speaker, 233 &destroy_speaker,
257 &destroy_speaker, 234 CALLER2};
258 CALLER2
259};
260 235
261 236
262static struct GNUNET_SPEAKER_Handle phone_speaker = { 237static struct GNUNET_SPEAKER_Handle phone_speaker = {&enable_speaker,
263 &enable_speaker, 238 &play,
264 &play, 239 &disable_speaker,
265 &disable_speaker, 240 &destroy_speaker,
266 &destroy_speaker, 241 PHONE0};
267 PHONE0
268};
269 242
270 243
271static int 244static int
@@ -276,8 +249,7 @@ enable_mic (void *cls,
276 const char *origin = CLS_STR (cls); 249 const char *origin = CLS_STR (cls);
277 struct MicContext *mc; 250 struct MicContext *mc;
278 251
279 LOG_DEBUG ("Mic %s enabled\n", 252 LOG_DEBUG ("Mic %s enabled\n", origin);
280 origin);
281 if (PHONE0 == cls) 253 if (PHONE0 == cls)
282 { 254 {
283 phone_rdc = rdc; 255 phone_rdc = rdc;
@@ -301,8 +273,7 @@ disable_mic (void *cls)
301 const char *origin = CLS_STR (cls); 273 const char *origin = CLS_STR (cls);
302 struct MicContext *mc; 274 struct MicContext *mc;
303 275
304 LOG_DEBUG ("Mic %s disabled\n", 276 LOG_DEBUG ("Mic %s disabled\n", origin);
305 origin);
306 if (PHONE0 == cls) 277 if (PHONE0 == cls)
307 { 278 {
308 phone_rdc = NULL; 279 phone_rdc = NULL;
@@ -324,33 +295,26 @@ destroy_mic (void *cls)
324{ 295{
325 const char *origin = CLS_STR (cls); 296 const char *origin = CLS_STR (cls);
326 297
327 LOG_DEBUG ("Mic %s destroyed\n", 298 LOG_DEBUG ("Mic %s destroyed\n", origin);
328 origin);
329} 299}
330 300
331 301
332static struct GNUNET_MICROPHONE_Handle call1_mic = { 302static struct GNUNET_MICROPHONE_Handle call1_mic = {&enable_mic,
333 &enable_mic, 303 &disable_mic,
334 &disable_mic, 304 &destroy_mic,
335 &destroy_mic, 305 CALLER1};
336 CALLER1
337};
338 306
339 307
340static struct GNUNET_MICROPHONE_Handle call2_mic = { 308static struct GNUNET_MICROPHONE_Handle call2_mic = {&enable_mic,
341 &enable_mic, 309 &disable_mic,
342 &disable_mic, 310 &destroy_mic,
343 &destroy_mic, 311 CALLER2};
344 CALLER2
345};
346 312
347 313
348static struct GNUNET_MICROPHONE_Handle phone_mic = { 314static struct GNUNET_MICROPHONE_Handle phone_mic = {&enable_mic,
349 &enable_mic, 315 &disable_mic,
350 &disable_mic, 316 &destroy_mic,
351 &destroy_mic, 317 PHONE0};
352 PHONE0
353};
354 318
355 319
356/** 320/**
@@ -363,8 +327,7 @@ end_test (void *cls)
363{ 327{
364 (void) cls; 328 (void) cls;
365 timeout_task = NULL; 329 timeout_task = NULL;
366 fprintf (stderr, 330 fprintf (stderr, "Timeout!\n");
367 "Timeout!\n");
368 GNUNET_SCHEDULER_shutdown (); 331 GNUNET_SCHEDULER_shutdown ();
369} 332}
370 333
@@ -423,17 +386,14 @@ do_shutdown (void *cls)
423 386
424 387
425static void 388static void
426caller_event_handler (void *cls, 389caller_event_handler (void *cls, enum GNUNET_CONVERSATION_CallerEventCode code)
427 enum GNUNET_CONVERSATION_CallerEventCode code)
428{ 390{
429 (void) cls; 391 (void) cls;
430 switch (code) 392 switch (code)
431 { 393 {
432 case GNUNET_CONVERSATION_EC_CALLER_SUSPEND: 394 case GNUNET_CONVERSATION_EC_CALLER_SUSPEND:
433 case GNUNET_CONVERSATION_EC_CALLER_RESUME: 395 case GNUNET_CONVERSATION_EC_CALLER_RESUME:
434 LOG (GNUNET_ERROR_TYPE_WARNING, 396 LOG (GNUNET_ERROR_TYPE_WARNING, "Unexpected caller code: %d\n", code);
435 "Unexpected caller code: %d\n",
436 code);
437 break; 397 break;
438 } 398 }
439} 399}
@@ -490,17 +450,14 @@ phone_event_handler (void *cls,
490 } 450 }
491 break; 451 break;
492 default: 452 default:
493 LOG (GNUNET_ERROR_TYPE_WARNING, 453 LOG (GNUNET_ERROR_TYPE_WARNING, "Unexpected phone code: %d\n", code);
494 "Unexpected phone code: %d\n",
495 code);
496 break; 454 break;
497 } 455 }
498} 456}
499 457
500 458
501static void 459static void
502call_event_handler (void *cls, 460call_event_handler (void *cls, enum GNUNET_CONVERSATION_CallEventCode code)
503 enum GNUNET_CONVERSATION_CallEventCode code)
504{ 461{
505 const char *cid = cls; 462 const char *cid = cls;
506 463
@@ -541,6 +498,7 @@ call_event_handler (void *cls,
541 498
542static void 499static void
543caller_ego_create_cont (void *cls, 500caller_ego_create_cont (void *cls,
501 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk,
544 const char *emsg) 502 const char *emsg)
545{ 503{
546 (void) cls; 504 (void) cls;
@@ -550,19 +508,14 @@ caller_ego_create_cont (void *cls,
550 508
551 509
552static void 510static void
553namestore_put_cont (void *cls, 511namestore_put_cont (void *cls, int32_t success, const char *emsg)
554 int32_t success,
555 const char *emsg)
556{ 512{
557 (void) cls; 513 (void) cls;
558 qe = NULL; 514 qe = NULL;
559 GNUNET_assert (GNUNET_YES == success); 515 GNUNET_assert (GNUNET_YES == success);
560 GNUNET_assert (NULL == emsg); 516 GNUNET_assert (NULL == emsg);
561 GNUNET_assert (NULL == op); 517 GNUNET_assert (NULL == op);
562 op = GNUNET_IDENTITY_create (id, 518 op = GNUNET_IDENTITY_create (id, "caller-ego", &caller_ego_create_cont, NULL);
563 "caller-ego",
564 &caller_ego_create_cont,
565 NULL);
566} 519}
567 520
568 521
@@ -587,23 +540,21 @@ identity_cb (void *cls,
587 GNUNET_asprintf (&gns_name, 540 GNUNET_asprintf (&gns_name,
588 "phone.%s", 541 "phone.%s",
589 GNUNET_GNSRECORD_pkey_to_zkey (&pub)); 542 GNUNET_GNSRECORD_pkey_to_zkey (&pub));
590 phone = GNUNET_CONVERSATION_phone_create (cfg, 543 phone =
591 ego, 544 GNUNET_CONVERSATION_phone_create (cfg, ego, &phone_event_handler, NULL);
592 &phone_event_handler,
593 NULL);
594 GNUNET_assert (NULL != phone); 545 GNUNET_assert (NULL != phone);
595 memset (&rd, 0, sizeof (rd)); 546 memset (&rd, 0, sizeof (rd));
596 GNUNET_CONVERSATION_phone_get_record (phone, 547 GNUNET_CONVERSATION_phone_get_record (phone, &rd);
597 &rd);
598 GNUNET_assert (rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE); 548 GNUNET_assert (rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE);
599 rd.expiration_time = UINT64_MAX; 549 rd.expiration_time = UINT64_MAX;
600 qe = GNUNET_NAMESTORE_records_store (ns, 550 qe =
601 GNUNET_IDENTITY_ego_get_private_key (ego), 551 GNUNET_NAMESTORE_records_store (ns,
602 "phone" /* GNS label */, 552 GNUNET_IDENTITY_ego_get_private_key (ego),
603 1, 553 "phone" /* GNS label */,
604 &rd, 554 1,
605 &namestore_put_cont, 555 &rd,
606 NULL); 556 &namestore_put_cont,
557 NULL);
607 return; 558 return;
608 } 559 }
609 if (0 == strcmp (name, "caller-ego")) 560 if (0 == strcmp (name, "caller-ego"))
@@ -632,8 +583,7 @@ identity_cb (void *cls,
632 583
633 584
634static void 585static void
635phone_ego_create_cont (void *cls, 586phone_ego_create_cont (void *cls, const char *emsg)
636 const char *emsg)
637{ 587{
638 (void) cls; 588 (void) cls;
639 op = NULL; 589 op = NULL;
@@ -649,32 +599,23 @@ run (void *cls,
649 (void) cls; 599 (void) cls;
650 (void) peer; 600 (void) peer;
651 cfg = c; 601 cfg = c;
652 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 602 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL);
653 &end_test, 603 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
654 NULL); 604 id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL);
655 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 605 op = GNUNET_IDENTITY_create (id, "phone-ego", &phone_ego_create_cont, NULL);
656 NULL);
657 id = GNUNET_IDENTITY_connect (cfg,
658 &identity_cb,
659 NULL);
660 op = GNUNET_IDENTITY_create (id,
661 "phone-ego",
662 &phone_ego_create_cont,
663 NULL);
664 ns = GNUNET_NAMESTORE_connect (cfg); 606 ns = GNUNET_NAMESTORE_connect (cfg);
665} 607}
666 608
667 609
668int 610int
669main (int argc, 611main (int argc, char *argv[])
670 char *argv[])
671{ 612{
672 (void) argc; 613 (void) argc;
673 (void) argv; 614 (void) argv;
674 if (0 != GNUNET_TESTING_peer_run ("test_conversation_api_twocalls", 615 if (0 != GNUNET_TESTING_peer_run ("test_conversation_api_twocalls",
675 "test_conversation.conf", 616 "test_conversation.conf",
676 &run, 617 &run,
677 NULL)) 618 NULL))
678 return 1; 619 return 1;
679 if (call1_finished && call2_finished) 620 if (call1_finished && call2_finished)
680 return 0; 621 return 0;