diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-04 18:28:06 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-04 18:28:06 +0000 |
commit | 1c2c08b45a80d047927b8925c52f1cf50e08a055 (patch) | |
tree | ce04c5e97130591b3725aea356b37e278422f61a /src/conversation | |
parent | 695da6ce5cdfeca5ae2c08ed82565de65f2f69bb (diff) | |
download | gnunet-1c2c08b45a80d047927b8925c52f1cf50e08a055.tar.gz gnunet-1c2c08b45a80d047927b8925c52f1cf50e08a055.zip |
-handle audio in mesh
Diffstat (limited to 'src/conversation')
-rw-r--r-- | src/conversation/gnunet-service-conversation-new.c | 122 |
1 files changed, 101 insertions, 21 deletions
diff --git a/src/conversation/gnunet-service-conversation-new.c b/src/conversation/gnunet-service-conversation-new.c index f60a26523..e669f6f82 100644 --- a/src/conversation/gnunet-service-conversation-new.c +++ b/src/conversation/gnunet-service-conversation-new.c | |||
@@ -639,15 +639,6 @@ handle_mesh_hangup_message (void *cls, | |||
639 | "HANGUP message received for non-existing line, dropping tunnel.\n"); | 639 | "HANGUP message received for non-existing line, dropping tunnel.\n"); |
640 | return GNUNET_SYSERR; | 640 | return GNUNET_SYSERR; |
641 | } | 641 | } |
642 | hup = (struct ClientPhoneHangupMessage *) buf; | ||
643 | hup->header.size = sizeof (buf); | ||
644 | hup->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); | ||
645 | memcpy (&hup[1], reason, len); | ||
646 | GNUNET_SERVER_notification_context_unicast (nc, | ||
647 | line->client, | ||
648 | &hup->header, | ||
649 | GNUNET_NO); | ||
650 | GNUNET_MESH_receive_done (tunnel); | ||
651 | *tunnel_ctx = NULL; | 642 | *tunnel_ctx = NULL; |
652 | switch (line->status) | 643 | switch (line->status) |
653 | { | 644 | { |
@@ -665,7 +656,7 @@ handle_mesh_hangup_message (void *cls, | |||
665 | case LS_CALLEE_SHUTDOWN: | 656 | case LS_CALLEE_SHUTDOWN: |
666 | line->status = LS_CALLEE_LISTEN; | 657 | line->status = LS_CALLEE_LISTEN; |
667 | destroy_line_mesh_tunnels (line); | 658 | destroy_line_mesh_tunnels (line); |
668 | break; | 659 | return GNUNET_OK; |
669 | case LS_CALLER_CALLING: | 660 | case LS_CALLER_CALLING: |
670 | line->status = LS_CALLER_SHUTDOWN; | 661 | line->status = LS_CALLER_SHUTDOWN; |
671 | mq_done_finish_caller_shutdown (line); | 662 | mq_done_finish_caller_shutdown (line); |
@@ -676,8 +667,17 @@ handle_mesh_hangup_message (void *cls, | |||
676 | break; | 667 | break; |
677 | case LS_CALLER_SHUTDOWN: | 668 | case LS_CALLER_SHUTDOWN: |
678 | mq_done_finish_caller_shutdown (line); | 669 | mq_done_finish_caller_shutdown (line); |
679 | break; | 670 | return GNUNET_OK; |
680 | } | 671 | } |
672 | hup = (struct ClientPhoneHangupMessage *) buf; | ||
673 | hup->header.size = sizeof (buf); | ||
674 | hup->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); | ||
675 | memcpy (&hup[1], reason, len); | ||
676 | GNUNET_SERVER_notification_context_unicast (nc, | ||
677 | line->client, | ||
678 | &hup->header, | ||
679 | GNUNET_NO); | ||
680 | GNUNET_MESH_receive_done (tunnel); | ||
681 | return GNUNET_OK; | 681 | return GNUNET_OK; |
682 | } | 682 | } |
683 | 683 | ||
@@ -699,20 +699,68 @@ handle_mesh_pickup_message (void *cls, | |||
699 | { | 699 | { |
700 | const struct MeshPhonePickupMessage *msg; | 700 | const struct MeshPhonePickupMessage *msg; |
701 | struct Line *line = *tunnel_ctx; | 701 | struct Line *line = *tunnel_ctx; |
702 | const char *metadata; | ||
703 | size_t len = ntohs (message->size) - sizeof (struct MeshPhonePickupMessage); | ||
704 | char buf[len + sizeof (struct ClientPhonePickupMessage)]; | ||
705 | struct ClientPhonePickupMessage *pick; | ||
702 | 706 | ||
703 | msg = (const struct MeshPhonePickupMessage *) message; | 707 | msg = (const struct MeshPhonePickupMessage *) message; |
704 | GNUNET_break (0); // FIXME | 708 | len = ntohs (msg->header.size) - sizeof (struct MeshPhonePickupMessage); |
705 | 709 | metadata = (const char *) &msg[1]; | |
706 | 710 | if ( (0 == len) || | |
711 | ('\0' != metadata[len - 1]) ) | ||
712 | { | ||
713 | metadata = NULL; | ||
714 | len = 0; | ||
715 | } | ||
716 | if (NULL == line) | ||
717 | { | ||
718 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
719 | "PICKUP message received for non-existing line, dropping tunnel.\n"); | ||
720 | return GNUNET_SYSERR; | ||
721 | } | ||
722 | GNUNET_MESH_receive_done (tunnel); | ||
723 | switch (line->status) | ||
724 | { | ||
725 | case LS_CALLEE_LISTEN: | ||
726 | GNUNET_break (0); | ||
727 | return GNUNET_SYSERR; | ||
728 | case LS_CALLEE_RINGING: | ||
729 | case LS_CALLEE_CONNECTED: | ||
730 | GNUNET_break_op (0); | ||
731 | destroy_line_mesh_tunnels (line); | ||
732 | line->status = LS_CALLEE_LISTEN; | ||
733 | return GNUNET_SYSERR; | ||
734 | case LS_CALLEE_SHUTDOWN: | ||
735 | GNUNET_break_op (0); | ||
736 | line->status = LS_CALLEE_LISTEN; | ||
737 | destroy_line_mesh_tunnels (line); | ||
738 | break; | ||
739 | case LS_CALLER_CALLING: | ||
740 | line->status = LS_CALLER_CONNECTED; | ||
741 | break; | ||
742 | case LS_CALLER_CONNECTED: | ||
743 | GNUNET_break_op (0); | ||
744 | return GNUNET_OK; | ||
745 | case LS_CALLER_SHUTDOWN: | ||
746 | GNUNET_break_op (0); | ||
747 | mq_done_finish_caller_shutdown (line); | ||
748 | return GNUNET_SYSERR; | ||
749 | } | ||
750 | pick = (struct ClientPhonePickupMessage *) buf; | ||
751 | pick->header.size = sizeof (buf); | ||
752 | pick->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP); | ||
753 | memcpy (&pick[1], metadata, len); | ||
754 | GNUNET_SERVER_notification_context_unicast (nc, | ||
755 | line->client, | ||
756 | &pick->header, | ||
757 | GNUNET_NO); | ||
707 | line->tunnel_unreliable = GNUNET_MESH_tunnel_create (mesh, | 758 | line->tunnel_unreliable = GNUNET_MESH_tunnel_create (mesh, |
708 | line, | 759 | line, |
709 | &line->target, | 760 | &line->target, |
710 | GNUNET_APPLICATION_TYPE_CONVERSATION_AUDIO, | 761 | GNUNET_APPLICATION_TYPE_CONVERSATION_AUDIO, |
711 | GNUNET_YES, | 762 | GNUNET_YES, |
712 | GNUNET_NO); | 763 | GNUNET_NO); |
713 | |||
714 | |||
715 | GNUNET_MESH_receive_done (tunnel); | ||
716 | return GNUNET_OK; | 764 | return GNUNET_OK; |
717 | } | 765 | } |
718 | 766 | ||
@@ -733,10 +781,8 @@ handle_mesh_busy_message (void *cls, | |||
733 | const struct GNUNET_MessageHeader *message) | 781 | const struct GNUNET_MessageHeader *message) |
734 | { | 782 | { |
735 | struct Line *line = *tunnel_ctx; | 783 | struct Line *line = *tunnel_ctx; |
736 | const struct MeshPhoneBusyMessage *msg; | ||
737 | struct ClientPhoneBusyMessage busy; | 784 | struct ClientPhoneBusyMessage busy; |
738 | 785 | ||
739 | msg = (const struct MeshPhoneBusyMessage *) message; | ||
740 | if (NULL == line) | 786 | if (NULL == line) |
741 | { | 787 | { |
742 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 788 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -797,9 +843,43 @@ handle_mesh_audio_message (void *cls, | |||
797 | const struct GNUNET_MessageHeader *message) | 843 | const struct GNUNET_MessageHeader *message) |
798 | { | 844 | { |
799 | const struct MeshAudioMessage *msg; | 845 | const struct MeshAudioMessage *msg; |
846 | struct Line *line = *tunnel_ctx; | ||
847 | struct GNUNET_PeerIdentity sender; | ||
848 | size_t msize = ntohs (message->size) - sizeof (struct MeshAudioMessage); | ||
849 | char buf[msize + sizeof (struct ClientAudioMessage)]; | ||
850 | struct ClientAudioMessage *cam; | ||
800 | 851 | ||
801 | msg = (const struct MeshAudioMessage *) message; | 852 | msg = (const struct MeshAudioMessage *) message; |
802 | GNUNET_break (0); // FIXME | 853 | if (NULL == line) |
854 | { | ||
855 | sender = *GNUNET_MESH_tunnel_get_info (tunnel, | ||
856 | GNUNET_MESH_OPTION_PEER)->peer; | ||
857 | for (line = lines_head; NULL != line; line = line->next) | ||
858 | if ( (line->local_line == ntohl (msg->remote_line)) && | ||
859 | (LS_CALLEE_CONNECTED == line->status) && | ||
860 | (0 == memcmp (&line->target, | ||
861 | &sender, | ||
862 | sizeof (struct GNUNET_PeerIdentity))) && | ||
863 | (NULL == line->tunnel_unreliable) ) | ||
864 | break; | ||
865 | if (NULL == line) | ||
866 | { | ||
867 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
868 | "Received AUDIO data for non-existing line %u, dropping.\n", | ||
869 | ntohl (msg->remote_line)); | ||
870 | return GNUNET_SYSERR; | ||
871 | } | ||
872 | line->tunnel_unreliable = tunnel; | ||
873 | *tunnel_ctx = line; | ||
874 | } | ||
875 | cam = (struct ClientAudioMessage *) buf; | ||
876 | cam->header.size = htons (sizeof (buf)); | ||
877 | cam->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO); | ||
878 | memcpy (&cam[1], &msg[1], msize); | ||
879 | GNUNET_SERVER_notification_context_unicast (nc, | ||
880 | line->client, | ||
881 | &cam->header, | ||
882 | GNUNET_YES); | ||
803 | GNUNET_MESH_receive_done (tunnel); | 883 | GNUNET_MESH_receive_done (tunnel); |
804 | return GNUNET_OK; | 884 | return GNUNET_OK; |
805 | } | 885 | } |