diff options
Diffstat (limited to 'src/conversation/conversation_api2.c')
-rw-r--r-- | src/conversation/conversation_api2.c | 176 |
1 files changed, 169 insertions, 7 deletions
diff --git a/src/conversation/conversation_api2.c b/src/conversation/conversation_api2.c index 236bd5734..39ea6e8f1 100644 --- a/src/conversation/conversation_api2.c +++ b/src/conversation/conversation_api2.c | |||
@@ -312,7 +312,7 @@ handle_phone_hangup (void *cls, | |||
312 | * @param msg the message | 312 | * @param msg the message |
313 | */ | 313 | */ |
314 | static void | 314 | static void |
315 | handle_audio_message (void *cls, | 315 | handle_phone_audio_message (void *cls, |
316 | const struct GNUNET_MessageHeader *msg) | 316 | const struct GNUNET_MessageHeader *msg) |
317 | { | 317 | { |
318 | struct GNUNET_CONVERSATION_Phone *phone = cls; | 318 | struct GNUNET_CONVERSATION_Phone *phone = cls; |
@@ -374,7 +374,7 @@ reconnect_phone (struct GNUNET_CONVERSATION_Phone *phone) | |||
374 | { &handle_phone_hangup, | 374 | { &handle_phone_hangup, |
375 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, | 375 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, |
376 | 0 }, | 376 | 0 }, |
377 | { &handle_audio_message, | 377 | { &handle_phone_audio_message, |
378 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, | 378 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, |
379 | 0 }, | 379 | 0 }, |
380 | { NULL, 0, 0 } | 380 | { NULL, 0, 0 } |
@@ -608,6 +608,32 @@ GNUNET_CONVERSATION_phone_destroy (struct GNUNET_CONVERSATION_Phone *phone) | |||
608 | 608 | ||
609 | /* ******************************* Call API *************************** */ | 609 | /* ******************************* Call API *************************** */ |
610 | 610 | ||
611 | /** | ||
612 | * Possible states of the phone. | ||
613 | */ | ||
614 | enum CallState | ||
615 | { | ||
616 | /** | ||
617 | * We still need to lookup the callee. | ||
618 | */ | ||
619 | CS_LOOKUP = 0, | ||
620 | |||
621 | /** | ||
622 | * The call is ringing. | ||
623 | */ | ||
624 | CS_RINGING, | ||
625 | |||
626 | /** | ||
627 | * The call is in an active conversation. | ||
628 | */ | ||
629 | CS_ACTIVE, | ||
630 | |||
631 | /** | ||
632 | * The call is in termination. | ||
633 | */ | ||
634 | CS_SHUTDOWN | ||
635 | }; | ||
636 | |||
611 | 637 | ||
612 | /** | 638 | /** |
613 | * Handle for an outgoing call. | 639 | * Handle for an outgoing call. |
@@ -623,7 +649,7 @@ struct GNUNET_CONVERSATION_Call | |||
623 | /** | 649 | /** |
624 | * Handle to talk with CONVERSATION service. | 650 | * Handle to talk with CONVERSATION service. |
625 | */ | 651 | */ |
626 | struct GNUNET_CLIENT_Handle *client; | 652 | struct GNUNET_CLIENT_Connection *client; |
627 | 653 | ||
628 | /** | 654 | /** |
629 | * Our caller identity. | 655 | * Our caller identity. |
@@ -638,12 +664,12 @@ struct GNUNET_CONVERSATION_Call | |||
638 | /** | 664 | /** |
639 | * Our speaker. | 665 | * Our speaker. |
640 | */ | 666 | */ |
641 | struct GNUNET_CONVERSATION_Speaker *speaker; | 667 | struct GNUNET_SPEAKER_Handle *speaker; |
642 | 668 | ||
643 | /** | 669 | /** |
644 | * Our microphone. | 670 | * Our microphone. |
645 | */ | 671 | */ |
646 | struct GNUNET_CONVERSATION_Microphone *mic; | 672 | struct GNUNET_MICROPHONE_Handle *mic; |
647 | 673 | ||
648 | /** | 674 | /** |
649 | * Function to call with events. | 675 | * Function to call with events. |
@@ -656,6 +682,11 @@ struct GNUNET_CONVERSATION_Call | |||
656 | void *event_handler_cls; | 682 | void *event_handler_cls; |
657 | 683 | ||
658 | /** | 684 | /** |
685 | * Handle for transmitting to the CONVERSATION service. | ||
686 | */ | ||
687 | struct GNUNET_MQ_Handle *mq; | ||
688 | |||
689 | /** | ||
659 | * Connection to GNS (can be NULL). | 690 | * Connection to GNS (can be NULL). |
660 | */ | 691 | */ |
661 | struct GNUNET_GNS_Handle *gns; | 692 | struct GNUNET_GNS_Handle *gns; |
@@ -670,10 +701,111 @@ struct GNUNET_CONVERSATION_Call | |||
670 | */ | 701 | */ |
671 | struct PhoneRecord phone_record; | 702 | struct PhoneRecord phone_record; |
672 | 703 | ||
704 | /** | ||
705 | * State machine for the call. | ||
706 | */ | ||
707 | enum CallState state; | ||
708 | |||
673 | }; | 709 | }; |
674 | 710 | ||
675 | 711 | ||
676 | /** | 712 | /** |
713 | * The call got disconnected, reconnect to the service. | ||
714 | * | ||
715 | * @param call call to reconnect | ||
716 | */ | ||
717 | static void | ||
718 | reconnect_call (struct GNUNET_CONVERSATION_Call *call); | ||
719 | |||
720 | |||
721 | /** | ||
722 | * We received a `struct ClientAudioMessage` | ||
723 | * | ||
724 | * @param cls the `struct GNUNET_CONVERSATION_Call` | ||
725 | * @param msg the message | ||
726 | */ | ||
727 | static void | ||
728 | handle_call_audio_message (void *cls, | ||
729 | const struct GNUNET_MessageHeader *msg) | ||
730 | { | ||
731 | struct GNUNET_CONVERSATION_Call *call = cls; | ||
732 | const struct ClientAudioMessage *am; | ||
733 | |||
734 | am = (const struct ClientAudioMessage *) msg; | ||
735 | switch (call->state) | ||
736 | { | ||
737 | case CS_LOOKUP: | ||
738 | GNUNET_break (0); | ||
739 | reconnect_call (call); | ||
740 | break; | ||
741 | case CS_RINGING: | ||
742 | GNUNET_break (0); | ||
743 | reconnect_call (call); | ||
744 | break; | ||
745 | case CS_ACTIVE: | ||
746 | call->speaker->play (call->speaker->cls, | ||
747 | ntohs (msg->size) - sizeof (struct ClientAudioMessage), | ||
748 | &am[1]); | ||
749 | break; | ||
750 | case CS_SHUTDOWN: | ||
751 | GNUNET_CONVERSATION_call_stop (call, NULL); | ||
752 | break; | ||
753 | |||
754 | } | ||
755 | } | ||
756 | |||
757 | |||
758 | /** | ||
759 | * Iterator called on obtained result for a GNS lookup. | ||
760 | * | ||
761 | * @param cls closure with the `struct GNUNET_CONVERSATION_Call` | ||
762 | * @param rd_count number of records in @a rd | ||
763 | * @param rd the records in reply | ||
764 | */ | ||
765 | static void | ||
766 | handle_gns_response (void *cls, | ||
767 | uint32_t rd_count, | ||
768 | const struct GNUNET_NAMESTORE_RecordData *rd) | ||
769 | { | ||
770 | struct GNUNET_CONVERSATION_Call *call = cls; | ||
771 | uint32_t i; | ||
772 | |||
773 | for (i=0;i<rd_count;i++) | ||
774 | { | ||
775 | if (GNUNET_NAMESTORE_TYPE_PHONE == rd[i].record_type) | ||
776 | { | ||
777 | if (rd[i].data_size != sizeof (struct PhoneRecord)) | ||
778 | { | ||
779 | GNUNET_break_op (0); | ||
780 | continue; | ||
781 | } | ||
782 | memcpy (&call->phone_record, | ||
783 | rd[i].data, | ||
784 | rd[i].data_size); | ||
785 | GNUNET_break (0); | ||
786 | // FIXME: send call request! | ||
787 | return; | ||
788 | } | ||
789 | } | ||
790 | /* not found */ | ||
791 | call->event_handler (call->event_handler_cls, | ||
792 | GNUNET_CONVERSATION_EC_GNS_FAIL); | ||
793 | GNUNET_CONVERSATION_call_stop (call, NULL); | ||
794 | } | ||
795 | |||
796 | |||
797 | /** | ||
798 | * The call got disconnected, reconnect to the service. | ||
799 | * | ||
800 | * @param call call to reconnect | ||
801 | */ | ||
802 | static void | ||
803 | reconnect_call (struct GNUNET_CONVERSATION_Call *call) | ||
804 | { | ||
805 | } | ||
806 | |||
807 | |||
808 | /** | ||
677 | * Call the phone of another user. | 809 | * Call the phone of another user. |
678 | * | 810 | * |
679 | * @param cfg configuration to use, specifies our phone service | 811 | * @param cfg configuration to use, specifies our phone service |
@@ -696,7 +828,35 @@ GNUNET_CONVERSATION_call_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
696 | GNUNET_CONVERSATION_EventHandler event_handler, | 828 | GNUNET_CONVERSATION_EventHandler event_handler, |
697 | void *event_handler_cls) | 829 | void *event_handler_cls) |
698 | { | 830 | { |
699 | GNUNET_assert (0); | 831 | struct GNUNET_CONVERSATION_Call *call; |
832 | struct GNUNET_CRYPTO_EccPublicSignKey my_zone; | ||
833 | |||
834 | GNUNET_IDENTITY_ego_get_public_key (caller_id, | ||
835 | &my_zone); | ||
836 | call = GNUNET_new (struct GNUNET_CONVERSATION_Call); | ||
837 | call->cfg = cfg; | ||
838 | call->caller_id = caller_id; | ||
839 | call->callee = GNUNET_strdup (callee); | ||
840 | call->speaker = speaker; | ||
841 | call->mic = mic; | ||
842 | call->event_handler = event_handler; | ||
843 | call->event_handler_cls = event_handler_cls; | ||
844 | call->client = GNUNET_CLIENT_connect ("conversation", cfg); | ||
845 | call->gns = GNUNET_GNS_connect (cfg); | ||
846 | if ( (NULL == call->client) || | ||
847 | (NULL == call->gns) ) | ||
848 | { | ||
849 | GNUNET_CONVERSATION_call_stop (call, NULL); | ||
850 | return NULL; | ||
851 | } | ||
852 | call->gns_lookup = GNUNET_GNS_lookup (call->gns, callee, | ||
853 | &my_zone, | ||
854 | GNUNET_NAMESTORE_TYPE_PHONE, | ||
855 | GNUNET_NO, | ||
856 | NULL /* FIXME: add shortening support */, | ||
857 | &handle_gns_response, call); | ||
858 | GNUNET_assert (NULL != call->gns_lookup); | ||
859 | return call; | ||
700 | } | 860 | } |
701 | 861 | ||
702 | 862 | ||
@@ -708,10 +868,12 @@ GNUNET_CONVERSATION_call_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
708 | * reason given to the other user for why we hung up | 868 | * reason given to the other user for why we hung up |
709 | */ | 869 | */ |
710 | void | 870 | void |
711 | GNUNET_CONVERSATION_call_stop (const struct GNUNET_CONVERSATION_Call *call, | 871 | GNUNET_CONVERSATION_call_stop (struct GNUNET_CONVERSATION_Call *call, |
712 | const char *reason) | 872 | const char *reason) |
713 | { | 873 | { |
714 | GNUNET_assert (0); | 874 | GNUNET_assert (0); |
875 | // FIXME | ||
876 | GNUNET_free (call); | ||
715 | } | 877 | } |
716 | 878 | ||
717 | 879 | ||