aboutsummaryrefslogtreecommitdiff
path: root/src/conversation/test_conversation_api.c
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/test_conversation_api.c
parent3d9f1acfb62cd53fc7d1441eb33e1341c9ff3790 (diff)
downloadgnunet-34c8bfb80b82a1a7f7d3db3c41e705b09a1fad7e.tar.gz
gnunet-34c8bfb80b82a1a7f7d3db3c41e705b09a1fad7e.zip
fix build issues
Diffstat (limited to 'src/conversation/test_conversation_api.c')
-rw-r--r--src/conversation/test_conversation_api.c174
1 files changed, 61 insertions, 113 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}