aboutsummaryrefslogtreecommitdiff
path: root/src/conversation/conversation_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-08-11 18:04:19 +0000
committerChristian Grothoff <christian@grothoff.org>2016-08-11 18:04:19 +0000
commit9c37ec935877bc6196febec8f6b2f0ad036189b9 (patch)
tree93b0ab56d432abb92fb10d4b5d0e01f6c1411333 /src/conversation/conversation_api.c
parent7a5835e38561a55ea15d7caa9910bb6cdf0da79f (diff)
downloadgnunet-9c37ec935877bc6196febec8f6b2f0ad036189b9.tar.gz
gnunet-9c37ec935877bc6196febec8f6b2f0ad036189b9.zip
-converting API to use new CADET ports
Diffstat (limited to 'src/conversation/conversation_api.c')
-rw-r--r--src/conversation/conversation_api.c97
1 files changed, 61 insertions, 36 deletions
diff --git a/src/conversation/conversation_api.c b/src/conversation/conversation_api.c
index 3c0a68f4f..5dd9cf79e 100644
--- a/src/conversation/conversation_api.c
+++ b/src/conversation/conversation_api.c
@@ -238,8 +238,11 @@ transmit_phone_audio (void *cls,
238 data_size, 238 data_size,
239 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO); 239 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO);
240 am->cid = caller->cid; 240 am->cid = caller->cid;
241 GNUNET_memcpy (&am[1], data, data_size); 241 GNUNET_memcpy (&am[1],
242 GNUNET_MQ_send (phone->mq, e); 242 data,
243 data_size);
244 GNUNET_MQ_send (phone->mq,
245 e);
243} 246}
244 247
245 248
@@ -280,6 +283,26 @@ handle_phone_ring (void *cls,
280 283
281 284
282/** 285/**
286 * Find the record of the caller matching the @a cid
287 *
288 * @param phone phone to search
289 * @param cid caller ID to search for (in NBO)
290 * @return NULL if @a cid was not found
291 */
292static struct GNUNET_CONVERSATION_Caller *
293find_caller (struct GNUNET_CONVERSATION_Phone *phone,
294 uint32_t cid)
295{
296 struct GNUNET_CONVERSATION_Caller *caller;
297
298 for (caller = phone->caller_head;NULL != caller;caller = caller->next)
299 if (cid == caller->cid)
300 return caller;
301 return NULL;
302}
303
304
305/**
283 * We received a `struct ClientPhoneHangupMessage`. 306 * We received a `struct ClientPhoneHangupMessage`.
284 * 307 *
285 * @param cls the `struct GNUNET_CONVERSATION_Phone *` 308 * @param cls the `struct GNUNET_CONVERSATION_Phone *`
@@ -292,9 +315,8 @@ handle_phone_hangup (void *cls,
292 struct GNUNET_CONVERSATION_Phone *phone = cls; 315 struct GNUNET_CONVERSATION_Phone *phone = cls;
293 struct GNUNET_CONVERSATION_Caller *caller; 316 struct GNUNET_CONVERSATION_Caller *caller;
294 317
295 for (caller = phone->caller_head; NULL != caller; caller = caller->next) 318 caller = find_caller (phone,
296 if (hang->cid == caller->cid) 319 hang->cid);
297 break;
298 if (NULL == caller) 320 if (NULL == caller)
299 { 321 {
300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 322 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -351,9 +373,8 @@ handle_phone_suspend (void *cls,
351 struct GNUNET_CONVERSATION_Phone *phone = cls; 373 struct GNUNET_CONVERSATION_Phone *phone = cls;
352 struct GNUNET_CONVERSATION_Caller *caller; 374 struct GNUNET_CONVERSATION_Caller *caller;
353 375
354 for (caller = phone->caller_head; NULL != caller; caller = caller->next) 376 caller = find_caller (phone,
355 if (suspend->cid == caller->cid) 377 suspend->cid);
356 break;
357 if (NULL == caller) 378 if (NULL == caller)
358 return; 379 return;
359 switch (caller->state) 380 switch (caller->state)
@@ -394,9 +415,8 @@ handle_phone_resume (void *cls,
394 struct GNUNET_CONVERSATION_Phone *phone = cls; 415 struct GNUNET_CONVERSATION_Phone *phone = cls;
395 struct GNUNET_CONVERSATION_Caller *caller; 416 struct GNUNET_CONVERSATION_Caller *caller;
396 417
397 for (caller = phone->caller_head; NULL != caller; caller = caller->next) 418 caller = find_caller (phone,
398 if (resume->cid == caller->cid) 419 resume->cid);
399 break;
400 if (NULL == caller) 420 if (NULL == caller)
401 return; 421 return;
402 switch (caller->state) 422 switch (caller->state)
@@ -455,9 +475,8 @@ handle_phone_audio (void *cls,
455 struct GNUNET_CONVERSATION_Phone *phone = cls; 475 struct GNUNET_CONVERSATION_Phone *phone = cls;
456 struct GNUNET_CONVERSATION_Caller *caller; 476 struct GNUNET_CONVERSATION_Caller *caller;
457 477
458 for (caller = phone->caller_head; NULL != caller; caller = caller->next) 478 caller = find_caller (phone,
459 if (am->cid == caller->cid) 479 am->cid);
460 break;
461 if (NULL == caller) 480 if (NULL == caller)
462 return; 481 return;
463 switch (caller->state) 482 switch (caller->state)
@@ -572,9 +591,11 @@ reconnect_phone (struct GNUNET_CONVERSATION_Phone *phone)
572 phone); 591 phone);
573 if (NULL == phone->mq) 592 if (NULL == phone->mq)
574 return; 593 return;
575 e = GNUNET_MQ_msg (reg, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER); 594 e = GNUNET_MQ_msg (reg,
576 reg->line = phone->my_record.line; 595 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER);
577 GNUNET_MQ_send (phone->mq, e); 596 reg->line_port = phone->my_record.line_port;
597 GNUNET_MQ_send (phone->mq,
598 e);
578 phone->state = PS_READY; 599 phone->state = PS_READY;
579} 600}
580 601
@@ -596,10 +617,11 @@ GNUNET_CONVERSATION_phone_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
596 void *event_handler_cls) 617 void *event_handler_cls)
597{ 618{
598 struct GNUNET_CONVERSATION_Phone *phone; 619 struct GNUNET_CONVERSATION_Phone *phone;
599 unsigned long long line; 620 char *line;
621 struct GNUNET_HashCode line_port;
600 622
601 if (GNUNET_OK != 623 if (GNUNET_OK !=
602 GNUNET_CONFIGURATION_get_value_number (cfg, 624 GNUNET_CONFIGURATION_get_value_string (cfg,
603 "CONVERSATION", 625 "CONVERSATION",
604 "LINE", 626 "LINE",
605 &line)) 627 &line))
@@ -609,14 +631,9 @@ GNUNET_CONVERSATION_phone_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
609 "LINE"); 631 "LINE");
610 return NULL; 632 return NULL;
611 } 633 }
612 if (line >= HIGH_BIT) 634 GNUNET_CRYPTO_hash (line,
613 { 635 strlen (line),
614 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, 636 &line_port);
615 "CONVERSATION",
616 "LINE",
617 _("number too large"));
618 return NULL;
619 }
620 phone = GNUNET_new (struct GNUNET_CONVERSATION_Phone); 637 phone = GNUNET_new (struct GNUNET_CONVERSATION_Phone);
621 if (GNUNET_OK != 638 if (GNUNET_OK !=
622 GNUNET_CRYPTO_get_peer_identity (cfg, 639 GNUNET_CRYPTO_get_peer_identity (cfg,
@@ -631,8 +648,9 @@ GNUNET_CONVERSATION_phone_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
631 phone->event_handler = event_handler; 648 phone->event_handler = event_handler;
632 phone->event_handler_cls = event_handler_cls; 649 phone->event_handler_cls = event_handler_cls;
633 phone->ns = GNUNET_NAMESTORE_connect (cfg); 650 phone->ns = GNUNET_NAMESTORE_connect (cfg);
634 phone->my_record.line = htonl ((uint32_t) line); 651 phone->my_record.version = htonl (1);
635 phone->my_record.version = htonl (0); 652 phone->my_record.reserved = htonl (0);
653 phone->my_record.line_port = line_port;
636 reconnect_phone (phone); 654 reconnect_phone (phone);
637 if ( (NULL == phone->mq) || 655 if ( (NULL == phone->mq) ||
638 (NULL == phone->ns) ) 656 (NULL == phone->ns) )
@@ -689,9 +707,11 @@ GNUNET_CONVERSATION_caller_pick_up (struct GNUNET_CONVERSATION_Caller *caller,
689 GNUNET_assert (CS_RINGING == caller->state); 707 GNUNET_assert (CS_RINGING == caller->state);
690 caller->speaker = speaker; 708 caller->speaker = speaker;
691 caller->mic = mic; 709 caller->mic = mic;
692 e = GNUNET_MQ_msg (pick, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP); 710 e = GNUNET_MQ_msg (pick,
711 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP);
693 pick->cid = caller->cid; 712 pick->cid = caller->cid;
694 GNUNET_MQ_send (phone->mq, e); 713 GNUNET_MQ_send (phone->mq,
714 e);
695 caller->state = CS_ACTIVE; 715 caller->state = CS_ACTIVE;
696 caller->event_handler = event_handler; 716 caller->event_handler = event_handler;
697 caller->event_handler_cls = event_handler_cls; 717 caller->event_handler_cls = event_handler_cls;
@@ -730,7 +750,8 @@ GNUNET_CONVERSATION_caller_hang_up (struct GNUNET_CONVERSATION_Caller *caller)
730 e = GNUNET_MQ_msg (hang, 750 e = GNUNET_MQ_msg (hang,
731 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); 751 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP);
732 hang->cid = caller->cid; 752 hang->cid = caller->cid;
733 GNUNET_MQ_send (phone->mq, e); 753 GNUNET_MQ_send (phone->mq,
754 e);
734 GNUNET_free (caller); 755 GNUNET_free (caller);
735} 756}
736 757
@@ -781,9 +802,11 @@ GNUNET_CONVERSATION_caller_suspend (struct GNUNET_CONVERSATION_Caller *caller)
781 } 802 }
782 caller->speaker = NULL; 803 caller->speaker = NULL;
783 caller->mic = NULL; 804 caller->mic = NULL;
784 e = GNUNET_MQ_msg (suspend, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND); 805 e = GNUNET_MQ_msg (suspend,
806 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND);
785 suspend->cid = caller->cid; 807 suspend->cid = caller->cid;
786 GNUNET_MQ_send (phone->mq, e); 808 GNUNET_MQ_send (phone->mq,
809 e);
787 if (CS_ACTIVE == caller->state) 810 if (CS_ACTIVE == caller->state)
788 caller->state = CS_CALLEE_SUSPENDED; 811 caller->state = CS_CALLEE_SUSPENDED;
789 else 812 else
@@ -811,9 +834,11 @@ GNUNET_CONVERSATION_caller_resume (struct GNUNET_CONVERSATION_Caller *caller,
811 (CS_BOTH_SUSPENDED == caller->state) ); 834 (CS_BOTH_SUSPENDED == caller->state) );
812 caller->speaker = speaker; 835 caller->speaker = speaker;
813 caller->mic = mic; 836 caller->mic = mic;
814 e = GNUNET_MQ_msg (resume, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME); 837 e = GNUNET_MQ_msg (resume,
838 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME);
815 resume->cid = caller->cid; 839 resume->cid = caller->cid;
816 GNUNET_MQ_send (phone->mq, e); 840 GNUNET_MQ_send (phone->mq,
841 e);
817 if (CS_CALLEE_SUSPENDED == caller->state) 842 if (CS_CALLEE_SUSPENDED == caller->state)
818 { 843 {
819 caller->state = CS_ACTIVE; 844 caller->state = CS_ACTIVE;