diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-06-03 00:44:25 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-06-03 00:44:25 +0200 |
commit | 34c8bfb80b82a1a7f7d3db3c41e705b09a1fad7e (patch) | |
tree | 601520ce682cf786bc4f34b6e4d95a9061bd48af /src/conversation/test_conversation_api_twocalls.c | |
parent | 3d9f1acfb62cd53fc7d1441eb33e1341c9ff3790 (diff) | |
download | gnunet-34c8bfb80b82a1a7f7d3db3c41e705b09a1fad7e.tar.gz gnunet-34c8bfb80b82a1a7f7d3db3c41e705b09a1fad7e.zip |
fix build issues
Diffstat (limited to 'src/conversation/test_conversation_api_twocalls.c')
-rw-r--r-- | src/conversation/test_conversation_api_twocalls.c | 205 |
1 files changed, 73 insertions, 132 deletions
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 | ||
48 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 46 | static 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 | ||
123 | static struct MicContext call1_mic_ctx; | 120 | static 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 | ||
188 | static void | 173 | static void |
189 | play (void *cls, | 174 | play (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 | ||
244 | static struct GNUNET_SPEAKER_Handle call1_speaker = { | 223 | static 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 | ||
253 | static struct GNUNET_SPEAKER_Handle call2_speaker = { | 230 | static 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 | ||
262 | static struct GNUNET_SPEAKER_Handle phone_speaker = { | 237 | static 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 | ||
271 | static int | 244 | static 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 | ||
332 | static struct GNUNET_MICROPHONE_Handle call1_mic = { | 302 | static 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 | ||
340 | static struct GNUNET_MICROPHONE_Handle call2_mic = { | 308 | static 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 | ||
348 | static struct GNUNET_MICROPHONE_Handle phone_mic = { | 314 | static 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 | ||
425 | static void | 388 | static void |
426 | caller_event_handler (void *cls, | 389 | caller_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 | ||
501 | static void | 459 | static void |
502 | call_event_handler (void *cls, | 460 | call_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 | ||
542 | static void | 499 | static void |
543 | caller_ego_create_cont (void *cls, | 500 | caller_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 | ||
552 | static void | 510 | static void |
553 | namestore_put_cont (void *cls, | 511 | namestore_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 | ||
634 | static void | 585 | static void |
635 | phone_ego_create_cont (void *cls, | 586 | phone_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 | ||
668 | int | 610 | int |
669 | main (int argc, | 611 | main (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; |